diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-04 18:12:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-04 18:12:07 +0300 |
commit | a155ff5671d06afd4c219a49b6c9fd673af69876 (patch) | |
tree | ea9f3422fcfe751f954561ff579569ba9a742eb3 /app/services | |
parent | 157061839634d24bdb937316373f35bf1fb1f71e (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/organizations/base_service.rb | 5 | ||||
-rw-r--r-- | app/services/organizations/update_service.rb | 46 |
2 files changed, 51 insertions, 0 deletions
diff --git a/app/services/organizations/base_service.rb b/app/services/organizations/base_service.rb index 19bbc64ebdd..3e734e3cd0c 100644 --- a/app/services/organizations/base_service.rb +++ b/app/services/organizations/base_service.rb @@ -9,6 +9,11 @@ module Organizations def initialize(current_user: nil, params: {}) @current_user = current_user @params = params.dup + return unless @params.key?(:description) + + organization_detail_attributes = { description: @params.delete(:description) } + @params[:organization_detail_attributes] ||= {} + @params[:organization_detail_attributes].merge!(organization_detail_attributes) end end end diff --git a/app/services/organizations/update_service.rb b/app/services/organizations/update_service.rb new file mode 100644 index 00000000000..e262bd15bc0 --- /dev/null +++ b/app/services/organizations/update_service.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +module Organizations + class UpdateService < ::Organizations::BaseService + attr_reader :organization + + def initialize(organization, current_user:, params: {}) + @organization = organization + @current_user = current_user + @params = params.dup + return unless @params.key?(:description) + + organization_detail_attributes = { description: @params.delete(:description) } + # TODO: Remove explicit passing of id once https://github.com/rails/rails/issues/48714 is resolved. + organization_detail_attributes[:id] = organization.id + @params[:organization_detail_attributes] ||= {} + @params[:organization_detail_attributes].merge!(organization_detail_attributes) + end + + def execute + return error_no_permissions unless allowed? + + if organization.update(params) + ServiceResponse.success(payload: organization) + else + error_updating + end + end + + private + + def allowed? + current_user&.can?(:admin_organization, organization) + end + + def error_no_permissions + ServiceResponse.error(message: [_('You have insufficient permissions to update the organization')]) + end + + def error_updating + message = organization.errors.full_messages || _('Failed to update organization') + + ServiceResponse.error(payload: organization, message: Array(message)) + end + end +end |