diff options
Diffstat (limited to 'app/services/releases/links/update_service.rb')
-rw-r--r-- | app/services/releases/links/update_service.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/app/services/releases/links/update_service.rb b/app/services/releases/links/update_service.rb new file mode 100644 index 00000000000..c29de86f31b --- /dev/null +++ b/app/services/releases/links/update_service.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module Releases + module Links + class UpdateService < BaseService + def execute(link) + return ServiceResponse.error(reason: REASON_FORBIDDEN, message: _('Access Denied')) unless allowed? + return ServiceResponse.error(reason: REASON_NOT_FOUND, message: _('Link does not exist')) unless link + + if link.update(allowed_params) + ServiceResponse.success(payload: { link: link }) + else + ServiceResponse.error(reason: REASON_BAD_REQUEST, message: link.errors.full_messages) + end + end + + private + + def allowed? + Ability.allowed?(current_user, :update_release, release) + end + end + end +end |