discourse_subscription_client 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/discourse_subscription_client/suppliers_controller.rb +1 -1
- data/app/models/subscription_client_resource.rb +11 -5
- data/db/migrate/20240917131841_add_keys_to_subscription_client_resource.rb +8 -0
- data/lib/discourse_subscription_client/subscriptions/update_result.rb +34 -14
- data/lib/discourse_subscription_client/subscriptions.rb +4 -0
- data/lib/discourse_subscription_client/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea189a1e70964148ffbcad4fb0ee45b8274c77d84b0dedf06f785108666090eb
|
4
|
+
data.tar.gz: d275e4c8551df79ebace036fbc1550715f1b7220bc4c9c6cb1cb552b7b9cfe25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c5dd6fe8540cc4644e8e35d2f22b61f91c9f3ae5286c4b7a33e99f2a4c5be8facd9dd260f88c2da92b0d869e090d7cb440a990f87db1330634dd0a4327b8364
|
7
|
+
data.tar.gz: 0f8e839f5c58e48c10850917154f7febcec84a3f004f098c672776521889fa29fb8e05d6366664ba9a3326d0816862bb71f70553258c050da016463e9bd3f59d
|
@@ -4,15 +4,21 @@ class SubscriptionClientResource < ActiveRecord::Base
|
|
4
4
|
belongs_to :supplier, class_name: "SubscriptionClientSupplier"
|
5
5
|
has_many :notices, class_name: "SubscriptionClientNotice", as: :notice_subject, dependent: :destroy
|
6
6
|
has_many :subscriptions, foreign_key: "resource_id", class_name: "SubscriptionClientSubscription", dependent: :destroy
|
7
|
+
|
8
|
+
def source_url(bucket)
|
9
|
+
"s3://#{access_key_id}:#{secret_access_key}@#{bucket}"
|
10
|
+
end
|
7
11
|
end
|
8
12
|
|
9
13
|
# == Schema Information
|
10
14
|
#
|
11
15
|
# Table name: subscription_client_resources
|
12
16
|
#
|
13
|
-
# id
|
14
|
-
# supplier_id
|
15
|
-
# name
|
16
|
-
# created_at
|
17
|
-
# updated_at
|
17
|
+
# id :bigint not null, primary key
|
18
|
+
# supplier_id :bigint
|
19
|
+
# name :string not null
|
20
|
+
# created_at :datetime not null
|
21
|
+
# updated_at :datetime not null
|
22
|
+
# access_key_id :string
|
23
|
+
# secret_access_key :string
|
18
24
|
#
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class AddKeysToSubscriptionClientResource < ActiveRecord::Migration[7.0]
|
4
|
+
def change
|
5
|
+
add_column :subscription_client_resources, :access_key_id, :string, if_not_exists: true
|
6
|
+
add_column :subscription_client_resources, :secret_access_key, :string, if_not_exists: true
|
7
|
+
end
|
8
|
+
end
|
@@ -3,16 +3,21 @@
|
|
3
3
|
module ::DiscourseSubscriptionClient
|
4
4
|
class Subscriptions
|
5
5
|
class UpdateResult
|
6
|
-
|
6
|
+
REQUIRED_SUBSCRIPTION_KEYS ||= %i[
|
7
7
|
resource_id
|
8
8
|
product_id
|
9
9
|
price_id
|
10
10
|
].freeze
|
11
|
-
|
11
|
+
OPTIONAL_SUBSCRIPTION_KEYS ||= %i[
|
12
12
|
product_name
|
13
13
|
price_name
|
14
14
|
].freeze
|
15
|
-
|
15
|
+
SUBSCRIPTION_KEYS = REQUIRED_SUBSCRIPTION_KEYS + OPTIONAL_SUBSCRIPTION_KEYS
|
16
|
+
REQUIRED_RESOURCE_KEYS ||= %i[
|
17
|
+
resource
|
18
|
+
access_key_id
|
19
|
+
secret_access_key
|
20
|
+
]
|
16
21
|
|
17
22
|
attr_reader :errors,
|
18
23
|
:errored_suppliers,
|
@@ -35,16 +40,10 @@ module ::DiscourseSubscriptionClient
|
|
35
40
|
return []
|
36
41
|
end
|
37
42
|
|
38
|
-
|
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) } }
|
43
|
+
subscriptions_data = format_subscriptions_data(subscriptions_data)
|
44
|
+
resources_data = format_resources_data(raw_data[:resources])
|
45
45
|
|
46
46
|
# we only care about subscriptions for resources on this instance
|
47
|
-
|
48
47
|
resources = SubscriptionClientResource.where(
|
49
48
|
supplier_id: supplier.id,
|
50
49
|
name: subscriptions_data.map { |data| data[:resource] }
|
@@ -56,9 +55,11 @@ module ::DiscourseSubscriptionClient
|
|
56
55
|
if resource.present?
|
57
56
|
data[:resource_id] = resource.id
|
58
57
|
result << OpenStruct.new(
|
59
|
-
required: data.slice(*
|
60
|
-
create: data.slice(*
|
61
|
-
subscription: nil
|
58
|
+
required: data.slice(*REQUIRED_SUBSCRIPTION_KEYS),
|
59
|
+
create: data.slice(*SUBSCRIPTION_KEYS),
|
60
|
+
subscription: nil,
|
61
|
+
resource: resource,
|
62
|
+
resource_data: resources_data[resource.name]
|
62
63
|
)
|
63
64
|
else
|
64
65
|
info("no_resource", supplier, resource: data[:resource])
|
@@ -66,6 +67,25 @@ module ::DiscourseSubscriptionClient
|
|
66
67
|
end
|
67
68
|
end
|
68
69
|
|
70
|
+
def format_subscriptions_data(subscriptions_data)
|
71
|
+
subscriptions_data
|
72
|
+
.map(&:symbolize_keys)
|
73
|
+
.each { |data| data[:resource_id] = data[:resource] }
|
74
|
+
.select { |data| REQUIRED_SUBSCRIPTION_KEYS.all? { |key| data.key?(key) } }
|
75
|
+
end
|
76
|
+
|
77
|
+
def format_resources_data(resources_data)
|
78
|
+
return {} unless resources_data
|
79
|
+
|
80
|
+
resources_data
|
81
|
+
.compact
|
82
|
+
.map(&:symbolize_keys)
|
83
|
+
.select { |data| REQUIRED_RESOURCE_KEYS.all? { |key| data.key?(key) } }
|
84
|
+
.each_with_object({}) do |data, result|
|
85
|
+
result[data[:resource]] = data.slice(:access_key_id, :secret_access_key)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
69
89
|
def connection_error(supplier)
|
70
90
|
error("supplier_connection", supplier)
|
71
91
|
end
|
@@ -37,6 +37,8 @@ module DiscourseSubscriptionClient
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
DiscourseEvent.trigger(:subscription_client_subscriptions_updated, @result)
|
41
|
+
|
40
42
|
@result.errors.blank?
|
41
43
|
end
|
42
44
|
|
@@ -85,6 +87,8 @@ module DiscourseSubscriptionClient
|
|
85
87
|
@result.failed_to_create_subscription(supplier, subscription_ids: data.required)
|
86
88
|
end
|
87
89
|
end
|
90
|
+
|
91
|
+
data.resource.update(data.resource_data) if data.resource.present? && data.resource_data.present?
|
88
92
|
end
|
89
93
|
end
|
90
94
|
|
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.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Angus McLeod
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|
@@ -258,6 +258,7 @@ files:
|
|
258
258
|
- db/migrate/20230221100535_create_subscription_client_subscriptions.rb
|
259
259
|
- db/migrate/20230221100540_create_subscription_client_requests.rb
|
260
260
|
- db/migrate/20230223135957_add_products_to_subscription_client_suppliers.rb
|
261
|
+
- db/migrate/20240917131841_add_keys_to_subscription_client_resource.rb
|
261
262
|
- extensions/discourse_subscription_client/current_user_serializer.rb
|
262
263
|
- extensions/discourse_subscription_client/guardian.rb
|
263
264
|
- extensions/discourse_subscription_client/site_serializer.rb
|