Allow anyone who can read an inventory to see adhoc commands run on that inventory

This implicitly solves one of the issues with #2804, but is in general a
better behavior in general we believe.
This commit is contained in:
Akita Noek
2016-07-08 12:09:39 -04:00
parent 33547259e2
commit ee3d4dc42d

View File

@@ -1075,10 +1075,7 @@ class AdHocCommandAccess(BaseAccess):
''' '''
I can only see/run ad hoc commands when: I can only see/run ad hoc commands when:
- I am a superuser. - I am a superuser.
- I am an org admin and have permission to read the credential. - I have read access to the inventory
- I am a normal user with a user/team permission that has at least read
permission on the inventory and the run_ad_hoc_commands flag set, and I
can read the credential.
''' '''
model = AdHocCommand model = AdHocCommand
@@ -1089,11 +1086,8 @@ class AdHocCommandAccess(BaseAccess):
if self.user.is_superuser: if self.user.is_superuser:
return qs.all() return qs.all()
credential_ids = set(self.user.get_queryset(Credential).values_list('id', flat=True))
inventory_qs = Inventory.accessible_objects(self.user, 'read_role') inventory_qs = Inventory.accessible_objects(self.user, 'read_role')
return qs.filter(inventory__in=inventory_qs)
return qs.filter(credential_id__in=credential_ids,
inventory__in=inventory_qs)
def can_add(self, data): def can_add(self, data):
if not data or '_method' in data: # So the browseable API will work? if not data or '_method' in data: # So the browseable API will work?
@@ -1101,11 +1095,11 @@ class AdHocCommandAccess(BaseAccess):
self.check_license() self.check_license()
# If a credential is provided, the user should have read access to it. # If a credential is provided, the user should have use access to it.
credential_pk = get_pk_from_dict(data, 'credential') credential_pk = get_pk_from_dict(data, 'credential')
if credential_pk: if credential_pk:
credential = get_object_or_400(Credential, pk=credential_pk) credential = get_object_or_400(Credential, pk=credential_pk)
if self.user not in credential.read_role: if self.user not in credential.use_role:
return False return False
# Check that the user has the run ad hoc command permission on the # Check that the user has the run ad hoc command permission on the