mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 10:00:01 -03:30
Add code that allows getting just the root groups for an inventory.
This commit is contained in:
parent
e528ede913
commit
5b65b3bfac
@ -216,6 +216,8 @@ class InventoryTest(BaseTest):
|
||||
##################################################
|
||||
# GROUPS->inventories POST via subcollection
|
||||
|
||||
root_groups = '/api/v1/inventories/1/root_groups/'
|
||||
|
||||
url = '/api/v1/inventories/1/groups/'
|
||||
new_group_a = dict(name='web100')
|
||||
new_group_b = dict(name='web101')
|
||||
@ -239,7 +241,11 @@ class InventoryTest(BaseTest):
|
||||
self.post(url5, data=new_group_d, expect=400, auth=self.get_other_credentials())
|
||||
got = self.get(url5, expect=200, auth=self.get_other_credentials())
|
||||
self.assertEquals(got['count'], 4)
|
||||
|
||||
|
||||
# side check: see if root groups URL is operational. These are groups without parents.
|
||||
root_groups = self.get(root_groups, expect=200, auth=self.get_super_credentials())
|
||||
self.assertEquals(root_groups['count'], 2)
|
||||
|
||||
remove_me = added_by_collection
|
||||
remove_me['disassociate'] = 1
|
||||
self.post(url5, data=remove_me, expect=204, auth=self.get_other_credentials())
|
||||
|
||||
@ -74,6 +74,7 @@ inventory_urls = patterns('lib.main.views',
|
||||
url(r'^(?P<pk>[0-9]+)/$', 'inventory_detail'),
|
||||
url(r'^(?P<pk>[0-9]+)/hosts/$', 'inventory_hosts_list'),
|
||||
url(r'^(?P<pk>[0-9]+)/groups/$', 'inventory_groups_list'),
|
||||
url(r'^(?P<pk>[0-9]+)/root_groups/$', 'inventory_root_groups_list'),
|
||||
)
|
||||
|
||||
hosts_urls = patterns('lib.main.views',
|
||||
|
||||
@ -876,6 +876,25 @@ class InventoryGroupsList(BaseSubList):
|
||||
# FIXME: verify that you can can_read permission on the inventory is required
|
||||
return base
|
||||
|
||||
class InventoryRootGroupsList(BaseSubList):
|
||||
|
||||
model = Group
|
||||
serializer_class = GroupSerializer
|
||||
permission_classes = (CustomRbac,)
|
||||
parent_model = Inventory
|
||||
relationship = 'groups'
|
||||
postable = True
|
||||
inject_primary_key_on_post_as = 'inventory'
|
||||
severable = False
|
||||
filter_fields = ('name',)
|
||||
|
||||
def _get_queryset(self):
|
||||
inventory = Inventory.objects.get(pk=self.kwargs['pk'])
|
||||
base = inventory.groups
|
||||
all_ids = base.values_list('id', flat=True)
|
||||
base.exclude(parents__id__in = all_ids)
|
||||
return base
|
||||
|
||||
class GroupsVariableDetail(VariableBaseDetail):
|
||||
|
||||
model = VariableData
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user