fix: Set account default language in account API (#5086)
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
class AccountBuilder
|
class AccountBuilder
|
||||||
include CustomExceptions::Account
|
include CustomExceptions::Account
|
||||||
pattr_initialize [:account_name!, :email!, :confirmed, :user, :user_full_name, :user_password, :super_admin]
|
pattr_initialize [:account_name!, :email!, :confirmed, :user, :user_full_name, :user_password, :super_admin, :locale]
|
||||||
|
|
||||||
def perform
|
def perform
|
||||||
if @user.nil?
|
if @user.nil?
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ class Api::V1::AccountsController < Api::BaseController
|
|||||||
user_full_name: account_params[:user_full_name],
|
user_full_name: account_params[:user_full_name],
|
||||||
email: account_params[:email],
|
email: account_params[:email],
|
||||||
user_password: account_params[:password],
|
user_password: account_params[:password],
|
||||||
|
locale: account_params[:locale],
|
||||||
user: current_user
|
user: current_user
|
||||||
).perform
|
).perform
|
||||||
if @user
|
if @user
|
||||||
|
|||||||
@@ -27,6 +27,6 @@ class Platform::Api::V1::AccountsController < PlatformController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def account_params
|
def account_params
|
||||||
params.permit(:name)
|
params.permit(:name, :locale)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ json.data do
|
|||||||
json.name account_user.account.name
|
json.name account_user.account.name
|
||||||
json.active_at account_user.active_at
|
json.active_at account_user.active_at
|
||||||
json.role account_user.role
|
json.role account_user.role
|
||||||
|
json.locale account_user.account.locale
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class SetDefaultLocaleAtAccounts < ActiveRecord::Migration[6.1]
|
||||||
|
def change
|
||||||
|
change_column_default :accounts, :locale, from: nil, to: 0
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2022_07_20_080126) do
|
ActiveRecord::Schema.define(version: 2022_07_20_123615) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "pg_stat_statements"
|
enable_extension "pg_stat_statements"
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ RSpec.describe 'Accounts API', type: :request do
|
|||||||
with_modified_env ENABLE_ACCOUNT_SIGNUP: 'true' do
|
with_modified_env ENABLE_ACCOUNT_SIGNUP: 'true' do
|
||||||
allow(account_builder).to receive(:perform).and_return([user, account])
|
allow(account_builder).to receive(:perform).and_return([user, account])
|
||||||
|
|
||||||
params = { account_name: 'test', email: email, user: nil, user_full_name: user_full_name, password: 'Password1!' }
|
params = { account_name: 'test', email: email, user: nil, locale: nil, user_full_name: user_full_name, password: 'Password1!' }
|
||||||
|
|
||||||
post api_v1_accounts_url,
|
post api_v1_accounts_url,
|
||||||
params: params,
|
params: params,
|
||||||
@@ -27,6 +27,7 @@ RSpec.describe 'Accounts API', type: :request do
|
|||||||
expect(AccountBuilder).to have_received(:new).with(params.except(:password).merge(user_password: params[:password]))
|
expect(AccountBuilder).to have_received(:new).with(params.except(:password).merge(user_password: params[:password]))
|
||||||
expect(account_builder).to have_received(:perform)
|
expect(account_builder).to have_received(:perform)
|
||||||
expect(response.headers.keys).to include('access-token', 'token-type', 'client', 'expiry', 'uid')
|
expect(response.headers.keys).to include('access-token', 'token-type', 'client', 'expiry', 'uid')
|
||||||
|
expect(response.body).to include('en')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -37,7 +38,7 @@ RSpec.describe 'Accounts API', type: :request do
|
|||||||
allow(ChatwootCaptcha).to receive(:new).and_return(captcha)
|
allow(ChatwootCaptcha).to receive(:new).and_return(captcha)
|
||||||
allow(captcha).to receive(:valid?).and_return(true)
|
allow(captcha).to receive(:valid?).and_return(true)
|
||||||
|
|
||||||
params = { account_name: 'test', email: email, user: nil, user_full_name: user_full_name, password: 'Password1!',
|
params = { account_name: 'test', email: email, user: nil, locale: nil, user_full_name: user_full_name, password: 'Password1!',
|
||||||
h_captcha_client_response: '123' }
|
h_captcha_client_response: '123' }
|
||||||
|
|
||||||
post api_v1_accounts_url,
|
post api_v1_accounts_url,
|
||||||
@@ -46,6 +47,7 @@ RSpec.describe 'Accounts API', type: :request do
|
|||||||
|
|
||||||
expect(ChatwootCaptcha).to have_received(:new).with('123')
|
expect(ChatwootCaptcha).to have_received(:new).with('123')
|
||||||
expect(response.headers.keys).to include('access-token', 'token-type', 'client', 'expiry', 'uid')
|
expect(response.headers.keys).to include('access-token', 'token-type', 'client', 'expiry', 'uid')
|
||||||
|
expect(response.body).to include('en')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -53,7 +55,7 @@ RSpec.describe 'Accounts API', type: :request do
|
|||||||
with_modified_env ENABLE_ACCOUNT_SIGNUP: 'true' do
|
with_modified_env ENABLE_ACCOUNT_SIGNUP: 'true' do
|
||||||
allow(account_builder).to receive(:perform).and_return(nil)
|
allow(account_builder).to receive(:perform).and_return(nil)
|
||||||
|
|
||||||
params = { account_name: nil, email: nil, user: nil, user_full_name: nil }
|
params = { account_name: nil, email: nil, user: nil, locale: 'en', user_full_name: nil }
|
||||||
|
|
||||||
post api_v1_accounts_url,
|
post api_v1_accounts_url,
|
||||||
params: params,
|
params: params,
|
||||||
@@ -130,6 +132,7 @@ RSpec.describe 'Accounts API', type: :request do
|
|||||||
expect(response.body).to include(account.domain)
|
expect(response.body).to include(account.domain)
|
||||||
expect(response.body).to include(account.support_email)
|
expect(response.body).to include(account.support_email)
|
||||||
expect(response.body).to include(account.auto_resolve_duration.to_s)
|
expect(response.body).to include(account.auto_resolve_duration.to_s)
|
||||||
|
expect(response.body).to include(account.locale)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -30,6 +30,15 @@ RSpec.describe 'Platform Accounts API', type: :request do
|
|||||||
expect(response.body).to include('Test Account')
|
expect(response.body).to include('Test Account')
|
||||||
expect(platform_app.platform_app_permissibles.first.permissible.name).to eq('Test Account')
|
expect(platform_app.platform_app_permissibles.first.permissible.name).to eq('Test Account')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'creates an account with locale' do
|
||||||
|
post '/platform/api/v1/accounts', params: { name: 'Test Account', locale: 'es' },
|
||||||
|
headers: { api_access_token: platform_app.access_token.token }, as: :json
|
||||||
|
|
||||||
|
expect(response).to have_http_status(:success)
|
||||||
|
expect(response.body).to include('Test Account')
|
||||||
|
expect(response.body).to include('es')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ RSpec.describe Account do
|
|||||||
account = create(:account)
|
account = create(:account)
|
||||||
query = "select * from information_schema.sequences where sequence_name in ('camp_dpid_seq_#{account.id}', 'conv_dpid_seq_#{account.id}');"
|
query = "select * from information_schema.sequences where sequence_name in ('camp_dpid_seq_#{account.id}', 'conv_dpid_seq_#{account.id}');"
|
||||||
expect(ActiveRecord::Base.connection.execute(query).count).to eq(2)
|
expect(ActiveRecord::Base.connection.execute(query).count).to eq(2)
|
||||||
|
expect(account.locale).to eq('en')
|
||||||
account.destroy
|
account.destroy
|
||||||
expect(ActiveRecord::Base.connection.execute(query).count).to eq(0)
|
expect(ActiveRecord::Base.connection.execute(query).count).to eq(0)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user