summaryrefslogtreecommitdiff
path: root/app/services/users/signup_service.rb
blob: 1087ae76216e5917d6e947ec7af69726f37f714f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 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
        success
      else
        error(@user.errors.full_messages.join('. '))
      end
    end

    private

    def assign_attributes
      @user.assign_attributes(params) unless params.empty?
    end

    def inject_validators
      class << @user
        validates :role, presence: true
        validates :setup_for_company, inclusion: { in: [true, false], message: :blank } if Gitlab.com?
      end
    end
  end
end