Welcome to mirror list, hosted at ThFree Co, Russian Federation.

award_emoji.rb « v3 « api « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1e35283631f013803761371686dd16da50f80652 (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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
module API
  module V3
    class AwardEmoji < Grape::API
      include PaginationParams

      before { authenticate! }
      AWARDABLES = %w[issue merge_request snippet].freeze

      resource :projects do
        AWARDABLES.each do |awardable_type|
          awardable_string = awardable_type.pluralize
          awardable_id_string = "#{awardable_type}_id"

          params do
            requires :id, type: String, desc: 'The ID of a project'
            requires :"#{awardable_id_string}", type: Integer, desc: "The ID of an Issue, Merge Request or Snippet"
          end

          [":id/#{awardable_string}/:#{awardable_id_string}/award_emoji",
           ":id/#{awardable_string}/:#{awardable_id_string}/notes/:note_id/award_emoji"].each do |endpoint|
            desc 'Delete a +awardables+ award emoji' do
              detail 'This feature was introduced in 8.9'
              success ::API::Entities::AwardEmoji
            end
            params do
              requires :award_id, type: Integer, desc: 'The ID of an award emoji'
            end
            delete "#{endpoint}/:award_id" do
              award = awardable.award_emoji.find(params[:award_id])

              unauthorized! unless award.user == current_user || current_user.admin?

              present award.destroy, with: ::API::Entities::AwardEmoji
            end
          end
        end
      end

      helpers do
        def awardable
          @awardable ||=
            begin
              if params.include?(:note_id)
                note_id = params.delete(:note_id)

                awardable.notes.find(note_id)
              elsif params.include?(:issue_id)
                user_project.issues.find(params[:issue_id])
              elsif params.include?(:merge_request_id)
                user_project.merge_requests.find(params[:merge_request_id])
              else
                user_project.snippets.find(params[:snippet_id])
              end
            end
        end
      end
    end
  end
end