From d5a781f43eb4130d805c65963bc01486ecb445d1 Mon Sep 17 00:00:00 2001 From: Luke Sneeringer Date: Thu, 21 May 2015 11:35:34 -0400 Subject: [PATCH] Remaining license differentiation for activity streams. --- awx/api/views.py | 128 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 125 insertions(+), 3 deletions(-) diff --git a/awx/api/views.py b/awx/api/views.py index 4258128dd1..04c06e31a9 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -508,7 +508,7 @@ class OrganizationList(ListCreateAPIView): # if no organizations exist in the system. if (not feature_enabled('multiple_organizations') and self.model.objects.filter(active=True).count() > 0): - raise LicenseForbids('This Tower license only permits a single ' + raise LicenseForbids('Your Tower license only permits a single ' 'organization to exist.') # Okay, create the organization as usual. @@ -566,7 +566,7 @@ class OrganizationActivityStreamList(SubListAPIView): def get(self, request, *args, **kwargs): # Sanity check: Does this license allow activity streams? # If not, forbid this request. - if not feature_enabled('activity_stream'): + if not feature_enabled('activity_streams'): raise LicenseForbids('Your license does not allow use of ' 'the activity stream.') @@ -635,7 +635,7 @@ class TeamActivityStreamList(SubListAPIView): def get(self, request, *args, **kwargs): # Sanity check: Does this license allow activity streams? # If not, forbid this request. - if not feature_enabled('activity_stream'): + if not feature_enabled('activity_streams'): raise LicenseForbids('Your license does not allow use of ' 'the activity stream.') @@ -718,6 +718,16 @@ class ProjectActivityStreamList(SubListAPIView): relationship = 'activitystream_set' new_in_145 = True + def get(self, request, *args, **kwargs): + # Sanity check: Does this license allow activity streams? + # If not, forbid this request. + if not feature_enabled('activity_streams'): + raise LicenseForbids('Your license does not allow use of ' + 'the activity stream.') + + # Okay, let it through. + return super(type(self), self).get(request, *args, **kwargs) + def get_queryset(self): parent = self.get_parent_object() self.check_parent_access(parent) @@ -851,6 +861,16 @@ class UserActivityStreamList(SubListAPIView): relationship = 'activitystream_set' new_in_145 = True + def get(self, request, *args, **kwargs): + # Sanity check: Does this license allow activity streams? + # If not, forbid this request. + if not feature_enabled('activity_streams'): + raise LicenseForbids('Your license does not allow use of ' + 'the activity stream.') + + # Okay, let it through. + return super(type(self), self).get(request, *args, **kwargs) + def get_queryset(self): parent = self.get_parent_object() self.check_parent_access(parent) @@ -907,6 +927,16 @@ class CredentialActivityStreamList(SubListAPIView): relationship = 'activitystream_set' new_in_145 = True + def get(self, request, *args, **kwargs): + # Sanity check: Does this license allow activity streams? + # If not, forbid this request. + if not feature_enabled('activity_streams'): + raise LicenseForbids('Your license does not allow use of ' + 'the activity stream.') + + # Okay, let it through. + return super(type(self), self).get(request, *args, **kwargs) + class PermissionDetail(RetrieveUpdateDestroyAPIView): model = Permission @@ -955,6 +985,16 @@ class InventoryActivityStreamList(SubListAPIView): relationship = 'activitystream_set' new_in_145 = True + def get(self, request, *args, **kwargs): + # Sanity check: Does this license allow activity streams? + # If not, forbid this request. + if not feature_enabled('activity_streams'): + raise LicenseForbids('Your license does not allow use of ' + 'the activity stream.') + + # Okay, let it through. + return super(type(self), self).get(request, *args, **kwargs) + def get_queryset(self): parent = self.get_parent_object() self.check_parent_access(parent) @@ -1059,6 +1099,16 @@ class HostActivityStreamList(SubListAPIView): relationship = 'activitystream_set' new_in_145 = True + def get(self, request, *args, **kwargs): + # Sanity check: Does this license allow activity streams? + # If not, forbid this request. + if not feature_enabled('activity_streams'): + raise LicenseForbids('Your license does not allow use of ' + 'the activity stream.') + + # Okay, let it through. + return super(type(self), self).get(request, *args, **kwargs) + def get_queryset(self): parent = self.get_parent_object() self.check_parent_access(parent) @@ -1267,6 +1317,16 @@ class GroupActivityStreamList(SubListAPIView): relationship = 'activitystream_set' new_in_145 = True + def get(self, request, *args, **kwargs): + # Sanity check: Does this license allow activity streams? + # If not, forbid this request. + if not feature_enabled('activity_streams'): + raise LicenseForbids('Your license does not allow use of ' + 'the activity stream.') + + # Okay, let it through. + return super(type(self), self).get(request, *args, **kwargs) + def get_queryset(self): parent = self.get_parent_object() self.check_parent_access(parent) @@ -1543,6 +1603,16 @@ class InventorySourceActivityStreamList(SubListAPIView): relationship = 'activitystream_set' new_in_145 = True + def get(self, request, *args, **kwargs): + # Sanity check: Does this license allow activity streams? + # If not, forbid this request. + if not feature_enabled('activity_streams'): + raise LicenseForbids('Your license does not allow use of ' + 'the activity stream.') + + # Okay, let it through. + return super(type(self), self).get(request, *args, **kwargs) + class InventorySourceHostsList(SubListAPIView): model = Host @@ -1744,6 +1814,16 @@ class JobTemplateActivityStreamList(SubListAPIView): relationship = 'activitystream_set' new_in_145 = True + def get(self, request, *args, **kwargs): + # Sanity check: Does this license allow activity streams? + # If not, forbid this request. + if not feature_enabled('activity_streams'): + raise LicenseForbids('Your license does not allow use of ' + 'the activity stream.') + + # Okay, let it through. + return super(type(self), self).get(request, *args, **kwargs) + class JobTemplateCallback(GenericAPIView): model = JobTemplate @@ -1989,6 +2069,16 @@ class JobActivityStreamList(SubListAPIView): relationship = 'activitystream_set' new_in_145 = True + def get(self, request, *args, **kwargs): + # Sanity check: Does this license allow activity streams? + # If not, forbid this request. + if not feature_enabled('activity_streams'): + raise LicenseForbids('Your license does not allow use of ' + 'the activity stream.') + + # Okay, let it through. + return super(type(self), self).get(request, *args, **kwargs) + class JobStart(GenericAPIView): model = Job @@ -2579,6 +2669,16 @@ class AdHocCommandActivityStreamList(SubListAPIView): relationship = 'activitystream_set' new_in_220 = True + def get(self, request, *args, **kwargs): + # Sanity check: Does this license allow activity streams? + # If not, forbid this request. + if not feature_enabled('activity_streams'): + raise LicenseForbids('Your license does not allow use of ' + 'the activity stream.') + + # Okay, let it through. + return super(type(self), self).get(request, *args, **kwargs) + class SystemJobList(ListCreateAPIView): @@ -2670,12 +2770,34 @@ class ActivityStreamList(SimpleListAPIView): serializer_class = ActivityStreamSerializer new_in_145 = True + def get(self, request, *args, **kwargs): + # Sanity check: Does this license allow activity streams? + # If not, forbid this request. + if not feature_enabled('activity_streams'): + raise LicenseForbids('Your license does not allow use of ' + 'the activity stream.') + + # Okay, let it through. + return super(type(self), self).get(request, *args, **kwargs) + + class ActivityStreamDetail(RetrieveAPIView): model = ActivityStream serializer_class = ActivityStreamSerializer new_in_145 = True + def get(self, request, *args, **kwargs): + # Sanity check: Does this license allow activity streams? + # If not, forbid this request. + if not feature_enabled('activity_streams'): + raise LicenseForbids('Your license does not allow use of ' + 'the activity stream.') + + # Okay, let it through. + return super(type(self), self).get(request, *args, **kwargs) + + # Create view functions for all of the class-based views to simplify inclusion # in URL patterns and reverse URL lookups, converting CamelCase names to # lowercase_with_underscore (e.g. MyView.as_view() becomes my_view).