From 9292653bf926ef499a57c1f57bcbc671f840ac19 Mon Sep 17 00:00:00 2001 From: smartdev58 <30475578+smartdev58@users.noreply.github.com> Date: Thu, 15 Dec 2022 04:24:02 +0200 Subject: [PATCH] fix: Update enabled_features logic to fix superadmin edit action (#5959) Co-authored-by: Pranav Raj S --- .../platform/api/v1/accounts_controller.rb | 3 +-- app/models/concerns/featurable.rb | 2 +- .../platform/api/v1/models/_account.json.jbuilder | 2 +- .../platform/api/v1/accounts_controller_spec.rb | 14 ++++++++------ 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/controllers/platform/api/v1/accounts_controller.rb b/app/controllers/platform/api/v1/accounts_controller.rb index 2873cc22c..1ea7d4954 100644 --- a/app/controllers/platform/api/v1/accounts_controller.rb +++ b/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 diff --git a/app/models/concerns/featurable.rb b/app/models/concerns/featurable.rb index 4b96f16b4..5e6b8b8db 100644 --- a/app/models/concerns/featurable.rb +++ b/app/models/concerns/featurable.rb @@ -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) diff --git a/app/views/platform/api/v1/models/_account.json.jbuilder b/app/views/platform/api/v1/models/_account.json.jbuilder index 9a22e6518..135f0a33d 100644 --- a/app/views/platform/api/v1/models/_account.json.jbuilder +++ b/app/views/platform/api/v1/models/_account.json.jbuilder @@ -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 diff --git a/spec/controllers/platform/api/v1/accounts_controller_spec.rb b/spec/controllers/platform/api/v1/accounts_controller_spec.rb index c335035d5..c41464f1f 100644 --- a/spec/controllers/platform/api/v1/accounts_controller_spec.rb +++ b/spec/controllers/platform/api/v1/accounts_controller_spec.rb @@ -42,14 +42,16 @@ RSpec.describe 'Platform Accounts API', type: :request do 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, @@ -59,10 +61,10 @@ RSpec.describe 'Platform Accounts API', type: :request do 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