chore: improve plan-based feature handling with plan hierarchy (#11335)
- Refactor HandleStripeEventService to better manage features by plan - Add constants for features available in each plan tier (Startup, Business, Enterprise) - Add channel_instagram to Startup plan features - Improve downgrade handling to properly disable higher-tier features - Clean up and optimize tests for maintainability - Add comprehensive test coverage for plan upgrades and downgrades --------- Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
@@ -9,10 +9,17 @@ class AccountDashboard < Administrate::BaseDashboard
|
||||
# on pages throughout the dashboard.
|
||||
|
||||
enterprise_attribute_types = if ChatwootApp.enterprise?
|
||||
{
|
||||
limits: Enterprise::AccountLimitsField,
|
||||
all_features: Enterprise::AccountFeaturesField
|
||||
attributes = {
|
||||
limits: AccountLimitsField
|
||||
}
|
||||
|
||||
# Only show manually managed features in Chatwoot Cloud deployment
|
||||
attributes[:manually_managed_features] = ManuallyManagedFeaturesField if ChatwootApp.chatwoot_cloud?
|
||||
|
||||
# Add all_features last so it appears after manually_managed_features
|
||||
attributes[:all_features] = AccountFeaturesField
|
||||
|
||||
attributes
|
||||
else
|
||||
{}
|
||||
end
|
||||
@@ -46,7 +53,14 @@ class AccountDashboard < Administrate::BaseDashboard
|
||||
|
||||
# SHOW_PAGE_ATTRIBUTES
|
||||
# an array of attributes that will be displayed on the model's show page.
|
||||
enterprise_show_page_attributes = ChatwootApp.enterprise? ? %i[custom_attributes limits all_features] : []
|
||||
enterprise_show_page_attributes = if ChatwootApp.enterprise?
|
||||
attrs = %i[custom_attributes limits]
|
||||
attrs << :manually_managed_features if ChatwootApp.chatwoot_cloud?
|
||||
attrs << :all_features
|
||||
attrs
|
||||
else
|
||||
[]
|
||||
end
|
||||
SHOW_PAGE_ATTRIBUTES = (%i[
|
||||
id
|
||||
name
|
||||
@@ -61,7 +75,14 @@ class AccountDashboard < Administrate::BaseDashboard
|
||||
# FORM_ATTRIBUTES
|
||||
# an array of attributes that will be displayed
|
||||
# on the model's form (`new` and `edit`) pages.
|
||||
enterprise_form_attributes = ChatwootApp.enterprise? ? %i[limits all_features] : []
|
||||
enterprise_form_attributes = if ChatwootApp.enterprise?
|
||||
attrs = %i[limits]
|
||||
attrs << :manually_managed_features if ChatwootApp.chatwoot_cloud?
|
||||
attrs << :all_features
|
||||
attrs
|
||||
else
|
||||
[]
|
||||
end
|
||||
FORM_ATTRIBUTES = (%i[
|
||||
name
|
||||
locale
|
||||
@@ -96,6 +117,11 @@ class AccountDashboard < Administrate::BaseDashboard
|
||||
# to prevent an error from being raised (wrong number of arguments)
|
||||
# Reference: https://github.com/thoughtbot/administrate/pull/2356/files#diff-4e220b661b88f9a19ac527c50d6f1577ef6ab7b0bed2bfdf048e22e6bfa74a05R204
|
||||
def permitted_attributes(action)
|
||||
super + [limits: {}]
|
||||
attrs = super + [limits: {}]
|
||||
|
||||
# Add manually_managed_features to permitted attributes only for Chatwoot Cloud
|
||||
attrs << { manually_managed_features: [] } if ChatwootApp.chatwoot_cloud?
|
||||
|
||||
attrs
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user