diff --git a/hc/accounts/migrations/0040_auto_20210722_1244.py b/hc/accounts/migrations/0040_auto_20210722_1244.py new file mode 100644 index 00000000..491d3bd0 --- /dev/null +++ b/hc/accounts/migrations/0040_auto_20210722_1244.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.4 on 2021-07-22 12:44 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0039_remove_profile_reports_allowed'), + ] + + operations = [ + migrations.AddField( + model_name='member', + name='role', + field=models.CharField(choices=[('r', 'Read-only'), ('w', 'Member')], default='w', max_length=1), + ), + migrations.AlterField( + model_name='member', + name='rw', + field=models.BooleanField(default=True, null=True), + ), + ] diff --git a/hc/accounts/models.py b/hc/accounts/models.py index 67afa351..266a9a44 100644 --- a/hc/accounts/models.py +++ b/hc/accounts/models.py @@ -358,7 +358,8 @@ class Project(models.Model): if self.owner_id == user.id: return False - Member.objects.create(user=user, project=self, rw=rw) + role = Member.Role.REGULAR if rw else Member.Role.READONLY + Member.objects.create(user=user, project=self, rw=rw, role=role) checks_url = reverse("hc-checks", args=[self.code]) user.profile.send_instant_login_link(self, redirect_url=checks_url) return True @@ -419,10 +420,17 @@ class Project(models.Model): class Member(models.Model): + class Role(models.TextChoices): + READONLY = "r", "Read-only" + REGULAR = "w", "Member" + user = models.ForeignKey(User, models.CASCADE, related_name="memberships") project = models.ForeignKey(Project, models.CASCADE) transfer_request_date = models.DateTimeField(null=True, blank=True) - rw = models.BooleanField(default=True) + rw = models.BooleanField(default=True, null=True) + role = models.CharField( + max_length=1, default=Role.REGULAR, choices=Role.choices, blank=True, null=True + ) class Meta: constraints = [ diff --git a/hc/accounts/tests/test_project.py b/hc/accounts/tests/test_project.py index 4b799899..89f739e8 100644 --- a/hc/accounts/tests/test_project.py +++ b/hc/accounts/tests/test_project.py @@ -79,6 +79,7 @@ class ProjectTestCase(BaseTestCase): # The read-write flag should be set self.assertTrue(member.rw) + self.assertEqual(member.role, member.Role.REGULAR) # The new user should not have their own project self.assertFalse(member.user.project_set.exists()) @@ -98,8 +99,8 @@ class ProjectTestCase(BaseTestCase): project=self.project, user__email="frank@example.org" ) - # The new user should not have their own project self.assertFalse(member.rw) + self.assertEqual(member.role, member.Role.READONLY) def test_it_adds_member_from_another_team(self): # With team limit at zero, we should not be able to invite any new users