debian-mirror-gitlab/app/services/users/create_service.rb

30 lines
719 B
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module Users
class CreateService < BaseService
2017-09-10 17:25:29 +05:30
include NewUserNotifier
2017-08-17 22:00:37 +05:30
def initialize(current_user, params = {})
@current_user = current_user
@params = params.dup
end
def execute(skip_authorization: false)
user = Users::BuildService.new(current_user, params).execute(skip_authorization: skip_authorization)
2020-03-13 15:44:24 +05:30
reset_token = user.generate_reset_token if user.recently_sent_password_reset?
2017-08-17 22:00:37 +05:30
2020-03-13 15:44:24 +05:30
after_create_hook(user, reset_token) if user.save
2017-08-17 22:00:37 +05:30
user
end
2020-03-13 15:44:24 +05:30
private
def after_create_hook(user, reset_token)
notify_new_user(user, reset_token)
end
2017-08-17 22:00:37 +05:30
end
end
2020-03-13 15:44:24 +05:30
Users::CreateService.prepend_if_ee('EE::Users::CreateService')