From 634509a7f308cbaebf20ed3a349ac5062f0b0d2c Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 1 Apr 2021 17:19:29 -0700 Subject: [PATCH] Associate users with their invites --- .../migrations/0060_siteinvite_invitees.py | 21 +++++++++++++++++++ bookwyrm/models/site.py | 1 + bookwyrm/views/authentication.py | 1 + 3 files changed, 23 insertions(+) create mode 100644 bookwyrm/migrations/0060_siteinvite_invitees.py diff --git a/bookwyrm/migrations/0060_siteinvite_invitees.py b/bookwyrm/migrations/0060_siteinvite_invitees.py new file mode 100644 index 00000000..acd00977 --- /dev/null +++ b/bookwyrm/migrations/0060_siteinvite_invitees.py @@ -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 + ), + ), + ] diff --git a/bookwyrm/models/site.py b/bookwyrm/models/site.py index c3c1d8a4..1eb31869 100644 --- a/bookwyrm/models/site.py +++ b/bookwyrm/models/site.py @@ -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 """ diff --git a/bookwyrm/views/authentication.py b/bookwyrm/views/authentication.py index eef5c79f..22689a28 100644 --- a/bookwyrm/views/authentication.py +++ b/bookwyrm/views/authentication.py @@ -108,6 +108,7 @@ class Register(View): ) if invite: invite.times_used += 1 + invite.invitees.add(user) invite.save() login(request, user)