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