fix: Update enabled_features logic to fix superadmin edit action (#5959)

Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
smartdev58 2022-12-15 04:24:02 +02:00 committed by GitHub
parent 2a1a38f986
commit 9292653bf9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 10 deletions

View file

@ -1,8 +1,7 @@
class Platform::Api::V1::AccountsController < PlatformController class Platform::Api::V1::AccountsController < PlatformController
def create def create
@resource = Account.new(account_params) @resource = Account.create!(account_params)
update_resource_features update_resource_features
@resource.save!
@platform_app.platform_app_permissibles.find_or_create_by(permissible: @resource) @platform_app.platform_app_permissibles.find_or_create_by(permissible: @resource)
end end

View file

@ -16,7 +16,7 @@ module Featurable
include FlagShihTzu include FlagShihTzu
has_flags FEATURES.merge(column: 'feature_flags').merge(QUERY_MODE) has_flags FEATURES.merge(column: 'feature_flags').merge(QUERY_MODE)
after_initialize :enable_default_features before_create :enable_default_features
end end
def enable_features(*names) def enable_features(*names)

View file

@ -3,7 +3,7 @@ json.name resource.name
json.locale resource.locale json.locale resource.locale
json.domain resource.domain json.domain resource.domain
json.support_email resource.support_email json.support_email resource.support_email
json.enabled_features resource.enabled_features json.features resource.enabled_features
json.custom_attributes resource.custom_attributes json.custom_attributes resource.custom_attributes
json.limits resource.limits json.limits resource.limits
json.status resource.status json.status resource.status

View file

@ -42,14 +42,16 @@ RSpec.describe 'Platform Accounts API', type: :request do
json_response = JSON.parse(response.body) json_response = JSON.parse(response.body)
expect(json_response['name']).to eq('Test Account') expect(json_response['name']).to eq('Test Account')
expect(json_response['locale']).to eq('es') 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 end
it 'creates an account with feature flags' do it 'creates an account with feature flags' do
InstallationConfig.where(name: 'ACCOUNT_LEVEL_FEATURE_DEFAULTS').first_or_create!(value: [{ 'name' => 'inbox_management', InstallationConfig.where(name: 'ACCOUNT_LEVEL_FEATURE_DEFAULTS').first_or_create!(value: [{ 'name' => 'inbox_management',
'enabled' => true }, 'enabled' => true },
{ 'name' => 'disable_branding', { 'name' => 'disable_branding',
'enabled' => true }]) 'enabled' => true },
{ 'name' => 'help_center',
'enabled' => false }])
post '/platform/api/v1/accounts', params: { name: 'Test Account', features: { post '/platform/api/v1/accounts', params: { name: 'Test Account', features: {
ip_lookup: true, ip_lookup: true,
@ -59,10 +61,10 @@ RSpec.describe 'Platform Accounts API', type: :request do
json_response = JSON.parse(response.body) json_response = JSON.parse(response.body)
expect(json_response['name']).to include('Test Account') expect(json_response['name']).to include('Test Account')
expect(json_response['enabled_features']['inbox_management']).to be(true) expect(json_response['features']['inbox_management']).to be(true)
expect(json_response['enabled_features']['ip_lookup']).to be(true) expect(json_response['features']['ip_lookup']).to be(true)
expect(json_response['enabled_features']['help_center']).to be(true) expect(json_response['features']['help_center']).to be(true)
expect(json_response['enabled_features']['disable_branding']).to be_nil expect(json_response['features']['disable_branding']).to be_nil
end end
it 'creates an account with limits settings' do it 'creates an account with limits settings' do