File: note.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (49 lines) | stat: -rw-r--r-- 1,504 bytes parent folder | download
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
# frozen_string_literal: true

module Mutations
  module Notes
    module Create
      class Note < Base
        graphql_name 'CreateNote'
        description "Creates a Note.\n#{QUICK_ACTION_ONLY_WARNING}"

        argument :discussion_id,
          ::Types::GlobalIDType[::Discussion],
          required: false,
          description: 'Global ID of the discussion the note is in reply to.'

        argument :merge_request_diff_head_sha,
          GraphQL::Types::String,
          required: false,
          description: 'SHA of the head commit which is used to ensure that ' \
            'the merge request has not been updated since the request was sent.'

        private

        def create_note_params(noteable, args)
          discussion_id = nil

          if gid = args[:discussion_id]
            discussion = GitlabSchema.find_by_gid(gid)

            authorize_discussion!(discussion)

            discussion_id = discussion.id
          end

          super(noteable, args).merge({
            in_reply_to_discussion_id: discussion_id,
            merge_request_diff_head_sha: args[:merge_request_diff_head_sha]
          })
        end

        def authorize_discussion!(discussion)
          unless Ability.allowed?(current_user, :read_note, discussion, scope: :user)
            raise Gitlab::Graphql::Errors::ResourceNotAvailable,
              "The discussion does not exist or you don't have permission to perform this action"
          end
        end
      end
    end
  end
end