feat: Ability to manage account features from super admin (#5455)

- This PR adds the ability to enable and disable features for an account from the super admin.
This commit is contained in:
Sojan Jose 2022-09-20 03:27:21 +05:30 committed by GitHub
parent 678a0af962
commit 97583e410c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 3 deletions

View file

@ -36,6 +36,7 @@ class SuperAdmin::AccountsController < SuperAdmin::ApplicationController
def resource_params
permitted_params = super
permitted_params[:limits] = permitted_params[:limits].to_h.compact
permitted_params[:selected_feature_flags] = params[:enabled_features].keys.map(&:to_sym) if params[:enabled_features].present?
permitted_params
end

View file

@ -8,7 +8,15 @@ class AccountDashboard < Administrate::BaseDashboard
# which determines how the attribute is displayed
# on pages throughout the dashboard.
enterprise_attribute_types = ChatwootApp.enterprise? ? { limits: Enterprise::AccountLimitsField } : {}
enterprise_attribute_types = if ChatwootApp.enterprise?
{
limits: Enterprise::AccountLimitsField,
all_features: Enterprise::AccountFeaturesField
}
else
{}
end
ATTRIBUTE_TYPES = {
id: Field::Number,
name: Field::String,
@ -37,7 +45,7 @@ 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[limits] : []
enterprise_show_page_attributes = ChatwootApp.enterprise? ? %i[limits all_features] : []
SHOW_PAGE_ATTRIBUTES = (%i[
id
name
@ -52,7 +60,7 @@ 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] : []
enterprise_form_attributes = ChatwootApp.enterprise? ? %i[limits all_features] : []
FORM_ATTRIBUTES = (%i[
name
locale

View file

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

View file

@ -0,0 +1,8 @@
<div class="field-unit__label">
<%= f.label field.attribute %>
</div>
<div class="field-unit__field">
<% field.data.each do |key,val| %>
<%= key %>: <%= check_box "enabled_features", "feature_#{key}", { checked: val }, true, false %>
<% end %>
</div>

View file

@ -0,0 +1,6 @@
<div class="field-unit__field">
<% field.data.each do |key,val| %>
<%= key %>: <%= val %> <br/>
<% end %>
</div>