Merge pull request #846 from mouse-reeve/track-invite-use

Associate users with their invites
This commit is contained in:
Mouse Reeve 2021-04-01 17:33:20 -07:00 committed by GitHub
commit 14353f0de7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 0 deletions

View file

@ -0,0 +1,21 @@
# Generated by Django 3.1.6 on 2021-04-02 00:14
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("bookwyrm", "0059_user_preferred_timezone"),
]
operations = [
migrations.AddField(
model_name="siteinvite",
name="invitees",
field=models.ManyToManyField(
related_name="invitees", to=settings.AUTH_USER_MODEL
),
),
]

View file

@ -58,6 +58,7 @@ class SiteInvite(models.Model):
use_limit = models.IntegerField(blank=True, null=True)
times_used = models.IntegerField(default=0)
user = models.ForeignKey(User, on_delete=models.CASCADE)
invitees = models.ManyToManyField(User, related_name="invitees")
def valid(self):
""" make sure it hasn't expired or been used """

View file

@ -108,6 +108,7 @@ class Register(View):
)
if invite:
invite.times_used += 1
invite.invitees.add(user)
invite.save()
login(request, user)