mirror of
https://github.com/ansible/awx.git
synced 2026-04-26 20:25:24 -02:30
deny endpoint access to system tracking feature based on license
This commit is contained in:
@@ -483,7 +483,7 @@ class BaseFactSerializer(BaseSerializer):
|
||||
|
||||
def get_fields(self):
|
||||
ret = super(BaseFactSerializer, self).get_fields()
|
||||
if 'module' in ret and feature_enabled('system_tracking'):
|
||||
if 'module' in ret:
|
||||
# TODO: the values_list may pull in a LOT of entries before the distinct is called
|
||||
modules = Fact.objects.all().values_list('module', flat=True).distinct()
|
||||
choices = [(o, o.title()) for o in modules]
|
||||
|
||||
@@ -1270,7 +1270,17 @@ class HostActivityStreamList(SubListAPIView):
|
||||
qs = self.request.user.get_queryset(self.model)
|
||||
return qs.filter(Q(host=parent) | Q(inventory=parent.inventory))
|
||||
|
||||
class HostFactVersionsList(ListAPIView, ParentMixin):
|
||||
class SystemTrackingEnforcementMixin(APIView):
|
||||
'''
|
||||
Use check_permissions instead of initial() because it's in the OPTION's path as well
|
||||
'''
|
||||
def check_permissions(self, request):
|
||||
if not feature_enabled("system_tracking"):
|
||||
raise LicenseForbids("Your license does not permit use "
|
||||
"of system tracking.")
|
||||
return super(SystemTrackingEnforcementMixin, self).check_permissions(request)
|
||||
|
||||
class HostFactVersionsList(ListAPIView, ParentMixin, SystemTrackingEnforcementMixin):
|
||||
|
||||
model = Fact
|
||||
serializer_class = FactVersionSerializer
|
||||
@@ -1278,10 +1288,6 @@ class HostFactVersionsList(ListAPIView, ParentMixin):
|
||||
new_in_220 = True
|
||||
|
||||
def get_queryset(self):
|
||||
if not feature_enabled("system_tracking"):
|
||||
raise LicenseForbids("Your license does not permit use "
|
||||
"of system tracking.")
|
||||
|
||||
from_spec = self.request.query_params.get('from', None)
|
||||
to_spec = self.request.query_params.get('to', None)
|
||||
module_spec = self.request.query_params.get('module', None)
|
||||
@@ -1299,7 +1305,7 @@ class HostFactVersionsList(ListAPIView, ParentMixin):
|
||||
queryset = self.get_queryset() or []
|
||||
return Response(dict(results=self.serializer_class(queryset, many=True).data))
|
||||
|
||||
class HostFactCompareView(SubDetailAPIView):
|
||||
class HostFactCompareView(SubDetailAPIView, SystemTrackingEnforcementMixin):
|
||||
|
||||
model = Fact
|
||||
new_in_220 = True
|
||||
@@ -1307,11 +1313,6 @@ class HostFactCompareView(SubDetailAPIView):
|
||||
serializer_class = FactSerializer
|
||||
|
||||
def retrieve(self, request, *args, **kwargs):
|
||||
# Sanity check: Does the license allow system tracking?
|
||||
if not feature_enabled('system_tracking'):
|
||||
raise LicenseForbids('Your license does not permit use '
|
||||
'of system tracking.')
|
||||
|
||||
datetime_spec = request.query_params.get('datetime', None)
|
||||
module_spec = request.query_params.get('module', "ansible")
|
||||
datetime_actual = dateutil.parser.parse(datetime_spec) if datetime_spec is not None else now()
|
||||
|
||||
Reference in New Issue
Block a user