summaryrefslogtreecommitdiff
path: root/app/services/notes
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2017-03-09 19:29:11 -0600
committerLuke "Jared" Bennett <lbennett@gitlab.com>2017-04-05 17:44:14 +0100
commit08bbb9fce66cb46d3262e6cd4c4379b59f065be0 (patch)
tree159eeb7ca43419f29926d6e77637db18bddd20a9 /app/services/notes
parent8bdfee8ba5fb0a8f48501e63274c8f9ce5708007 (diff)
downloadgitlab-ce-08bbb9fce66cb46d3262e6cd4c4379b59f065be0.tar.gz
Add option to start a new discussion on an MR
Diffstat (limited to 'app/services/notes')
-rw-r--r--app/services/notes/build_service.rb29
-rw-r--r--app/services/notes/create_service.rb6
2 files changed, 31 insertions, 4 deletions
diff --git a/app/services/notes/build_service.rb b/app/services/notes/build_service.rb
new file mode 100644
index 00000000000..47ed3e3fc3d
--- /dev/null
+++ b/app/services/notes/build_service.rb
@@ -0,0 +1,29 @@
+module Notes
+ class BuildService < BaseService
+ def execute
+ # TODO: Remove when we use a selectbox instead of a submit button
+ params[:type] = DiscussionNote.name if params.delete(:new_discussion)
+
+ in_reply_to_discussion_id = params.delete(:in_reply_to_discussion_id)
+ if project && in_reply_to_discussion_id.present?
+ discussion =
+ project.notes.find_original_discussion(in_reply_to_discussion_id) ||
+ project.notes.find_discussion(in_reply_to_discussion_id)
+
+ unless discussion
+ note = Note.new
+ note.errors.add(:base, 'Discussion to reply to cannot be found')
+ return note
+ end
+
+ params.merge!(discussion.reply_attributes)
+ end
+
+ note = Note.new(params)
+ note.project = project
+ note.author = current_user
+
+ note
+ end
+ end
+end
diff --git a/app/services/notes/create_service.rb b/app/services/notes/create_service.rb
index 61d66a26932..c08cddcbee5 100644
--- a/app/services/notes/create_service.rb
+++ b/app/services/notes/create_service.rb
@@ -3,10 +3,8 @@ module Notes
def execute
merge_request_diff_head_sha = params.delete(:merge_request_diff_head_sha)
- note = Note.new(params)
- note.project = project
- note.author = current_user
- note.system = false
+ note = Notes::BuildService.new(project, current_user, params).execute
+ return note unless note.valid?
# We execute commands (extracted from `params[:note]`) on the noteable
# **before** we save the note because if the note consists of commands