From 5f7de996bd0ee39a3a4a6207f2290cd54a5584aa Mon Sep 17 00:00:00 2001 From: Michael Abashian Date: Mon, 15 Feb 2016 10:19:27 -0500 Subject: [PATCH] Added logic to hide activity stream button when the feature is turned off. Also added logic to redirect the user to the dashboard when they try to navigate to the stream when the feature is not on. --- .../activity-stream/activitystream.route.js | 21 ++++++++++++++ .../src/bread-crumb/bread-crumb.directive.js | 29 +++++++++++++++++-- .../src/shared/features/features.service.js | 8 +++++ 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/awx/ui/client/src/activity-stream/activitystream.route.js b/awx/ui/client/src/activity-stream/activitystream.route.js index 8ba1357c6a..82e85b15f0 100644 --- a/awx/ui/client/src/activity-stream/activitystream.route.js +++ b/awx/ui/client/src/activity-stream/activitystream.route.js @@ -15,6 +15,27 @@ export default { label: "ACTIVITY STREAM" }, resolve: { + features: ['FeaturesService', 'ProcessErrors', '$state', function(FeaturesService, ProcessErrors, $state) { + FeaturesService.get() + .then(function(features) { + if(FeaturesService.featureEnabled('activity_streams')) { + // Good to go - pass the features along to the controller. + return features; + } + else { + // The activity stream feature isn't enabled. Take the user + // back to the dashboard + $state.go('dashboard'); + } + }) + .catch(function (response) { + ProcessErrors(null, response.data, response.status, null, { + hdr: 'Error!', + msg: 'Failed to get feature info. GET returned status: ' + + response.status + }); + }); + }], subTitle: [ '$stateParams', 'Rest', diff --git a/awx/ui/client/src/bread-crumb/bread-crumb.directive.js b/awx/ui/client/src/bread-crumb/bread-crumb.directive.js index 3a0f2ac876..cbfe6ff4cb 100644 --- a/awx/ui/client/src/bread-crumb/bread-crumb.directive.js +++ b/awx/ui/client/src/bread-crumb/bread-crumb.directive.js @@ -1,7 +1,7 @@ /* jshint unused: vars */ export default - [ 'templateUrl', '$state', function(templateUrl, $state) { + [ 'templateUrl', '$state', 'FeaturesService', function(templateUrl, $state, FeaturesService) { return { restrict: 'E', templateUrl: templateUrl('bread-crumb/bread-crumb'), @@ -32,10 +32,35 @@ export default streamConfig = (toState && toState.data) ? toState.data : {}; if(streamConfig && streamConfig.activityStream) { - scope.showActivityStreamButton = true; + + // Check to see if activity_streams is an enabled feature. $stateChangeSuccess fires + // after the resolve on the state declaration so features should be available at this + // point. We use the get() function call here just in case the features aren't available. + // The get() function will only fire off the server call if the features aren't already + // attached to the $rootScope. + + FeaturesService.get() + .then(function(features) { + if(FeaturesService.featureEnabled('activity_streams')) { + scope.showActivityStreamButton = true; + } + else { + scope.showActivityStreamButton = false; + } + }) + .catch(function (response) { + ProcessErrors(null, response.data, response.status, null, { + hdr: 'Error!', + msg: 'Failed to get feature info. GET returned status: ' + + response.status + }); + }); + } else { + scope.showActivityStreamButton = false; + } }); diff --git a/awx/ui/client/src/shared/features/features.service.js b/awx/ui/client/src/shared/features/features.service.js index 0f2010e59f..f620edd7ee 100644 --- a/awx/ui/client/src/shared/features/features.service.js +++ b/awx/ui/client/src/shared/features/features.service.js @@ -31,6 +31,14 @@ function ($rootScope, Rest, GetBasePath, ProcessErrors, $http, $q) { // as a resovled promise. return $q.when($rootScope.features); } + }, + featureEnabled: function(feature) { + if($rootScope.features && $rootScope.features[feature] && $rootScope.features[feature] == true) { + return true; + } + else { + return false; + } } }; }];