Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.19.0
0.19.10
18 changes: 10 additions & 8 deletions app/controllers/disco_app/concerns/authenticated_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,34 @@ 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
before_action :shopify_shop
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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/disco_app/user_sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def callback
end

def destroy
session[:shopify_user] = nil
session[:shopify_user_id] = nil
redirect_to root_path
end

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/disco_app/concerns/shop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 16 additions & 4 deletions app/models/disco_app/session_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,32 @@ 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

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
2 changes: 1 addition & 1 deletion app/views/layouts/embedded_app.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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' %>
});
</script>
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/embedded_app_modal.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand Down
4 changes: 2 additions & 2 deletions disco_app.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion initialise.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ''
Expand Down
2 changes: 1 addition & 1 deletion lib/disco_app/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/disco_app/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module DiscoApp

VERSION = '0.19.0'.freeze
VERSION = '0.19.10'.freeze

end
4 changes: 2 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down