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:
Sojan Jose
2025-04-28 14:13:56 -07:00
committed by GitHub
parent ef6949e32d
commit c63b583f90
26 changed files with 742 additions and 144 deletions

View File

@@ -0,0 +1,7 @@
require 'administrate/field/base'
class AccountFeaturesField < Administrate::Field::Base
def to_s
data
end
end

View File

@@ -0,0 +1,7 @@
require 'administrate/field/base'
class AccountLimitsField < Administrate::Field::Base
def to_s
data.present? ? data.to_json : { agents: nil, inboxes: nil, captain_responses: nil, captain_documents: nil }.to_json
end
end

View File

@@ -0,0 +1,31 @@
require 'administrate/field/base'
class ManuallyManagedFeaturesField < Administrate::Field::Base
def data
Internal::Accounts::InternalAttributesService.new(resource).manually_managed_features
end
def to_s
data.is_a?(Array) ? data.join(', ') : '[]'
end
def all_features
# Business and Enterprise plan features only
Enterprise::Billing::HandleStripeEventService::BUSINESS_PLAN_FEATURES +
Enterprise::Billing::HandleStripeEventService::ENTERPRISE_PLAN_FEATURES
end
def selected_features
# If we have direct array data, use it (for rendering after form submission)
return data if data.is_a?(Array)
# Otherwise, use the service to retrieve the data from internal_attributes
if resource.respond_to?(:internal_attributes)
service = Internal::Accounts::InternalAttributesService.new(resource)
return service.manually_managed_features
end
# Fallback to empty array if no data available
[]
end
end