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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7be1c54ac40f2c0221c35038e20c1daa1fac8f39c0736d11a858f805a6220791
4
- data.tar.gz: d8a564f4d2c9bc8ef052a47719c42dcc36df45ba42d8848d32fd6a8d03b0c8cb
3
+ metadata.gz: d17f2464b6f962f809428eea6207696f20a1d935ed573ec0f3970242712a8da9
4
+ data.tar.gz: f226a6927bc9e41fcd199572d5417850212de9d335ed58fa325b58b0842776d3
5
5
  SHA512:
6
- metadata.gz: f401dbabaa835f14619e4aa3263cee2df00048ae43c8fabd9fdae16e5c99806b6caf09896d4470c32923be77fe0a6b73d0efcd97589394d601647e3614e18d6a
7
- data.tar.gz: 0f10faf5cd3ed514bee5ef10555846c3c66f278e3adc8360a04d4ce8e5f56a12122aa86ed763b8c1988ca4815b39432d06219a1f981f4b0919244d387c4091e5
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.pre5", require_name: "discourse_subscription_client"
8
+ gem "discourse_subscription_client", "0.1.0.pre11", require_name: "discourse_subscription_client"
9
9
  ```
10
10
 
11
11
  ## Usage
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DiscourseSubscriptionClient
4
+ class NoAccessController < ApplicationController
5
+ def index
6
+ head :ok
7
+ end
8
+ end
9
+ end
@@ -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
- if DiscourseSubscriptionClient::Authorization.revoke(self)
14
- update(api_key: nil, user_id: nil, authorized_at: nil)
15
- deactivate_all_subscriptions!
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
- if products.present?
28
- products.each_with_object({}) do |product, result|
29
- result[product["product_id"]] = product["product_slug"]
30
- end
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
@@ -17,4 +17,6 @@ DiscourseSubscriptionClient::Engine.routes.draw do
17
17
  put "notices/:notice_id/dismiss" => "notices#dismiss"
18
18
  put "notices/:notice_id/hide" => "notices#hide"
19
19
  put "notices/:notice_id/show" => "notices#show"
20
+
21
+ get "no-access" => "no_access#index"
20
22
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  class AddProductsToSubscriptionClientSuppliers < ActiveRecord::Migration[7.0]
4
4
  def change
5
- add_column :subscription_client_suppliers, :products, :json
5
+ add_column :subscription_client_suppliers, :products, :json, if_not_exists: true
6
6
  end
7
7
  end
@@ -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://discourse.pluginmanager.org"
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
- result.resource = subscriptions.first.resource
113
- result.supplier = subscriptions.first.resource.supplier
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.find_by(url: url)
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 supplier&.name
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?(Array)
102
-
103
- data[:products].all? do |product|
104
- product.is_a?(Hash) &&
105
- %i[product_id product_slug].all? do |key|
106
- product.key?(key) && product[key].is_a?(String)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DiscourseSubscriptionClient
4
- VERSION = "0.1.0.pre10"
4
+ VERSION = "0.1.0.pre12"
5
5
  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.pre10
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-02-24 00:00:00.000000000 Z
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.3.26
296
+ rubygems_version: 3.4.6
296
297
  signing_key:
297
298
  specification_version: 4
298
299
  summary: Discourse plugin subscription client.