Welcome to mirror list, hosted at ThFree Co, Russian Federation.

create_service.rb « organizations « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 89c579032d2b442a5572fbfd4327f5182ffb01ff (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
# frozen_string_literal: true

module Organizations
  class CreateService < ::Organizations::BaseService
    def execute
      return error_no_permissions unless current_user&.can?(:create_organization)

      organization = Organization.create(params)

      return error_creating(organization) unless organization.persisted?

      ServiceResponse.success(payload: organization)
    end

    private

    def error_no_permissions
      ServiceResponse.error(message: [_('You have insufficient permissions to create organizations')])
    end

    def error_creating(organization)
      message = organization.errors.full_messages || _('Failed to create organization')

      ServiceResponse.error(message: Array(message))
    end
  end
end