diff --git a/awx/main/serializers.py b/awx/main/serializers.py index 82f6e83037..dd9d5f4690 100644 --- a/awx/main/serializers.py +++ b/awx/main/serializers.py @@ -507,6 +507,7 @@ class GroupSerializer(BaseSerializerWithVariables): res.update(dict( variable_data = reverse('main:group_variable_data', args=(obj.pk,)), hosts = reverse('main:group_hosts_list', args=(obj.pk,)), + potential_children = reverse('main:group_potential_children_list', args=(obj.pk,)), children = reverse('main:group_children_list', args=(obj.pk,)), all_hosts = reverse('main:group_all_hosts_list', args=(obj.pk,)), inventory = reverse('main:inventory_detail', args=(obj.inventory.pk,)), diff --git a/awx/main/templates/main/group_potential_children_list.md b/awx/main/templates/main/group_potential_children_list.md new file mode 100644 index 0000000000..1ec20f401f --- /dev/null +++ b/awx/main/templates/main/group_potential_children_list.md @@ -0,0 +1,9 @@ +# List Potential Child Groups for this {{ parent_model_verbose_name|title }}: + +Make a GET request to this resource to retrieve a list of +{{ model_verbose_name_plural }} available to be added as children of the +current {{ parent_model_verbose_name }}. + +{% include "main/_list_common.md" %} + +{% include "main/_new_in_awx.md" %} diff --git a/awx/main/urls.py b/awx/main/urls.py index 2070a6db9a..f58a6830f8 100644 --- a/awx/main/urls.py +++ b/awx/main/urls.py @@ -84,6 +84,7 @@ group_urls = patterns('awx.main.views', url(r'^(?P[0-9]+)/variable_data/$', 'group_variable_data'), url(r'^(?P[0-9]+)/job_events/$', 'group_job_events_list'), url(r'^(?P[0-9]+)/job_host_summaries/$', 'group_job_host_summaries_list'), + url(r'^(?P[0-9]+)/potential_children/$', 'group_potential_children_list'), ) inventory_source_urls = patterns('awx.main.views', diff --git a/awx/main/views.py b/awx/main/views.py index 8248f41032..9a8bb3718a 100644 --- a/awx/main/views.py +++ b/awx/main/views.py @@ -540,6 +540,22 @@ class GroupChildrenList(SubListCreateAPIView): return Response(status=status.HTTP_204_NO_CONTENT) +class GroupPotentialChildrenList(SubListAPIView): + + model = Group + serializer_class = GroupSerializer + parent_model = Group + new_in_14 = True + + def get_queryset(self): + parent = self.get_parent_object() + self.check_parent_access(parent) + qs = self.request.user.get_queryset(self.model) + except_pks = set([parent.pk]) + except_pks.update(parent.all_parents.values_list('pk', flat=True)) + except_pks.update(parent.all_children.values_list('pk', flat=True)) + return qs.exclude(pk__in=except_pks) + class GroupHostsList(SubListCreateAPIView): ''' the list of hosts directly below a group '''