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:
parent
678a0af962
commit
97583e410c
5 changed files with 33 additions and 3 deletions
|
@ -36,6 +36,7 @@ class SuperAdmin::AccountsController < SuperAdmin::ApplicationController
|
||||||
def resource_params
|
def resource_params
|
||||||
permitted_params = super
|
permitted_params = super
|
||||||
permitted_params[:limits] = permitted_params[:limits].to_h.compact
|
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
|
permitted_params
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,15 @@ class AccountDashboard < Administrate::BaseDashboard
|
||||||
# which determines how the attribute is displayed
|
# which determines how the attribute is displayed
|
||||||
# on pages throughout the dashboard.
|
# 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 = {
|
ATTRIBUTE_TYPES = {
|
||||||
id: Field::Number,
|
id: Field::Number,
|
||||||
name: Field::String,
|
name: Field::String,
|
||||||
|
@ -37,7 +45,7 @@ class AccountDashboard < Administrate::BaseDashboard
|
||||||
|
|
||||||
# SHOW_PAGE_ATTRIBUTES
|
# SHOW_PAGE_ATTRIBUTES
|
||||||
# an array of attributes that will be displayed on the model's show page.
|
# 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[
|
SHOW_PAGE_ATTRIBUTES = (%i[
|
||||||
id
|
id
|
||||||
name
|
name
|
||||||
|
@ -52,7 +60,7 @@ class AccountDashboard < Administrate::BaseDashboard
|
||||||
# FORM_ATTRIBUTES
|
# FORM_ATTRIBUTES
|
||||||
# an array of attributes that will be displayed
|
# an array of attributes that will be displayed
|
||||||
# on the model's form (`new` and `edit`) pages.
|
# 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[
|
FORM_ATTRIBUTES = (%i[
|
||||||
name
|
name
|
||||||
locale
|
locale
|
||||||
|
|
7
app/fields/enterprise/account_features_field.rb
Normal file
7
app/fields/enterprise/account_features_field.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
require 'administrate/field/base'
|
||||||
|
|
||||||
|
class Enterprise::AccountFeaturesField < Administrate::Field::Base
|
||||||
|
def to_s
|
||||||
|
data
|
||||||
|
end
|
||||||
|
end
|
8
app/views/fields/account_features_field/_form.html.erb
Normal file
8
app/views/fields/account_features_field/_form.html.erb
Normal 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>
|
6
app/views/fields/account_features_field/_show.html.erb
Normal file
6
app/views/fields/account_features_field/_show.html.erb
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<div class="field-unit__field">
|
||||||
|
<% field.data.each do |key,val| %>
|
||||||
|
<%= key %>: <%= val %> <br/>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue