Browse Source

Add Member.role field

pull/545/head
Pēteris Caune 3 years ago
parent
commit
5230dbb425
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
3 changed files with 35 additions and 3 deletions
  1. +23
    -0
      hc/accounts/migrations/0040_auto_20210722_1244.py
  2. +10
    -2
      hc/accounts/models.py
  3. +2
    -1
      hc/accounts/tests/test_project.py

+ 23
- 0
hc/accounts/migrations/0040_auto_20210722_1244.py View File

@ -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),
),
]

+ 10
- 2
hc/accounts/models.py View File

@ -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 = [


+ 2
- 1
hc/accounts/tests/test_project.py View File

@ -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="[email protected]"
)
# 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


Loading…
Cancel
Save