summaryrefslogtreecommitdiff
path: root/app/services/releases/links/destroy_service.rb
blob: 9edde2f357ba11f7c5b273b8d5f6f90a35436752 (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
# frozen_string_literal: true

module Releases
  module Links
    class DestroyService < BaseService
      def execute(link)
        return ServiceResponse.error(message: _('Access Denied')) unless allowed?
        return ServiceResponse.error(message: _('Link does not exist')) unless link

        if link.destroy
          ServiceResponse.success(payload: { link: link })
        else
          ServiceResponse.error(message: link.errors.full_messages)
        end
      end

      private

      def allowed?
        Ability.allowed?(current_user, :destroy_release, release)
      end
    end
  end
end