diff --git a/VERSION b/VERSION index 1cf0537c..53b45081 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.19.0 +0.19.10 \ No newline at end of file diff --git a/app/controllers/disco_app/concerns/authenticated_controller.rb b/app/controllers/disco_app/concerns/authenticated_controller.rb index ed52d15d..1deb8408 100644 --- a/app/controllers/disco_app/concerns/authenticated_controller.rb +++ b/app/controllers/disco_app/concerns/authenticated_controller.rb @@ -4,6 +4,7 @@ module DiscoApp::Concerns::AuthenticatedController include ShopifyApp::LoginProtection included do + around_action :activate_shopify_session before_action :auto_login before_action :check_shop_whitelist before_action :login_again_if_different_user_or_shop @@ -11,25 +12,26 @@ module DiscoApp::Concerns::AuthenticatedController before_action :check_installed before_action :check_current_subscription before_action :check_active_charge - around_action :shopify_session layout 'embedded_app' end private def auto_login - return unless shop_session.nil? && request_hmac_valid? - + return unless current_shopify_session.nil? && request_hmac_valid? shop = DiscoApp::Shop.find_by(shopify_domain: sanitized_shop_name) return if shop.blank? - session[:shopify] = shop.id + session[:shop_id] = shop.id session[:shopify_domain] = sanitized_shop_name end def shopify_shop - if shop_session - @shop = DiscoApp::Shop.find_by!(shopify_domain: @shop_session.domain) + Rails.logger.info("-------Shop params--------") + Rails.logger.info(params) + Rails.logger.info("-------Shop params End--------") + if current_shopify_session + @shop = DiscoApp::Shop.find_by!(shopify_domain: current_shopify_session.shop) else redirect_to_login end @@ -69,9 +71,9 @@ def request_hmac_valid? end def check_shop_whitelist - return unless shop_session + return unless current_shopify_session return if ENV['WHITELISTED_DOMAINS'].blank? - return if ENV['WHITELISTED_DOMAINS'].include?(shop_session.url) + return if ENV['WHITELISTED_DOMAINS'].include?(current_shopify_session.url) redirect_to_login end diff --git a/app/controllers/disco_app/concerns/user_authenticated_controller.rb b/app/controllers/disco_app/concerns/user_authenticated_controller.rb index 629a6c8f..b6ec187a 100644 --- a/app/controllers/disco_app/concerns/user_authenticated_controller.rb +++ b/app/controllers/disco_app/concerns/user_authenticated_controller.rb @@ -10,7 +10,7 @@ module DiscoApp::Concerns::UserAuthenticatedController private def shopify_user - @user = DiscoApp::User.find(session[:shopify_user]) + @user = DiscoApp::User.find(session[:shopify_user_id]) rescue ActiveRecord::RecordNotFound redirect_to disco_app.new_user_session_path end diff --git a/app/controllers/disco_app/user_sessions_controller.rb b/app/controllers/disco_app/user_sessions_controller.rb index 50487c1b..fab9628a 100644 --- a/app/controllers/disco_app/user_sessions_controller.rb +++ b/app/controllers/disco_app/user_sessions_controller.rb @@ -20,7 +20,7 @@ def callback end def destroy - session[:shopify_user] = nil + session[:shopify_user_id] = nil redirect_to root_path end @@ -44,7 +44,7 @@ def authenticate def login_user @user = DiscoApp::User.create_user(associated_user(auth_hash), @shop) - session[:shopify_user] = @user.id + session[:shopify_user_id] = @user.id end def return_address diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index df791ab1..7de6cb47 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -21,7 +21,7 @@ def authenticate shop = DiscoApp::Shop.find_by!(shopify_domain: sanitized_shop_name) sess = ShopifyAPI::Session.new(domain: shop.shopify_domain, token: shop.shopify_token, api_version: shop.api_version) - session[:shopify] = ShopifyApp::SessionRepository.store(sess) + session[:shop_id] = ShopifyApp::SessionRepository.store(sess) session[:shopify_domain] = sanitized_shop_name redirect_to(disco_app.frame_path) && return diff --git a/app/models/disco_app/concerns/shop.rb b/app/models/disco_app/concerns/shop.rb index 3ff9d79d..f60f9a21 100644 --- a/app/models/disco_app/concerns/shop.rb +++ b/app/models/disco_app/concerns/shop.rb @@ -3,7 +3,7 @@ module DiscoApp::Concerns::Shop extend ActiveSupport::Concern included do - include ShopifyApp::SessionStorage + include ShopifyApp::ShopSessionStorage include ActionView::Helpers::DateHelper # Define relationships to plans and subscriptions. diff --git a/app/models/disco_app/session_storage.rb b/app/models/disco_app/session_storage.rb index 3ce832ed..0d3de251 100644 --- a/app/models/disco_app/session_storage.rb +++ b/app/models/disco_app/session_storage.rb @@ -2,8 +2,12 @@ module DiscoApp class SessionStorage def self.store(session, *args) - shop = Shop.find_or_initialize_by(shopify_domain: session.url) - shop.shopify_token = session.token + shop = DiscoApp::Shop.find_or_initialize_by(shopify_domain: session.shop) + Rails.logger.info("-------Session Storage--------") + Rails.logger.info(session.inspect) + Rails.logger.info(shop.inspect) + Rails.logger.info("-------Session Storage End--------") + shop.shopify_token = session.access_token shop.save! shop.id end @@ -11,11 +15,19 @@ def self.store(session, *args) def self.retrieve(id) return unless id - shop = Shop.find(id) - ShopifyAPI::Session.new(domain: shop.shopify_domain, token: shop.shopify_token, api_version: shop.api_version) + shop = DiscoApp::Shop.find(id) + ShopifyAPI::Auth::Session.new(shop: shop.shopify_domain, access_token: shop.shopify_token) rescue ActiveRecord::RecordNotFound nil end + def self.retrieve_by_shopify_domain(shopify_domain) + shop = DiscoApp::Shop.find_by(shopify_domain: shopify_domain) + ShopifyAPI::Auth::Session.new(shop: shop.shopify_domain, access_token: shop.shopify_token) + end + + def self.destroy_by_shopify_domain(shopify_domain) + destroy_by(shopify_domain: shopify_domain) + end end end diff --git a/app/views/layouts/embedded_app.html.erb b/app/views/layouts/embedded_app.html.erb index 2c2ec8c0..304d8e71 100644 --- a/app/views/layouts/embedded_app.html.erb +++ b/app/views/layouts/embedded_app.html.erb @@ -8,7 +8,7 @@ // Initialise the Shopify App. ShopifyApp.init({ "apiKey": "<%= ShopifyApp.configuration.api_key %>", - "shopOrigin": "<%= "https://#{ @shop_session.domain }" if @shop_session %>", + "shopOrigin": "<%= "https://#{ @shop_session.shop }" if @shop_session %>", "debug": <%= Rails.env.development? ? 'true' : 'false' %> }); diff --git a/app/views/layouts/embedded_app_modal.html.erb b/app/views/layouts/embedded_app_modal.html.erb index dc05e9b1..78a57f1b 100644 --- a/app/views/layouts/embedded_app_modal.html.erb +++ b/app/views/layouts/embedded_app_modal.html.erb @@ -7,7 +7,7 @@ // Initialise the Shopify App. ShopifyApp.init({ "apiKey": "<%= ShopifyApp.configuration.api_key %>", - "shopOrigin": "<%= "https://#{ @shop_session.domain }" if @shop_session %>", + "shopOrigin": "<%= "https://#{ @shop_session.shop }" if @shop_session %>", "debug": <%= Rails.env.development? ? 'true' : 'false' %>, "forceRedirect": false }); diff --git a/disco_app.gemspec b/disco_app.gemspec index d7186ef1..ec80448c 100644 --- a/disco_app.gemspec +++ b/disco_app.gemspec @@ -41,8 +41,8 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'rails_12factor', '~> 0.0.3' s.add_runtime_dependency 'react-rails', '~> 2.5' s.add_runtime_dependency 'sass-rails', '~> 6.0' - s.add_runtime_dependency 'shopify_api', '~> 9.0' - s.add_runtime_dependency 'shopify_app', '~> 12.0.7' + s.add_runtime_dependency 'shopify_api', '~> 14.0.1' + s.add_runtime_dependency 'shopify_app', '~> 22.0.0' s.add_runtime_dependency 'sidekiq', '~> 6.0' s.add_runtime_dependency 'sinatra', '~> 2.0' s.add_runtime_dependency 'turbolinks', '~> 5.2' diff --git a/initialise.sh b/initialise.sh index 83f68f40..dc87ce3c 100755 --- a/initialise.sh +++ b/initialise.sh @@ -24,7 +24,7 @@ fi APP_NAME="$1" RAILS_VERSION="${RAILS_VERSION:-6.0.2}" NODE_VERSION="${NODE_VERSION:-13.7.0}" -DISCO_APP_VERSION="${DISCO_APP_VERSION:-0.19.0}" +DISCO_APP_VERSION="${DISCO_APP_VERSION:-0.19.10}" if [ -z $APP_NAME ]; then echo '' diff --git a/lib/disco_app/session.rb b/lib/disco_app/session.rb index 12b2af5d..e430bb38 100644 --- a/lib/disco_app/session.rb +++ b/lib/disco_app/session.rb @@ -8,7 +8,7 @@ class Session < ActiveRecord::SessionStore::Session def set_shop_id! return false unless loaded? - write_attribute(:shop_id, data[:shopify] || data['shopify']) + write_attribute(:shop_id, data[:shop_id] || data['shop_id']) end end diff --git a/lib/disco_app/version.rb b/lib/disco_app/version.rb index e240fa04..916e8b77 100644 --- a/lib/disco_app/version.rb +++ b/lib/disco_app/version.rb @@ -1,5 +1,5 @@ module DiscoApp - VERSION = '0.19.0'.freeze + VERSION = '0.19.10'.freeze end diff --git a/test/test_helper.rb b/test/test_helper.rb index 1052defa..6676df2f 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -62,13 +62,13 @@ class ActiveSupport::TestCase include DiscoApp::Test::FileFixtures def log_in_as(shop) - session[:shopify] = shop.id + session[:shop_id] = shop.id session[:shopify_domain] = shop.shopify_domain session[:api_version] = shop.api_version end def log_out - session[:shopify] = nil + session[:shop_id] = nil session[:shopify_domain] = nil session[:api_version] = nil end