2022-03-25 12:22:27 +01:00
|
|
|
# frozen_string_literal: true
|
2021-09-24 11:58:42 +02:00
|
|
|
class CustomWizard::Subscription
|
2022-09-23 15:52:05 +02:00
|
|
|
STANDARD_PRODUCT_ID = 'prod_MH11woVoZU5AWb'
|
|
|
|
BUSINESS_PRODUCT_ID = 'prod_MH0wT627okh3Ef'
|
|
|
|
COMMUNITY_PRODUCT_ID = 'prod_MU7l9EjxhaukZ7'
|
2022-03-25 12:18:54 +01:00
|
|
|
|
|
|
|
def self.attributes
|
|
|
|
{
|
|
|
|
wizard: {
|
|
|
|
required: {
|
|
|
|
none: [],
|
|
|
|
standard: ['*'],
|
2022-09-23 15:52:05 +02:00
|
|
|
business: ['*'],
|
|
|
|
community: ['*']
|
2022-03-25 12:18:54 +01:00
|
|
|
},
|
|
|
|
permitted: {
|
|
|
|
none: [],
|
|
|
|
standard: ['*'],
|
2022-09-23 15:52:05 +02:00
|
|
|
business: ['*'],
|
|
|
|
community: ['*']
|
2022-03-25 12:18:54 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
step: {
|
|
|
|
condition: {
|
|
|
|
none: [],
|
|
|
|
standard: ['*'],
|
2022-09-23 15:52:05 +02:00
|
|
|
business: ['*'],
|
|
|
|
community: ['*']
|
2022-03-25 12:18:54 +01:00
|
|
|
},
|
|
|
|
required_data: {
|
|
|
|
none: [],
|
|
|
|
standard: ['*'],
|
2022-09-23 15:52:05 +02:00
|
|
|
business: ['*'],
|
|
|
|
community: ['*']
|
2022-03-25 12:18:54 +01:00
|
|
|
},
|
|
|
|
permitted_params: {
|
|
|
|
none: [],
|
|
|
|
standard: ['*'],
|
2022-09-23 15:52:05 +02:00
|
|
|
business: ['*'],
|
|
|
|
community: ['*']
|
2022-03-25 12:18:54 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
field: {
|
|
|
|
condition: {
|
|
|
|
none: [],
|
|
|
|
standard: ['*'],
|
2022-09-23 15:52:05 +02:00
|
|
|
business: ['*'],
|
|
|
|
community: ['*']
|
2022-03-25 12:18:54 +01:00
|
|
|
},
|
|
|
|
type: {
|
2022-03-25 17:08:24 +01:00
|
|
|
none: ['text', 'textarea', 'text_only', 'date', 'time', 'date_time', 'number', 'checkbox', 'dropdown', 'upload'],
|
2022-03-25 12:18:54 +01:00
|
|
|
standard: ['*'],
|
2022-09-23 15:52:05 +02:00
|
|
|
business: ['*'],
|
|
|
|
community: ['*']
|
2022-03-25 12:18:54 +01:00
|
|
|
},
|
|
|
|
realtime_validations: {
|
|
|
|
none: [],
|
|
|
|
standard: ['*'],
|
2022-09-23 15:52:05 +02:00
|
|
|
business: ['*'],
|
|
|
|
community: ['*']
|
2022-03-25 12:18:54 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
action: {
|
|
|
|
type: {
|
2022-03-25 17:08:24 +01:00
|
|
|
none: ['create_topic', 'update_profile', 'open_composer', 'route_to'],
|
|
|
|
standard: ['create_topic', 'update_profile', 'open_composer', 'route_to', 'send_message', 'watch_categories', 'add_to_group'],
|
2022-09-23 15:52:05 +02:00
|
|
|
business: ['*'],
|
|
|
|
community: ['*']
|
2022-03-25 12:18:54 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
custom_field: {
|
|
|
|
klass: {
|
|
|
|
none: ['topic', 'post'],
|
|
|
|
standard: ['topic', 'post'],
|
2022-09-23 15:52:05 +02:00
|
|
|
business: ['*'],
|
|
|
|
community: ['*']
|
2022-03-25 12:18:54 +01:00
|
|
|
},
|
|
|
|
type: {
|
|
|
|
none: ['string', 'boolean', 'integer'],
|
|
|
|
standard: ['string', 'boolean', 'integer'],
|
2022-09-23 15:52:05 +02:00
|
|
|
business: ['*'],
|
|
|
|
community: ['*']
|
2022-03-25 12:18:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
@subscription = find_subscription
|
|
|
|
end
|
|
|
|
|
|
|
|
def includes?(feature, attribute, value)
|
|
|
|
attributes = self.class.attributes[feature]
|
|
|
|
|
|
|
|
## Attribute is not part of a subscription
|
|
|
|
return true unless attributes.present? && attributes.key?(attribute)
|
|
|
|
|
|
|
|
values = attributes[attribute][type]
|
|
|
|
|
|
|
|
## Subscription type does not support the attribute.
|
|
|
|
return false if values.blank?
|
|
|
|
|
|
|
|
## Subscription type supports all values of the attribute.
|
2022-03-25 17:08:24 +01:00
|
|
|
return true if values.first === "*"
|
2022-03-25 12:18:54 +01:00
|
|
|
|
|
|
|
## Subscription type supports some values of the attributes.
|
|
|
|
values.include?(value)
|
|
|
|
end
|
|
|
|
|
|
|
|
def type
|
|
|
|
return :none unless subscribed?
|
|
|
|
return :standard if standard?
|
|
|
|
return :business if business?
|
2022-09-23 15:52:05 +02:00
|
|
|
return :community if community?
|
2022-03-25 12:18:54 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def subscribed?
|
2022-09-23 15:52:05 +02:00
|
|
|
standard? || business? || community?
|
2022-03-25 12:18:54 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def standard?
|
|
|
|
@subscription.product_id === STANDARD_PRODUCT_ID
|
|
|
|
end
|
|
|
|
|
|
|
|
def business?
|
|
|
|
@subscription.product_id === BUSINESS_PRODUCT_ID
|
|
|
|
end
|
|
|
|
|
2022-09-23 15:52:05 +02:00
|
|
|
def community?
|
|
|
|
@subscription.product_id === COMMUNITY_PRODUCT_ID
|
|
|
|
end
|
|
|
|
|
2022-03-25 12:18:54 +01:00
|
|
|
def client_installed?
|
|
|
|
defined?(SubscriptionClient) == 'constant' && SubscriptionClient.class == Module
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_subscription
|
|
|
|
subscription = nil
|
|
|
|
|
|
|
|
if client_installed?
|
|
|
|
subscription = SubscriptionClientSubscription.active
|
2022-09-23 15:52:05 +02:00
|
|
|
.where(product_id: [STANDARD_PRODUCT_ID, BUSINESS_PRODUCT_ID, COMMUNITY_PRODUCT_ID])
|
2022-03-25 12:18:54 +01:00
|
|
|
.order("product_id = '#{BUSINESS_PRODUCT_ID}' DESC")
|
|
|
|
.first
|
|
|
|
end
|
|
|
|
|
|
|
|
unless subscription
|
|
|
|
subscription = OpenStruct.new(product_id: nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
subscription
|
|
|
|
end
|
|
|
|
|
2021-08-10 11:00:42 +02:00
|
|
|
def self.subscribed?
|
2022-03-25 12:18:54 +01:00
|
|
|
new.subscribed?
|
2021-08-10 11:00:42 +02:00
|
|
|
end
|
2021-08-18 08:59:43 +02:00
|
|
|
|
2022-03-25 12:18:54 +01:00
|
|
|
def self.business?
|
|
|
|
new.business?
|
|
|
|
end
|
|
|
|
|
2022-09-23 15:52:05 +02:00
|
|
|
def self.community?
|
|
|
|
new.community?
|
|
|
|
end
|
|
|
|
|
2022-03-25 12:18:54 +01:00
|
|
|
def self.standard?
|
|
|
|
new.standard?
|
|
|
|
end
|
2021-09-01 04:19:00 +02:00
|
|
|
|
2022-03-25 12:18:54 +01:00
|
|
|
def self.type
|
|
|
|
new.type
|
2021-09-01 04:19:00 +02:00
|
|
|
end
|
2022-03-25 17:08:24 +01:00
|
|
|
|
|
|
|
def self.client_installed?
|
|
|
|
new.client_installed?
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.includes?(feature, attribute, value)
|
|
|
|
new.includes?(feature, attribute, value)
|
|
|
|
end
|
2021-09-07 14:11:50 +02:00
|
|
|
end
|