Skip to content

Commit

Permalink
Merge pull request #1658 from Shopify/klenotiw/add-unified-admin
Browse files Browse the repository at this point in the history
Support Unified Admin
  • Loading branch information
klenotiw committed Mar 21, 2023
2 parents 5be04c3 + 03882c8 commit 1f8db98
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Unreleased
----------

* Support Unified Admin [#1658](https://github.com/Shopify/shopify_app/pull/1658)
* Set `access_scopes` column to string by default [#1636](https://github.com/Shopify/shopify_app/pull/1636)

21.4.1 (Feb 21, 2023)
Expand Down
12 changes: 11 additions & 1 deletion lib/shopify_app/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ def sanitize_shop_domain(shop_domain)
no_shop_name_in_subdomain = uri.host == trusted_domain
from_trusted_domain = trusted_domain == uri.domain

return myshopify_domain_from_unified_admin(uri) if unified_admin?(uri) && from_trusted_domain
return nil if no_shop_name_in_subdomain || uri.host&.empty?
return uri.host if from_trusted_domain
end

nil
end

Expand Down Expand Up @@ -65,6 +65,16 @@ def uri_from_shop_domain(shop_domain)
rescue Addressable::URI::InvalidURIError
nil
end

def unified_admin?(uri)
uri.host.split(".").first == "admin"
end

def myshopify_domain_from_unified_admin(uri)
shop = uri.path.split("/").last

"#{shop}.myshopify.com"
end
end
end
end
10 changes: 10 additions & 0 deletions test/shopify_app/utils_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ class UtilsTest < ActiveSupport::TestCase
assert ShopifyApp::Utils.sanitize_shop_domain("some-shoppe-over-the-rainbow.myshopify.io")
end

test "convert unified admin to old domain" do
trailing_forward_slash_url = "https://admin.shopify.com/store/store-name/"
unified_admin_url = "https://admin.shopify.com/store/store-name"

expected = "store-name.myshopify.com"

assert_equal expected, ShopifyApp::Utils.sanitize_shop_domain(trailing_forward_slash_url)
assert_equal expected, ShopifyApp::Utils.sanitize_shop_domain(unified_admin_url)
end

["myshop.com", "myshopify.com", "shopify.com", "two words", "store.myshopify.com.evil.com",
"/foo/bar", "foo.myshopify.io.evil.ru",].each do |bad_url|
test "sanitize_shop_domain for a non-myshopify URL (#{bad_url})" do
Expand Down

0 comments on commit 1f8db98

Please sign in to comment.