disco_app 0.6.9 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9001ca6c8a25c9ea7df2b970754c13dd131efd3d267082486203c4f5fa38fcdc
4
- data.tar.gz: 87bff693bed4d65f2636971fbd01d0ac378c763feed04b9576a5a014d10ae465
3
+ metadata.gz: 68caa1ce47b61667169703ebd83a0cd91959e663bcfabc1993ec060892139e81
4
+ data.tar.gz: 1f4b759c70b234668f9691a628acd56e0dbee57dfc7fe9542ebbc15d25d6862d
5
5
  SHA512:
6
- metadata.gz: f71bb8a81019f810d0f36cf08eff95d1703a5d15275332b2892284cf0cc383625e3c17278b535c18a2a88e2be4b5fb4e3b7fb802f00ea30324fd3078b14d5e75
7
- data.tar.gz: 1b6f4733ee9eb8272426e0375a3c0ad30df950113c33ec521b2b879c1f1c000ffaf9b80304bc93612baf5d998c82badeff876d94a05aaac3d85e6454148524db
6
+ metadata.gz: f3c6c70e1e0c8c7e7eea4d729afe768830b6caeecac921a1b2ac0b6b9d224ff686a6a5b7f8312ff8fa66b7a47f8a79261fe645a552e0786afcba2bd7355287c9
7
+ data.tar.gz: c957d6a3eafb4214f7fd548dc145b9f301b1d4ac70ec7f36a328c96f7c5c20aeab24ef97fde384c8973acdcf6e7cda948f4dd5781237d72a3693338b80f7bc7f
@@ -18,7 +18,7 @@ var ShopifyAdminLink = React.createClass({
18
18
  },
19
19
 
20
20
  render: function() {
21
- var href = '/admin' + this.props.href;
21
+ var href = ShopifyApp.shopOrigin + '/admin' + this.props.href;
22
22
  return (
23
23
  <a className={this.props.className} href={href} onClick={this.handleClick}>
24
24
  {this.props.label}
@@ -24,7 +24,7 @@ module DiscoApp
24
24
  query_hash = Rack::Utils.parse_query(request.query_string)
25
25
  signature = query_hash.delete("signature")
26
26
  sorted_params = query_hash.collect{ |k, v| "#{k}=#{Array(v).join(',')}" }.sort.join
27
- calculated_signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha256'), ShopifyApp.configuration.secret, sorted_params)
27
+ calculated_signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), ShopifyApp.configuration.secret, sorted_params)
28
28
  signature == calculated_signature
29
29
  end
30
30
 
@@ -18,7 +18,7 @@ module DiscoApp
18
18
  return true unless Rails.env.production?
19
19
  data = request.body.read.to_s
20
20
  hmac_header = request.headers['HTTP_X_SHOPIFY_HMAC_SHA256']
21
- digest = OpenSSL::Digest::Digest.new('sha256')
21
+ digest = OpenSSL::Digest.new('sha256')
22
22
  calculated_hmac = Base64.encode64(OpenSSL::HMAC.digest(digest, ShopifyApp.configuration.secret, data)).strip
23
23
  request.body.rewind
24
24
  calculated_hmac == hmac_header
@@ -10,11 +10,14 @@ module DiscoApp::Concerns::AppUninstalledJob
10
10
  # Perform application uninstallation.
11
11
  #
12
12
  # - Mark charge status as "cancelled" unless charges have been waived.
13
+ # - Remove any stored sessions for the shop.
13
14
  #
14
15
  def perform(domain, shop_data)
15
16
  unless @shop.charge_waived?
16
17
  @shop.charge_cancelled!
17
18
  end
19
+
20
+ @shop.sessions.delete_all
18
21
  end
19
22
 
20
23
  end
@@ -8,6 +8,9 @@ module DiscoApp::Concerns::Shop
8
8
  has_many :subscriptions
9
9
  has_many :plans, through: :subscriptions
10
10
 
11
+ # Define relationship to sessions.
12
+ has_many :sessions, class_name: 'DiscoApp::Session', dependent: :destroy
13
+
11
14
  # Define possible installation statuses as an enum.
12
15
  enum status: [:never_installed, :awaiting_install, :installing, :installed, :awaiting_uninstall, :uninstalling, :uninstalled]
13
16
 
@@ -0,0 +1,12 @@
1
+ class CreateDiscoAppSessions < ActiveRecord::Migration
2
+ def change
3
+ create_table :disco_app_sessions do |t|
4
+ t.string :session_id, :null => false
5
+ t.text :data
6
+ t.timestamps
7
+ end
8
+
9
+ add_index :disco_app_sessions, :session_id, :unique => true
10
+ add_index :disco_app_sessions, :updated_at
11
+ end
12
+ end
@@ -0,0 +1,6 @@
1
+ class AddShopIdToDiscoAppSessions < ActiveRecord::Migration
2
+ def change
3
+ add_column :disco_app_sessions, :shop_id, :integer, null: true
4
+ add_foreign_key :disco_app_sessions, :disco_app_shops, column: :shop_id, on_delete: :cascade
5
+ end
6
+ end
@@ -2,6 +2,8 @@ require 'shopify_app'
2
2
  require 'bootstrap-sass'
3
3
  require 'jquery-rails'
4
4
  require 'turbolinks'
5
+ require 'activerecord/session_store'
6
+ require 'disco_app/session'
5
7
 
6
8
  module DiscoApp
7
9
  class Engine < ::Rails::Engine
@@ -16,7 +18,7 @@ module DiscoApp
16
18
 
17
19
  # Ensure our frame assets are included for precompilation.
18
20
  initializer 'disco_app.assets.precompile' do |app|
19
- app.config.assets.precompile += %w(disco_app/frame.css disco_app/frame.js)
21
+ app.config.assets.precompile += %w(disco_app/icon.svg disco_app/frame.css disco_app/frame.js)
20
22
  end
21
23
 
22
24
  end
@@ -0,0 +1,12 @@
1
+ class DiscoApp::Session < ActiveRecord::SessionStore::Session
2
+
3
+ before_save :set_shop_id!
4
+
5
+ private
6
+
7
+ def set_shop_id!
8
+ return false unless loaded?
9
+ write_attribute(:shop_id, data[:shopify] || data['shopify'])
10
+ end
11
+
12
+ end
@@ -1,3 +1,3 @@
1
1
  module DiscoApp
2
- VERSION = "0.6.9"
2
+ VERSION = '0.7.0'
3
3
  end
@@ -27,10 +27,11 @@ class DiscoAppGenerator < Rails::Generators::Base
27
27
  gsub_file 'Gemfile', /^# Use sqlite3 as the database for Active Record\ngem 'sqlite3'/m, ''
28
28
 
29
29
  # Add gems common to all environments.
30
- gem 'shopify_app', '~> 6.2.0'
30
+ gem 'shopify_app', '~> 6.4.1'
31
31
  gem 'sidekiq', '~> 3.5.1'
32
32
  gem 'puma', '~> 2.14.0'
33
33
  gem 'bootstrap-sass', '~> 3.3.5.1'
34
+ gem 'activerecord-session_store', '~> 0.1.2'
34
35
 
35
36
  # Add gems for development and testing only.
36
37
  gem_group :development, :test do
@@ -68,6 +69,11 @@ class DiscoAppGenerator < Rails::Generators::Base
68
69
  application "config.x.shopify_charges_real = ENV['SHOPIFY_CHARGES_REAL'] == 'true'\n", env: :production
69
70
  application "# Allow real charges in production with an ENV variable", env: :production
70
71
 
72
+ # Configure session storage.
73
+ application "ActiveRecord::SessionStore::Session.table_name = 'disco_app_sessions'"
74
+ application "ActionDispatch::Session::ActiveRecordStore.session_class = DiscoApp::Session"
75
+ application "# Configure custom session storage"
76
+
71
77
  # Set Sidekiq as the queue adapter in production.
72
78
  application "config.active_job.queue_adapter = :sidekiq\n", env: :production
73
79
  application "# Use Sidekiq as the active job backend", env: :production
@@ -108,6 +114,7 @@ class DiscoAppGenerator < Rails::Generators::Base
108
114
  copy_file 'initializers/shopify_app.rb', 'config/initializers/shopify_app.rb'
109
115
  copy_file 'initializers/disco_app.rb', 'config/initializers/disco_app.rb'
110
116
  copy_file 'initializers/shopify_session_repository.rb', 'config/initializers/shopify_session_repository.rb'
117
+ copy_file 'initializers/session_store.rb', 'config/initializers/session_store.rb'
111
118
 
112
119
  # Copy default home controller and view
113
120
  copy_file 'controllers/home_controller.rb', 'app/controllers/home_controller.rb'
@@ -7,8 +7,8 @@ module DiscoApp
7
7
  # Install the Rollbar and OJ gems.
8
8
  def install_gems
9
9
  # Add gem to Gemfile
10
- gem 'rollbar', '~> 2.4.0'
11
- gem 'oj', '~> 2.12.14'
10
+ gem 'rollbar', '~> 2.7.1'
11
+ gem 'oj', '~> 2.14.3'
12
12
 
13
13
  # Install gem.
14
14
  Bundler.with_clean_env do
@@ -0,0 +1,2 @@
1
+ # Use an ActiveRecord-based session store.
2
+ Rails.application.config.session_store :active_record_store, :key => '_disco_app_session'
@@ -0,0 +1,9 @@
1
+ namespace :sessions do
2
+
3
+ desc 'Clean out any stale sessions.'
4
+ task clean: [:environment, 'db:load_config'] do
5
+ threshold = (ENV['SESSIONS_CLEAN_THRESHOLD_DAYS'] || 30).to_i.days.ago
6
+ ActiveRecord::Base.connection.execute("DELETE FROM #{ActiveRecord::SessionStore::Session.table_name} WHERE updated_at < '#{threshold}'")
7
+ end
8
+
9
+ end
@@ -27,6 +27,10 @@ module Dummy
27
27
  # Set the default host for absolute URL routing purposes
28
28
  routes.default_url_options[:host] = ENV['DEFAULT_HOST']
29
29
 
30
+ # Configure custom session storage
31
+ ActionDispatch::Session::ActiveRecordStore.session_class = DiscoApp::Session
32
+ ActiveRecord::SessionStore::Session.table_name = 'disco_app_sessions'
33
+
30
34
  # Explicitly prevent real charges being created by default
31
35
  config.x.shopify_charges_real = false
32
36
 
@@ -1,3 +1,2 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- Rails.application.config.session_store :cookie_store, key: '_dummy_session'
1
+ # Use an ActiveRecord-based session store.
2
+ Rails.application.config.session_store :active_record_store, :key => '_disco_app_session'
@@ -11,7 +11,7 @@
11
11
  #
12
12
  # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(version: 20151017234409) do
14
+ ActiveRecord::Schema.define(version: 20160113194418) do
15
15
 
16
16
  create_table "disco_app_plans", force: :cascade do |t|
17
17
  t.integer "status"
@@ -23,6 +23,17 @@ ActiveRecord::Schema.define(version: 20151017234409) do
23
23
  t.datetime "updated_at", null: false
24
24
  end
25
25
 
26
+ create_table "disco_app_sessions", force: :cascade do |t|
27
+ t.string "session_id", null: false
28
+ t.text "data"
29
+ t.datetime "created_at"
30
+ t.datetime "updated_at"
31
+ t.integer "shop_id"
32
+ end
33
+
34
+ add_index "disco_app_sessions", ["session_id"], name: "index_disco_app_sessions_on_session_id", unique: true
35
+ add_index "disco_app_sessions", ["updated_at"], name: "index_disco_app_sessions_on_updated_at"
36
+
26
37
  create_table "disco_app_shops", force: :cascade do |t|
27
38
  t.string "shopify_domain", null: false
28
39
  t.string "shopify_token", null: false
@@ -0,0 +1,31 @@
1
+ require 'test_helper'
2
+
3
+ class DiscoApp::SessionTest < ActiveSupport::TestCase
4
+
5
+ def setup
6
+ @shop = disco_app_shops(:widget_store)
7
+ @session = DiscoApp::Session.create(
8
+ session_id: 'a91bfc51fa79c9d09d43e2615d9345d4',
9
+ data: {
10
+ :shopify => @shop.id,
11
+ :shopify_domain => @shop.shopify_domain
12
+ }
13
+ )
14
+ end
15
+
16
+ test 'logged in sessions are linked to their shop' do
17
+ assert_equal @shop.id, @session.shop_id
18
+ end
19
+
20
+ test 'can fetch sessions for a particular shop through association' do
21
+ assert_equal 1, @shop.sessions.size
22
+ end
23
+
24
+ test 'sessions can be deleted by shop' do
25
+ DiscoApp::Session.create(session_id: 'a91bfc51fa79c9d09d43e2615d9345d5', data: {})
26
+ assert_equal 2, DiscoApp::Session.count
27
+ @shop.sessions.delete_all
28
+ assert_equal 1, DiscoApp::Session.count
29
+ end
30
+
31
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: disco_app
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.9
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Ballard
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 6.2.0
33
+ version: 6.4.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 6.2.0
40
+ version: 6.4.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: puma
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
152
  version: 3.2.0
153
+ - !ruby/object:Gem::Dependency
154
+ name: activerecord-session_store
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 0.1.2
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 0.1.2
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: sqlite3
155
169
  requirement: !ruby/object:Gem::Requirement
@@ -316,8 +330,11 @@ files:
316
330
  - db/migrate/20151017231302_create_disco_app_plans.rb
317
331
  - db/migrate/20151017232027_create_disco_app_subscriptions.rb
318
332
  - db/migrate/20151017234409_move_shop_to_disco_app_engine.rb
333
+ - db/migrate/20160112233706_create_disco_app_sessions.rb
334
+ - db/migrate/20160113194418_add_shop_id_to_disco_app_sessions.rb
319
335
  - lib/disco_app.rb
320
336
  - lib/disco_app/engine.rb
337
+ - lib/disco_app/session.rb
321
338
  - lib/disco_app/support/file_fixtures.rb
322
339
  - lib/disco_app/test_help.rb
323
340
  - lib/disco_app/version.rb
@@ -332,11 +349,13 @@ files:
332
349
  - lib/generators/disco_app/templates/config/puma.rb
333
350
  - lib/generators/disco_app/templates/controllers/home_controller.rb
334
351
  - lib/generators/disco_app/templates/initializers/disco_app.rb
352
+ - lib/generators/disco_app/templates/initializers/session_store.rb
335
353
  - lib/generators/disco_app/templates/initializers/shopify_app.rb
336
354
  - lib/generators/disco_app/templates/initializers/shopify_session_repository.rb
337
355
  - lib/generators/disco_app/templates/root/Procfile
338
356
  - lib/generators/disco_app/templates/views/home/index.html.erb
339
357
  - lib/tasks/carrier_service.rake
358
+ - lib/tasks/sessions.rake
340
359
  - lib/tasks/start.rake
341
360
  - lib/tasks/webhooks.rake
342
361
  - test/controllers/disco_app/install_controller_test.rb
@@ -394,6 +413,7 @@ files:
394
413
  - test/jobs/disco_app/app_installed_job_test.rb
395
414
  - test/jobs/disco_app/app_uninstalled_job_test.rb
396
415
  - test/models/disco_app/plan_test.rb
416
+ - test/models/disco_app/session_test.rb
397
417
  - test/models/disco_app/shop_test.rb
398
418
  - test/models/disco_app/subscription_test.rb
399
419
  - test/services/disco_app/subscription_service_test.rb
@@ -482,5 +502,6 @@ test_files:
482
502
  - test/integration/navigation_test.rb
483
503
  - test/models/disco_app/plan_test.rb
484
504
  - test/models/disco_app/shop_test.rb
505
+ - test/models/disco_app/session_test.rb
485
506
  - test/models/disco_app/subscription_test.rb
486
507
  - test/services/disco_app/subscription_service_test.rb