disco_app 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/stylesheets/disco_app/disco/_grid.scss +12 -0
- data/app/controllers/disco_app/webhooks_controller.rb +1 -1
- data/app/jobs/disco_app/concerns/app_installed_job.rb +2 -28
- data/app/jobs/disco_app/concerns/synchronise_webhooks_job.rb +49 -0
- data/app/jobs/disco_app/synchronise_webhooks_job.rb +3 -0
- data/app/models/disco_app/concerns/shop.rb +1 -1
- data/lib/disco_app/support/file_fixtures.rb +23 -0
- data/lib/disco_app/test_help.rb +11 -0
- data/lib/disco_app/version.rb +1 -1
- data/lib/generators/disco_app/disco_app_generator.rb +5 -18
- data/lib/tasks/start.rake +3 -0
- data/lib/tasks/webhooks.rake +10 -0
- metadata +7 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5341341dc5eed693f033ebff1b63c7c53d068838321446867753c87c39eb58c
|
4
|
+
data.tar.gz: f3b11e3a89df6491a290aa57376e8d9836ce2456026be50856c6e0e702db7ec2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 935f6a935d67afa3d7d04ff62939eef451dbcce4d407a56e08b2bb7162311581b019aa1c0052595d7158179aa23f3d93ad91edbf52dac6055a5ec7c5ea997397
|
7
|
+
data.tar.gz: 3767fc325cf46e9bfaba54b38e952783b4c8c5070929007f71fd534807a2d8cce30129225f43883842f511a561cb3cf8187129f0cc90f49f43094f7568d464a7
|
@@ -33,6 +33,13 @@
|
|
33
33
|
justify-content: center;
|
34
34
|
}
|
35
35
|
|
36
|
+
.next-grid--right-aligned {
|
37
|
+
-webkit-box-pack: end;
|
38
|
+
-webkit-justify-content: flex-end;
|
39
|
+
-ms-flex-pack: end;
|
40
|
+
justify-content: flex-end;
|
41
|
+
}
|
42
|
+
|
36
43
|
.next-grid__cell {
|
37
44
|
@include flex(1, 1, 0%);
|
38
45
|
padding: 10px;
|
@@ -41,6 +48,11 @@
|
|
41
48
|
min-width: 0;
|
42
49
|
}
|
43
50
|
|
51
|
+
.next-grid__cell--third {
|
52
|
+
@include flex(0, 0, 33.333%);
|
53
|
+
max-width: 33.333%;
|
54
|
+
}
|
55
|
+
|
44
56
|
.next-grid__cell--no-flex {
|
45
57
|
@include flex(0 0 auto);
|
46
58
|
}
|
@@ -22,7 +22,7 @@ module DiscoApp
|
|
22
22
|
end
|
23
23
|
|
24
24
|
# Decode the body data and enqueue the appropriate job.
|
25
|
-
data = ActiveSupport::JSON::decode(request.body.read)
|
25
|
+
data = ActiveSupport::JSON::decode(request.body.read).with_indifferent_access
|
26
26
|
job_class.perform_later(domain, data)
|
27
27
|
|
28
28
|
render nothing: true
|
@@ -9,38 +9,12 @@ module DiscoApp::Concerns::AppInstalledJob
|
|
9
9
|
|
10
10
|
# Perform application installation.
|
11
11
|
#
|
12
|
-
# -
|
13
|
-
# webhook_topics methods.
|
12
|
+
# - Synchronise webhooks.
|
14
13
|
# - Perform initial update of shop information.
|
15
14
|
#
|
16
15
|
def perform(domain)
|
17
|
-
(
|
18
|
-
ShopifyAPI::Webhook.create(topic: topic, address: webhooks_url, format: 'json')
|
19
|
-
end
|
20
|
-
|
16
|
+
DiscoApp::SynchroniseWebhooksJob.perform_now(domain)
|
21
17
|
DiscoApp::ShopUpdateJob.perform_now(domain)
|
22
18
|
end
|
23
19
|
|
24
|
-
protected
|
25
|
-
|
26
|
-
# Return a list of additional webhook topics to listen for. This method
|
27
|
-
# can be overridden in the application to provide a list of app-specific
|
28
|
-
# webhooks that should be created during installation.
|
29
|
-
def webhook_topics
|
30
|
-
[]
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
# Return a list of webhook topics that will always be set up for the
|
36
|
-
# # application.
|
37
|
-
def base_webhook_topics
|
38
|
-
[:'app/uninstalled', :'shop/update']
|
39
|
-
end
|
40
|
-
|
41
|
-
# Return the absolute URL to the webhooks endpoint.
|
42
|
-
def webhooks_url
|
43
|
-
DiscoApp::Engine.routes.url_helpers.webhooks_url
|
44
|
-
end
|
45
|
-
|
46
20
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module DiscoApp::Concerns::SynchroniseWebhooksJob
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
# Ensure the webhooks registered with our shop are the same as those listed
|
5
|
+
# in our application configuration.
|
6
|
+
def perform(shopify_domain)
|
7
|
+
# Get the full list of expected webhook topics.
|
8
|
+
expected_topics = [:'app/uninstalled', :'shop/update'] + topics
|
9
|
+
|
10
|
+
# Registered any webhooks that haven't been registered yet.
|
11
|
+
(expected_topics - current_topics).each do |topic|
|
12
|
+
ShopifyAPI::Webhook.create(topic: topic, address: webhooks_url, format: 'json')
|
13
|
+
end
|
14
|
+
|
15
|
+
# Remove any extraneous topics.
|
16
|
+
current_webhooks.each do |webhook|
|
17
|
+
unless expected_topics.include?(webhook.topic.to_sym)
|
18
|
+
webhook.delete
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
|
25
|
+
# Return a list of additional webhook topics to listen for. This method
|
26
|
+
# can be overridden in the application to provide a list of app-specific
|
27
|
+
# webhooks that should be created during synchronisation.
|
28
|
+
def topics
|
29
|
+
[]
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
# Return a list of currently registered topics.
|
35
|
+
def current_topics
|
36
|
+
current_webhooks.map(&:topic).map(&:to_sym)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Return a list of current registered webhooks.
|
40
|
+
def current_webhooks
|
41
|
+
@current_webhooks ||= ShopifyAPI::Webhook.find(:all)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Return the absolute URL to the webhooks endpoint.
|
45
|
+
def webhooks_url
|
46
|
+
DiscoApp::Engine.routes.url_helpers.webhooks_url
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -17,7 +17,7 @@ module DiscoApp::Concerns::Shop
|
|
17
17
|
# Define some useful scopes.
|
18
18
|
scope :status, -> (status) { where status: status }
|
19
19
|
scope :installed, -> { where status: statuses[:installed] }
|
20
|
-
scope :has_active_shopify_plan, -> { where.not(plan_name: [:cancelled, :frozen]) }
|
20
|
+
scope :has_active_shopify_plan, -> { where.not(plan_name: [:cancelled, :frozen, :fraudulent]) }
|
21
21
|
|
22
22
|
# Alias 'with_shopify_session' as 'temp', as per our existing conventions.
|
23
23
|
alias_method :temp, :with_shopify_session
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module DiscoApp::Test
|
2
|
+
module FileFixtures
|
3
|
+
|
4
|
+
# Return an XML fixture as an XML string.
|
5
|
+
def xml_fixture(path)
|
6
|
+
filename = Rails.root.join('test', 'fixtures', 'xml', "#{path}.xml")
|
7
|
+
File.read(filename)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Return a JSON fixture as an indifferent hash.
|
11
|
+
def json_fixture(path, dir: 'json', parse: true)
|
12
|
+
filename = Rails.root.join('test', 'fixtures', dir, "#{path}.json")
|
13
|
+
return File.read(filename) unless parse
|
14
|
+
HashWithIndifferentAccess.new(ActiveSupport::JSON.decode(File.read(filename)))
|
15
|
+
end
|
16
|
+
|
17
|
+
# Webhook fixtures are special-case JSON fixtures.
|
18
|
+
def webhook_fixture(path, parse: true)
|
19
|
+
json_fixture(path, dir: 'webhooks', parse: parse)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'disco_app/support/file_fixtures'
|
2
|
+
|
3
|
+
# Make our helper modules available inside fixtures.
|
4
|
+
ActiveRecord::FixtureSet.context_class.send :include, DiscoApp::Test::FileFixtures
|
5
|
+
|
6
|
+
# Include FileFixture helpers in base TestCase class.
|
7
|
+
class ActiveSupport::TestCase
|
8
|
+
|
9
|
+
include DiscoApp::Test::FileFixtures
|
10
|
+
|
11
|
+
end
|
data/lib/disco_app/version.rb
CHANGED
@@ -83,24 +83,6 @@ class DiscoAppGenerator < Rails::Generators::Base
|
|
83
83
|
copy_file 'config/puma.rb', 'config/puma.rb'
|
84
84
|
end
|
85
85
|
|
86
|
-
# Create Rakefiles
|
87
|
-
def create_rakefiles
|
88
|
-
rakefile 'start.rake' do
|
89
|
-
<<-RAKEFILE.strip_heredoc
|
90
|
-
task start: :environment do
|
91
|
-
system 'bundle exec rails server -b 127.0.0.1 -p 3000'
|
92
|
-
end
|
93
|
-
RAKEFILE
|
94
|
-
end
|
95
|
-
rakefile 'console.rake' do
|
96
|
-
<<-RAKEFILE.strip_heredoc
|
97
|
-
task console: :environment do
|
98
|
-
system 'bundle exec rails console'
|
99
|
-
end
|
100
|
-
RAKEFILE
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
86
|
# Set up routes.
|
105
87
|
def setup_routes
|
106
88
|
route "mount DiscoApp::Engine, at: '/'"
|
@@ -135,6 +117,11 @@ class DiscoAppGenerator < Rails::Generators::Base
|
|
135
117
|
remove_file 'app/views/layout/embedded_app.html.erb'
|
136
118
|
end
|
137
119
|
|
120
|
+
# Add the Disco App test helper to test/test_helper.rb
|
121
|
+
def add_test_helper
|
122
|
+
inject_into_file 'test/test_helper.rb', "require 'disco_app/test_help'\n", { after: "require 'rails/test_help'\n" }
|
123
|
+
end
|
124
|
+
|
138
125
|
# Copy engine migrations over.
|
139
126
|
def install_migrations
|
140
127
|
rake 'disco_app:install:migrations'
|
@@ -0,0 +1,10 @@
|
|
1
|
+
namespace :webhooks do
|
2
|
+
|
3
|
+
desc 'Synchronise webhooks across all installed shops.'
|
4
|
+
task sync: :environment do
|
5
|
+
DiscoApp::Shop.installed.has_active_shopify_plan.each do |shop|
|
6
|
+
DiscoApp::SynchroniseWebhooksJob.perform_later(shop.shopify_domain)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
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.
|
4
|
+
version: 0.6.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gavin Ballard
|
@@ -278,8 +278,10 @@ files:
|
|
278
278
|
- app/jobs/disco_app/concerns/app_installed_job.rb
|
279
279
|
- app/jobs/disco_app/concerns/app_uninstalled_job.rb
|
280
280
|
- app/jobs/disco_app/concerns/shop_update_job.rb
|
281
|
+
- app/jobs/disco_app/concerns/synchronise_webhooks_job.rb
|
281
282
|
- app/jobs/disco_app/shop_job.rb
|
282
283
|
- app/jobs/disco_app/shop_update_job.rb
|
284
|
+
- app/jobs/disco_app/synchronise_webhooks_job.rb
|
283
285
|
- app/models/disco_app/concerns/plan.rb
|
284
286
|
- app/models/disco_app/concerns/shop.rb
|
285
287
|
- app/models/disco_app/concerns/subscription.rb
|
@@ -313,6 +315,8 @@ files:
|
|
313
315
|
- db/migrate/20151017234409_move_shop_to_disco_app_engine.rb
|
314
316
|
- lib/disco_app.rb
|
315
317
|
- lib/disco_app/engine.rb
|
318
|
+
- lib/disco_app/support/file_fixtures.rb
|
319
|
+
- lib/disco_app/test_help.rb
|
316
320
|
- lib/disco_app/version.rb
|
317
321
|
- lib/generators/disco_app/USAGE
|
318
322
|
- lib/generators/disco_app/disco_app_generator.rb
|
@@ -327,6 +331,8 @@ files:
|
|
327
331
|
- lib/generators/disco_app/templates/initializers/shopify_session_repository.rb
|
328
332
|
- lib/generators/disco_app/templates/root/Procfile
|
329
333
|
- lib/generators/disco_app/templates/views/home/index.html.erb
|
334
|
+
- lib/tasks/start.rake
|
335
|
+
- lib/tasks/webhooks.rake
|
330
336
|
- test/controllers/disco_app/install_controller_test.rb
|
331
337
|
- test/controllers/disco_app/webhooks_controller_test.rb
|
332
338
|
- test/controllers/home_controller_test.rb
|