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

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

34 lines
855 B
Ruby
Raw Normal View History

2021-11-11 11:23:49 +05:30
# frozen_string_literal: true
module CustomerRelations
module Organizations
class UpdateService < BaseService
def execute(organization)
return error_no_permissions unless allowed?
2022-07-16 23:28:13 +05:30
handle_active_param
2021-11-11 11:23:49 +05:30
return error_updating(organization) unless organization.update(params)
ServiceResponse.success(payload: organization)
end
private
2022-07-16 23:28:13 +05:30
def handle_active_param
return if params[:active].nil?
active = params.delete(:active)
params[:state] = active ? 'active' : 'inactive'
end
2021-11-11 11:23:49 +05:30
def error_no_permissions
error('You have insufficient permissions to update an organization for this group')
end
def error_updating(organization)
error(organization&.errors&.full_messages || 'Failed to update organization')
end
end
end
end