Use AWS data instead of Salesforce territory to activate Heap

We discovered that we didn't need the Salesforce sales territory data to
determine if an account requires GDPR compliance or not. Instead, we can
use the existing billing code data plus the AWS regions.

This removes the previous dependency on Salesforce territory data, adds
the dependency on AWS region codes, and modifies specs and callsites
accordingly.

refs FOO-3253
flag=send_usage_metrics
test plan=specs pass

Change-Id: If8710ec59704eed6a5fbe8e7e007119842c47a11
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/306495
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Xander Moffatt <xmoffatt@instructure.com>
Reviewed-by: Charley Kline <ckline@instructure.com>
QA-Review: Charley Kline <ckline@instructure.com>
Product-Review: Charley Kline <ckline@instructure.com>
This commit is contained in:
Sean Scally 2022-12-02 10:21:52 -08:00
parent 488496ca46
commit 4814f47619
3 changed files with 11 additions and 16 deletions

View File

@ -74,7 +74,7 @@ module FeatureFlags
end end
def self.usage_metrics_allowed_hook(context) def self.usage_metrics_allowed_hook(context)
UsageMetricsPredicate.new(context).call UsageMetricsPredicate.new(context, Shard.current.database_server.config[:region]).call
end end
def self.analytics_2_after_state_change_hook(_user, context, _old_state, _new_state) def self.analytics_2_after_state_change_hook(_user, context, _old_state, _new_state)

View File

@ -20,12 +20,13 @@
module FeatureFlags module FeatureFlags
class UsageMetricsPredicate class UsageMetricsPredicate
def initialize(context) def initialize(context, region)
@context = context @context = context
@region = region
end end
def call def call
overridden? || (us_billing_code? && domestic_territory?) overridden? || (us_billing_code? && in_approved_us_aws_region?)
end end
private private
@ -35,18 +36,11 @@ module FeatureFlags
end end
def us_billing_code? def us_billing_code?
verify_external_integration? "salesforce_billing_country_code", "US" @context&.root_account&.external_integration_keys&.find_by(key_type: "salesforce_billing_country_code")&.key_value == "US"
end end
# Calling out here that `key_type: "salesforce_territory_region")&.key_value == "domestic"` def in_approved_us_aws_region?
# is totally made up right now and won't resolve anything until we add salesforce ["us-east-1", "us-west-2"].include? @region
# data with these values
def domestic_territory?
verify_external_integration? "salesforce_territory_region", "domestic"
end
def verify_external_integration?(key, value)
@context&.root_account&.external_integration_keys&.find_by(key_type: key)&.key_value == value
end end
end end
end end

View File

@ -23,7 +23,8 @@ describe FeatureFlags::UsageMetricsPredicate do
let(:external_integration_keys) { nil } let(:external_integration_keys) { nil }
let(:root_account) { double(settings: settings, external_integration_keys: external_integration_keys) } let(:root_account) { double(settings: settings, external_integration_keys: external_integration_keys) }
let(:context) { double(root_account: root_account) } let(:context) { double(root_account: root_account) }
let(:predicate) { FeatureFlags::UsageMetricsPredicate.new context } let(:region) { nil }
let(:predicate) { FeatureFlags::UsageMetricsPredicate.new context, region }
it "defaults to false" do it "defaults to false" do
expect(predicate.call).to be_falsey expect(predicate.call).to be_falsey
@ -37,13 +38,13 @@ describe FeatureFlags::UsageMetricsPredicate do
end end
end end
describe "when in domestic territory and us billing" do describe "when US billing country and approved US aws region" do
let(:external_integration_keys) do let(:external_integration_keys) do
keys = double keys = double
allow(keys).to receive(:find_by).with({ key_type: "salesforce_billing_country_code" }) { double(key_value: "US") } allow(keys).to receive(:find_by).with({ key_type: "salesforce_billing_country_code" }) { double(key_value: "US") }
allow(keys).to receive(:find_by).with({ key_type: "salesforce_territory_region" }) { double(key_value: "domestic") }
keys keys
end end
let(:region) { "us-east-1" }
it "returns true" do it "returns true" do
expect(predicate.call).to be_truthy expect(predicate.call).to be_truthy