discourse_subscription_client 0.1.0.pre10 → 0.1.0.pre12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/app/controllers/discourse_subscription_client/no_access_controller.rb +9 -0
- data/app/models/subscription_client_supplier.rb +8 -14
- data/config/routes.rb +2 -0
- data/db/migrate/20230223135957_add_products_to_subscription_client_suppliers.rb +1 -1
- data/lib/discourse_subscription_client/engine.rb +10 -3
- data/lib/discourse_subscription_client/resources.rb +13 -19
- data/lib/discourse_subscription_client/subscriptions/result.rb +3 -2
- data/lib/discourse_subscription_client/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d17f2464b6f962f809428eea6207696f20a1d935ed573ec0f3970242712a8da9
|
4
|
+
data.tar.gz: f226a6927bc9e41fcd199572d5417850212de9d335ed58fa325b58b0842776d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cda4eb9051cbeb1a62e317a314d79bd08a2e0eb255775adf6e0c45ff53bb527ab3b14338d0a90d4f09fc28a8da20ebb3f375eeba33bc43770d7eb07734d99fa7
|
7
|
+
data.tar.gz: 72cfb38e708e8a4c8bb56cb8d38a7374300d194e68c461ef32bca490a199e00775463ec3196fca50b0166ee6d49ad0b04e9e25fda689811eab127074ac81e915
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@ This gem is only for use with Discourse plugins. It provides subscription client
|
|
5
5
|
Add this line to your plugin's `plugin.rb` file
|
6
6
|
|
7
7
|
```ruby
|
8
|
-
gem "discourse_subscription_client", "0.1.0.
|
8
|
+
gem "discourse_subscription_client", "0.1.0.pre11", require_name: "discourse_subscription_client"
|
9
9
|
```
|
10
10
|
|
11
11
|
## Usage
|
@@ -10,26 +10,20 @@ class SubscriptionClientSupplier < ActiveRecord::Base
|
|
10
10
|
scope :authorized, -> { where("api_key IS NOT NULL") }
|
11
11
|
|
12
12
|
def destroy_authorization
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
true
|
17
|
-
else
|
18
|
-
false
|
19
|
-
end
|
13
|
+
DiscourseSubscriptionClient::Authorization.revoke(self)
|
14
|
+
update(api_key: nil, user_id: nil, authorized_at: nil)
|
15
|
+
deactivate_all_subscriptions!
|
20
16
|
end
|
21
17
|
|
22
18
|
def authorized?
|
23
19
|
api_key.present?
|
24
20
|
end
|
25
21
|
|
26
|
-
def product_slugs
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
else
|
32
|
-
{}
|
22
|
+
def product_slugs(resource)
|
23
|
+
return {} unless products.present? && products[resource]
|
24
|
+
|
25
|
+
products[resource].each_with_object({}) do |product, result|
|
26
|
+
result[product["product_id"]] = product["product_slug"]
|
33
27
|
end
|
34
28
|
end
|
35
29
|
|
data/config/routes.rb
CHANGED
@@ -29,6 +29,7 @@ module DiscourseSubscriptionClient
|
|
29
29
|
../../app/models/subscription_client_resource
|
30
30
|
../../app/models/subscription_client_subscription
|
31
31
|
../../app/models/subscription_client_supplier
|
32
|
+
../../app/controllers/discourse_subscription_client/no_access_controller
|
32
33
|
../../app/controllers/discourse_subscription_client/admin_controller
|
33
34
|
../../app/controllers/discourse_subscription_client/subscriptions_controller
|
34
35
|
../../app/controllers/discourse_subscription_client/suppliers_controller
|
@@ -87,7 +88,7 @@ module DiscourseSubscriptionClient
|
|
87
88
|
end
|
88
89
|
|
89
90
|
def plugin_status_server_url
|
90
|
-
"https://
|
91
|
+
"https://coop.pavilion.tech"
|
91
92
|
end
|
92
93
|
|
93
94
|
def database_exists?
|
@@ -109,9 +110,15 @@ module DiscourseSubscriptionClient
|
|
109
110
|
result = DiscourseSubscriptionClient::Subscriptions::Result.new
|
110
111
|
return result unless subscriptions.exists?
|
111
112
|
|
112
|
-
|
113
|
-
|
113
|
+
resource = subscriptions.first.resource
|
114
|
+
supplier = resource.supplier
|
115
|
+
products = supplier.product_slugs(resource_name)
|
116
|
+
return result unless products.present?
|
117
|
+
|
118
|
+
result.resource = resource
|
119
|
+
result.supplier = supplier
|
114
120
|
result.subscriptions = subscriptions.to_a
|
121
|
+
result.products = products
|
115
122
|
|
116
123
|
result
|
117
124
|
end
|
@@ -42,21 +42,13 @@ module DiscourseSubscriptionClient
|
|
42
42
|
supplier_urls = @resources.map { |resource| resource[:supplier_url] }.uniq.compact
|
43
43
|
|
44
44
|
supplier_urls.each do |url|
|
45
|
-
supplier = SubscriptionClientSupplier.
|
45
|
+
supplier = SubscriptionClientSupplier.find_or_create_by(url: url)
|
46
|
+
request = DiscourseSubscriptionClient::Request.new(:supplier, supplier.id)
|
47
|
+
data = request.perform("#{url}/subscription-server")
|
46
48
|
|
47
|
-
if
|
49
|
+
if valid_supplier_data?(data)
|
50
|
+
supplier.update(name: data[:supplier], products: data[:products])
|
48
51
|
@suppliers << supplier
|
49
|
-
else
|
50
|
-
supplier ||= SubscriptionClientSupplier.create!(url: url)
|
51
|
-
request = DiscourseSubscriptionClient::Request.new(:supplier, supplier.id)
|
52
|
-
data = request.perform("#{url}/subscription-server")
|
53
|
-
|
54
|
-
if valid_supplier_data?(data)
|
55
|
-
supplier.update(name: data[:supplier], products: data[:products])
|
56
|
-
@suppliers << supplier
|
57
|
-
else
|
58
|
-
supplier.destroy!
|
59
|
-
end
|
60
52
|
end
|
61
53
|
end
|
62
54
|
end
|
@@ -98,12 +90,14 @@ module DiscourseSubscriptionClient
|
|
98
90
|
return false unless data.present? && data.is_a?(Hash)
|
99
91
|
return false unless %i[supplier products].all? { |key| data.key?(key) }
|
100
92
|
return false unless data[:supplier].is_a?(String)
|
101
|
-
return false unless data[:products].is_a?(
|
102
|
-
|
103
|
-
data[:products].all? do |
|
104
|
-
|
105
|
-
|
106
|
-
|
93
|
+
return false unless data[:products].is_a?(Hash)
|
94
|
+
|
95
|
+
data[:products].all? do |_resource, products|
|
96
|
+
products.is_a?(Array) &&
|
97
|
+
products.all? do |product|
|
98
|
+
%i[product_id product_slug].all? do |key|
|
99
|
+
product.key?(key) && product[key].is_a?(String)
|
100
|
+
end
|
107
101
|
end
|
108
102
|
end
|
109
103
|
end
|
@@ -5,10 +5,11 @@ module DiscourseSubscriptionClient
|
|
5
5
|
class Result
|
6
6
|
attr_accessor :supplier,
|
7
7
|
:resource,
|
8
|
-
:subscriptions
|
8
|
+
:subscriptions,
|
9
|
+
:products
|
9
10
|
|
10
11
|
def any?
|
11
|
-
supplier.present? && resource.present? && subscriptions.present?
|
12
|
+
supplier.present? && resource.present? && subscriptions.present? && products.present?
|
12
13
|
end
|
13
14
|
end
|
14
15
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: discourse_subscription_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.
|
4
|
+
version: 0.1.0.pre12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Angus McLeod
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|
@@ -233,6 +233,7 @@ files:
|
|
233
233
|
- app/assets/config/discourse_subscription_client_manifest.js
|
234
234
|
- app/assets/stylesheets/discourse_subscription_client/application.css
|
235
235
|
- app/controllers/discourse_subscription_client/admin_controller.rb
|
236
|
+
- app/controllers/discourse_subscription_client/no_access_controller.rb
|
236
237
|
- app/controllers/discourse_subscription_client/notices_controller.rb
|
237
238
|
- app/controllers/discourse_subscription_client/subscriptions_controller.rb
|
238
239
|
- app/controllers/discourse_subscription_client/suppliers_controller.rb
|
@@ -292,7 +293,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
292
293
|
- !ruby/object:Gem::Version
|
293
294
|
version: 1.3.1
|
294
295
|
requirements: []
|
295
|
-
rubygems_version: 3.
|
296
|
+
rubygems_version: 3.4.6
|
296
297
|
signing_key:
|
297
298
|
specification_version: 4
|
298
299
|
summary: Discourse plugin subscription client.
|