diff --git a/awx/api/views.py b/awx/api/views.py index f493a9ae0d..cc7599db78 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -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(): diff --git a/awx/main/fields.py b/awx/main/fields.py index 25f4a85e66..a492932b43 100644 --- a/awx/main/fields.py +++ b/awx/main/fields.py @@ -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: diff --git a/awx/main/managers.py b/awx/main/managers.py index 5884c88938..0969ad311a 100644 --- a/awx/main/managers.py +++ b/awx/main/managers.py @@ -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