Skip to content

Commit

Permalink
feat: Ability to manage account features from super admin (#5455)
Browse files Browse the repository at this point in the history
- This PR adds the ability to enable and disable features for an account from the super admin.
  • Loading branch information
sojan-official committed Sep 19, 2022
1 parent 678a0af commit 97583e4
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/controllers/super_admin/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 11 additions & 3 deletions app/dashboards/account_dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions app/fields/enterprise/account_features_field.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'administrate/field/base'

class Enterprise::AccountFeaturesField < Administrate::Field::Base
def to_s
data
end
end
8 changes: 8 additions & 0 deletions app/views/fields/account_features_field/_form.html.erb
Original file line number Diff line number Diff line change
@@ -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 changes: 6 additions & 0 deletions app/views/fields/account_features_field/_show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="field-unit__field">
<% field.data.each do |key,val| %>
<%= key %>: <%= val %> <br/>
<% end %>
</div>

0 comments on commit 97583e4

Please sign in to comment.