mirror of
https://github.com/ansible/awx.git
synced 2024-10-31 06:51:10 +03:00
Work on update/cancel serializers/views to return correct field names in OPTIONS response.
This commit is contained in:
parent
696475591a
commit
564ba7bf68
@ -131,7 +131,7 @@ class BaseSerializerMetaclass(serializers.SerializerMetaclass):
|
||||
'''
|
||||
|
||||
@classmethod
|
||||
def _update_meta(self, base, meta, other=None):
|
||||
def _update_meta(cls, base, meta, other=None):
|
||||
for attr in dir(other):
|
||||
if attr.startswith('_'):
|
||||
continue
|
||||
@ -679,6 +679,14 @@ class ProjectPlaybooksSerializer(ProjectSerializer):
|
||||
return ret.get('playbooks', [])
|
||||
|
||||
|
||||
class ProjectUpdateViewSerializer(ProjectSerializer):
|
||||
|
||||
can_update = serializers.BooleanField(source='can_update', read_only=True)
|
||||
|
||||
class Meta:
|
||||
fields = ('can_update',)
|
||||
|
||||
|
||||
class ProjectUpdateSerializer(UnifiedJobSerializer, ProjectOptionsSerializer):
|
||||
|
||||
class Meta:
|
||||
@ -699,6 +707,14 @@ class ProjectUpdateListSerializer(ProjectUpdateSerializer, UnifiedJobListSeriali
|
||||
pass
|
||||
|
||||
|
||||
class ProjectUpdateCancelSerializer(ProjectUpdateSerializer):
|
||||
|
||||
can_cancel = serializers.BooleanField(source='can_cancel', read_only=True)
|
||||
|
||||
class Meta:
|
||||
fields = ('can_cancel',)
|
||||
|
||||
|
||||
class BaseSerializerWithVariables(BaseSerializer):
|
||||
|
||||
def validate_variables(self, attrs, source):
|
||||
@ -744,6 +760,13 @@ class InventorySerializer(BaseSerializerWithVariables):
|
||||
return ret
|
||||
|
||||
|
||||
class InventoryScriptSerializer(InventorySerializer):
|
||||
|
||||
class Meta:
|
||||
fields = ('id',)
|
||||
exclude = ('id',)
|
||||
|
||||
|
||||
class HostSerializer(BaseSerializerWithVariables):
|
||||
|
||||
class Meta:
|
||||
@ -1064,6 +1087,14 @@ class InventorySourceSerializer(UnifiedJobTemplateSerializer, InventorySourceOpt
|
||||
return ret
|
||||
|
||||
|
||||
class InventorySourceUpdateSerializer(InventorySourceSerializer):
|
||||
|
||||
can_update = serializers.BooleanField(source='can_update', read_only=True)
|
||||
|
||||
class Meta:
|
||||
fields = ('can_update',)
|
||||
|
||||
|
||||
class InventoryUpdateSerializer(UnifiedJobSerializer, InventorySourceOptionsSerializer):
|
||||
|
||||
class Meta:
|
||||
@ -1084,6 +1115,14 @@ class InventoryUpdateListSerializer(InventoryUpdateSerializer, UnifiedJobListSer
|
||||
pass
|
||||
|
||||
|
||||
class InventoryUpdateCancelSerializer(InventoryUpdateSerializer):
|
||||
|
||||
can_cancel = serializers.BooleanField(source='can_cancel', read_only=True)
|
||||
|
||||
class Meta:
|
||||
fields = ('can_cancel',)
|
||||
|
||||
|
||||
class TeamSerializer(BaseSerializer):
|
||||
|
||||
class Meta:
|
||||
@ -1355,6 +1394,15 @@ class JobSerializer(UnifiedJobSerializer, JobOptionsSerializer):
|
||||
ret['job_template'] = None
|
||||
return ret
|
||||
|
||||
|
||||
class JobCancelSerializer(JobSerializer):
|
||||
|
||||
can_cancel = serializers.BooleanField(source='can_cancel', read_only=True)
|
||||
|
||||
class Meta:
|
||||
fields = ('can_cancel',)
|
||||
|
||||
|
||||
class SystemJobTemplateSerializer(UnifiedJobTemplateSerializer):
|
||||
|
||||
class Meta:
|
||||
|
@ -721,18 +721,12 @@ class ProjectUpdatesList(SubListAPIView):
|
||||
relationship = 'project_updates'
|
||||
new_in_13 = True
|
||||
|
||||
class ProjectUpdateView(GenericAPIView):
|
||||
class ProjectUpdateView(RetrieveAPIView):
|
||||
|
||||
model = Project
|
||||
serializer_class = ProjectUpdateViewSerializer
|
||||
new_in_13 = True
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
obj = self.get_object()
|
||||
data = dict(
|
||||
can_update=obj.can_update,
|
||||
)
|
||||
return Response(data)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
obj = self.get_object()
|
||||
if obj.can_update:
|
||||
@ -753,19 +747,13 @@ class ProjectUpdateDetail(RetrieveDestroyAPIView):
|
||||
serializer_class = ProjectUpdateSerializer
|
||||
new_in_13 = True
|
||||
|
||||
class ProjectUpdateCancel(GenericAPIView):
|
||||
class ProjectUpdateCancel(RetrieveAPIView):
|
||||
|
||||
model = ProjectUpdate
|
||||
serializer_class = ProjectUpdateCancelSerializer
|
||||
is_job_cancel = True
|
||||
new_in_13 = True
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
obj = self.get_object()
|
||||
data = dict(
|
||||
can_cancel=obj.can_cancel,
|
||||
)
|
||||
return Response(data)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
obj = self.get_object()
|
||||
if obj.can_cancel:
|
||||
@ -1198,6 +1186,7 @@ class GroupVariableData(BaseVariableData):
|
||||
class InventoryScriptView(RetrieveAPIView):
|
||||
|
||||
model = Inventory
|
||||
serializer_class = InventoryScriptSerializer
|
||||
authentication_classes = [JobTaskAuthentication] + \
|
||||
api_settings.DEFAULT_AUTHENTICATION_CLASSES
|
||||
permission_classes = (JobTaskPermission,)
|
||||
@ -1285,6 +1274,7 @@ class InventoryScriptView(RetrieveAPIView):
|
||||
class InventoryTreeView(RetrieveAPIView):
|
||||
|
||||
model = Inventory
|
||||
serializer_class = GroupTreeSerializer
|
||||
filter_backends = ()
|
||||
new_in_13 = True
|
||||
|
||||
@ -1400,19 +1390,13 @@ class InventorySourceUpdatesList(SubListAPIView):
|
||||
relationship = 'inventory_updates'
|
||||
new_in_14 = True
|
||||
|
||||
class InventorySourceUpdateView(GenericAPIView):
|
||||
class InventorySourceUpdateView(RetrieveAPIView):
|
||||
|
||||
model = InventorySource
|
||||
serializer_class = InventorySourceUpdateSerializer
|
||||
is_job_start = True
|
||||
new_in_14 = True
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
obj = self.get_object()
|
||||
data = dict(
|
||||
can_update=obj.can_update,
|
||||
)
|
||||
return Response(data)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
obj = self.get_object()
|
||||
if obj.can_update:
|
||||
@ -1431,19 +1415,13 @@ class InventoryUpdateDetail(RetrieveDestroyAPIView):
|
||||
serializer_class = InventoryUpdateSerializer
|
||||
new_in_14 = True
|
||||
|
||||
class InventoryUpdateCancel(GenericAPIView):
|
||||
class InventoryUpdateCancel(RetrieveAPIView):
|
||||
|
||||
model = InventoryUpdate
|
||||
serializer_class = InventoryUpdateCancelSerializer
|
||||
is_job_cancel = True
|
||||
new_in_14 = True
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
obj = self.get_object()
|
||||
data = dict(
|
||||
can_cancel=obj.can_cancel,
|
||||
)
|
||||
return Response(data)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
obj = self.get_object()
|
||||
if obj.can_cancel:
|
||||
@ -1475,6 +1453,7 @@ class JobTemplateDetail(RetrieveUpdateDestroyAPIView):
|
||||
class JobTemplateLaunch(GenericAPIView):
|
||||
|
||||
model = JobTemplate
|
||||
# FIXME: Add serializer class to define fields in OPTIONS request!
|
||||
is_job_start = True
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
@ -1524,6 +1503,7 @@ class JobTemplateSchedulesList(SubListCreateAPIView):
|
||||
class JobTemplateSurveySpec(GenericAPIView):
|
||||
|
||||
model = JobTemplate
|
||||
# FIXME: Add serializer class to define fields in OPTIONS request!
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
obj = self.get_object()
|
||||
@ -1582,6 +1562,7 @@ class JobTemplateActivityStreamList(SubListAPIView):
|
||||
class JobTemplateCallback(GenericAPIView):
|
||||
|
||||
model = JobTemplate
|
||||
# FIXME: Add serializer class to define fields in OPTIONS request!
|
||||
permission_classes = (JobTemplateCallbackPermission,)
|
||||
|
||||
@csrf_exempt
|
||||
@ -1753,6 +1734,7 @@ class SystemJobTemplateDetail(RetrieveAPIView):
|
||||
class SystemJobTemplateLaunch(GenericAPIView):
|
||||
|
||||
model = SystemJobTemplate
|
||||
# FIXME: Add serializer class to define fields in OPTIONS request!
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
return Response({})
|
||||
@ -1825,6 +1807,7 @@ class JobActivityStreamList(SubListAPIView):
|
||||
class JobStart(GenericAPIView):
|
||||
|
||||
model = Job
|
||||
# FIXME: Add serializer class to define fields in OPTIONS request!
|
||||
is_job_start = True
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
@ -1851,18 +1834,12 @@ class JobStart(GenericAPIView):
|
||||
else:
|
||||
return self.http_method_not_allowed(request, *args, **kwargs)
|
||||
|
||||
class JobCancel(GenericAPIView):
|
||||
class JobCancel(RetrieveAPIView):
|
||||
|
||||
model = Job
|
||||
serializer_class = JobCancelSerializer
|
||||
is_job_cancel = True
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
obj = self.get_object()
|
||||
data = dict(
|
||||
can_cancel=obj.can_cancel,
|
||||
)
|
||||
return Response(data)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
obj = self.get_object()
|
||||
if obj.can_cancel:
|
||||
@ -1874,6 +1851,7 @@ class JobCancel(GenericAPIView):
|
||||
class JobRelaunch(GenericAPIView):
|
||||
|
||||
model = Job
|
||||
# FIXME: Add serializer class to define fields in OPTIONS request!
|
||||
|
||||
@csrf_exempt
|
||||
@transaction.non_atomic_requests
|
||||
|
Loading…
Reference in New Issue
Block a user