Add field on inventory detail to indicate if the user has permission to run ad hoc commands.

This commit is contained in:
Chris Church
2015-04-06 14:58:26 -04:00
parent 037c7342c0
commit 96df8a6d37
3 changed files with 56 additions and 1 deletions

View File

@@ -785,6 +785,18 @@ class InventorySerializer(BaseSerializerWithVariables):
return ret
class InventoryDetailSerializer(InventorySerializer):
class Meta:
fields = ('*', 'can_run_ad_hoc_commands')
can_run_ad_hoc_commands = serializers.SerializerMethodField('get_can_run_ad_hoc_commands')
def get_can_run_ad_hoc_commands(self, obj):
view = self.context.get('view', None)
return bool(obj and view and view.request and view.request.user and view.request.user.can_access(Inventory, 'run_ad_hoc_commands', obj))
class InventoryScriptSerializer(InventorySerializer):
class Meta:

View File

@@ -887,7 +887,7 @@ class InventoryList(ListCreateAPIView):
class InventoryDetail(RetrieveUpdateDestroyAPIView):
model = Inventory
serializer_class = InventorySerializer
serializer_class = InventoryDetailSerializer
def destroy(self, request, *args, **kwargs):
with ignore_inventory_computed_fields():