Skip to content

Commit

Permalink
Merge e56223b into efd2eae
Browse files Browse the repository at this point in the history
  • Loading branch information
victor-salles committed Aug 3, 2022
2 parents efd2eae + e56223b commit a152bc9
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 28 deletions.
20 changes: 1 addition & 19 deletions bothub/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,17 @@ class Meta:
LEVEL_READER = 1
LEVEL_CONTRIBUTOR = 2
LEVEL_ADMIN = 3
LEVEL_TRANSLATE = 4

ROLE_NOT_SETTED = 0
ROLE_USER = 1
ROLE_CONTRIBUTOR = 2
ROLE_ADMIN = 3
ROLE_TRANSLATE = 4

ROLE_CHOICES = [
(ROLE_NOT_SETTED, _("not set")),
(ROLE_USER, _("user")),
(ROLE_CONTRIBUTOR, _("contributor")),
(ROLE_ADMIN, _("admin")),
(ROLE_TRANSLATE, _("translate")),
]

uuid = models.UUIDField(
Expand Down Expand Up @@ -191,9 +188,6 @@ def level(self):
if self.role == OrganizationAuthorization.ROLE_ADMIN:
return OrganizationAuthorization.LEVEL_ADMIN

if self.role == OrganizationAuthorization.ROLE_TRANSLATE:
return OrganizationAuthorization.LEVEL_TRANSLATE

return OrganizationAuthorization.LEVEL_NOTHING # pragma: no cover

@property
Expand All @@ -202,7 +196,6 @@ def can_read(self):
OrganizationAuthorization.LEVEL_READER,
OrganizationAuthorization.LEVEL_CONTRIBUTOR,
OrganizationAuthorization.LEVEL_ADMIN,
OrganizationAuthorization.LEVEL_TRANSLATE,
]

@property
Expand All @@ -221,7 +214,6 @@ def can_translate(self):
return self.level in [
OrganizationAuthorization.LEVEL_CONTRIBUTOR,
OrganizationAuthorization.LEVEL_ADMIN,
OrganizationAuthorization.LEVEL_TRANSLATE,
]

@property
Expand Down Expand Up @@ -912,9 +904,7 @@ def get_user_authorization(self, user):
if self.owner.is_organization:
org_auth = self.owner.organization.get_organization_authorization(user)

# Excluding ROLE_TRANSLATE as it does not correspond to the same role in the client app (connect).
# todo: update this conditional with corresponding role rule
if repo_auth.role < org_auth.role and org_auth.role < RepositoryAuthorization.ROLE_TRANSLATE:
if repo_auth.role < org_auth.role:
repo_auth.role = org_auth.role
repo_auth.save(update_fields=['role'])
return repo_auth
Expand Down Expand Up @@ -1984,20 +1974,17 @@ class Meta:
LEVEL_READER = 1
LEVEL_CONTRIBUTOR = 2
LEVEL_ADMIN = 3
LEVEL_TRANSLATE = 4

ROLE_NOT_SETTED = 0
ROLE_USER = 1
ROLE_CONTRIBUTOR = 2
ROLE_ADMIN = 3
ROLE_TRANSLATE = 4

ROLE_CHOICES = [
(ROLE_NOT_SETTED, _("not set")),
(ROLE_USER, _("user")),
(ROLE_CONTRIBUTOR, _("contributor")),
(ROLE_ADMIN, _("admin")),
(ROLE_TRANSLATE, _("translate")),
]

uuid = models.UUIDField(
Expand Down Expand Up @@ -2060,9 +2047,6 @@ def level(self):
if role == RepositoryAuthorization.ROLE_ADMIN:
return RepositoryAuthorization.LEVEL_ADMIN

if role == RepositoryAuthorization.ROLE_TRANSLATE:
return RepositoryAuthorization.LEVEL_TRANSLATE

return RepositoryAuthorization.LEVEL_NOTHING # pragma: no cover

@property
Expand All @@ -2071,7 +2055,6 @@ def can_read(self):
RepositoryAuthorization.LEVEL_READER,
RepositoryAuthorization.LEVEL_CONTRIBUTOR,
RepositoryAuthorization.LEVEL_ADMIN,
RepositoryAuthorization.LEVEL_TRANSLATE,
]

@property
Expand All @@ -2090,7 +2073,6 @@ def can_translate(self):
return self.level in [
RepositoryAuthorization.LEVEL_CONTRIBUTOR,
RepositoryAuthorization.LEVEL_ADMIN,
RepositoryAuthorization.LEVEL_TRANSLATE,
]

@property
Expand Down
9 changes: 0 additions & 9 deletions bothub/common/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,15 +726,6 @@ def test_organization_auth_over_repository_auth(self):
user_authorization = self.organization_repository.get_user_authorization(self.collaborator)
self.assertEqual(user_authorization.role, collaborator_repository_auth.role)

# Verify that org auth with (role >= 4) will not update the repository's authorization

# Set user's role to ROLE_TRANSLATE level at the Organization
collaborator_organization_auth.role = OrganizationAuthorization.ROLE_TRANSLATE
collaborator_organization_auth.save()

user_authorization = self.organization_repository.get_user_authorization(self.collaborator)
self.assertEqual(user_authorization.role, collaborator_repository_auth.role)


class RepositoryVersionTrainingTestCase(TestCase):
def setUp(self):
Expand Down

0 comments on commit a152bc9

Please sign in to comment.