mirror of
https://github.com/ansible/awx.git
synced 2026-02-17 19:20:05 -03:30
Working on Hosts and Groups
This commit is contained in:
@@ -282,3 +282,37 @@ class InventoryDetail(BaseDetail):
|
||||
serializer_class = InventorySerializer
|
||||
permission_classes = (CustomRbac,)
|
||||
|
||||
class HostsList(BaseList):
|
||||
|
||||
model = Host
|
||||
serializer_class = HostSerializer
|
||||
permission_classes = (CustomRbac,)
|
||||
|
||||
def _get_queryset(self):
|
||||
'''
|
||||
I can see hosts when:
|
||||
I'm a superuser,
|
||||
or an organization admin of an inventory they are in
|
||||
or when I have allowing read permissions via a user or team on an inventory they are in
|
||||
'''
|
||||
base = Host.objects
|
||||
if self.request.user.is_superuser:
|
||||
return base.all()
|
||||
admin_of = base.filter(inventory__organization__admins__in = [ self.request.user ]).distinct()
|
||||
has_user_perms = base.filter(
|
||||
inventory__permissions__user__in = [ self.request.user ],
|
||||
inventory__permissions__permission_type__in = PERMISSION_TYPES_ALLOWING_INVENTORY_READ,
|
||||
).distinct()
|
||||
has_team_perms = base.filter(
|
||||
inventory__permissions__team__in = self.request.user.teams.all(),
|
||||
inventory__permissions__permission_type__in = PERMISSION_TYPES_ALLOWING_INVENTORY_READ,
|
||||
).distinct()
|
||||
return admin_of | has_user_perms | has_team_perms
|
||||
|
||||
class HostsDetail(BaseDetail):
|
||||
|
||||
model = Host
|
||||
serializer_class = HostSerializer
|
||||
permission_classes = (CustomRbac,)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user