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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Duncalfe <lduncalfe@eml.cc>2019-07-04 06:33:14 +0300
committerLuke Duncalfe <lduncalfe@eml.cc>2019-07-10 03:13:48 +0300
commit073c8b25ea36b6b96eab05eb675e8726b1d5318e (patch)
tree5f83a17cf6e461106d8ddf8f1b84f743a09547d6 /app/graphql/mutations
parent254f78f5dc36d4aef26d1ab2a924e4fa916221c6 (diff)
GraphQL support for Notes created in discussions
A new `discussion_id` argument on the `createNote` mutation allows people to create a note within that discussion. The ability to lazy-load Discussions has been added, so GraphQL.object_from_id can treat Discussions the same as AR objects and batch load them. https://gitlab.com/gitlab-org/gitlab-ce/issues/62826 https://gitlab.com/gitlab-org/gitlab-ee/issues/9489
Diffstat (limited to 'app/graphql/mutations')
-rw-r--r--app/graphql/mutations/notes/create/note.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/app/graphql/mutations/notes/create/note.rb b/app/graphql/mutations/notes/create/note.rb
index 3c571a4538f..5236e48026e 100644
--- a/app/graphql/mutations/notes/create/note.rb
+++ b/app/graphql/mutations/notes/create/note.rb
@@ -5,6 +5,35 @@ module Mutations
module Create
class Note < Base
graphql_name 'CreateNote'
+
+ argument :discussion_id,
+ GraphQL::ID_TYPE,
+ required: false,
+ description: 'The global id of the discussion this note is in reply to'
+
+ private
+
+ def create_note_params(noteable, args)
+ discussion_id = nil
+
+ if args[:discussion_id]
+ discussion = GitlabSchema.object_from_id(args[:discussion_id])
+ authorize_discussion!(discussion)
+
+ discussion_id = discussion.id
+ end
+
+ super(noteable, args).merge({
+ in_reply_to_discussion_id: discussion_id
+ })
+ 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