Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
Revert #1926 - Fix partners ability to login to external shops
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanna Chen committed Jan 24, 2022
1 parent f017613 commit c798d99
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ From version 2.6.0, the sections in this file adhere to the [keep a changelog](h

### Fixed
* [#1937](https://github.com/Shopify/shopify-cli/pull/1937): Fix `theme pull` to no longer add empty lines on Windows
* [#1892](): Add `-o`/`--only` parameter to filter files on `theme push`/`theme pull` commands

### Added
* [#1892](https://github.com/Shopify/shopify-cli/pull/1892): Add `-o`/`--only` parameter to filter files on `theme push`/`theme pull` commands
Expand Down
11 changes: 3 additions & 8 deletions lib/shopify_cli/commands/login.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class Login < ShopifyCLI::Command

def call(*)
shop = (options.flags[:shop] || @ctx.getenv("SHOPIFY_SHOP" || nil))
ShopifyCLI::DB.set(shop: self.class.validate_shop(shop, context: @ctx)) unless shop.nil?

if shop.nil? && Shopifolk.check
Shopifolk.reset
@ctx.puts(@ctx.message("core.tasks.select_org_and_shop.identified_as_shopify"))
Expand All @@ -33,23 +35,16 @@ def call(*)
ShopifyCLI::DB.set(organization_id: org["id"].to_i) unless org.nil?

end
# validate that shop belongs to organization
ShopifyCLI::DB.set(shop: self.class.validate_shop(shop: shop, org: org, context: @ctx)) unless shop.nil?
Whoami.call([], "whoami")
end

def self.help
ShopifyCLI::Context.message("core.login.help", ShopifyCLI::TOOL_NAME)
end

def self.validate_shop(shop:, org:, context:)
def self.validate_shop(shop, context:)
permanent_domain = shop_to_permanent_domain(shop)
context.abort(context.message("core.login.invalid_shop", shop)) unless permanent_domain
if org
stores_owned = org["stores"]
is_verified = stores_owned.any? { |store| store["shopDomain"] == permanent_domain }
context.abort(context.message("core.login.invalid_shop", shop)) unless is_verified
end
permanent_domain
end

Expand Down
2 changes: 1 addition & 1 deletion lib/shopify_cli/messages/messages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ module Messages
Usage: {{command:%s login [--store=STORE]}}
HELP
invalid_shop: <<~MESSAGE,
Invalid store provided (%s). Please make sure that the store belongs to your partner organization, and provide the store in the following format: my-store.myshopify.com
Invalid store provided (%s). Please provide the store in the following format: my-store.myshopify.com
MESSAGE
shop_prompt: <<~PROMPT,
What store are you connecting to? (e.g. my-store.myshopify.com; do {{bold:NOT}} include protocol part, e.g., https://)
Expand Down
6 changes: 1 addition & 5 deletions test/shopify-cli/commands/login_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def setup
@stub_org = {
"id" => "1234567",
"businessName" => "Test partner org",
"stores" => [{ "shopDomain" => "testshop.myshopify.io" }],
}
ShopifyCLI::PartnersAPI::Organizations.stubs(:fetch_all).with(@context).returns([@stub_org])
end
Expand Down Expand Up @@ -162,10 +161,7 @@ def test_login_with_shop_flag_bad_storenames
stub_request(:head, "https://#{store}.myshopify.com/admin")
.to_return(status: 404)

auth = mock
auth.expects(:authenticate)
IdentityAuth.expects(:new).with(ctx: @context).returns(auth)
ShopifyCLI::DB.expects(:set).with(organization_id: @stub_org["id"].to_i).once
CLI::UI::Prompt.expects(:ask).never

exception = assert_raises ShopifyCLI::Abort do
run_cmd("login --shop=#{store}")
Expand Down

0 comments on commit c798d99

Please sign in to comment.