Class: SubscriptionClientSupplier

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/subscription_client_supplier.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.publish_authorized_supplier_countObject



34
35
36
37
38
# File 'app/models/subscription_client_supplier.rb', line 34

def self.publish_authorized_supplier_count
  payload = { authorized_supplier_count: authorized.count }
  group_id_key = SiteSetting.subscription_client_allow_moderator_subscription_management ? :staff : :admins
  MessageBus.publish("/subscription_client", payload, group_ids: [Group::AUTO_GROUPS[group_id_key.to_sym]])
end

Instance Method Details

#authorized?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'app/models/subscription_client_supplier.rb', line 18

def authorized?
  api_key.present?
end

#deactivate_all_subscriptions!Object



30
31
32
# File 'app/models/subscription_client_supplier.rb', line 30

def deactivate_all_subscriptions!
  subscriptions.update_all(subscribed: false)
end

#destroy_authorizationObject



12
13
14
15
16
# File 'app/models/subscription_client_supplier.rb', line 12

def destroy_authorization
  DiscourseSubscriptionClient::Authorization.revoke(self)
  update(api_key: nil, user_id: nil, authorized_at: nil)
  deactivate_all_subscriptions!
end

#product_slugs(resource) ⇒ Object



22
23
24
25
26
27
28
# File 'app/models/subscription_client_supplier.rb', line 22

def product_slugs(resource)
  return {} unless products.present? && products[resource]

  products[resource].each_with_object({}) do |product, result|
    result[product["product_id"]] = product["product_slug"]
  end
end