From 6d13a265ff487843945e418729882081dec865e4 Mon Sep 17 00:00:00 2001 From: Nelson Wittwer Date: Tue, 5 Mar 2024 15:32:12 -0500 Subject: [PATCH 1/2] remove deprecated controller concerns --- .../concerns/shopify_app/authenticated.rb | 17 --- .../shopify_app/require_known_shop.rb | 16 --- docs/Upgrading.md | 18 ++- .../concerns/authenticated_test.rb | 35 ------ .../concerns/require_known_shop_test.rb | 117 ------------------ 5 files changed, 17 insertions(+), 186 deletions(-) delete mode 100644 app/controllers/concerns/shopify_app/authenticated.rb delete mode 100644 app/controllers/concerns/shopify_app/require_known_shop.rb delete mode 100644 test/controllers/concerns/authenticated_test.rb delete mode 100644 test/controllers/concerns/require_known_shop_test.rb diff --git a/app/controllers/concerns/shopify_app/authenticated.rb b/app/controllers/concerns/shopify_app/authenticated.rb deleted file mode 100644 index 9743f447c..000000000 --- a/app/controllers/concerns/shopify_app/authenticated.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -module ShopifyApp - module Authenticated - extend ActiveSupport::Concern - - included do - ShopifyApp::Logger.deprecated( - "Authenticated has been replaced by EnsureHasSession."\ - " Please use the EnsureHasSession controller concern for the same behavior", - "22.0.0", - ) - end - - include ShopifyApp::EnsureHasSession - end -end diff --git a/app/controllers/concerns/shopify_app/require_known_shop.rb b/app/controllers/concerns/shopify_app/require_known_shop.rb deleted file mode 100644 index 7aced050c..000000000 --- a/app/controllers/concerns/shopify_app/require_known_shop.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -module ShopifyApp - module RequireKnownShop - extend ActiveSupport::Concern - include ShopifyApp::EnsureInstalled - - included do - ShopifyApp::Logger.deprecated( - "RequireKnownShop has been replaced by EnsureInstalled."\ - " Please use the EnsureInstalled controller concern for the same behavior", - "22.0.0", - ) - end - end -end diff --git a/docs/Upgrading.md b/docs/Upgrading.md index 754909ee7..662b8e021 100644 --- a/docs/Upgrading.md +++ b/docs/Upgrading.md @@ -8,6 +8,8 @@ This file documents important changes needed to upgrade your app's Shopify App v [Unreleased](#unreleased) +[Upgrading to `v22.0.0`](#upgrading-to-v2020) + [Upgrading to `v20.3.0`](#upgrading-to-v2030) [Upgrading to `v20.2.0`](#upgrading-to-v2020) @@ -38,8 +40,22 @@ We also recommend the use of a staging site which matches your production enviro If you do run into issues, we recommend looking at our [debugging tips.](https://github.com/Shopify/shopify_app/blob/main/docs/Troubleshooting.md#debugging-tips) +## Upgrading to `v22.0.0` +#### Dropped support for Ruby 2.x +Support for Ruby 2.x has been dropped as it is no longer supported. You'll need to upgrade to 3.x.x + +#### Renamed Controller Concerns +The following controller concerns have been renamed/replaced in `v21.10.0` and have now been removed. To upgrade, please rename any usage in your apps's controllers that include them to the following: + +|Old Deprecated Controller Concern |Replaced By New Controller Concern| +|---|---| +|`Authenticated`|`EnsureHasSession`| +|`RequireKnownShop`|`EnsureInstalled`| + +The new names better reflect what assurances the including the controller concern provide. The new concern provide similar if not identical functionality as the concerns they replaced. + ## Upgrading to 21.3.0 -The `Itp` controller concern has been removed from `LoginProtection` which is included by the `Authenticated` controller concern. +The `Itp` controller concern has been removed from `LoginProtection` which is included by the `Authenticated`/`EnsureHasSession` controller concern. If any of your controllers are dependant on methods from `Itp` then you can include `ShopifyApp::Itp` directly. You may notice a deprecation notice saying, `Itp will be removed in an upcoming version`. This is because we intend on removing `Itp` completely in `v22.0.0`, but this will work in the meantime. diff --git a/test/controllers/concerns/authenticated_test.rb b/test/controllers/concerns/authenticated_test.rb deleted file mode 100644 index 38a4deac7..000000000 --- a/test/controllers/concerns/authenticated_test.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -class AuthenticatedTest < ActionController::TestCase - class AuthenticatedTestController < ActionController::Base - include ShopifyApp::Authenticated - - def index - end - end - - tests AuthenticatedTestController - - test "includes all the needed concerns" do - AuthenticatedTestController.include?(ShopifyApp::Localization) - AuthenticatedTestController.include?(ShopifyApp::LoginProtection) - AuthenticatedTestController.include?(ShopifyApp::CsrfProtection) - AuthenticatedTestController.include?(ShopifyApp::EmbeddedApp) - AuthenticatedTestController.include?(ShopifyApp::EnsureBilling) - end - - test "detects deprecation message" do - version = "22.0.0" - ShopifyApp::Logger.expects(:deprecated).with( - regexp_matches(/Authenticated has been replaced by EnsureHasSession./), version - ) - ShopifyApp::Logger.stubs(:deprecated).with("Itp will be removed in an upcoming version", version) - Class.new(ApplicationController) do - include ShopifyApp::Authenticated - end - - assert_within_deprecation_schedule(version) - end -end diff --git a/test/controllers/concerns/require_known_shop_test.rb b/test/controllers/concerns/require_known_shop_test.rb deleted file mode 100644 index da1ecf3b3..000000000 --- a/test/controllers/concerns/require_known_shop_test.rb +++ /dev/null @@ -1,117 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -class RequireKnownShopTest < ActionController::TestCase - class UnauthenticatedTestController < ActionController::Base - include ShopifyApp::RequireKnownShop - - def index - render(html: "

Success") - end - end - - tests UnauthenticatedTestController - - setup do - Rails.application.routes.draw do - get "/unauthenticated_test", to: "require_known_shop_test/unauthenticated_test#index" - end - end - - test "redirects to login if no shop param is present" do - get :index - - assert_redirected_to ShopifyApp.configuration.login_url - end - - test "redirects to login if no shop is not a valid shopify domain" do - invalid_shop = "https://shop1.example.com" - - get :index, params: { shop: invalid_shop } - - assert_redirected_to ShopifyApp.configuration.login_url - end - - test "redirects to login if the shop is not installed" do - ShopifyApp::SessionRepository.expects(:retrieve_shop_session_by_shopify_domain).returns(false) - - shopify_domain = "shop1.myshopify.com" - host = "mock-host" - - get :index, params: { shop: shopify_domain, host: host } - - redirect_url = URI("/login") - redirect_url.query = URI.encode_www_form( - shop: shopify_domain, - host: host, - return_to: request.fullpath, - ) - - assert_redirected_to redirect_url.to_s - end - - test "returns :ok if the shop is installed" do - session = mock - ShopifyApp::SessionRepository.stubs(:retrieve_shop_session_by_shopify_domain).returns(session) - - client = mock - ShopifyAPI::Clients::Rest::Admin.expects(:new).with(session: session).returns(client) - client.expects(:get) - - shopify_domain = "shop1.myshopify.com" - - get :index, params: { shop: shopify_domain } - - assert_response :ok - end - - test "detects incompatible controller concerns" do - replaced_message = "RequireKnownShop has been replaced by EnsureInstalled."\ - " Please use the EnsureInstalled controller concern for the same behavior" - - version = "22.0.0" - - ShopifyApp::Logger.stubs(:deprecated).with("Itp will be removed in an upcoming version", version) - ShopifyApp::Logger.stubs(:deprecated).with(replaced_message, version) - - ShopifyApp::Logger.expects(:deprecated).with(regexp_matches(/incompatible concerns/), version) - - Class.new(ApplicationController) do - include ShopifyApp::RequireKnownShop - include ShopifyApp::LoginProtection - end - - ShopifyApp::Logger.expects(:deprecated).with(regexp_matches(/incompatible concerns/), version) - - Class.new(ApplicationController) do - include ShopifyApp::RequireKnownShop - include ShopifyApp::EnsureHasSession # since this indirectly includes LoginProtection - end - - ShopifyApp::Logger.expects(:deprecated).with(regexp_matches(/incompatible concerns/), version) - - authenticated_controller = Class.new(ApplicationController) do - include ShopifyApp::EnsureHasSession - end - - Class.new(authenticated_controller) do - include ShopifyApp::RequireKnownShop - end - - assert_within_deprecation_schedule(version) - end - - test "detects name change deprecation message" do - message = "RequireKnownShop has been replaced by EnsureInstalled."\ - " Please use the EnsureInstalled controller concern for the same behavior" - version = "22.0.0" - ShopifyApp::Logger.expects(:deprecated).with(message, version) - - Class.new(ApplicationController) do - include ShopifyApp::RequireKnownShop - end - - assert_within_deprecation_schedule(version) - end -end From ccb391379bee7aed0c3b53c4f18491bc92b019cc Mon Sep 17 00:00:00 2001 From: Nelson Wittwer Date: Tue, 5 Mar 2024 15:36:58 -0500 Subject: [PATCH 2/2] update PR in changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 119ea469a..2612c399c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ Unreleased ---------- * ⚠️ [Breaking] Bumps minimum supported Ruby version to 3.0. Bumps `shopify_api` to 14.0 [1801](https://github.com/Shopify/shopify_app/pull/1801) +* ⚠️ [Breaking] Removes deprecated controller concerns that were renamed in `v21.10.0`. [1805](https://github.com/Shopify/shopify_app/pull/1805) * Make type param for webhooks route optional. This will fix a bug with CLI initiated webhooks.[1786](https://github.com/Shopify/shopify_app/pull/1786) * Fix redirecting to login when we catch a 401 response from Shopify, so that it can also handle cases where the app is already embedded when that happens.[1787](https://github.com/Shopify/shopify_app/pull/1787) * Always register webhooks with offline sessions.[1788](https://github.com/Shopify/shopify_app/pull/1788)