Skip to content

Commit

Permalink
Feature flag for Support Requests
Browse files Browse the repository at this point in the history
  • Loading branch information
jits committed Apr 17, 2019
1 parent 9acb00d commit ee8c249
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 39 deletions.
4 changes: 2 additions & 2 deletions platform-hub-api/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@
end
end

resources :support_request_templates do
resources :support_request_templates, constraints: lambda { |request| FeatureFlagService.is_enabled?(:support_requests) } do
get :form_field_types, on: :collection
get :git_hub_repos, on: :collection
end

resources :support_requests, only: [ :create ]
resources :support_requests, only: [ :create ], constraints: lambda { |request| FeatureFlagService.is_enabled?(:support_requests) }

resources :platform_themes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,84 @@
RSpec.describe SupportRequestTemplatesController, type: :routing do
describe 'routing' do

it 'routes to #index' do
expect(:get => '/support_request_templates').to route_to('support_request_templates#index')
end
context 'with support_requests feature flag enabled' do

it 'routes to #show' do
expect(:get => '/support_request_templates/1').to route_to('support_request_templates#show', :id => '1')
end
before do
FeatureFlagService.create_or_update(:support_requests, true)
end

it 'routes to #create' do
expect(:post => '/support_request_templates').to route_to('support_request_templates#create')
end
it 'routes to #index' do
expect(:get => '/support_request_templates').to route_to('support_request_templates#index')
end

it 'routes to #update via PUT' do
expect(:put => '/support_request_templates/1').to route_to('support_request_templates#update', :id => '1')
end
it 'routes to #show' do
expect(:get => '/support_request_templates/1').to route_to('support_request_templates#show', :id => '1')
end

it 'routes to #update via PATCH' do
expect(:patch => '/support_request_templates/1').to route_to('support_request_templates#update', :id => '1')
end
it 'routes to #create' do
expect(:post => '/support_request_templates').to route_to('support_request_templates#create')
end

it 'routes to #destroy' do
expect(:delete => '/support_request_templates/1').to route_to('support_request_templates#destroy', :id => '1')
end
it 'routes to #update via PUT' do
expect(:put => '/support_request_templates/1').to route_to('support_request_templates#update', :id => '1')
end

it 'routes to #update via PATCH' do
expect(:patch => '/support_request_templates/1').to route_to('support_request_templates#update', :id => '1')
end

it 'routes to #destroy' do
expect(:delete => '/support_request_templates/1').to route_to('support_request_templates#destroy', :id => '1')
end

it 'routes to #form_field_types' do
expect(:get => '/support_request_templates/form_field_types').to route_to('support_request_templates#form_field_types')
end

it 'routes to #git_hub_repos' do
expect(:get => '/support_request_templates/git_hub_repos').to route_to('support_request_templates#git_hub_repos')
end

it 'routes to #form_field_types' do
expect(:get => '/support_request_templates/form_field_types').to route_to('support_request_templates#form_field_types')
end

it 'routes to #git_hub_repos' do
expect(:get => '/support_request_templates/git_hub_repos').to route_to('support_request_templates#git_hub_repos')
context 'with support_requests feature flag disabled' do

before do
FeatureFlagService.create_or_update(:support_requests, false)
end

it 'route to #index is not routable' do
expect(:get => '/support_request_templates').to_not be_routable
end

it 'route to #show is not routable' do
expect(:get => '/support_request_templates/1').to_not be_routable
end

it 'route to #create is not routable' do
expect(:post => '/support_request_templates').to_not be_routable
end

it 'route to #update via PUT is not routable' do
expect(:put => '/support_request_templates/1').to_not be_routable
end

it 'route to #update via PATCH is not routable' do
expect(:patch => '/support_request_templates/1').to_not be_routable
end

it 'route to #destroy is not routable' do
expect(:delete => '/support_request_templates/1').to_not be_routable
end

it 'route to #form_field_types is not routable' do
expect(:get => '/support_request_templates/form_field_types').to_not be_routable
end

it 'route to #git_hub_repos is not routable' do
expect(:get => '/support_request_templates/git_hub_repos').to_not be_routable
end

end

end
Expand Down
24 changes: 22 additions & 2 deletions platform-hub-api/spec/routing/support_requests_routing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,28 @@
RSpec.describe SupportRequestsController, type: :routing do
describe 'routing' do

it 'routes to #create' do
expect(:post => '/support_requests').to route_to('support_requests#create')
context 'with support_requests feature flag enabled' do

before do
FeatureFlagService.create_or_update(:support_requests, true)
end

it 'routes to #create' do
expect(:post => '/support_requests').to route_to('support_requests#create')
end

end

context 'with support_requests feature flag disabled' do

before do
FeatureFlagService.create_or_update(:support_requests, false)
end

it 'route to #create is not routable' do
expect(:post => '/support_requests').to_not be_routable
end

end

end
Expand Down
3 changes: 2 additions & 1 deletion platform-hub-web/src/app/app.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ angular
kubernetesTokens: 'kubernetes_tokens',
kubernetesTokensEscalatePrivilege: 'kubernetes_tokens_escalate_privilege',
kubernetesTokensSync: 'kubernetes_tokens_sync',
projects: 'projects'
projects: 'projects',
supportRequests: 'support_requests'
});

// Run function
Expand Down
10 changes: 8 additions & 2 deletions platform-hub-web/src/app/app.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,8 @@ export const appRoutes = function ($stateProvider, $urlRouterProvider, $location
url: '/overview',
component: SupportRequestsOverview,
data: {
authenticate: true
authenticate: true,
featureFlags: [featureFlagKeys.supportRequests]
}
})
.state('help.support.requests.new', {
Expand All @@ -559,7 +560,8 @@ export const appRoutes = function ($stateProvider, $urlRouterProvider, $location
transition: '$transition$'
},
data: {
authenticate: true
authenticate: true,
featureFlags: [featureFlagKeys.supportRequests]
}
})
.state('help.support.request-templates', {
Expand All @@ -572,6 +574,7 @@ export const appRoutes = function ($stateProvider, $urlRouterProvider, $location
component: SupportRequestTemplatesList,
data: {
authenticate: true,
featureFlags: [featureFlagKeys.supportRequests],
rolesPermitted: ['admin']
}
})
Expand All @@ -583,6 +586,7 @@ export const appRoutes = function ($stateProvider, $urlRouterProvider, $location
},
data: {
authenticate: true,
featureFlags: [featureFlagKeys.supportRequests],
rolesPermitted: ['admin']
}
})
Expand All @@ -591,6 +595,7 @@ export const appRoutes = function ($stateProvider, $urlRouterProvider, $location
component: SupportRequestTemplatesForm,
data: {
authenticate: true,
featureFlags: [featureFlagKeys.supportRequests],
rolesPermitted: ['admin']
}
})
Expand All @@ -602,6 +607,7 @@ export const appRoutes = function ($stateProvider, $urlRouterProvider, $location
},
data: {
authenticate: true,
featureFlags: [featureFlagKeys.supportRequests],
rolesPermitted: ['admin']
}
})
Expand Down
4 changes: 2 additions & 2 deletions platform-hub-web/src/app/help/faq/faq-entries.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
Both the <a ui-sref="home">homepage</a> and the side nav bar contain <em>platform themes</em> – these are related groups of information, and links to docs and resources, that you may find useful when navigating the platform and figuring out how to perform certain tasks.
</p>

<p class="md-body-1">
<p class="md-body-1" ng-if="$ctrl.FeatureFlags.isEnabled($ctrl.featureFlagKeys.supportRequests)">
If you can't achieve what you need via these links or self-serve on the Hub (see FAQs below for more on self-serve) then you can request support from the {{$ctrl.AppSettings.getPlatformName()}} team by filling in
<a ui-sref="help.support.requests.overview">one of the available support request forms</a>.
</p>
Expand Down Expand Up @@ -110,7 +110,7 @@
</li>
</ul>
</li>
<li>
<li ng-if="$ctrl.FeatureFlags.isEnabled($ctrl.featureFlagKeys.supportRequests)">
You can <a ui-sref="help.support.requests.overview">make a support request</a>
</li>
</ul>
Expand Down
15 changes: 12 additions & 3 deletions platform-hub-web/src/app/help/search/search.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ export const SearchComponent = {
controller: SearchController
};

function SearchController($q, $state, $sce, hubApiService, PinnedHelpEntries, roleCheckerService, icons, _) {
function SearchController($q, $state, $sce, hubApiService, FeatureFlags, featureFlagKeys, PinnedHelpEntries, roleCheckerService, icons, _) {
'ngInject';

const ctrl = this;

ctrl.query = ctrl.transition && ctrl.transition.params().q;

ctrl.FeatureFlags = FeatureFlags;
ctrl.featureFlagKeys = featureFlagKeys;

ctrl.supportRequestsIcon = icons.supportRequests;
ctrl.qaEntriesIcon = icons.qaEntries;
ctrl.docsIcon = icons.docs;
Expand Down Expand Up @@ -84,7 +87,7 @@ function SearchController($q, $state, $sce, hubApiService, PinnedHelpEntries, ro
return hubApiService
.helpSearch(params)
.then(results => {
ctrl.results = processResults(results);
ctrl.results = filterResults(processResults(results));
ctrl.initialState = false;
})
.finally(() => {
Expand All @@ -96,7 +99,7 @@ function SearchController($q, $state, $sce, hubApiService, PinnedHelpEntries, ro
return PinnedHelpEntries
.get()
.then(items => {
angular.copy(items, ctrl.results);
angular.copy(filterResults(items), ctrl.results);
});
}

Expand Down Expand Up @@ -124,6 +127,12 @@ function SearchController($q, $state, $sce, hubApiService, PinnedHelpEntries, ro
});
}

function filterResults(results) {
return results.filter(r => {
return r.type !== 'support-request' || ctrl.FeatureFlags.isEnabled(ctrl.featureFlagKeys.supportRequests);
});
}

function hideSearchQueryStat(query) {
return hubApiService
.hideHelpSearchQueryStat({q: query})
Expand Down
6 changes: 4 additions & 2 deletions platform-hub-web/src/app/layout/shell.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ function ShellController($scope, $mdSidenav, authService, roleCheckerService, ev
title: 'Support Requests',
state: 'help.support.requests.overview',
activeState: 'help.support.requests',
icon: icons.supportRequests
icon: icons.supportRequests,
featureFlags: [featureFlagKeys.supportRequests]
},
{
title: 'About the Hub',
Expand Down Expand Up @@ -154,7 +155,8 @@ function ShellController($scope, $mdSidenav, authService, roleCheckerService, ev
title: 'Support Request Templates',
state: 'help.support.request-templates.list',
activeState: 'help.support.request-templates',
icon: icons.supportRequests
icon: icons.supportRequests,
featureFlags: [featureFlagKeys.supportRequests]
},
{
title: 'Contact Lists',
Expand Down
5 changes: 4 additions & 1 deletion platform-hub-web/src/app/layout/shell.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ <h1 flex>{{$ctrl.AppSettings.getAppTitle()}}</h1>
</md-sidemenu-group>

<md-sidemenu-group ng-if="$ctrl.shouldShowSection($ctrl.helpNavStates)">
<md-subheader class="md-no-sticky">Help &amp; Support</md-subheader>
<md-subheader class="md-no-sticky">
Help
<span ng-if="$ctrl.FeatureFlags.isEnabled($ctrl.featureFlagKeys.supportRequests)"> &amp; Support</span>
</md-subheader>

<md-sidemenu-button
ng-repeat="item in $ctrl.helpNavStates"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ export const PlatformThemesPageComponent = {
controller: PlatformThemesPageController
};

function PlatformThemesPageController(hubApiService, icons, UserScopes, _) {
function PlatformThemesPageController(hubApiService, icons, FeatureFlags, featureFlagKeys, UserScopes, _) {
'ngInject';

const ctrl = this;

const id = ctrl.transition.params().id;

ctrl.FeatureFlags = FeatureFlags;
ctrl.featureFlagKeys = featureFlagKeys;

ctrl.icons = {
internal_route: icons.internalLink,
external_link: icons.externalLink,
Expand Down Expand Up @@ -53,6 +56,7 @@ function PlatformThemesPageController(hubApiService, icons, UserScopes, _) {
}

function resourceIsVisible(resource) {
return resource.visible && UserScopes.isVisibleToCurrentUser(resource.user_scope);
const enabled = resource.kind !== 'support_request' || ctrl.FeatureFlags.isEnabled(ctrl.featureFlagKeys.supportRequests);
return enabled && resource.visible && UserScopes.isVisibleToCurrentUser(resource.user_scope);
}
}

0 comments on commit ee8c249

Please sign in to comment.