diff --git a/awx/api/generics.py b/awx/api/generics.py index 0c593925c0..1062135a28 100644 --- a/awx/api/generics.py +++ b/awx/api/generics.py @@ -296,7 +296,7 @@ class ParentMixin(object): raise PermissionDenied() -class SubListAPIView(ListAPIView, ParentMixin): +class SubListAPIView(ParentMixin, ListAPIView): # Base class for a read-only sublist view. # Subclasses should define at least: @@ -501,7 +501,7 @@ class DeleteLastUnattachLabelMixin(object): return res -class SubDetailAPIView(generics.RetrieveAPIView, GenericAPIView, ParentMixin): +class SubDetailAPIView(ParentMixin, generics.RetrieveAPIView, GenericAPIView): pass diff --git a/awx/api/views.py b/awx/api/views.py index 5962a0e2b4..dd57f1bf6e 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -88,6 +88,36 @@ def api_exception_handler(exc, context): return exception_handler(exc, context) +class ActivityStreamEnforcementMixin(object): + ''' + Mixin to check that license supports activity streams. + ''' + def check_permissions(self, request): + if not feature_enabled('activity_streams'): + raise LicenseForbids(_('Your license does not allow use of the activity stream.')) + return super(ActivityStreamEnforcementMixin, self).check_permissions(request) + + +class SystemTrackingEnforcementMixin(object): + ''' + Mixin to check that license supports system tracking. + ''' + 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 WorkflowsEnforcementMixin(object): + ''' + Mixin to check that license supports workflows. + ''' + def check_permissions(self, request): + if not feature_enabled('workflows'): + raise LicenseForbids(_('Your license does not allow use of workflows.')) + return super(WorkflowsEnforcementMixin, self).check_permissions(request) + + class ApiRootView(APIView): authentication_classes = [] @@ -795,7 +825,7 @@ class OrganizationTeamsList(SubListCreateAttachDetachAPIView): parent_key = 'organization' -class OrganizationActivityStreamList(SubListAPIView): +class OrganizationActivityStreamList(ActivityStreamEnforcementMixin, SubListAPIView): model = ActivityStream serializer_class = ActivityStreamSerializer @@ -803,16 +833,6 @@ class OrganizationActivityStreamList(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(OrganizationActivityStreamList, self).get(request, *args, **kwargs) - class OrganizationNotificationTemplatesList(SubListCreateAttachDetachAPIView): @@ -960,7 +980,7 @@ class TeamProjectsList(SubListAPIView): return self.model.accessible_objects(self.request.user, 'read_role').filter(pk__in=[t.content_object.pk for t in proj_roles]) -class TeamActivityStreamList(SubListAPIView): +class TeamActivityStreamList(ActivityStreamEnforcementMixin, SubListAPIView): model = ActivityStream serializer_class = ActivityStreamSerializer @@ -968,16 +988,6 @@ class TeamActivityStreamList(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(TeamActivityStreamList, self).get(request, *args, **kwargs) - def get_queryset(self): parent = self.get_parent_object() self.check_parent_access(parent) @@ -1061,7 +1071,7 @@ class ProjectSchedulesList(SubListCreateAttachDetachAPIView): new_in_148 = True -class ProjectActivityStreamList(SubListAPIView): +class ProjectActivityStreamList(ActivityStreamEnforcementMixin, SubListAPIView): model = ActivityStream serializer_class = ActivityStreamSerializer @@ -1069,16 +1079,6 @@ 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(ProjectActivityStreamList, self).get(request, *args, **kwargs) - def get_queryset(self): parent = self.get_parent_object() self.check_parent_access(parent) @@ -1348,7 +1348,7 @@ class UserAdminOfOrganizationsList(OrganizationCountsMixin, SubListAPIView): return my_qs & user_qs -class UserActivityStreamList(SubListAPIView): +class UserActivityStreamList(ActivityStreamEnforcementMixin, SubListAPIView): model = ActivityStream serializer_class = ActivityStreamSerializer @@ -1356,16 +1356,6 @@ 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(UserActivityStreamList, self).get(request, *args, **kwargs) - def get_queryset(self): parent = self.get_parent_object() self.check_parent_access(parent) @@ -1509,7 +1499,7 @@ class CredentialDetail(RetrieveUpdateDestroyAPIView): serializer_class = CredentialSerializer -class CredentialActivityStreamList(SubListAPIView): +class CredentialActivityStreamList(ActivityStreamEnforcementMixin, SubListAPIView): model = ActivityStream serializer_class = ActivityStreamSerializer @@ -1517,16 +1507,6 @@ 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(CredentialActivityStreamList, self).get(request, *args, **kwargs) - class CredentialAccessList(ResourceAccessList): @@ -1606,7 +1586,7 @@ class InventoryDetail(RetrieveUpdateDestroyAPIView): return super(InventoryDetail, self).destroy(request, *args, **kwargs) -class InventoryActivityStreamList(SubListAPIView): +class InventoryActivityStreamList(ActivityStreamEnforcementMixin, SubListAPIView): model = ActivityStream serializer_class = ActivityStreamSerializer @@ -1614,16 +1594,6 @@ 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(InventoryActivityStreamList, self).get(request, *args, **kwargs) - def get_queryset(self): parent = self.get_parent_object() self.check_parent_access(parent) @@ -1750,7 +1720,7 @@ class HostInventorySourcesList(SubListAPIView): new_in_148 = True -class HostActivityStreamList(SubListAPIView): +class HostActivityStreamList(ActivityStreamEnforcementMixin, SubListAPIView): model = ActivityStream serializer_class = ActivityStreamSerializer @@ -1758,16 +1728,6 @@ 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(HostActivityStreamList, self).get(request, *args, **kwargs) - def get_queryset(self): parent = self.get_parent_object() self.check_parent_access(parent) @@ -1775,18 +1735,7 @@ class HostActivityStreamList(SubListAPIView): return qs.filter(Q(host=parent) | Q(inventory=parent.inventory)) -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): +class HostFactVersionsList(SystemTrackingEnforcementMixin, ParentMixin, ListAPIView): model = Fact serializer_class = FactVersionSerializer @@ -1812,7 +1761,7 @@ class HostFactVersionsList(ListAPIView, ParentMixin, SystemTrackingEnforcementMi return Response(dict(results=self.serializer_class(queryset, many=True).data)) -class HostFactCompareView(SubDetailAPIView, SystemTrackingEnforcementMixin): +class HostFactCompareView(SystemTrackingEnforcementMixin, SubDetailAPIView): model = Fact new_in_220 = True @@ -1946,7 +1895,7 @@ class GroupInventorySourcesList(SubListAPIView): new_in_148 = True -class GroupActivityStreamList(SubListAPIView): +class GroupActivityStreamList(ActivityStreamEnforcementMixin, SubListAPIView): model = ActivityStream serializer_class = ActivityStreamSerializer @@ -1954,16 +1903,6 @@ 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(GroupActivityStreamList, self).get(request, *args, **kwargs) - def get_queryset(self): parent = self.get_parent_object() self.check_parent_access(parent) @@ -2204,7 +2143,7 @@ class InventorySourceSchedulesList(SubListCreateAttachDetachAPIView): new_in_148 = True -class InventorySourceActivityStreamList(SubListAPIView): +class InventorySourceActivityStreamList(ActivityStreamEnforcementMixin, SubListAPIView): model = ActivityStream serializer_class = ActivityStreamSerializer @@ -2212,16 +2151,6 @@ 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(InventorySourceActivityStreamList, self).get(request, *args, **kwargs) - class InventorySourceNotificationTemplatesAnyList(SubListCreateAttachDetachAPIView): @@ -2514,13 +2443,13 @@ class JobTemplateSurveySpec(GenericAPIView): return Response() -class WorkflowJobTemplateSurveySpec(JobTemplateSurveySpec): +class WorkflowJobTemplateSurveySpec(WorkflowsEnforcementMixin, JobTemplateSurveySpec): model = WorkflowJobTemplate parent_model = WorkflowJobTemplate -class JobTemplateActivityStreamList(SubListAPIView): +class JobTemplateActivityStreamList(ActivityStreamEnforcementMixin, SubListAPIView): model = ActivityStream serializer_class = ActivityStreamSerializer @@ -2528,16 +2457,6 @@ 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(JobTemplateActivityStreamList, self).get(request, *args, **kwargs) - class JobTemplateNotificationTemplatesAnyList(SubListCreateAttachDetachAPIView): @@ -2771,28 +2690,28 @@ class JobTemplateObjectRolesList(SubListAPIView): return Role.objects.filter(content_type=content_type, object_id=po.pk) -class WorkflowJobNodeList(ListAPIView): +class WorkflowJobNodeList(WorkflowsEnforcementMixin, ListAPIView): model = WorkflowJobNode serializer_class = WorkflowJobNodeListSerializer new_in_310 = True -class WorkflowJobNodeDetail(RetrieveAPIView): +class WorkflowJobNodeDetail(WorkflowsEnforcementMixin, RetrieveAPIView): model = WorkflowJobNode serializer_class = WorkflowJobNodeDetailSerializer new_in_310 = True -class WorkflowJobTemplateNodeList(ListCreateAPIView): +class WorkflowJobTemplateNodeList(WorkflowsEnforcementMixin, ListCreateAPIView): model = WorkflowJobTemplateNode serializer_class = WorkflowJobTemplateNodeListSerializer new_in_310 = True -class WorkflowJobTemplateNodeDetail(RetrieveUpdateDestroyAPIView): +class WorkflowJobTemplateNodeDetail(WorkflowsEnforcementMixin, RetrieveUpdateDestroyAPIView): model = WorkflowJobTemplateNode serializer_class = WorkflowJobTemplateNodeDetailSerializer @@ -2809,7 +2728,7 @@ class WorkflowJobTemplateNodeDetail(RetrieveUpdateDestroyAPIView): return super(WorkflowJobTemplateNodeDetail, self).update_raw_data(data) -class WorkflowJobTemplateNodeChildrenBaseList(EnforceParentRelationshipMixin, SubListCreateAttachDetachAPIView): +class WorkflowJobTemplateNodeChildrenBaseList(WorkflowsEnforcementMixin, EnforceParentRelationshipMixin, SubListCreateAttachDetachAPIView): model = WorkflowJobTemplateNode serializer_class = WorkflowJobTemplateNodeListSerializer @@ -2881,7 +2800,7 @@ class WorkflowJobTemplateNodeAlwaysNodesList(WorkflowJobTemplateNodeChildrenBase relationship = 'always_nodes' -class WorkflowJobNodeChildrenBaseList(SubListAPIView): +class WorkflowJobNodeChildrenBaseList(WorkflowsEnforcementMixin, SubListAPIView): model = WorkflowJobNode serializer_class = WorkflowJobNodeListSerializer @@ -2912,7 +2831,7 @@ class WorkflowJobNodeAlwaysNodesList(WorkflowJobNodeChildrenBaseList): # TODO: -class WorkflowJobTemplateList(ListCreateAPIView): +class WorkflowJobTemplateList(WorkflowsEnforcementMixin, ListCreateAPIView): model = WorkflowJobTemplate serializer_class = WorkflowJobTemplateListSerializer @@ -2931,7 +2850,7 @@ class WorkflowJobTemplateList(ListCreateAPIView): # TODO: -class WorkflowJobTemplateDetail(RetrieveUpdateDestroyAPIView): +class WorkflowJobTemplateDetail(WorkflowsEnforcementMixin, RetrieveUpdateDestroyAPIView): model = WorkflowJobTemplate serializer_class = WorkflowJobTemplateSerializer @@ -2939,7 +2858,7 @@ class WorkflowJobTemplateDetail(RetrieveUpdateDestroyAPIView): new_in_310 = True -class WorkflowJobTemplateCopy(GenericAPIView): +class WorkflowJobTemplateCopy(WorkflowsEnforcementMixin, GenericAPIView): model = WorkflowJobTemplate parent_model = WorkflowJobTemplate @@ -2965,12 +2884,12 @@ class WorkflowJobTemplateCopy(GenericAPIView): return Response(data, status=status.HTTP_201_CREATED) -class WorkflowJobTemplateLabelList(JobTemplateLabelList): +class WorkflowJobTemplateLabelList(WorkflowsEnforcementMixin, JobTemplateLabelList): parent_model = WorkflowJobTemplate new_in_310 = True -class WorkflowJobTemplateLaunch(RetrieveAPIView): +class WorkflowJobTemplateLaunch(WorkflowsEnforcementMixin, RetrieveAPIView): model = WorkflowJobTemplate @@ -3010,7 +2929,7 @@ class WorkflowJobTemplateLaunch(RetrieveAPIView): return Response(data, status=status.HTTP_201_CREATED) -class WorkflowJobRelaunch(GenericAPIView): +class WorkflowJobRelaunch(WorkflowsEnforcementMixin, GenericAPIView): model = WorkflowJob serializer_class = EmptySerializer @@ -3030,7 +2949,7 @@ class WorkflowJobRelaunch(GenericAPIView): # TODO: -class WorkflowJobTemplateWorkflowNodesList(SubListCreateAPIView): +class WorkflowJobTemplateWorkflowNodesList(WorkflowsEnforcementMixin, SubListCreateAPIView): model = WorkflowJobTemplateNode serializer_class = WorkflowJobTemplateNodeListSerializer @@ -3046,7 +2965,7 @@ class WorkflowJobTemplateWorkflowNodesList(SubListCreateAPIView): # TODO: -class WorkflowJobTemplateJobsList(SubListAPIView): +class WorkflowJobTemplateJobsList(WorkflowsEnforcementMixin, SubListAPIView): model = WorkflowJob serializer_class = WorkflowJobListSerializer @@ -3056,7 +2975,7 @@ class WorkflowJobTemplateJobsList(SubListAPIView): new_in_310 = True -class WorkflowJobTemplateSchedulesList(SubListCreateAttachDetachAPIView): +class WorkflowJobTemplateSchedulesList(WorkflowsEnforcementMixin, SubListCreateAttachDetachAPIView): view_name = _("Workflow Job Template Schedules") @@ -3068,7 +2987,7 @@ class WorkflowJobTemplateSchedulesList(SubListCreateAttachDetachAPIView): new_in_310 = True -class WorkflowJobTemplateNotificationTemplatesAnyList(SubListCreateAttachDetachAPIView): +class WorkflowJobTemplateNotificationTemplatesAnyList(WorkflowsEnforcementMixin, SubListCreateAttachDetachAPIView): model = NotificationTemplate serializer_class = NotificationTemplateSerializer @@ -3077,7 +2996,7 @@ class WorkflowJobTemplateNotificationTemplatesAnyList(SubListCreateAttachDetachA new_in_310 = True -class WorkflowJobTemplateNotificationTemplatesErrorList(SubListCreateAttachDetachAPIView): +class WorkflowJobTemplateNotificationTemplatesErrorList(WorkflowsEnforcementMixin, SubListCreateAttachDetachAPIView): model = NotificationTemplate serializer_class = NotificationTemplateSerializer @@ -3086,7 +3005,7 @@ class WorkflowJobTemplateNotificationTemplatesErrorList(SubListCreateAttachDetac new_in_310 = True -class WorkflowJobTemplateNotificationTemplatesSuccessList(SubListCreateAttachDetachAPIView): +class WorkflowJobTemplateNotificationTemplatesSuccessList(WorkflowsEnforcementMixin, SubListCreateAttachDetachAPIView): model = NotificationTemplate serializer_class = NotificationTemplateSerializer @@ -3095,14 +3014,14 @@ class WorkflowJobTemplateNotificationTemplatesSuccessList(SubListCreateAttachDet new_in_310 = True -class WorkflowJobTemplateAccessList(ResourceAccessList): +class WorkflowJobTemplateAccessList(WorkflowsEnforcementMixin, ResourceAccessList): model = User # needs to be User for AccessLists's resource_model = WorkflowJobTemplate new_in_310 = True -class WorkflowJobTemplateObjectRolesList(SubListAPIView): +class WorkflowJobTemplateObjectRolesList(WorkflowsEnforcementMixin, SubListAPIView): model = Role serializer_class = RoleSerializer @@ -3115,7 +3034,7 @@ class WorkflowJobTemplateObjectRolesList(SubListAPIView): return Role.objects.filter(content_type=content_type, object_id=po.pk) -class WorkflowJobTemplateActivityStreamList(SubListAPIView): +class WorkflowJobTemplateActivityStreamList(WorkflowsEnforcementMixin, ActivityStreamEnforcementMixin, SubListAPIView): model = ActivityStream serializer_class = ActivityStreamSerializer @@ -3123,19 +3042,9 @@ class WorkflowJobTemplateActivityStreamList(SubListAPIView): relationship = 'activitystream_set' new_in_310 = 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(WorkflowJobTemplateActivityStreamList, self).get(request, *args, **kwargs) - # TODO: -class WorkflowJobList(ListCreateAPIView): +class WorkflowJobList(WorkflowsEnforcementMixin, ListCreateAPIView): model = WorkflowJob serializer_class = WorkflowJobListSerializer @@ -3143,14 +3052,14 @@ class WorkflowJobList(ListCreateAPIView): # TODO: -class WorkflowJobDetail(RetrieveDestroyAPIView): +class WorkflowJobDetail(WorkflowsEnforcementMixin, RetrieveDestroyAPIView): model = WorkflowJob serializer_class = WorkflowJobSerializer new_in_310 = True -class WorkflowJobWorkflowNodesList(SubListAPIView): +class WorkflowJobWorkflowNodesList(WorkflowsEnforcementMixin, SubListAPIView): model = WorkflowJobNode serializer_class = WorkflowJobNodeListSerializer @@ -3161,7 +3070,7 @@ class WorkflowJobWorkflowNodesList(SubListAPIView): new_in_310 = True -class WorkflowJobCancel(RetrieveAPIView): +class WorkflowJobCancel(WorkflowsEnforcementMixin, RetrieveAPIView): model = WorkflowJob serializer_class = WorkflowJobCancelSerializer @@ -3179,7 +3088,7 @@ class WorkflowJobCancel(RetrieveAPIView): return self.http_method_not_allowed(request, *args, **kwargs) -class WorkflowJobNotificationsList(SubListAPIView): +class WorkflowJobNotificationsList(WorkflowsEnforcementMixin, SubListAPIView): model = Notification serializer_class = NotificationSerializer @@ -3188,7 +3097,7 @@ class WorkflowJobNotificationsList(SubListAPIView): new_in_310 = True -class WorkflowJobActivityStreamList(SubListAPIView): +class WorkflowJobActivityStreamList(WorkflowsEnforcementMixin, ActivityStreamEnforcementMixin, SubListAPIView): model = ActivityStream serializer_class = ActivityStreamSerializer @@ -3196,16 +3105,6 @@ class WorkflowJobActivityStreamList(SubListAPIView): relationship = 'activitystream_set' new_in_310 = 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(WorkflowJobActivityStreamList, self).get(request, *args, **kwargs) - class SystemJobTemplateList(ListAPIView): @@ -3320,11 +3219,11 @@ class JobLabelList(SubListAPIView): parent_key = 'job' -class WorkflowJobLabelList(JobLabelList): +class WorkflowJobLabelList(WorkflowsEnforcementMixin, JobLabelList): parent_model = WorkflowJob -class JobActivityStreamList(SubListAPIView): +class JobActivityStreamList(ActivityStreamEnforcementMixin, SubListAPIView): model = ActivityStream serializer_class = ActivityStreamSerializer @@ -3332,16 +3231,6 @@ 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(JobActivityStreamList, self).get(request, *args, **kwargs) - class JobStart(GenericAPIView): @@ -3916,7 +3805,7 @@ class AdHocCommandAdHocCommandEventsList(BaseAdHocCommandEventsList): new_in_220 = True -class AdHocCommandActivityStreamList(SubListAPIView): +class AdHocCommandActivityStreamList(ActivityStreamEnforcementMixin, SubListAPIView): model = ActivityStream serializer_class = ActivityStreamSerializer @@ -3924,16 +3813,6 @@ 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(AdHocCommandActivityStreamList, self).get(request, *args, **kwargs) - class AdHocCommandNotificationsList(SubListAPIView): @@ -4170,39 +4049,19 @@ class LabelDetail(RetrieveUpdateAPIView): new_in_300 = True -class ActivityStreamList(SimpleListAPIView): +class ActivityStreamList(ActivityStreamEnforcementMixin, SimpleListAPIView): 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(ActivityStreamList, self).get(request, *args, **kwargs) - - -class ActivityStreamDetail(RetrieveAPIView): +class ActivityStreamDetail(ActivityStreamEnforcementMixin, 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(ActivityStreamDetail, self).get(request, *args, **kwargs) - class RoleList(ListAPIView):