Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
victor-salles committed Jul 13, 2022
1 parent 78036be commit a06454d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
9 changes: 4 additions & 5 deletions bothub/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,13 +911,12 @@ 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:
repo_auth.role = org_auth.role
repo_auth.save(update_fields=['role'])
if repo_auth.role < org_auth.role and org_auth.role < RepositoryAuthorization.ROLE_TRANSLATE:
repo_auth.role = org_auth.role
repo_auth.save(update_fields=['role'])
return repo_auth

def get_absolute_url(self):
Expand Down
18 changes: 9 additions & 9 deletions bothub/common/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,8 @@ def setUp(self):
)
self.organization = Organization.objects.create(name="Weni")
self.organization_repository = Repository.objects.create(
owner=self.organization,
name="Organization Repository",
owner=self.organization,
name="Organization Repository",
slug="organization_repository"
)

Expand Down Expand Up @@ -692,8 +692,8 @@ def test_role_contributor_can_contribute(self):
self.assertTrue(authorization_user.can_contribute)

def test_organization_auth_over_repository_auth(self):
"""
Tests that a User's authorization role is of the highest level possible in a Repository,
"""
Tests that a User's authorization role is of the highest level possible in a Repository,
either using the RepositoryAuthorization or the OrganizationAuthorization.
The expected behavior is that the organization's authorization role should be passed to the repository's authorization for that user.
"""
Expand All @@ -709,15 +709,15 @@ def test_organization_auth_over_repository_auth(self):
collaborator_organization_auth = self.organization.organization_authorizations.create(
user=self.collaborator, role=initial_organization_role
)

# Validate that their access level corresponds to their role in the Organization and not the Repository, as it is higher at this point.
user_authorization = self.organization_repository.get_user_authorization(self.collaborator)
self.assertEqual(user_authorization.role, collaborator_organization_auth.role)

# Lower their level inside the Organization
collaborator_organization_auth.role = OrganizationAuthorization.ROLE_NOT_SETTED
collaborator_organization_auth.save()

# Validate that the repository authorization level was updated.
collaborator_repository_auth.refresh_from_db()
self.assertEqual(collaborator_repository_auth.role, initial_organization_role)
Expand All @@ -726,12 +726,12 @@ 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
# 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)

Expand Down

0 comments on commit a06454d

Please sign in to comment.