diff options
author | George Andrinopoulos <geoandri@gmail.com> | 2017-03-27 09:37:24 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-03-27 09:37:24 +0000 |
commit | 7c74a0209b2354ee9260bfebe9bbde5cd0c141bf (patch) | |
tree | f98ebab7adf9ca90ab7128c4f9e9605d84b13ae9 /lib/api/users.rb | |
parent | e19d4c511d21e14d2442546a5d00c5fbdf13308a (diff) | |
download | gitlab-ce-7c74a0209b2354ee9260bfebe9bbde5cd0c141bf.tar.gz |
Implement new service for creating user
Diffstat (limited to 'lib/api/users.rb')
-rw-r--r-- | lib/api/users.rb | 27 |
1 files changed, 4 insertions, 23 deletions
diff --git a/lib/api/users.rb b/lib/api/users.rb index 2d4d5a25221..a4201fe6fed 100644 --- a/lib/api/users.rb +++ b/lib/api/users.rb @@ -27,7 +27,7 @@ module API optional :location, type: String, desc: 'The location of the user' optional :admin, type: Boolean, desc: 'Flag indicating the user is an administrator' optional :can_create_group, type: Boolean, desc: 'Flag indicating the user can create groups' - optional :confirm, type: Boolean, desc: 'Flag indicating the account needs to be confirmed' + optional :skip_confirmation, type: Boolean, default: false, desc: 'Flag indicating the account is confirmed' optional :external, type: Boolean, desc: 'Flag indicating the user is an external user' all_or_none_of :extern_uid, :provider end @@ -97,29 +97,10 @@ module API post do authenticated_as_admin! - # Filter out params which are used later - user_params = declared_params(include_missing: false) - identity_attrs = user_params.slice(:provider, :extern_uid) - confirm = user_params.delete(:confirm) - user = User.new(user_params.except(:extern_uid, :provider, :reset_password)) - - if user_params.delete(:reset_password) - user.attributes = { - force_random_password: true, - password_expires_at: nil, - created_by_id: current_user.id - } - user.generate_password - user.generate_reset_token - end - - user.skip_confirmation! unless confirm - - if identity_attrs.any? - user.identities.build(identity_attrs) - end + params = declared_params(include_missing: false) + user = ::Users::CreateService.new(current_user, params).execute - if user.save + if user.persisted? present user, with: Entities::UserPublic else conflict!('Email has already been taken') if User. |