Skip to content

Commit

Permalink
Merge pull request #1581 from Shopify/klenotiw/renaming-concerns
Browse files Browse the repository at this point in the history
Adding Deprecation Logs
  • Loading branch information
klenotiw committed Dec 7, 2022
2 parents 6a5ba61 + 058657b commit d746c7f
Show file tree
Hide file tree
Showing 30 changed files with 422 additions and 153 deletions.
61 changes: 38 additions & 23 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ PATH
jwt (>= 2.2.3)
rails (> 5.2.1)
redirect_safely (~> 1.0)
shopify_api (~> 12.2)
shopify_api (~> 12.3)
sprockets-rails (>= 2.0.0)

GEM
Expand Down Expand Up @@ -85,7 +85,7 @@ GEM
ast (2.4.2)
binding_of_caller (1.0.0)
debug_inspector (>= 0.0.1)
browser_sniffer (2.1.0)
browser_sniffer (2.2.0)
builder (3.2.4)
byebug (11.1.3)
coderay (1.1.3)
Expand All @@ -104,14 +104,17 @@ GEM
multi_xml (>= 0.5.2)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
json (2.6.2)
json (2.6.3)
jwt (2.5.0)
language_server-protocol (3.17.0.1)
language_server-protocol (3.17.0.2)
loofah (2.19.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
mail (2.8.0)
mini_mime (>= 0.1.1)
net-imap
net-pop
net-smtp
marcel (1.0.2)
method_source (1.0.0)
mime-types (3.4.1)
Expand All @@ -120,18 +123,27 @@ GEM
mini_mime (1.1.2)
mini_portile2 (2.8.0)
minitest (5.16.3)
mocha (1.16.0)
mocha (2.0.2)
ruby2_keywords (>= 0.0.5)
multi_xml (0.6.0)
net-imap (0.3.1)
net-protocol
net-pop (0.1.2)
net-protocol
net-protocol (0.2.0)
timeout
net-smtp (0.3.3)
net-protocol
nio4r (2.5.8)
nokogiri (1.13.9)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
oj (3.13.21)
oj (3.13.23)
openssl (3.0.1)
parallel (1.22.1)
parser (3.1.2.1)
parser (3.1.3.0)
ast (~> 2.4.1)
prettier_print (1.0.2)
prettier_print (1.1.0)
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
Expand All @@ -140,8 +152,8 @@ GEM
pry-stack_explorer (0.6.1)
binding_of_caller (~> 1.0)
pry (~> 0.13)
public_suffix (5.0.0)
racc (1.6.0)
public_suffix (5.0.1)
racc (1.6.1)
rack (2.2.4)
rack-test (2.0.2)
rack (>= 1.3)
Expand Down Expand Up @@ -180,29 +192,31 @@ GEM
rb-readline (0.5.5)
redirect_safely (1.0.0)
activemodel
regexp_parser (2.6.0)
regexp_parser (2.6.1)
rexml (3.2.5)
rubocop (1.37.0)
rubocop (1.39.0)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.1.2.1)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.22.0, < 2.0)
rubocop-ast (>= 1.23.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.22.0)
rubocop-ast (1.24.0)
parser (>= 3.1.1.0)
rubocop-shopify (2.10.1)
rubocop (~> 1.35)
ruby-lsp (0.3.5)
ruby-lsp (0.3.6)
language_server-protocol (~> 3.17.0)
sorbet-runtime
syntax_tree (>= 4.0.2)
syntax_tree (>= 4.0.2, < 5.0.0)
ruby-progressbar (1.11.0)
securerandom (0.2.0)
shopify_api (12.2.1)
ruby2_keywords (0.0.5)
securerandom (0.2.1)
shopify_api (12.3.0)
activesupport
concurrent-ruby
hash_diff
httparty
Expand All @@ -211,20 +225,21 @@ GEM
openssl
securerandom
sorbet-runtime
zeitwerk (~> 2.5)
sorbet-runtime (0.5.10514)
zeitwerk (~> 2.5, < 2.6.5)
sorbet-runtime (0.5.10576)
sprockets (4.1.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.4.2)
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
sqlite3 (1.5.3)
sqlite3 (1.5.4)
mini_portile2 (~> 2.8.0)
syntax_tree (4.3.0)
prettier_print (>= 1.0.2)
thor (1.2.1)
timeout (0.3.1)
tzinfo (2.0.5)
concurrent-ruby (~> 1.0)
unicode-display_width (2.3.0)
Expand All @@ -235,7 +250,7 @@ GEM
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
zeitwerk (2.6.1)
zeitwerk (2.6.4)

PLATFORMS
ruby
Expand Down
13 changes: 4 additions & 9 deletions app/controllers/concerns/shopify_app/authenticated.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@ module Authenticated
extend ActiveSupport::Concern

included do
include ShopifyApp::Localization
include ShopifyApp::LoginProtection
include ShopifyApp::CsrfProtection
include ShopifyApp::EmbeddedApp
include ShopifyApp::EnsureBilling

before_action :login_again_if_different_user_or_shop
around_action :activate_shopify_session
after_action :add_top_level_redirection_headers
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
19 changes: 19 additions & 0 deletions app/controllers/concerns/shopify_app/ensure_has_session.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module ShopifyApp
module EnsureHasSession
extend ActiveSupport::Concern

included do
include ShopifyApp::Localization
include ShopifyApp::LoginProtection
include ShopifyApp::CsrfProtection
include ShopifyApp::EmbeddedApp
include ShopifyApp::EnsureBilling

before_action :login_again_if_different_user_or_shop
around_action :activate_shopify_session
after_action :add_top_level_redirection_headers
end
end
end
62 changes: 62 additions & 0 deletions app/controllers/concerns/shopify_app/ensure_installed.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# frozen_string_literal: true

module ShopifyApp
module EnsureInstalled
extend ActiveSupport::Concern
include ShopifyApp::RedirectForEmbedded

included do
if ancestors.include?(ShopifyApp::LoginProtection)
message = <<~EOS
We detected the use of incompatible concerns (EnsureInstalled and LoginProtection) in #{name},
which may lead to unpredictable behavior. In a future release of this library this will raise an error.
EOS

ShopifyApp::Logger.deprecated(message, "22.0.0")
end

before_action :check_shop_domain
before_action :check_shop_known
end

def current_shopify_domain
if params[:shop].blank?
ShopifyApp::Logger.info("Could not identify installed store from current_shopify_domain")
return
end

@shopify_domain ||= ShopifyApp::Utils.sanitize_shop_domain(params[:shop])
ShopifyApp::Logger.info("Installed store: #{@shopify_domain} - deduced from Shopify Admin params")
@shopify_domain
end

private

def check_shop_domain
redirect_to(ShopifyApp.configuration.login_url) unless current_shopify_domain
end

def check_shop_known
@shop = SessionRepository.retrieve_shop_session_by_shopify_domain(current_shopify_domain)
unless @shop
if embedded_param?
redirect_for_embedded
else
redirect_to(shop_login)
end
end
end

def shop_login
url = URI(ShopifyApp.configuration.login_url)

url.query = URI.encode_www_form(
shop: params[:shop],
host: params[:host],
return_to: request.fullpath,
)

url.to_s
end
end
end
49 changes: 3 additions & 46 deletions app/controllers/concerns/shopify_app/require_known_shop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,11 @@
module ShopifyApp
module RequireKnownShop
extend ActiveSupport::Concern
include ShopifyApp::RedirectForEmbedded
include ShopifyApp::EnsureInstalled

included do
if ancestors.include?(ShopifyApp::LoginProtection)
ActiveSupport::Deprecation.warn(<<~EOS)
We detected the use of incompatible concerns (RequireKnownShop and LoginProtection) in #{name},
which may lead to unpredictable behavior. In a future release of this library this will raise an error.
EOS

end

before_action :check_shop_domain
before_action :check_shop_known
end

def current_shopify_domain
return if params[:shop].blank?

@shopify_domain ||= ShopifyApp::Utils.sanitize_shop_domain(params[:shop])
end

private

def check_shop_domain
redirect_to(ShopifyApp.configuration.login_url) unless current_shopify_domain
end

def check_shop_known
@shop = SessionRepository.retrieve_shop_session_by_shopify_domain(current_shopify_domain)
unless @shop
if embedded_param?
redirect_for_embedded
else
redirect_to(shop_login)
end
end
end

def shop_login
url = URI(ShopifyApp.configuration.login_url)

url.query = URI.encode_www_form(
shop: params[:shop],
host: params[:host],
return_to: request.fullpath,
)

url.to_s
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
2 changes: 1 addition & 1 deletion app/controllers/shopify_app/authenticated_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module ShopifyApp
class AuthenticatedController < ActionController::Base
include ShopifyApp::Authenticated
include ShopifyApp::EnsureHasSession

protect_from_forgery with: :exception
end
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/shopify_app/callback_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ def callback
auth_query: ShopifyAPI::Auth::Oauth::AuthQuery.new(**filtered_params),
)
rescue => e
unless e.class.module_parent == ShopifyAPI::Errors
ActiveSupport::Deprecation.warn(<<~EOS)
if e.class.module_parent != ShopifyAPI::Errors
message = <<~EOS
An error of type #{e.class} was rescued. This is not part of `ShopifyAPI::Errors`, which could indicate a
bug in your app, or a bug in the shopify_app gem. Future versions of the gem may re-raise this error rather
than rescuing it.
EOS
ShopifyApp::Logger.deprecated(message, "22.0.0")
end
return respond_with_error
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class AddMarketingActivityExtensionGenerator < Rails::Generators::Base
source_root File.expand_path("../templates", __FILE__)

def generate_app_extension
ShopifyApp::Logger.deprecated("MarketingActivitiesController will be removed in an upcoming version", "22.0.0")
template("marketing_activities_controller.rb", "app/controllers/marketing_activities_controller.rb")
generate_routes
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

class AuthenticatedController < ApplicationController
include ShopifyApp::Authenticated
include ShopifyApp::EnsureHasSession
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class HomeController < ApplicationController
include ShopifyApp::EmbeddedApp
include ShopifyApp::RequireKnownShop
include ShopifyApp::EnsureInstalled
include ShopifyApp::ShopAccessScopesVerification

def index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Rails.application.config.after_initialize do
is_private: !ENV.fetch('SHOPIFY_APP_PRIVATE_SHOP', '').empty?,
is_embedded: ShopifyApp.configuration.embedded_app,
session_storage: ShopifyApp::SessionRepository,
log_level: :info,
logger: Rails.logger,
private_shop: ENV.fetch('SHOPIFY_APP_PRIVATE_SHOP', nil),
user_agent_prefix: "ShopifyApp/#{ShopifyApp::VERSION}"
Expand Down
5 changes: 5 additions & 0 deletions lib/shopify_app/controller_concerns/itp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
module ShopifyApp
# Cookie management helpers required for ITP implementation
module Itp
extend ActiveSupport::Concern
included do
ShopifyApp::Logger.deprecated("Itp will be removed in an upcoming version", "22.0.0")
end

private

def set_test_cookie
Expand Down
Loading

0 comments on commit d746c7f

Please sign in to comment.