mirror of
https://github.com/ansible/awx.git
synced 2026-01-16 12:20:45 -03:30
Merge pull request #4483 from ryanpetrello/multi-owner
fix bug where cred org permission was not checked Reviewed-by: https://github.com/softwarefactory-project-zuul[bot]
This commit is contained in:
commit
c35fbd6853
@ -1168,15 +1168,20 @@ class CredentialAccess(BaseAccess):
|
||||
return True
|
||||
if data and data.get('user', None):
|
||||
user_obj = get_object_from_data('user', User, data)
|
||||
return bool(self.user == user_obj or UserAccess(self.user).can_admin(user_obj, None, check_setting=False))
|
||||
if not bool(self.user == user_obj or UserAccess(self.user).can_admin(user_obj, None, check_setting=False)):
|
||||
return False
|
||||
if data and data.get('team', None):
|
||||
team_obj = get_object_from_data('team', Team, data)
|
||||
return check_user_access(self.user, Team, 'change', team_obj, None)
|
||||
if not check_user_access(self.user, Team, 'change', team_obj, None):
|
||||
return False
|
||||
if data and data.get('organization', None):
|
||||
organization_obj = get_object_from_data('organization', Organization, data)
|
||||
return any([check_user_access(self.user, Organization, 'change', organization_obj, None),
|
||||
self.user in organization_obj.credential_admin_role])
|
||||
return False
|
||||
if not any([check_user_access(self.user, Organization, 'change', organization_obj, None),
|
||||
self.user in organization_obj.credential_admin_role]):
|
||||
return False
|
||||
if not any(data.get(key, None) for key in ('user', 'team', 'organization')):
|
||||
return False # you have to provide 1 owner field
|
||||
return True
|
||||
|
||||
@check_superuser
|
||||
def can_use(self, obj):
|
||||
|
||||
@ -74,6 +74,19 @@ def test_org_credential_access_admin(role_name, alice, org_credential):
|
||||
'organization': org_credential.organization.pk})
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_org_and_user_credential_access(alice, organization):
|
||||
"""Address specific bug where any user could make an org credential
|
||||
in another org without any permissions to that org
|
||||
"""
|
||||
# Owner is both user and org, but org permission should still be checked
|
||||
assert not CredentialAccess(alice).can_add({
|
||||
'name': 'New credential.',
|
||||
'user': alice.pk,
|
||||
'organization': organization.pk
|
||||
})
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_org_credential_access_member(alice, org_credential):
|
||||
org_credential.admin_role.members.add(alice)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user