Sync feature flag with the outcomes service

closes OUT-3886

flag=account_level_mastery_scales

test plan:
  - test with associated outcome_service patch set
  - provision outcomes service on a canvas account
    not in the default shard
  - go to account settings, then feature options
  - enable the "Account and Course Level Outcome Proficiencies"
    feature option
  - confirm in the outcomes service that the service
    feature flag was also enabled:
    % switch_to_shard! 'host.outcomes.docker'
    > Outcomes.flipper[:context_proficiencies].enabled? Account.default
  - perform same test when disabling the feature option
    in canvas

Change-Id: I267ff4acb12c52ef0897ce738dc4c847ee708926
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/249764
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Michael Brewer-Davis <mbd@instructure.com>
Reviewed-by: Pat Renner <prenner@instructure.com>
QA-Review: Pat Renner <prenner@instructure.com>
Product-Review: Augusto Callejas <acallejas@instructure.com>
This commit is contained in:
Augusto Callejas 2020-10-09 13:07:20 -10:00
parent 8122b4dab6
commit 918ccf42b3
4 changed files with 65 additions and 0 deletions

View File

@ -47,8 +47,32 @@ module OutcomesService
end
end
def toggle_feature_flag(root_account, feature_flag, state)
feature_flag_url = "#{url(root_account)}/api/features/#{state ? 'enable' : 'disable'}"
response = CanvasHttp.post(
feature_flag_url,
headers_for(root_account, 'features.manage'),
form_data: {
feature_flag: feature_flag
}
)
return unless response && response.code != '204'
Canvas::Errors.capture(
"Unexpected response from Outcomes Service toggling feature flag",
status_code: response.code,
body: response.body
)
end
private
def headers_for(context, scope, overrides = {})
{
'Authorization' => OutcomesService::Service.jwt(context, scope, overrides: overrides)
}
end
def settings(context)
context.root_account.settings.dig(:provision, 'outcomes') || {}
end

View File

@ -42,6 +42,7 @@ account_level_mastery_scales:
display_name: Account and Course Level Outcome Proficiencies
description: Allows Account & Course Level mastery scales and calculation,
replacing per-outcome criterion ratings & calculation methods
after_state_change_proc: mastery_scales_after_change_hook
usage_rights_discussion_topics:
state: hidden
applies_to: RootAccount

View File

@ -99,5 +99,23 @@ module FeatureFlags
)
end
end
def self.mastery_scales_after_change_hook(_user, context, _old_state, new_state)
if context.is_a?(Account) && OutcomesService::Service.enabled_in_context?(context)
OutcomesService::Service.send_later_if_production_enqueue_args(
:toggle_feature_flag,
{
priority: Delayed::LOW_PRIORITY,
n_strand: [
'outcomes_service_toggle_context_proficiencies_feature_flag',
context.global_root_account_id
]
},
context.root_account,
'context_proficiencies',
new_state == 'on'
)
end
end
end
end

View File

@ -83,5 +83,27 @@ describe OutcomesService::Service do
)
end
end
describe '.toggle_feature_flag' do
def expect_post(url)
expect(CanvasHttp).to receive(:post).with(
url,
hash_including('Authorization'),
form_data: {
feature_flag: 'fake_flag'
}
)
end
it 'enables feature flag' do
expect_post('http://canvas.test/api/features/enable')
Service.toggle_feature_flag(root_account, 'fake_flag', true)
end
it 'disables feature flag' do
expect_post('http://canvas.test/api/features/disable')
Service.toggle_feature_flag(root_account, 'fake_flag', false)
end
end
end
end