discourse_subscription_client 0.1.0.pre4 → 0.1.0.pre6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +47 -15
  3. data/app/models/subscription_client_subscription.rb +6 -1
  4. data/app/models/subscription_client_supplier.rb +6 -0
  5. data/config/routes.rb +1 -0
  6. data/config/settings.yml +0 -2
  7. data/db/migrate/20230221100514_create_subscription_client_suppliers.rb +1 -1
  8. data/db/migrate/20230221100524_create_subscription_client_resources.rb +1 -1
  9. data/db/migrate/20230221100529_create_subscription_client_notices.rb +1 -1
  10. data/db/migrate/20230221100535_create_subscription_client_subscriptions.rb +1 -1
  11. data/db/migrate/20230221100540_create_subscription_client_requests.rb +1 -1
  12. data/db/migrate/20230223135957_add_products_to_subscription_client_suppliers.rb +7 -0
  13. data/extensions/discourse_subscription_client/{current_user.rb → current_user_serializer.rb} +12 -0
  14. data/extensions/discourse_subscription_client/site_serializer.rb +15 -0
  15. data/lib/discourse_subscription_client/engine.rb +26 -5
  16. data/lib/discourse_subscription_client/resources.rb +16 -3
  17. data/lib/discourse_subscription_client/subscriptions/result.rb +6 -109
  18. data/lib/discourse_subscription_client/subscriptions/update_result.rb +118 -0
  19. data/lib/discourse_subscription_client/subscriptions.rb +1 -1
  20. data/lib/discourse_subscription_client/version.rb +1 -1
  21. metadata +23 -6
  22. /data/app/jobs/{regular/discourse_subscription_client_find_resources.rb → discourse_subscription_client_find_resources.rb} +0 -0
  23. /data/app/jobs/{scheduled/discourse_subscription_client_update_notices.rb → discourse_subscription_client_update_notices.rb} +0 -0
  24. /data/app/jobs/{scheduled/discourse_subscription_client_update_subscriptions.rb → discourse_subscription_client_update_subscriptions.rb} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 307c93dedfd3a85110f7ad12a1d7e6e91bb1aecaaffc7e6025fec54905aa0df7
4
- data.tar.gz: 11dd2c79ba1d825028cc32d2fabc31b0d889be2cb4d2f3c1ad1664c23025dad0
3
+ metadata.gz: 3449957ada14519fd11be48009e904a8fbfc06d6f12f2ede952a1b7e426c2b53
4
+ data.tar.gz: 3befbc23e94b37dfcf7f9f7ecef9aa07d7bba851d2c9a0395a990af7adbcc501
5
5
  SHA512:
6
- metadata.gz: f22185915974d1abbc65ae2b0ed1b14022eb14ebdf7a9f8d12e03b3a00968d93ec69d39c25ad286149d95cec29e8e5035b4c52f38fbd362720664970f0044472
7
- data.tar.gz: 6f47325b66b776ac2485989006b7d63f3d6e389f5cf0c53b5c4eb8914d8cb16481dcc05d46eeecada45a9ecd620ca70bd64ea2f502af0d3fcfe09a1760c5cc4e
6
+ metadata.gz: 057bd00307d2c7f8a9d5aec6e71871efee9fa5ffe52bddee16ca4a3c2373cf21f7d9dfa18ea16be62435184c5112c4f4b2d9366f740189a8bddb293fbdfa404e
7
+ data.tar.gz: 9d2a38b104215c347bc51caa6725c0f1c5123de9cd9d0c916c825814cda2b9c3586c52332f1485c37858a073c0aad5258f6ab86055910b104a55ce2d47c215c5
data/README.md CHANGED
@@ -1,28 +1,60 @@
1
- # DiscourseSubscriptionClient
2
- Short description and motivation.
1
+ # Discourse Subscription Client Gem
2
+ This gem is only for use with Discourse plugins. It provides subscription client support to a Discourse plugin, primarily for use with the Discourse Subscription Server plugin.
3
+
4
+ ## Installation
5
+ Add this line to your plugin's `plugin.rb` file
6
+
7
+ ```ruby
8
+ gem "discourse_subscription_client", "0.1.0.pre5", require_name: "discourse_subscription_client"
9
+ ```
3
10
 
4
11
  ## Usage
5
- How to use my plugin.
6
12
 
7
- ## Installation
8
- Add this line to your application's Gemfile:
13
+ The gem API is accessible through the `DiscourseSubscriptionClient` class. Supported methods are described below.
14
+
15
+ ### find_subscriptions
9
16
 
10
17
  ```ruby
11
- gem "discourse_subscription_client"
18
+ DiscourseSubscriptionClient.find_subscriptions(resource_name)
12
19
  ```
13
20
 
14
- And then execute:
15
- ```bash
16
- $ bundle
21
+ #### Arguments
22
+
23
+ ##### resource_name
24
+
25
+ The name of a resource defined in the `discourse-subscription-server` plugin's `subscription_server_subscriptions` setting.
26
+
27
+ #### Returns
28
+
29
+ Returns a `DiscourseSubscriptionClient::Subscriptions::Result` object, containing the supplier, resource and any active subscriptions.
30
+
31
+ #### Example
32
+
33
+ ```ruby
34
+ result = DiscourseSubscriptionClient.find_subscriptions("discourse-custom-wizard")
35
+ result.supplier # <DiscourseSubscriptionSupplier name="Pavilion" ...>
36
+ result.resource # <DiscourseSubscriptionResource name="discourse-custom-wizard" ...>
37
+ result.subscriptions # [<DiscourseSubscriptionSubscription product_name="Business" ...>]
17
38
  ```
18
39
 
19
- Or install it yourself as:
20
- ```bash
21
- $ gem install discourse_subscription_client
40
+ ## Development
41
+
42
+ ### Tests
43
+ The gem has to create a dummy Discourse environment when running specs, so there are a few testing quirks.
44
+
45
+ Discourse migrations go in `db/migrate` as normal. They are including in the rails migrations_paths in `lib/discourse_subscription_client/engine.rb`.
46
+
47
+ If you add new migrations, run test migrations as normal (from the root of the gem)
48
+
49
+ ```
50
+ RAILS_ENV=test rake db:drop db:create db:migrate
22
51
  ```
23
52
 
24
- ## Contributing
25
- Contribution directions go here.
53
+ If you're not adding new migrations you only need to load the schema. If you are running migrations you need to also load the schema (in addition to running the migrations)
54
+
55
+ ```
56
+ RAILS_ENV=test rake db:schema:load
57
+ ```
26
58
 
27
59
  ## License
28
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
60
+ The gem is available as open source under the terms of the [GNU GPL v2 License](https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html).
@@ -6,7 +6,12 @@ class SubscriptionClientSubscription < ActiveRecord::Base
6
6
 
7
7
  belongs_to :resource, class_name: "SubscriptionClientResource"
8
8
 
9
- scope :active, -> { where("subscribed = true AND updated_at > ?", SubscriptionClientSubscription.update_period) }
9
+ scope :active, lambda {
10
+ where(
11
+ "subscription_client_subscriptions.subscribed = true AND
12
+ subscription_client_subscriptions.updated_at > ?", SubscriptionClientSubscription.update_period
13
+ )
14
+ }
10
15
 
11
16
  def active
12
17
  subscribed && updated_at.to_datetime > self.class.update_period.to_datetime
@@ -23,6 +23,12 @@ class SubscriptionClientSupplier < ActiveRecord::Base
23
23
  api_key.present?
24
24
  end
25
25
 
26
+ def product_slugs
27
+ @product_slugs ||= products.each_with_object({}) do |product, result|
28
+ result[product["product_id"]] = product["product_slug"]
29
+ end
30
+ end
31
+
26
32
  def deactivate_all_subscriptions!
27
33
  subscriptions.update_all(subscribed: false)
28
34
  end
data/config/routes.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  DiscourseSubscriptionClient::Engine.routes.draw do
4
4
  get "" => "admin#index"
5
5
  get ".json" => "admin#index"
6
+ get "no-access" => "admin#index"
6
7
 
7
8
  get "suppliers" => "suppliers#index"
8
9
  get "suppliers/authorize" => "suppliers#authorize"
data/config/settings.yml CHANGED
@@ -1,7 +1,6 @@
1
1
  plugins:
2
2
  subscription_client_enabled:
3
3
  default: true
4
- client: true
5
4
  subscription_client_verbose_logs:
6
5
  default: false
7
6
  subscription_client_warning_notices_on_dashboard:
@@ -10,7 +9,6 @@ plugins:
10
9
  default: false
11
10
  subscription_client_allow_moderator_supplier_management:
12
11
  default: false
13
- client: true
14
12
  subscription_client_request_plugin_statuses:
15
13
  default: false
16
14
  hidden: true
@@ -2,7 +2,7 @@
2
2
 
3
3
  class CreateSubscriptionClientSuppliers < ActiveRecord::Migration[7.0]
4
4
  def change
5
- create_table :subscription_client_suppliers do |t|
5
+ create_table :subscription_client_suppliers, if_not_exists: true do |t|
6
6
  t.string :name
7
7
  t.string :url, null: false
8
8
  t.string :api_key
@@ -2,7 +2,7 @@
2
2
 
3
3
  class CreateSubscriptionClientResources < ActiveRecord::Migration[7.0]
4
4
  def change
5
- create_table :subscription_client_resources do |t|
5
+ create_table :subscription_client_resources, if_not_exists: true do |t|
6
6
  t.references :supplier, foreign_key: { to_table: :subscription_client_suppliers }
7
7
  t.string :name, null: false
8
8
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  class CreateSubscriptionClientNotices < ActiveRecord::Migration[7.0]
4
4
  def change
5
- create_table :subscription_client_notices do |t|
5
+ create_table :subscription_client_notices, if_not_exists: true do |t|
6
6
  t.string :title, null: false
7
7
  t.string :message
8
8
  t.integer :notice_type, null: false
@@ -2,7 +2,7 @@
2
2
 
3
3
  class CreateSubscriptionClientSubscriptions < ActiveRecord::Migration[7.0]
4
4
  def change
5
- create_table :subscription_client_subscriptions do |t|
5
+ create_table :subscription_client_subscriptions, if_not_exists: true do |t|
6
6
  t.references :resource, foreign_key: { to_table: :subscription_client_resources }
7
7
  t.string :product_id, null: false
8
8
  t.string :product_name
@@ -2,7 +2,7 @@
2
2
 
3
3
  class CreateSubscriptionClientRequests < ActiveRecord::Migration[7.0]
4
4
  def change
5
- create_table :subscription_client_requests do |t|
5
+ create_table :subscription_client_requests, if_not_exists: true do |t|
6
6
  t.bigint :request_id
7
7
  t.string :request_type
8
8
  t.datetime :expired_at
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddProductsToSubscriptionClientSuppliers < ActiveRecord::Migration[7.0]
4
+ def change
5
+ add_column :subscription_client_suppliers, :products, :json
6
+ end
7
+ end
@@ -2,6 +2,14 @@
2
2
 
3
3
  module DiscourseSubscriptionClient
4
4
  module CurrentUserSerializerExtension
5
+ def attributes
6
+ super.tap do |attrs|
7
+ attrs[:subscription_notice_count] = subscription_notice_count if include_subscription_notice_count?
8
+ attrs[:can_manage_subscriptions] = can_manage_subscriptions
9
+ attrs[:can_manage_suppliers] = can_manage_suppliers
10
+ end
11
+ end
12
+
5
13
  def subscription_notice_count
6
14
  SubscriptionClientNotice.list(visible: true).count
7
15
  end
@@ -13,5 +21,9 @@ module DiscourseSubscriptionClient
13
21
  def can_manage_subscriptions
14
22
  scope.can_manage_subscriptions?
15
23
  end
24
+
25
+ def can_manage_suppliers
26
+ scope.can_manage_suppliers?
27
+ end
16
28
  end
17
29
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DiscourseSubscriptionClient
4
+ module SiteSerializerExtension
5
+ def attributes
6
+ super.tap do |attrs|
7
+ attrs[:subscription_client_enabled] = subscription_client_enabled
8
+ end
9
+ end
10
+
11
+ def subscription_client_enabled
12
+ SiteSetting.subscription_client_enabled
13
+ end
14
+ end
15
+ end
@@ -23,6 +23,7 @@ module DiscourseSubscriptionClient
23
23
  ./notices
24
24
  ./subscriptions
25
25
  ./subscriptions/result
26
+ ./subscriptions/update_result
26
27
  ../../app/models/subscription_client_notice
27
28
  ../../app/models/subscription_client_resource
28
29
  ../../app/models/subscription_client_subscription
@@ -35,16 +36,17 @@ module DiscourseSubscriptionClient
35
36
  ../../app/serializers/discourse_subscription_client/resource_serializer
36
37
  ../../app/serializers/discourse_subscription_client/notice_serializer
37
38
  ../../app/serializers/discourse_subscription_client/subscription_serializer
38
- ../../app/jobs/regular/discourse_subscription_client_find_resources
39
- ../../app/jobs/scheduled/discourse_subscription_client_update_subscriptions
40
- ../../app/jobs/scheduled/discourse_subscription_client_update_notices
41
- ../../extensions/discourse_subscription_client/current_user
39
+ ../../app/jobs/discourse_subscription_client_find_resources
40
+ ../../app/jobs/discourse_subscription_client_update_subscriptions
41
+ ../../app/jobs/discourse_subscription_client_update_notices
42
+ ../../extensions/discourse_subscription_client/current_user_serializer
43
+ ../../extensions/discourse_subscription_client/site_serializer
42
44
  ../../extensions/discourse_subscription_client/guardian
43
45
  ].each do |path|
44
46
  require_relative path
45
47
  end
46
48
 
47
- Jobs.enqueue(:discourse_subscription_client_find_resources) if DiscourseSubscriptionClient.database_exists? && !Rails.env.test?
49
+ Jobs.enqueue(:discourse_subscription_client_find_resources) if !Rails.env.test? && DiscourseSubscriptionClient.database_exists?
48
50
 
49
51
  Rails.application.routes.append do
50
52
  mount DiscourseSubscriptionClient::Engine, at: "/admin/plugins/subscription-client"
@@ -54,6 +56,7 @@ module DiscourseSubscriptionClient
54
56
 
55
57
  Guardian.prepend DiscourseSubscriptionClient::GuardianExtension
56
58
  CurrentUserSerializer.prepend DiscourseSubscriptionClient::CurrentUserSerializerExtension
59
+ SiteSerializer.prepend DiscourseSubscriptionClient::SiteSerializerExtension
57
60
 
58
61
  User.has_many(:subscription_client_suppliers)
59
62
 
@@ -93,5 +96,23 @@ module DiscourseSubscriptionClient
93
96
  else
94
97
  true
95
98
  end
99
+
100
+ def find_subscriptions(resource_name = nil)
101
+ return nil unless resource_name
102
+
103
+ subscriptions = SubscriptionClientSubscription.active
104
+ .includes(resource: [:supplier])
105
+ .references(resource: [:supplier])
106
+ .where("subscription_client_resources.name = ? ", resource_name)
107
+
108
+ result = DiscourseSubscriptionClient::Subscriptions::Result.new
109
+ return result unless subscriptions.exists?
110
+
111
+ result.resource = subscriptions.first.resource
112
+ result.supplier = subscriptions.first.resource.supplier
113
+ result.subscriptions = subscriptions.to_a
114
+
115
+ result
116
+ end
96
117
  end
97
118
  end
@@ -51,8 +51,8 @@ module DiscourseSubscriptionClient
51
51
  request = DiscourseSubscriptionClient::Request.new(:supplier, supplier.id)
52
52
  data = request.perform("#{url}/subscription-server")
53
53
 
54
- if data
55
- supplier.update(name: data[:supplier])
54
+ if valid_supplier_data?(data)
55
+ supplier.update(name: data[:supplier], products: data[:products])
56
56
  @suppliers << supplier
57
57
  else
58
58
  supplier.destroy!
@@ -89,9 +89,22 @@ module DiscourseSubscriptionClient
89
89
 
90
90
  @resources << {
91
91
  name: metadata.name,
92
- supplier_url: metadata.subscription_url
92
+ supplier_url: ENV["TEST_SUBSCRIPTION_URL"] || metadata.subscription_url
93
93
  }
94
94
  end
95
95
  end
96
+
97
+ def valid_supplier_data?(data)
98
+ return false unless %i[supplier products].all? { |key| data.key?(key) }
99
+ return false unless data[:supplier].is_a?(String)
100
+ return false unless data[:products].is_a?(Array)
101
+
102
+ data[:products].all? do |product|
103
+ product.is_a?(Hash) &&
104
+ %i[product_id product_slug].all? do |key|
105
+ product.key?(key) && product[key].is_a?(String)
106
+ end
107
+ end
108
+ end
96
109
  end
97
110
  end
@@ -1,117 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module ::DiscourseSubscriptionClient
3
+ module DiscourseSubscriptionClient
4
4
  class Subscriptions
5
5
  class Result
6
- REQUIRED_KEYS ||= %i[
7
- resource_id
8
- product_id
9
- price_id
10
- ].freeze
11
- OPTIONAL_KEYS ||= %i[
12
- product_name
13
- price_name
14
- ].freeze
15
- KEYS = REQUIRED_KEYS + OPTIONAL_KEYS
6
+ attr_accessor :supplier,
7
+ :resource,
8
+ :subscriptions
16
9
 
17
- attr_reader :errors,
18
- :errored_suppliers,
19
- :infos
20
-
21
- def initialize
22
- @errors = []
23
- @infos = []
24
- end
25
-
26
- def not_authorized(supplier)
27
- error("not_authorized", supplier)
28
- end
29
-
30
- def retrieve_subscriptions(supplier, raw_data)
31
- subscriptions_data = raw_data[:subscriptions].compact
32
-
33
- unless subscriptions_data.present? && subscriptions_data.is_a?(Array)
34
- error("invalid_response", supplier)
35
- return []
36
- end
37
-
38
- # subscriptions must be properly formed
39
-
40
- subscriptions_data =
41
- subscriptions_data
42
- .map(&:symbolize_keys)
43
- .each { |data| data[:resource_id] = data[:resource] }
44
- .select { |data| REQUIRED_KEYS.all? { |key| data.key?(key) } }
45
-
46
- # we only care about subscriptions for resources on this instance
47
-
48
- resources = SubscriptionClientResource.where(
49
- supplier_id: supplier.id,
50
- name: subscriptions_data.map { |data| data[:resource] }
51
- )
52
-
53
- subscriptions_data.each_with_object([]) do |data, result|
54
- resource = resources.select { |r| r.name === data[:resource] }.first
55
-
56
- if resource.present?
57
- data[:resource_id] = resource.id
58
- result << OpenStruct.new(
59
- required: data.slice(*REQUIRED_KEYS),
60
- create: data.slice(*KEYS),
61
- subscription: nil
62
- )
63
- else
64
- info("no_resource", supplier, resource: data[:resource])
65
- end
66
- end
67
- end
68
-
69
- def connection_error(supplier)
70
- error("supplier_connection", supplier)
71
- end
72
-
73
- def no_suppliers
74
- info("no_suppliers")
75
- end
76
-
77
- def no_subscriptions(supplier)
78
- info("no_subscriptions", supplier)
79
- end
80
-
81
- def updated_subscription(supplier, subscription_ids: nil)
82
- info("updated_subscription", supplier, subscription_ids: subscription_ids)
83
- end
84
-
85
- def created_subscription(supplier, subscription_ids: nil)
86
- info("created_subscription", supplier, subscription_ids: subscription_ids)
87
- end
88
-
89
- def failed_to_create_subscription(supplier, subscription_ids: nil)
90
- info("failed_to_create_subscription", supplier, subscription_ids: subscription_ids)
91
- end
92
-
93
- def info(key, supplier = nil, subscription_ids: nil, resource: nil)
94
- attrs = {}
95
-
96
- if supplier
97
- attrs = {
98
- supplier: supplier.name,
99
- supplier_url: supplier.url,
100
- deep_interpolation: true,
101
- price: "",
102
- resource_name: ""
103
- }
104
- end
105
-
106
- attrs.merge!(subscription_ids) if subscription_ids.present?
107
- attrs[:resource] if resource.present?
108
-
109
- @infos << I18n.t("subscription_client.subscriptions.info.#{key}", **attrs)
110
- end
111
-
112
- def error(key, supplier)
113
- @errors << I18n.t("subscription_client.subscriptions.error.#{key}", supplier: supplier.name,
114
- supplier_url: supplier.url)
10
+ def any?
11
+ supplier.present? && resource.present? && subscriptions.present?
115
12
  end
116
13
  end
117
14
  end
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ::DiscourseSubscriptionClient
4
+ class Subscriptions
5
+ class UpdateResult
6
+ REQUIRED_KEYS ||= %i[
7
+ resource_id
8
+ product_id
9
+ price_id
10
+ ].freeze
11
+ OPTIONAL_KEYS ||= %i[
12
+ product_name
13
+ price_name
14
+ ].freeze
15
+ KEYS = REQUIRED_KEYS + OPTIONAL_KEYS
16
+
17
+ attr_reader :errors,
18
+ :errored_suppliers,
19
+ :infos
20
+
21
+ def initialize
22
+ @errors = []
23
+ @infos = []
24
+ end
25
+
26
+ def not_authorized(supplier)
27
+ error("not_authorized", supplier)
28
+ end
29
+
30
+ def retrieve_subscriptions(supplier, raw_data)
31
+ subscriptions_data = raw_data[:subscriptions].compact
32
+
33
+ unless subscriptions_data.present? && subscriptions_data.is_a?(Array)
34
+ error("invalid_response", supplier)
35
+ return []
36
+ end
37
+
38
+ # subscriptions must be properly formed
39
+
40
+ subscriptions_data =
41
+ subscriptions_data
42
+ .map(&:symbolize_keys)
43
+ .each { |data| data[:resource_id] = data[:resource] }
44
+ .select { |data| REQUIRED_KEYS.all? { |key| data.key?(key) } }
45
+
46
+ # we only care about subscriptions for resources on this instance
47
+
48
+ resources = SubscriptionClientResource.where(
49
+ supplier_id: supplier.id,
50
+ name: subscriptions_data.map { |data| data[:resource] }
51
+ )
52
+
53
+ subscriptions_data.each_with_object([]) do |data, result|
54
+ resource = resources.select { |r| r.name === data[:resource] }.first
55
+
56
+ if resource.present?
57
+ data[:resource_id] = resource.id
58
+ result << OpenStruct.new(
59
+ required: data.slice(*REQUIRED_KEYS),
60
+ create: data.slice(*KEYS),
61
+ subscription: nil
62
+ )
63
+ else
64
+ info("no_resource", supplier, resource: data[:resource])
65
+ end
66
+ end
67
+ end
68
+
69
+ def connection_error(supplier)
70
+ error("supplier_connection", supplier)
71
+ end
72
+
73
+ def no_suppliers
74
+ info("no_suppliers")
75
+ end
76
+
77
+ def no_subscriptions(supplier)
78
+ info("no_subscriptions", supplier)
79
+ end
80
+
81
+ def updated_subscription(supplier, subscription_ids: nil)
82
+ info("updated_subscription", supplier, subscription_ids: subscription_ids)
83
+ end
84
+
85
+ def created_subscription(supplier, subscription_ids: nil)
86
+ info("created_subscription", supplier, subscription_ids: subscription_ids)
87
+ end
88
+
89
+ def failed_to_create_subscription(supplier, subscription_ids: nil)
90
+ info("failed_to_create_subscription", supplier, subscription_ids: subscription_ids)
91
+ end
92
+
93
+ def info(key, supplier = nil, subscription_ids: nil, resource: nil)
94
+ attrs = {}
95
+
96
+ if supplier
97
+ attrs = {
98
+ supplier: supplier.name,
99
+ supplier_url: supplier.url,
100
+ deep_interpolation: true,
101
+ price: "",
102
+ resource_name: ""
103
+ }
104
+ end
105
+
106
+ attrs.merge!(subscription_ids) if subscription_ids.present?
107
+ attrs[:resource] if resource.present?
108
+
109
+ @infos << I18n.t("subscription_client.subscriptions.info.#{key}", **attrs)
110
+ end
111
+
112
+ def error(key, supplier)
113
+ @errors << I18n.t("subscription_client.subscriptions.error.#{key}", supplier: supplier.name,
114
+ supplier_url: supplier.url)
115
+ end
116
+ end
117
+ end
118
+ end
@@ -13,7 +13,7 @@ module DiscourseSubscriptionClient
13
13
  def update
14
14
  return unless SiteSetting.subscription_client_enabled
15
15
 
16
- @result = DiscourseSubscriptionClient::Subscriptions::Result.new
16
+ @result = DiscourseSubscriptionClient::Subscriptions::UpdateResult.new
17
17
 
18
18
  if @suppliers.blank?
19
19
  @result.no_suppliers
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DiscourseSubscriptionClient
4
- VERSION = "0.1.0.pre4"
4
+ VERSION = "0.1.0.pre6"
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.pre4
4
+ version: 0.1.0.pre6
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-21 00:00:00.000000000 Z
11
+ date: 2023-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: 7.0.4.1
139
+ - !ruby/object:Gem::Dependency
140
+ name: rails_multisite
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: rspec-activemodel-mocks
141
155
  requirement: !ruby/object:Gem::Requirement
@@ -222,9 +236,9 @@ files:
222
236
  - app/controllers/discourse_subscription_client/notices_controller.rb
223
237
  - app/controllers/discourse_subscription_client/subscriptions_controller.rb
224
238
  - app/controllers/discourse_subscription_client/suppliers_controller.rb
225
- - app/jobs/regular/discourse_subscription_client_find_resources.rb
226
- - app/jobs/scheduled/discourse_subscription_client_update_notices.rb
227
- - app/jobs/scheduled/discourse_subscription_client_update_subscriptions.rb
239
+ - app/jobs/discourse_subscription_client_find_resources.rb
240
+ - app/jobs/discourse_subscription_client_update_notices.rb
241
+ - app/jobs/discourse_subscription_client_update_subscriptions.rb
228
242
  - app/models/subscription_client_notice.rb
229
243
  - app/models/subscription_client_request.rb
230
244
  - app/models/subscription_client_resource.rb
@@ -242,8 +256,10 @@ files:
242
256
  - db/migrate/20230221100529_create_subscription_client_notices.rb
243
257
  - db/migrate/20230221100535_create_subscription_client_subscriptions.rb
244
258
  - db/migrate/20230221100540_create_subscription_client_requests.rb
245
- - extensions/discourse_subscription_client/current_user.rb
259
+ - db/migrate/20230223135957_add_products_to_subscription_client_suppliers.rb
260
+ - extensions/discourse_subscription_client/current_user_serializer.rb
246
261
  - extensions/discourse_subscription_client/guardian.rb
262
+ - extensions/discourse_subscription_client/site_serializer.rb
247
263
  - lib/discourse_subscription_client.rb
248
264
  - lib/discourse_subscription_client/authorization.rb
249
265
  - lib/discourse_subscription_client/engine.rb
@@ -252,6 +268,7 @@ files:
252
268
  - lib/discourse_subscription_client/resources.rb
253
269
  - lib/discourse_subscription_client/subscriptions.rb
254
270
  - lib/discourse_subscription_client/subscriptions/result.rb
271
+ - lib/discourse_subscription_client/subscriptions/update_result.rb
255
272
  - lib/discourse_subscription_client/version.rb
256
273
  homepage: https://github.com/paviliondev/discourse_subscription_client
257
274
  licenses: