Skip to content

Commit

Permalink
fix: Update enabled_features logic to fix superadmin edit action (#5959)
Browse files Browse the repository at this point in the history
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
  • Loading branch information
smartdev58 and pranavrajs committed Dec 15, 2022
1 parent 2a1a38f commit 9292653
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
3 changes: 1 addition & 2 deletions app/controllers/platform/api/v1/accounts_controller.rb
@@ -1,8 +1,7 @@
class Platform::Api::V1::AccountsController < PlatformController
def create
@resource = Account.new(account_params)
@resource = Account.create!(account_params)
update_resource_features
@resource.save!
@platform_app.platform_app_permissibles.find_or_create_by(permissible: @resource)
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/featurable.rb
Expand Up @@ -16,7 +16,7 @@ module Featurable
include FlagShihTzu
has_flags FEATURES.merge(column: 'feature_flags').merge(QUERY_MODE)

after_initialize :enable_default_features
before_create :enable_default_features
end

def enable_features(*names)
Expand Down
2 changes: 1 addition & 1 deletion app/views/platform/api/v1/models/_account.json.jbuilder
Expand Up @@ -3,7 +3,7 @@ json.name resource.name
json.locale resource.locale
json.domain resource.domain
json.support_email resource.support_email
json.enabled_features resource.enabled_features
json.features resource.enabled_features
json.custom_attributes resource.custom_attributes
json.limits resource.limits
json.status resource.status
14 changes: 8 additions & 6 deletions spec/controllers/platform/api/v1/accounts_controller_spec.rb
Expand Up @@ -42,14 +42,16 @@
json_response = JSON.parse(response.body)
expect(json_response['name']).to eq('Test Account')
expect(json_response['locale']).to eq('es')
expect(json_response['enabled_features']['agent_management']).to be(true)
expect(json_response['features']['agent_management']).to be(true)
end

it 'creates an account with feature flags' do
InstallationConfig.where(name: 'ACCOUNT_LEVEL_FEATURE_DEFAULTS').first_or_create!(value: [{ 'name' => 'inbox_management',
'enabled' => true },
{ 'name' => 'disable_branding',
'enabled' => true }])
'enabled' => true },
{ 'name' => 'help_center',
'enabled' => false }])

post '/platform/api/v1/accounts', params: { name: 'Test Account', features: {
ip_lookup: true,
Expand All @@ -59,10 +61,10 @@

json_response = JSON.parse(response.body)
expect(json_response['name']).to include('Test Account')
expect(json_response['enabled_features']['inbox_management']).to be(true)
expect(json_response['enabled_features']['ip_lookup']).to be(true)
expect(json_response['enabled_features']['help_center']).to be(true)
expect(json_response['enabled_features']['disable_branding']).to be_nil
expect(json_response['features']['inbox_management']).to be(true)
expect(json_response['features']['ip_lookup']).to be(true)
expect(json_response['features']['help_center']).to be(true)
expect(json_response['features']['disable_branding']).to be_nil
end

it 'creates an account with limits settings' do
Expand Down

0 comments on commit 9292653

Please sign in to comment.