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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e9c613aa210fef7c5beacc341e3f704e131d67c5b79af85857458b0386c14a1
4
- data.tar.gz: 99cd4b1e1f61ad63f1f8d96ecf81091442cea1e4141c9b41a0c3f02da3018418
3
+ metadata.gz: ea189a1e70964148ffbcad4fb0ee45b8274c77d84b0dedf06f785108666090eb
4
+ data.tar.gz: d275e4c8551df79ebace036fbc1550715f1b7220bc4c9c6cb1cb552b7b9cfe25
5
5
  SHA512:
6
- metadata.gz: 0d2b1d5314c41feaeda861642cd459466861945a9596990353db26c5124ea7f758215bf1b2f9d6beee810ca0400f9fadb3b4da3b8bfe6ec3b609093090bb5339
7
- data.tar.gz: 8c412d3337fe1c7f6790ada74217bd678d50ab411a20bb908ac829c39ad086d9776880bfc921ecfdd3f250d0511a59c9dbdf96814dff767370a3f6f0dd58c804
6
+ metadata.gz: 5c5dd6fe8540cc4644e8e35d2f22b61f91c9f3ae5286c4b7a33e99f2a4c5be8facd9dd260f88c2da92b0d869e090d7cb440a990f87db1330634dd0a4327b8364
7
+ data.tar.gz: 0f8e839f5c58e48c10850917154f7febcec84a3f004f098c672776521889fa29fb8e05d6366664ba9a3326d0816862bb71f70553258c050da016463e9bd3f59d
@@ -47,7 +47,7 @@ module DiscourseSubscriptionClient
47
47
 
48
48
  def destroy
49
49
  if @supplier.destroy_authorization
50
- render json: success_json.merge(supplier: @supplier.reload)
50
+ render json: success_json.merge(supplier_id: @supplier.id)
51
51
  else
52
52
  render json: failed_json
53
53
  end
@@ -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 :bigint not null, primary key
14
- # supplier_id :bigint
15
- # name :string not null
16
- # created_at :datetime not null
17
- # updated_at :datetime not null
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
- REQUIRED_KEYS ||= %i[
6
+ REQUIRED_SUBSCRIPTION_KEYS ||= %i[
7
7
  resource_id
8
8
  product_id
9
9
  price_id
10
10
  ].freeze
11
- OPTIONAL_KEYS ||= %i[
11
+ OPTIONAL_SUBSCRIPTION_KEYS ||= %i[
12
12
  product_name
13
13
  price_name
14
14
  ].freeze
15
- KEYS = REQUIRED_KEYS + OPTIONAL_KEYS
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
- # 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) } }
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(*REQUIRED_KEYS),
60
- create: data.slice(*KEYS),
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DiscourseSubscriptionClient
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.4"
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.2
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-02-23 00:00:00.000000000 Z
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