debian-mirror-gitlab/app/services/customer_relations/organizations/create_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

29 lines
751 B
Ruby
Raw Normal View History

2021-11-11 11:23:49 +05:30
# frozen_string_literal: true
module CustomerRelations
module Organizations
class CreateService < BaseService
# returns the created organization
def execute
return error_no_permissions unless allowed?
2021-11-18 22:05:49 +05:30
organization = Organization.create(params.merge(group_id: group.id))
2021-11-11 11:23:49 +05:30
return error_creating(organization) unless organization.persisted?
ServiceResponse.success(payload: organization)
end
private
def error_no_permissions
error('You have insufficient permissions to create an organization for this group')
end
def error_creating(organization)
error(organization&.errors&.full_messages || 'Failed to create organization')
end
end
end
end