Skip to content

Commit

Permalink
Merge pull request #287 from UKHomeOffice/feature-switches-for-announ…
Browse files Browse the repository at this point in the history
…cements-and-support-requests

Feature flags for announcements and support requests
  • Loading branch information
jits authored Apr 18, 2019
2 parents 9acb00d + c9d22be commit ea07815
Show file tree
Hide file tree
Showing 16 changed files with 506 additions and 255 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ module AnnouncementsProcessorJobTriggerService
extend self

def trigger
if AnnouncementsProcessorJob.is_already_queued?
if !FeatureFlagService.is_enabled?(:announcements)
Rails.logger.info 'Announcements feature flag is turned off... will not trigger announcements processor job'
elsif AnnouncementsProcessorJob.is_already_queued?
Rails.logger.info 'Announcements processor job already in queue... will not trigger another one'
else
Rails.logger.info 'Triggering the announcements processor job'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ def initialize email_batch_size, logger
end

def run
return unless FeatureFlagService.is_enabled?(:announcements)

Announcement.published.awaiting_delivery_or_resend.each(&method(:process))
end

Expand Down
10 changes: 5 additions & 5 deletions platform-hub-api/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
post '/me/agree_terms_of_service', to: 'me#agree_terms_of_service'
post '/me/complete_hub_onboarding', to: 'me#complete_hub_onboarding'
post '/me/complete_services_onboarding', to: 'me#complete_services_onboarding'
post '/me/global_announcements/mark_all_read', to: 'me#global_announcements_mark_all_read'
post '/me/global_announcements/mark_all_read', to: 'me#global_announcements_mark_all_read', constraints: lambda { |_| FeatureFlagService.is_enabled?(:announcements) }
get '/me/kubernetes_tokens', to: 'me#kubernetes_tokens', constraints: lambda { |_| FeatureFlagService.is_enabled?(:kubernetes_tokens) }

resources :feature_flags, only: [ :index ] do
Expand Down 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 All @@ -102,12 +102,12 @@
except: [ :create ],
constraints: { id: ContactList::ID_REGEX_FOR_ROUTES }

resources :announcement_templates do
resources :announcement_templates, constraints: lambda { |_| FeatureFlagService.is_enabled?(:announcements) } do
get :form_field_types, on: :collection
post :preview, on: :collection
end

resources :announcements do
resources :announcements, constraints: lambda { |_| FeatureFlagService.is_enabled?(:announcements) } do
get :global, on: :collection
post :mark_sticky, on: :member
post :unmark_sticky, on: :member
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,84 @@
RSpec.describe AnnouncementTemplatesController, type: :routing do
describe 'routing' do

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

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

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

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

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

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

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

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

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

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

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

it 'routes to #preview' do
expect(:post => '/announcement_templates/preview').to route_to('announcement_templates#preview')
context 'with announcements feature flag disabled' do

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

it 'routes to #index' do
expect(:get => '/announcement_templates').to_not be_routable
end

it 'routes to #show' do
expect(:get => '/announcement_templates/1').to_not be_routable
end

it 'routes to #create' do
expect(:post => '/announcement_templates').to_not be_routable
end

it 'routes to #update via PUT' do
expect(:put => '/announcement_templates/1').to_not be_routable
end

it 'routes to #update via PATCH' do
expect(:patch => '/announcement_templates/1').to_not be_routable
end

it 'routes to #destroy' do
expect(:delete => '/announcement_templates/1').to_not be_routable
end

it 'routes to #form_field_types' do
expect(:get => '/announcement_templates/form_field_types').to_not be_routable
end

it 'routes to #preview' do
expect(:post => '/announcement_templates/preview').to_not be_routable
end

end

end
Expand Down
112 changes: 84 additions & 28 deletions platform-hub-api/spec/routing/announcements_routing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,100 @@
RSpec.describe AnnouncementsController, type: :routing do
describe 'routing' do

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

it 'routes to #global' do
expect(:get => '/announcements/global').to route_to('announcements#global')
end
before do
FeatureFlagService.create_or_update(:announcements, true)
end

it 'routes to #show' do
expect(:get => '/announcements/1').to route_to('announcements#show', :id => '1')
end
it 'routes to #index' do
expect(:get => '/announcements').to route_to('announcements#index')
end

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

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

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

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

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

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

it 'routes to #mark_sticky' do
expect(:post => '/announcements/1/mark_sticky').to route_to('announcements#mark_sticky', :id => '1')
end

it 'routes to #unmark_sticky' do
expect(:post => '/announcements/1/unmark_sticky').to route_to('announcements#unmark_sticky', :id => '1')
end

it 'routes to #resend' do
expect(:post => '/announcements/1/resend').to route_to('announcements#resend', :id => '1')
end

it 'routes to #unmark_sticky' do
expect(:post => '/announcements/1/unmark_sticky').to route_to('announcements#unmark_sticky', :id => '1')
end

it 'routes to #resend' do
expect(:post => '/announcements/1/resend').to route_to('announcements#resend', :id => '1')
context 'with announcements feature flag disabled' do

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

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

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

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

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

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

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

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

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

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

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

end

end
Expand Down
20 changes: 18 additions & 2 deletions platform-hub-api/spec/routing/me_routing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,24 @@
expect(:post => '/me/complete_services_onboarding').to route_to('me#complete_services_onboarding')
end

it 'routes to #global_announcements_mark_all_read' do
expect(:post => '/me/global_announcements/mark_all_read').to route_to('me#global_announcements_mark_all_read')
context 'with announcements feature flag enabled' do
before do
FeatureFlagService.create_or_update(:announcements, true)
end

it 'routes to #global_announcements_mark_all_read' do
expect(:post => '/me/global_announcements/mark_all_read').to route_to('me#global_announcements_mark_all_read')
end
end

context 'with announcements feature flag disabled' do
before do
FeatureFlagService.create_or_update(:announcements, false)
end

it 'route to #global_announcements_mark_all_read is not routable' do
expect(:post => '/me/global_announcements/mark_all_read').to_not be_routable
end
end

context 'with kubernetes_tokens feature flag enabled' do
Expand Down
Loading

0 comments on commit ea07815

Please sign in to comment.