mirror of
https://github.com/ansible/awx.git
synced 2026-01-23 23:41:23 -03:30
Make kind read-only for PUT/PATCH, use isinstance in Host Manager, update field fasly check
This commit is contained in:
parent
bdb13ecd71
commit
af35838aff
@ -1686,6 +1686,15 @@ class InventoryDetail(RetrieveUpdateDestroyAPIView):
|
||||
model = Inventory
|
||||
serializer_class = InventoryDetailSerializer
|
||||
|
||||
def update(self, request, *args, **kwargs):
|
||||
obj = self.get_object()
|
||||
kind = self.request.data.get('kind') or kwargs.get('kind')
|
||||
|
||||
# Do not allow changes to an Inventory kind.
|
||||
if kind is not None and obj.kind != kind:
|
||||
return self.http_method_not_allowed(request, *args, **kwargs)
|
||||
return super(InventoryDetail, self).update(request, *args, **kwargs)
|
||||
|
||||
def destroy(self, request, *args, **kwargs):
|
||||
with ignore_inventory_computed_fields():
|
||||
with ignore_inventory_group_removal():
|
||||
|
||||
@ -331,8 +331,10 @@ class ImplicitRoleField(models.ForeignKey):
|
||||
|
||||
class DynamicFilterField(models.TextField):
|
||||
def get_prep_value(self, value):
|
||||
if value is None:
|
||||
return value
|
||||
# Change any false value to none.
|
||||
# https://docs.python.org/2/library/stdtypes.html#truth-value-testing
|
||||
if not value:
|
||||
return None
|
||||
try:
|
||||
DynamicFilter().query_from_string(value)
|
||||
except RuntimeError, e:
|
||||
|
||||
@ -27,9 +27,8 @@ class HostManager(models.Manager):
|
||||
set. Use the `host_filter` to generate the queryset for the hosts.
|
||||
"""
|
||||
qs = super(HostManager, self).get_queryset()
|
||||
if hasattr(self, 'instance') and self.instance is not None:
|
||||
if hasattr(self.instance, 'kind') and self.instance.kind == 'dynamic':
|
||||
if hasattr(self.instance, 'host_filter') and self.instance.host_filter is not None:
|
||||
if hasattr(self, 'instance') and isinstance(self.instance, models.Inventory):
|
||||
if self.instance.kind == 'dynamic' and self.instance.host_filter is not None:
|
||||
q = DynamicFilter.query_from_string(self.instance.host_filter)
|
||||
# If we are using host_filters, disable the core_filters, this allows
|
||||
# us to access all of the available Host entries, not just the ones associated
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user