Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

use service to have notification settings created

ulferts46152c752681
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 423440dc90c..ae31c81140a 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -99,22 +99,18 @@ class UsersController < ApplicationController
end
def create
- @user = User.new(language: Setting.default_language)
- @user.attributes = permitted_params.user_create_as_admin(false, @user.change_password_allowed?)
- @user.admin = params[:user][:admin] || false
- @user.login = params[:user][:login] || @user.mail
+ call = Users::CreateService
+ .new(user: current_user)
+ .call(create_params)
- if UserInvitation.invite_user! @user
- respond_to do |format|
- format.html do
- flash[:notice] = I18n.t(:notice_successful_create)
- redirect_to(params[:continue] ? new_user_path : edit_user_path(@user))
- end
- end
+ @user = call.result
+
+ if call.success?
+ flash[:notice] = I18n.t(:notice_successful_create)
+ redirect_to(params[:continue] ? new_user_path : edit_user_path(@user))
else
- respond_to do |format|
- format.html { render action: 'new' }
- end
+ @errors = call.errors
+ render action: 'new'
end
end
@@ -337,4 +333,12 @@ class UsersController < ApplicationController
update_params
end
+
+ def create_params
+ permitted_params
+ .user_create_as_admin(false, false)
+ .merge(admin: params[:user][:admin] || false,
+ login: params[:user][:login] || params[:user][:mail],
+ status: User.statuses[:invited])
+ end
end
diff --git a/app/models/permitted_params.rb b/app/models/permitted_params.rb
index 397d8123b26..caf3fcf9275 100644
--- a/app/models/permitted_params.rb
+++ b/app/models/permitted_params.rb
@@ -208,7 +208,7 @@ class PermittedParams
additional_params << :force_password_change if change_password_allowed
additional_params << :admin
end
-
+
additional_params << :login if Users::BaseContract.new(User.new, current_user).writable?(:login)
user additional_params
diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb
index ccc09b8951e..87e68e490cd 100644
--- a/app/views/users/new.html.erb
+++ b/app/views/users/new.html.erb
@@ -36,6 +36,8 @@ See docs/COPYRIGHT.rdoc for more details.
<%= toolbar title: t(:label_user_new) %>
+<%= error_messages_for_contract @user, @errors %>
+
<%= labelled_tabular_form_for @user,
url: { action: "create" },
html: { class: nil, autocomplete: 'off' },