add lti variable expansion for usage metrics

why:
* internal LTI tools can key off the Canvas feature flag

refs INTEROP-7810
flag=none

test plan:
* with the flag off
* update an existing ContextExternalTool in a rails console, or install
a new tool with this variable expansion:
`metrics=$com.instructure.Account.usage_metrics_enabled`
* launch the tool
* that custom variable should have expanded to `false`
* enable the flag with
`Account.site_admin.enable_feature! :send_usage_metrics`
* launch the tool again (may require a rails cache clear)
* that custom variable should have expanded to `true`

Change-Id: I80b62acec34eeefc0be3bde30bee8e1f341b5e26
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/305701
QA-Review: Evan Battaglia <ebattaglia@instructure.com>
Reviewed-by: Jacob Burroughs <jburroughs@instructure.com>
Product-Review: Evan Battaglia <ebattaglia@instructure.com>
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
This commit is contained in:
Xander Moffatt 2022-11-17 15:48:55 -07:00 committed by Evan Battaglia
parent 9d3f968718
commit eb8952e49b
3 changed files with 39 additions and 0 deletions

View File

@ -1501,3 +1501,10 @@ in Canvas-side GET request that triggers the LTI launch.
```
[{"id":"3","name":"First Module"},{"id":"5","name":"Second Module"}]
```
## com.instructure.Account.usage_metrics_enabled
**Availability**: *always*

View File

@ -1691,6 +1691,11 @@ module Lti
val&.to_json
}
register_expansion "com.instructure.Account.usage_metrics_enabled", [],
lambda {
@root_account.feature_enabled?(:send_usage_metrics)
}
private
def unique_submission_dates

View File

@ -464,6 +464,33 @@ module Lti
end
end
context "com.instructure.Account.usage_metrics_enabled" do
subject { variable_expander.expand_variables!(exp_hash) }
let(:exp_hash) { { test: "$com.instructure.Account.usage_metrics_enabled" } }
context "when flag is disabled" do
before do
root_account.disable_feature! :send_usage_metrics
end
it "expands to false" do
expect(subject[:test]).to eq false
end
end
context "when flag is enabled and account allows it" do
before do
root_account.settings[:enable_usage_metrics] = true
root_account.enable_feature! :send_usage_metrics
end
it "expands to true" do
expect(subject[:test]).to eq true
end
end
end
it "has a substitution for com.instructure.Assignment.lti.id" do
exp_hash = { test: "$com.instructure.Assignment.lti.id" }
variable_expander.expand_variables!(exp_hash)