From fa4a613517a4a236ea5e98a1964e52c8b4eef595 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Thu, 28 Jul 2016 20:39:35 -0600 Subject: [PATCH] Add 'Resolved all discussions' system note --- app/controllers/projects/discussions_controller.rb | 2 ++ app/controllers/projects/notes_controller.rb | 2 ++ app/models/merge_request.rb | 5 +++++ .../merge_requests/all_discussions_resolved_service.rb | 9 +++++++++ app/services/notes/delete_service.rb | 4 ++++ app/services/system_note_service.rb | 6 ++++++ 6 files changed, 28 insertions(+) create mode 100644 app/services/merge_requests/all_discussions_resolved_service.rb diff --git a/app/controllers/projects/discussions_controller.rb b/app/controllers/projects/discussions_controller.rb index 11c8f714a95..86e3f865c6f 100644 --- a/app/controllers/projects/discussions_controller.rb +++ b/app/controllers/projects/discussions_controller.rb @@ -9,6 +9,8 @@ class Projects::DiscussionsController < Projects::ApplicationController discussion.resolve!(current_user) + MergeRequests::AllDiscussionsResolvedService.new(project, current_user).execute(merge_request) + render json: { resolved_by: discussion.resolved_by.try(:name), discussion_headline_html: view_to_html_string('discussions/_headline', discussion: discussion) diff --git a/app/controllers/projects/notes_controller.rb b/app/controllers/projects/notes_controller.rb index 027a2d7dcb2..1849311d26d 100644 --- a/app/controllers/projects/notes_controller.rb +++ b/app/controllers/projects/notes_controller.rb @@ -72,6 +72,8 @@ class Projects::NotesController < Projects::ApplicationController note.resolve!(current_user) + MergeRequests::AllDiscussionsResolvedService.new(project, current_user).execute(note.noteable) + discussion = note.discussion render json: { diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 04cec923f2e..484e37ff31a 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -401,6 +401,11 @@ class MergeRequest < ActiveRecord::Base discussions end + def discussions_resolved? + all_discussions = discussions + all_discussions.any?(&:resolvable?) && all_discussions.none?(&:to_be_resolved?) + end + def hook_attrs attrs = { source: source_project.try(:hook_attrs), diff --git a/app/services/merge_requests/all_discussions_resolved_service.rb b/app/services/merge_requests/all_discussions_resolved_service.rb new file mode 100644 index 00000000000..d0fe226c196 --- /dev/null +++ b/app/services/merge_requests/all_discussions_resolved_service.rb @@ -0,0 +1,9 @@ +module MergeRequests + class AllDiscussionsResolvedService < MergeRequests::BaseService + def execute(merge_request) + return unless merge_request.discussions_resolved? + + SystemNoteService.resolve_all_discussions(merge_request, project, current_user) + end + end +end diff --git a/app/services/notes/delete_service.rb b/app/services/notes/delete_service.rb index 7f1b30ec84e..40d519cdf66 100644 --- a/app/services/notes/delete_service.rb +++ b/app/services/notes/delete_service.rb @@ -3,6 +3,10 @@ module Notes def execute(note) note.destroy note.reset_events_cache + + if note.resolvable? + MergeRequests::AllDiscussionsResolvedService.new(project, current_user).execute(note.noteable) + end end end end diff --git a/app/services/system_note_service.rb b/app/services/system_note_service.rb index 1ab3b5789bc..a9d5bad5122 100644 --- a/app/services/system_note_service.rb +++ b/app/services/system_note_service.rb @@ -156,6 +156,12 @@ class SystemNoteService create_note(noteable: noteable, project: project, author: author, note: body) end + def self.resolve_all_discussions(merge_request, project, author) + body = "Resolved all discussions" + + create_note(noteable: merge_request, project: project, author: author, note: body) + end + # Called when the title of a Noteable is changed # # noteable - Noteable object that responds to `title`