2021-09-07 14:11:50 +02:00
|
|
|
# frozen_string_literal: true
|
2021-09-24 11:58:42 +02:00
|
|
|
class CustomWizard::Subscription::Subscription
|
2021-08-10 08:45:23 +02:00
|
|
|
include ActiveModel::Serialization
|
|
|
|
|
|
|
|
attr_reader :type,
|
|
|
|
:updated_at
|
|
|
|
|
2022-02-14 07:32:17 +01:00
|
|
|
NONE ||= "none"
|
|
|
|
STANDARD ||= "standard"
|
|
|
|
BUSINESS ||= "business"
|
|
|
|
FEATURES ||= {
|
|
|
|
actions: {
|
|
|
|
type: {
|
|
|
|
create_topic: NONE,
|
|
|
|
update_profile: NONE,
|
|
|
|
open_composer: NONE,
|
|
|
|
route_to: NONE,
|
|
|
|
send_message: STANDARD,
|
|
|
|
watch_categories: STANDARD,
|
|
|
|
add_to_group: STANDARD,
|
|
|
|
send_to_api: BUSINESS,
|
|
|
|
create_category: BUSINESS,
|
|
|
|
create_group: BUSINESS
|
|
|
|
}
|
|
|
|
},
|
|
|
|
custom_fields: {
|
|
|
|
klass: {
|
|
|
|
topic: NONE,
|
|
|
|
post: NONE,
|
|
|
|
group: BUSINESS,
|
|
|
|
category: BUSINESS
|
|
|
|
},
|
|
|
|
type: {
|
|
|
|
string: NONE,
|
|
|
|
boolean: NONE,
|
|
|
|
integer: NONE,
|
|
|
|
json: STANDARD
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-01 04:19:00 +02:00
|
|
|
def initialize(subscription)
|
|
|
|
if subscription
|
|
|
|
@type = subscription.type
|
|
|
|
@updated_at = subscription.updated_at
|
2021-08-10 08:45:23 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def active?
|
2021-09-01 04:19:00 +02:00
|
|
|
types.include?(type) && updated_at.to_datetime > (Time.zone.now - 2.hours).to_datetime
|
2021-08-10 08:45:23 +02:00
|
|
|
end
|
2022-02-14 07:32:17 +01:00
|
|
|
|
|
|
|
def can_use_feature?(feature, attribute, value)
|
|
|
|
feature_type = FEATURES.dig(*[feature.to_sym, attribute.to_sym, value.to_sym])
|
|
|
|
!feature_type || has_required_type?(feature_type)
|
|
|
|
end
|
|
|
|
|
|
|
|
def has_required_type?(t)
|
|
|
|
t && type_index(t) >= type_index(type)
|
|
|
|
end
|
|
|
|
|
|
|
|
def type_index(t)
|
|
|
|
self.class.types.index(t)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.types
|
|
|
|
[NONE, STANDARD, BUSINESS]
|
|
|
|
end
|
2021-09-07 14:11:50 +02:00
|
|
|
end
|