Skip to content

Commit

Permalink
Separate service open feature flags
Browse files Browse the repository at this point in the history
We have a single feature flag controlling access to 3 different apps,
which makes releasing them separately impossible.

There is no reason for them to share a single feature flag so I'm
introducing 2 extra flags to give us the granularity we want.

Each service, Check + Quals, will have a unique feature flag to control
opening the service up to the public. Also, there is now a separate
feature flag for the support interface too.
  • Loading branch information
felixclack committed Dec 4, 2023
1 parent 170a13c commit 4453105
Show file tree
Hide file tree
Showing 31 changed files with 71 additions and 39 deletions.
6 changes: 0 additions & 6 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ class ApplicationController < ActionController::Base
include DfE::Analytics::Requests
default_form_builder(GOVUKDesignSystemFormBuilder::FormBuilder)

http_basic_authenticate_with(
name: ENV.fetch("SUPPORT_USERNAME", nil),
password: ENV.fetch("SUPPORT_PASSWORD", nil),
unless: -> { FeatureFlags::FeatureFlag.active?("service_open") }
)

def trigger_request_event
return unless DfE::Analytics.enabled?

Expand Down
6 changes: 6 additions & 0 deletions app/controllers/check_records/check_records_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ class CheckRecordsController < ApplicationController
before_action :authenticate_dsi_user!
before_action :handle_expired_session!

http_basic_authenticate_with(
name: ENV.fetch("SUPPORT_USERNAME", nil),
password: ENV.fetch("SUPPORT_PASSWORD", nil),
unless: -> { FeatureFlags::FeatureFlag.active?("check_service_open") }
)

layout "check_records_layout"

def current_dsi_user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ class QualificationsInterfaceController < ApplicationController
before_action :authenticate_user!
before_action :handle_expired_token!

http_basic_authenticate_with(
name: ENV.fetch("SUPPORT_USERNAME", nil),
password: ENV.fetch("SUPPORT_PASSWORD", nil),
unless: -> { FeatureFlags::FeatureFlag.active?("qualifications_service_open") }
)

layout "qualifications_layout"

def current_user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ module SupportInterface
class SupportInterfaceController < ApplicationController
include SupportNamespaceable

http_basic_authenticate_with(
name: ENV.fetch("SUPPORT_USERNAME", nil),
password: ENV.fetch("SUPPORT_PASSWORD", nil),
unless: -> { FeatureFlags::FeatureFlag.active?("support_service_open") }
)

layout "support_layout"

before_action :authenticate_staff!
Expand Down
23 changes: 17 additions & 6 deletions config/feature_flags.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
layout: support_layout
parent_controller: "SupportInterface::SupportInterfaceController"
feature_flags:
service_open:
check_service_open:
author: Felix Clack
description: Remove the basic authentication when accessing the main
website. Keeps it in place for the support interface. This flag should
always be inactive on non-production deployments, to prevent accidental
access by members of the public. Once the service goes live, this flag
should always be active on production.
description: Remove the basic authentication when accessing Check a teacher's
record. This flag should always be inactive on non-production deployments,
to prevent accidental access by members of the public. Once the service
goes live, this flag should always be active on production.
qualifications_service_open:
author: Felix Clack
description: Remove the basic authentication when accessing AYTQ.
This flag should always be inactive on non-production deployments, to
prevent accidental access by members of the public. Once the service goes
live, this flag should always be active on production.
support_service_open:
author: Felix Clack
description: Remove the basic authentication when accessing the support
interface. This flag should always be inactive on non-production
deployments, to prevent accidental access by members of the public.
Once the service goes live, this flag should always be active on production.
staff_http_basic_auth:
author: Felix Clack
description: Allow signing in as a staff user using HTTP Basic
Expand Down
12 changes: 10 additions & 2 deletions spec/support/system/activate_features_steps.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
module ActivateFeaturesSteps
def given_the_service_is_open
FeatureFlags::FeatureFlag.activate(:service_open)
def given_the_check_service_is_open
FeatureFlags::FeatureFlag.activate(:check_service_open)
end

def given_the_qualifications_service_is_open
FeatureFlags::FeatureFlag.activate(:qualifications_service_open)
end

def given_the_support_service_is_open
FeatureFlags::FeatureFlag.activate(:support_service_open)
end

def and_staff_http_basic_is_active
Expand Down
2 changes: 1 addition & 1 deletion spec/system/check_records/user_gives_feedback_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
include CheckRecords::AuthenticationSteps

scenario "User gives feedback", test: :with_stubbed_auth do
given_the_service_is_open
given_the_check_service_is_open
when_i_sign_in_via_dsi
and_i_click_on_feedback
then_i_see_the_feedback_form
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

scenario "User searches with a last name and date of birth and finds a restricted record",
test: %i[with_stubbed_auth with_fake_quals_api] do
given_the_service_is_open
given_the_check_service_is_open
when_i_sign_in_via_dsi
and_search_returns_a_restricted_record
then_i_see_the_restriction_on_the_result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

scenario "User tries to view a teacher with invalid TRN",
test: %i[with_stubbed_auth with_fake_quals_api] do
given_the_service_is_open
given_the_check_service_is_open
when_i_sign_in_via_dsi
and_view_a_teacher_with_an_invalid_trn
then_i_see_a_not_found_page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

scenario "User searches with invalid values and sees errors",
test: %i[with_stubbed_auth with_fake_quals_api] do
given_the_service_is_open
given_the_check_service_is_open
when_i_sign_in_via_dsi
and_press_find_record
then_i_see_the_error_summary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

scenario "User searches with a last name and date of birth and finds no matches",
test: %i[with_stubbed_auth with_fake_quals_api] do
given_the_service_is_open
given_the_check_service_is_open
when_i_sign_in_via_dsi
and_search_returns_no_records
then_i_see_no_records
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

scenario "User searches with a last name and date of birth and finds a record",
test: %i[with_stubbed_auth with_fake_quals_api] do
given_the_service_is_open
given_the_check_service_is_open
when_i_sign_in_via_dsi
and_search_with_a_valid_name_and_dob
then_i_see_a_teacher_record_in_the_results
Expand Down
2 changes: 1 addition & 1 deletion spec/system/check_records/user_session_expires_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
after { travel_back }

scenario "Session expires", test: :with_stubbed_auth do
given_the_service_is_open
given_the_check_service_is_open
and_i_am_signed_in_via_dsi
and_my_session_expires
when_i_refresh_the_page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
include CommonSteps

scenario "User views Check records homepage" do
given_the_service_is_open
given_the_check_service_is_open
when_i_visit_the_check_records_homepage
then_i_see_the_check_records_nav
and_event_tracking_is_working
Expand Down
2 changes: 1 addition & 1 deletion spec/system/qualifications/start_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
include CommonSteps

scenario "when a user views the start page", test: :with_stubbed_auth do
given_the_service_is_open
given_the_qualifications_service_is_open

when_i_visit_the_qualifications_start_page
then_i_see_the_start_page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
include QualificationAuthenticationSteps

scenario "User signs in via Identity", test: %i[with_stubbed_auth with_fake_quals_api] do
given_the_service_is_open
given_the_qualifications_service_is_open
and_identity_auth_is_mocked
when_i_go_to_the_sign_in_page
and_click_the_sign_in_button
Expand Down
2 changes: 1 addition & 1 deletion spec/system/qualifications/user_signs_out_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
include QualificationAuthenticationSteps

scenario "User signs out", test: %i[with_stubbed_auth with_fake_quals_api] do
given_the_service_is_open
given_the_qualifications_service_is_open
and_identity_auth_is_mocked
and_i_am_signed_in_via_identity
when_i_click_the_sign_out_link
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

scenario "Access token expires while viewing qualifications",
test: %i[with_stubbed_auth with_fake_quals_api] do
given_the_service_is_open
given_the_qualifications_service_is_open
and_i_am_signed_in_via_identity

when_i_visit_the_qualifications_page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

scenario "when a certificate is missing",
test: %i[with_stubbed_auth with_fake_quals_api] do
given_the_service_is_open
given_the_qualifications_service_is_open
and_i_am_signed_in_via_identity

when_i_visit_the_qualifications_page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
include QualificationAuthenticationSteps

scenario "User updates their details", test: %i[with_stubbed_auth with_fake_quals_api] do
given_the_service_is_open
given_the_qualifications_service_is_open
and_i_am_signed_in_via_identity
when_i_visit_view_and_update_details
then_i_see_the_landing_page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"User views qualifications with missing data",
test: %i[with_stubbed_auth with_fake_quals_api]
) do
given_the_service_is_open
given_the_qualifications_service_is_open
and_i_am_signed_in_via_identity_as_a_user_with_partial_quals_data

when_i_visit_the_qualifications_page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

scenario "The details are retrieved from the API",
test: %i[with_stubbed_auth with_fake_quals_api] do
given_the_service_is_open
given_the_qualifications_service_is_open
and_i_am_signed_in_via_identity
then_i_see_my_details_as_returned_by_the_api
and_event_tracking_is_working
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
include QualificationAuthenticationSteps

scenario "when they have no ITT", test: %i[with_stubbed_auth with_fake_quals_api] do
given_the_service_is_open
given_the_qualifications_service_is_open
and_i_am_signed_in_via_identity

when_i_visit_the_qualifications_page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

scenario "when they have qualifications",
test: %i[with_stubbed_auth with_fake_quals_api] do
given_the_service_is_open
given_the_qualifications_service_is_open
and_i_am_signed_in_via_identity

when_i_visit_the_qualifications_page
Expand Down
2 changes: 1 addition & 1 deletion spec/system/support/basic_auth_user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
include CommonSteps

scenario "Access is restricted by basic auth", type: :system do
given_the_service_is_open
given_the_support_service_is_open
and_staff_http_basic_is_active

when_i_visit_the_support_interface
Expand Down
2 changes: 1 addition & 1 deletion spec/system/support/staff_change_password_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
include CommonSteps

scenario "Staff changes password" do
given_the_service_is_open
given_the_support_service_is_open
and_a_staff_user_exists

when_i_visit_the_staff_page
Expand Down
2 changes: 1 addition & 1 deletion spec/system/support/staff_http_flag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
include CommonSteps

scenario "Feature flag is disabled and no Staff accounts exist" do
given_the_service_is_open
given_the_support_service_is_open

when_i_visit_the_support_interface
then_i_am_unauthorized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
include CommonSteps

scenario "Initial support user invites Staff" do
given_the_service_is_open
given_the_support_service_is_open
and_staff_http_basic_is_active

when_i_am_authorized_with_basic_auth
Expand Down
2 changes: 1 addition & 1 deletion spec/system/support/staff_invite_as_staff_member_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
include CommonSteps

scenario "Staff user invites another Staff member" do
given_the_service_is_open
given_the_support_service_is_open
and_a_staff_member_exists
and_i_am_logged_in_as_a_staff_member
when_i_visit_the_staff_page
Expand Down
2 changes: 1 addition & 1 deletion spec/system/support/staff_login_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
include CommonSteps

scenario "Staff user logs in" do
given_the_service_is_open
given_the_support_service_is_open
and_a_staff_user_exists
when_i_visit_the_support_interface
then_i_see_the_staff_login_page
Expand Down
3 changes: 2 additions & 1 deletion spec/system/support/staff_sign_out_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
include CommonSteps

scenario "Staff user signs out" do
given_the_service_is_open
given_the_support_service_is_open
given_the_qualifications_service_is_open
and_a_staff_user_exists
when_i_visit_the_support_interface
then_i_see_the_staff_login_page
Expand Down

0 comments on commit 4453105

Please sign in to comment.