mirror of
https://github.com/ansible/awx.git
synced 2026-01-14 03:10:42 -03:30
provide id field in attaching sublists
This commit is contained in:
parent
86210b611c
commit
dfa892aae1
@ -32,6 +32,7 @@ from awx.main.models import * # noqa
|
||||
from awx.main.utils import * # noqa
|
||||
from awx.api.serializers import ResourceAccessListElementSerializer
|
||||
from awx.api.versioning import URLPathVersioning, get_request_version
|
||||
from awx.api.metadata import SublistAttachDetatchMetadata
|
||||
|
||||
__all__ = ['APIView', 'GenericAPIView', 'ListAPIView', 'SimpleListAPIView',
|
||||
'ListCreateAPIView', 'SubListAPIView', 'SubListCreateAPIView',
|
||||
@ -611,6 +612,8 @@ class SubListAttachDetachAPIView(SubListCreateAttachDetachAPIView):
|
||||
'''
|
||||
Derived version of SubListCreateAttachDetachAPIView that prohibits creation
|
||||
'''
|
||||
metadata_class = SublistAttachDetatchMetadata
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
sub_id = request.data.get('id', None)
|
||||
if not sub_id:
|
||||
|
||||
@ -173,6 +173,8 @@ class Metadata(metadata.SimpleMetadata):
|
||||
meta.pop('defined_in_file', False)
|
||||
|
||||
if meta.pop('read_only', False):
|
||||
if field == 'id' and hasattr(view, 'attach'):
|
||||
continue
|
||||
actions[method].pop(field)
|
||||
|
||||
return actions
|
||||
@ -252,3 +254,15 @@ class JobTypeMetadata(Metadata):
|
||||
index += 1
|
||||
return res
|
||||
|
||||
|
||||
class SublistAttachDetatchMetadata(Metadata):
|
||||
|
||||
def determine_actions(self, request, view):
|
||||
actions = super(SublistAttachDetatchMetadata, self).determine_actions(request, view)
|
||||
method = 'POST'
|
||||
if method in actions:
|
||||
for field in actions[method]:
|
||||
if field == 'id':
|
||||
continue
|
||||
actions[method].pop(field)
|
||||
return actions
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user