Class: SubscriptionClientSupplier
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- SubscriptionClientSupplier
- Defined in:
- app/models/subscription_client_supplier.rb
Class Method Summary collapse
Instance Method Summary collapse
- #authorized? ⇒ Boolean
- #deactivate_all_subscriptions! ⇒ Object
- #destroy_authorization ⇒ Object
- #product_slugs(resource) ⇒ Object
Class Method Details
.publish_authorized_supplier_count ⇒ Object
34 35 36 37 38 |
# File 'app/models/subscription_client_supplier.rb', line 34 def self. payload = { authorized_supplier_count: .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
18 19 20 |
# File 'app/models/subscription_client_supplier.rb', line 18 def 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_authorization ⇒ Object
12 13 14 15 16 |
# File 'app/models/subscription_client_supplier.rb', line 12 def 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 |