Do not set source=signup on initial admin user creation.
This commit is contained in:
parent
9b84a64a37
commit
5b43ba89e1
1 changed files with 15 additions and 6 deletions
|
@ -96,20 +96,26 @@ class UsersController < ApplicationController
|
||||||
user.param_set_associations(params)
|
user.param_set_associations(params)
|
||||||
|
|
||||||
begin
|
begin
|
||||||
# check if it's first user
|
|
||||||
|
# check if it's first user, tje admin user
|
||||||
|
# inital admin account
|
||||||
count = User.all.count()
|
count = User.all.count()
|
||||||
|
admin_account_exists = true
|
||||||
|
if count <= 2
|
||||||
|
admin_account_exists = false
|
||||||
|
end
|
||||||
|
|
||||||
# if it's a signup, add user to customer role
|
# if it's a signup, add user to customer role
|
||||||
if !current_user
|
if !current_user
|
||||||
|
|
||||||
# check if feature is enabled
|
# check if feature is enabled
|
||||||
if !Setting.get('user_create_account')
|
if admin_account_exists && !Setting.get('user_create_account')
|
||||||
render json: { error: 'Feature not enabled!' }, status: :unprocessable_entity
|
render json: { error: 'Feature not enabled!' }, status: :unprocessable_entity
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
# check signup option only after admin account is created
|
# check signup option only after admin account is created
|
||||||
if count > 2 && !params[:signup]
|
if admin_account_exists && !params[:signup]
|
||||||
render json: { error: 'Only signup with not authenticate user possible!' }, status: :unprocessable_entity
|
render json: { error: 'Only signup with not authenticate user possible!' }, status: :unprocessable_entity
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -135,7 +141,10 @@ class UsersController < ApplicationController
|
||||||
user.group_ids = group_ids
|
user.group_ids = group_ids
|
||||||
|
|
||||||
# remember source (in case show email verify banner)
|
# remember source (in case show email verify banner)
|
||||||
|
# if not inital user creation
|
||||||
|
if admin_account_exists
|
||||||
user.source = 'signup'
|
user.source = 'signup'
|
||||||
|
end
|
||||||
|
|
||||||
# else do assignment as defined
|
# else do assignment as defined
|
||||||
else
|
else
|
||||||
|
@ -162,7 +171,7 @@ class UsersController < ApplicationController
|
||||||
user.save!
|
user.save!
|
||||||
|
|
||||||
# if first user was added, set system init done
|
# if first user was added, set system init done
|
||||||
if count <= 2
|
if !admin_account_exists
|
||||||
Setting.set('system_init_done', true)
|
Setting.set('system_init_done', true)
|
||||||
|
|
||||||
# fetch org logo
|
# fetch org logo
|
||||||
|
@ -191,7 +200,7 @@ class UsersController < ApplicationController
|
||||||
NotificationFactory::Mailer.notification(
|
NotificationFactory::Mailer.notification(
|
||||||
template: 'signup',
|
template: 'signup',
|
||||||
user: user,
|
user: user,
|
||||||
objects: result
|
objects: result,
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
user_new = User.find(user.id).attributes_with_associations
|
user_new = User.find(user.id).attributes_with_associations
|
||||||
|
|
Loading…
Reference in a new issue