diff --git a/lib/feature_flags/hooks.rb b/lib/feature_flags/hooks.rb index cbe30afe06e..8cc5ec4c6af 100644 --- a/lib/feature_flags/hooks.rb +++ b/lib/feature_flags/hooks.rb @@ -74,7 +74,7 @@ module FeatureFlags end def self.usage_metrics_allowed_hook(context) - UsageMetricsPredicate.new(context).call + UsageMetricsPredicate.new(context, Shard.current.database_server.config[:region]).call end def self.analytics_2_after_state_change_hook(_user, context, _old_state, _new_state) diff --git a/lib/feature_flags/usage_metrics_predicate.rb b/lib/feature_flags/usage_metrics_predicate.rb index 816fc12fcfd..bbe9ac089c1 100644 --- a/lib/feature_flags/usage_metrics_predicate.rb +++ b/lib/feature_flags/usage_metrics_predicate.rb @@ -20,12 +20,13 @@ module FeatureFlags class UsageMetricsPredicate - def initialize(context) + def initialize(context, region) @context = context + @region = region end def call - overridden? || (us_billing_code? && domestic_territory?) + overridden? || (us_billing_code? && in_approved_us_aws_region?) end private @@ -35,18 +36,11 @@ module FeatureFlags end 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 - # Calling out here that `key_type: "salesforce_territory_region")&.key_value == "domestic"` - # is totally made up right now and won't resolve anything until we add salesforce - # 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 + def in_approved_us_aws_region? + ["us-east-1", "us-west-2"].include? @region end end end diff --git a/spec/lib/feature_flags/usage_metrics_predicate_spec.rb b/spec/lib/feature_flags/usage_metrics_predicate_spec.rb index e5a167a64be..b9c3c31379e 100644 --- a/spec/lib/feature_flags/usage_metrics_predicate_spec.rb +++ b/spec/lib/feature_flags/usage_metrics_predicate_spec.rb @@ -23,7 +23,8 @@ describe FeatureFlags::UsageMetricsPredicate do let(:external_integration_keys) { nil } let(:root_account) { double(settings: settings, external_integration_keys: external_integration_keys) } 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 expect(predicate.call).to be_falsey @@ -37,13 +38,13 @@ describe FeatureFlags::UsageMetricsPredicate do 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 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_territory_region" }) { double(key_value: "domestic") } keys end + let(:region) { "us-east-1" } it "returns true" do expect(predicate.call).to be_truthy