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

35 lines
739 B
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
module Users
class SignupService < BaseService
def initialize(current_user, params = {})
@user = current_user
@params = params.dup
end
def execute
assign_attributes
inject_validators
if @user.save
2023-03-17 16:20:25 +05:30
ServiceResponse.success
2019-12-26 22:10:19 +05:30
else
2023-03-17 16:20:25 +05:30
ServiceResponse.error(message: @user.errors.full_messages.join('. '))
2019-12-26 22:10:19 +05:30
end
end
private
def assign_attributes
@user.assign_attributes(params) unless params.empty?
end
def inject_validators
class << @user
validates :role, presence: true
2020-11-24 15:15:51 +05:30
validates :setup_for_company, inclusion: { in: [true, false], message: :blank } if Gitlab.com?
2019-12-26 22:10:19 +05:30
end
end
end
end