mirror of
https://github.com/ansible/awx.git
synced 2026-02-26 15:36:04 -03:30
Always allow resource creation via global list
This commit is contained in:
@@ -599,7 +599,7 @@ class InstanceGroupInstanceList(InstanceGroupMembershipMixin, SubListAttachDetac
|
|||||||
search_fields = ('hostname',)
|
search_fields = ('hostname',)
|
||||||
|
|
||||||
|
|
||||||
class ScheduleList(ListAPIView):
|
class ScheduleList(ListCreateAPIView):
|
||||||
|
|
||||||
view_name = _("Schedules")
|
view_name = _("Schedules")
|
||||||
model = Schedule
|
model = Schedule
|
||||||
@@ -1291,7 +1291,7 @@ class ProjectUpdateNotificationsList(SubListAPIView):
|
|||||||
search_fields = ('subject', 'notification_type', 'body',)
|
search_fields = ('subject', 'notification_type', 'body',)
|
||||||
|
|
||||||
|
|
||||||
class ProjectUpdateScmInventoryUpdates(SubListCreateAPIView):
|
class ProjectUpdateScmInventoryUpdates(SubListAPIView):
|
||||||
|
|
||||||
view_name = _("Project Update SCM Inventory Updates")
|
view_name = _("Project Update SCM Inventory Updates")
|
||||||
model = InventoryUpdate
|
model = InventoryUpdate
|
||||||
@@ -1484,10 +1484,11 @@ class OAuth2TokenActivityStreamList(ActivityStreamEnforcementMixin, SubListAPIVi
|
|||||||
search_fields = ('changes',)
|
search_fields = ('changes',)
|
||||||
|
|
||||||
|
|
||||||
class UserTeamsList(ListAPIView):
|
class UserTeamsList(SubListAPIView):
|
||||||
|
|
||||||
model = User
|
model = Team
|
||||||
serializer_class = TeamSerializer
|
serializer_class = TeamSerializer
|
||||||
|
parent_model = User
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
u = get_object_or_404(User, pk=self.kwargs['pk'])
|
u = get_object_or_404(User, pk=self.kwargs['pk'])
|
||||||
@@ -1665,7 +1666,7 @@ class CredentialTypeDetail(RetrieveUpdateDestroyAPIView):
|
|||||||
return super(CredentialTypeDetail, self).destroy(request, *args, **kwargs)
|
return super(CredentialTypeDetail, self).destroy(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class CredentialTypeCredentialList(SubListAPIView):
|
class CredentialTypeCredentialList(SubListCreateAPIView):
|
||||||
|
|
||||||
model = Credential
|
model = Credential
|
||||||
parent_model = CredentialType
|
parent_model = CredentialType
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from rest_framework.generics import ListAPIView
|
|||||||
# AWX
|
# AWX
|
||||||
from awx.main.views import ApiErrorView
|
from awx.main.views import ApiErrorView
|
||||||
from awx.api.views import JobList, InventorySourceList
|
from awx.api.views import JobList, InventorySourceList
|
||||||
|
from awx.api.generics import ListCreateAPIView, SubListAttachDetachAPIView
|
||||||
|
|
||||||
|
|
||||||
HTTP_METHOD_NAMES = [
|
HTTP_METHOD_NAMES = [
|
||||||
@@ -73,3 +74,30 @@ def test_views_have_search_fields(all_views):
|
|||||||
for v in views_missing_search
|
for v in views_missing_search
|
||||||
]))
|
]))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_global_creation_always_possible(all_views):
|
||||||
|
"""To not make life very difficult for clients, this test
|
||||||
|
asserts that all creatable resources can be created by
|
||||||
|
POSTing to the global resource list
|
||||||
|
"""
|
||||||
|
views_by_model = {}
|
||||||
|
for View in all_views:
|
||||||
|
if not getattr(View, 'deprecated', False) and issubclass(View, ListAPIView) and hasattr(View, 'model'):
|
||||||
|
views_by_model.setdefault(View.model, []).append(View)
|
||||||
|
for model, views in views_by_model.items():
|
||||||
|
creatable = False
|
||||||
|
global_view = None
|
||||||
|
creatable_view = None
|
||||||
|
for View in views:
|
||||||
|
if '{}ListView'.format(model.__name__) == View.__name__:
|
||||||
|
global_view = View
|
||||||
|
if issubclass(View, ListCreateAPIView) and not issubclass(View, SubListAttachDetachAPIView):
|
||||||
|
creatable = True
|
||||||
|
creatable_view = View
|
||||||
|
if not creatable or not global_view:
|
||||||
|
continue
|
||||||
|
assert 'POST' in global_view().allowed_methods, (
|
||||||
|
'Resource {} should be creatable in global list view {}. '
|
||||||
|
'Can be created now in {}'.format(model, global_view, creatable_view)
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user