Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration option for user access scopes strategy #1599

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Unreleased
----------
* Add configuration option for user access strategy [#1599](https://github.com/Shopify/shopify_app/pull/1599)
* Fixes a bug with `EnsureAuthenticatedLinks` causing deep links to not work [#1549](https://github.com/Shopify/shopify_app/pull/1549)
* Ensure online token is properly used when using `current_shopify_session` [#1566](https://github.com/Shopify/shopify_app/pull/1566)
* Added debug logs, you can read more about logging [here](./docs/logging.md). [#1545](https://github.com/Shopify/shopify_app/pull/1545)
Expand Down
10 changes: 10 additions & 0 deletions lib/shopify_app/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,17 @@ def shop_access_scopes_strategy
ShopifyApp::AccessScopes::ShopStrategy
end

def user_access_scopes_strategy=(class_name)
unless class_name.is_a?(String)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a string to be consistent with user_session_repository and shop_session_repository.

raise ConfigurationError, "Invalid user access scopes strategy - expected a string"
end

@user_access_scopes_strategy = class_name.safe_constantize
end

def user_access_scopes_strategy
return @user_access_scopes_strategy if @user_access_scopes_strategy

return ShopifyApp::AccessScopes::NoopStrategy unless reauth_on_access_scope_changes

ShopifyApp::AccessScopes::UserStrategy
Expand Down
19 changes: 19 additions & 0 deletions test/shopify_app/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,23 @@ class ConfigurationTest < ActiveSupport::TestCase
assert_equal ShopifyApp::AccessScopes::ShopStrategy, ShopifyApp.configuration.shop_access_scopes_strategy
assert_equal ShopifyApp::AccessScopes::UserStrategy, ShopifyApp.configuration.user_access_scopes_strategy
end

test "user access scopes strategy is configurable with a string" do
my_strategy = "Object"
ShopifyApp.configure do |config|
config.user_access_scopes_strategy = my_strategy

This comment was marked as resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use a string.

end

assert_equal ShopifyApp::AccessScopes::NoopStrategy, ShopifyApp.configuration.shop_access_scopes_strategy
assert_equal Object, ShopifyApp.configuration.user_access_scopes_strategy
end

test "user access scopes strategy is not configurable with a constant" do
error = assert_raises ShopifyApp::ConfigurationError do
ShopifyApp.configure do |config|
config.user_access_scopes_strategy = Object
end
end
assert_equal "Invalid user access scopes strategy - expected a string", error.message
end
end