Fixes #3189 - Unable to create inital admin user via web installer

This commit is contained in:
Mantas 2020-10-06 13:34:36 +03:00 committed by Thorsten Eckel
parent 1a42d9ada3
commit 138edc437b
7 changed files with 51 additions and 18 deletions

View file

@ -238,10 +238,7 @@ class Admin extends App.WizardFullScreen
fail: (settings, details) =>
@formEnable(e)
if _.isArray(details.error)
@form.showAlert( App.i18n.translateInline( details.error[0], details.error[1] ) )
else
@form.showAlert(details.error_human || details.error || 'Unable to create user!')
@form.showAlert(details.error_human || details.error || 'Unable to create user!')
)
relogin: (data, status, xhr) =>
@ -965,7 +962,7 @@ class Agent extends App.WizardFullScreen
@html App.view('getting_started/agent')()
new App.ControllerForm(
@form = new App.ControllerForm(
el: @$('.js-agent-form')
model: App.User
screen: 'invite_agent'
@ -1012,11 +1009,7 @@ class Agent extends App.WizardFullScreen
fail: (settings, details) =>
@formEnable(e)
App.Event.trigger 'notify', {
type: 'error'
msg: App.i18n.translateContent(details.error_human || 'Can\'t create user!')
timeout: 2500
}
@form.showAlert details.error_human || 'Can\'t create user!'
)
App.Config.set('getting_started/agents', Agent, 'Routes')

View file

@ -75,7 +75,7 @@ class Index extends App.ControllerContent
)
fail: (settings, details) =>
@formEnable(e)
@form.showAlert(details.error_human || details.error || 'Unable to update object!')
@form.showAlert(details.error_human || details.error || 'Unable to create user!')
)
resend: (e) =>

View file

@ -968,7 +968,8 @@ curl http://localhost/api/v1/users/avatar -v -u #{login}:#{password} -H "Content
result = PasswordPolicy.new(clean_user_params[:password])
if !result.valid?
raise Exceptions::UnprocessableEntity, result.error
render json: { error: result.error }, status: :unprocessable_entity
return
end
user = User.new(clean_user_params)
@ -1026,7 +1027,8 @@ curl http://localhost/api/v1/users/avatar -v -u #{login}:#{password} -H "Content
# check password policy
result = PasswordPolicy.new(clean_user_params[:password])
if !result.valid?
raise Exceptions::UnprocessableEntity, result.error
render json: { error: result.error }, status: :unprocessable_entity
return
end
user = User.new(clean_user_params)

View file

@ -168,8 +168,7 @@ RSpec.describe 'User', type: :request do
params = { email: 'some_new_customer@example.com', password: 'asdasdasdasd', signup: true }
post '/api/v1/users', params: params, headers: headers, as: :json
expect(response).to have_http_status(:unprocessable_entity)
expect(json_response['error']).to be_truthy
expect(json_response['error']).to include('Invalid password')
expect(json_response['error']).to be_a(Array).and(include(match(/Invalid password/)))
end
it 'verified with no current user', authenticated_as: :admin do

View file

@ -0,0 +1,19 @@
require 'rails_helper'
RSpec.describe 'Getting Started > Admin', type: :system, authenticated_as: false, set_up: false do
it 'shows password strength error' do
visit 'getting_started/admin'
fill_in 'firstname', with: 'Test'
fill_in 'lastname', with: 'Test'
fill_in 'email', with: 'test@example.com'
fill_in 'password', with: 'asdasdasdasd'
fill_in 'password_confirm', with: 'asdasdasdasd'
click '.btn--success'
within '.js-danger' do
expect(page).to have_text('Invalid password,').and(have_no_text('["'))
end
end
end

View file

@ -0,0 +1,18 @@
require 'rails_helper'
RSpec.describe 'Getting Started > Agents', type: :system do
it 'shows password strength error' do
visit 'getting_started/agents'
fill_in 'firstname', with: 'Test'
fill_in 'lastname', with: 'Test'
fill_in 'email', with: 'master@example.com'
click '.btn--success'
within '.js-danger' do
expect(page)
.to have_text("Email address 'master@example.com' is already used for other user.")
end
end
end

View file

@ -7,11 +7,13 @@ RSpec.describe 'Signup', type: :system, authenticated_as: false do
fill_in 'firstname', with: 'Test'
fill_in 'lastname', with: 'Test'
fill_in 'email', with: 'test@example.com'
fill_in 'password', with: 'badpw'
fill_in 'password_confirm', with: 'badpw'
fill_in 'password', with: 'asdasdasdasd'
fill_in 'password_confirm', with: 'asdasdasdasd'
click '.js-submit'
expect(page).to have_text 'Invalid password,'
within '.js-danger' do
expect(page).to have_text('Invalid password,').and(have_no_text('["'))
end
end
end