Merge remote-tracking branch 'ansible/devel' into merge-devel

This commit is contained in:
Akita Noek
2016-03-18 15:40:13 -04:00
84 changed files with 2911 additions and 157946 deletions

View File

@@ -54,7 +54,7 @@ from social.backends.utils import load_backends
# AWX
from awx.main.task_engine import TaskSerializer, TASK_FILE, TEMPORARY_TASK_FILE
from awx.main.tasks import mongodb_control, send_notifications
from awx.main.tasks import send_notifications
from awx.main.access import get_user_queryset
from awx.main.ha import is_ha_environment
from awx.api.authentication import TaskAuthentication, TokenGetAuthentication
@@ -275,7 +275,6 @@ class ApiV1ConfigView(APIView):
# Only stop mongod if license removal succeeded
if has_error is None:
mongodb_control.delay('stop')
return Response(status=status.HTTP_204_NO_CONTENT)
else:
return Response({"error": "Failed to remove license (%s)" % has_error}, status=status.HTTP_400_BAD_REQUEST)
@@ -572,6 +571,78 @@ class OrganizationList(ListCreateAPIView):
# Okay, create the organization as usual.
return super(OrganizationList, self).create(request, *args, **kwargs)
def get_serializer_context(self, *args, **kwargs):
full_context = super(OrganizationList, self).get_serializer_context(*args, **kwargs)
if self.request is None:
return full_context
db_results = {}
org_qs = self.request.user.get_queryset(self.model)
org_id_list = org_qs.values('id')
if len(org_id_list) == 0:
if self.request.method == 'POST':
full_context['related_field_counts'] = {}
return full_context
inv_qs = self.request.user.get_queryset(Inventory)
project_qs = self.request.user.get_queryset(Project)
user_qs = self.request.user.get_queryset(User)
# Produce counts of Foreign Key relationships
db_results['inventories'] = inv_qs\
.values('organization').annotate(Count('organization')).order_by('organization')
db_results['teams'] = self.request.user.get_queryset(Team)\
.values('organization').annotate(Count('organization')).order_by('organization')
# TODO: When RBAC branch merges, change this to project relationship
JT_reference = 'inventory__organization'
# Extra filter is applied on the inventory, because this catches
# the case of deleted (and purged) inventory
db_results['job_templates'] = self.request.user.get_queryset(JobTemplate)\
.filter(inventory__in=inv_qs)\
.values(JT_reference).annotate(Count(JT_reference))\
.order_by(JT_reference)
# Produce counts of m2m relationships
db_results['projects'] = Organization.projects.through.objects\
.filter(project__in=project_qs, organization__in=org_qs)\
.values('organization')\
.annotate(Count('organization')).order_by('organization')
# TODO: When RBAC branch merges, change these to role relation
db_results['users'] = Organization.users.through.objects\
.filter(user__in=user_qs, organization__in=org_qs)\
.values('organization')\
.annotate(Count('organization')).order_by('organization')
db_results['admins'] = Organization.admins.through.objects\
.filter(user__in=user_qs, organization__in=org_qs)\
.values('organization')\
.annotate(Count('organization')).order_by('organization')
count_context = {}
for org in org_id_list:
org_id = org['id']
count_context[org_id] = {
'inventories': 0, 'teams': 0, 'users': 0, 'job_templates': 0,
'admins': 0, 'projects': 0}
for res in db_results:
if res == 'job_templates':
org_reference = JT_reference
else:
org_reference = 'organization'
for entry in db_results[res]:
org_id = entry[org_reference]
if org_id in count_context:
count_context[org_id][res] = entry['%s__count' % org_reference]
full_context['related_field_counts'] = count_context
return full_context
class OrganizationDetail(RetrieveUpdateDestroyAPIView):
model = Organization
@@ -1907,8 +1978,11 @@ class JobTemplateSurveySpec(GenericAPIView):
def get(self, request, *args, **kwargs):
obj = self.get_object()
if not obj.survey_enabled:
return Response(status=status.HTTP_404_NOT_FOUND)
# Sanity check: Are surveys available on this license?
# If not, do not allow them to be used.
if not feature_enabled('surveys'):
raise LicenseForbids('Your license does not allow '
'adding surveys.')
return Response(obj.survey_spec)
def post(self, request, *args, **kwargs):
@@ -2226,6 +2300,27 @@ class SystemJobTemplateJobsList(SubListAPIView):
relationship = 'jobs'
parent_key = 'system_job_template'
class SystemJobTemplateNotifiersAnyList(SubListCreateAttachDetachAPIView):
model = Notifier
serializer_class = NotifierSerializer
parent_model = SystemJobTemplate
relationship = 'notifiers_any'
class SystemJobTemplateNotifiersErrorList(SubListCreateAttachDetachAPIView):
model = Notifier
serializer_class = NotifierSerializer
parent_model = SystemJobTemplate
relationship = 'notifiers_error'
class SystemJobTemplateNotifiersSuccessList(SubListCreateAttachDetachAPIView):
model = Notifier
serializer_class = NotifierSerializer
parent_model = SystemJobTemplate
relationship = 'notifiers_success'
class JobList(ListCreateAPIView):
model = Job
@@ -2906,6 +3001,12 @@ class SystemJobCancel(RetrieveAPIView):
else:
return self.http_method_not_allowed(request, *args, **kwargs)
class SystemJobNotificationsList(SubListAPIView):
model = Notification
serializer_class = NotificationSerializer
parent_model = SystemJob
relationship = 'notifications'
class UnifiedJobTemplateList(ListAPIView):