Commit fa4a6135 authored by Douwe Maan's avatar Douwe Maan

Add 'Resolved all discussions' system note

parent 220b82a4
...@@ -9,6 +9,8 @@ class Projects::DiscussionsController < Projects::ApplicationController ...@@ -9,6 +9,8 @@ class Projects::DiscussionsController < Projects::ApplicationController
discussion.resolve!(current_user) discussion.resolve!(current_user)
MergeRequests::AllDiscussionsResolvedService.new(project, current_user).execute(merge_request)
render json: { render json: {
resolved_by: discussion.resolved_by.try(:name), resolved_by: discussion.resolved_by.try(:name),
discussion_headline_html: view_to_html_string('discussions/_headline', discussion: discussion) discussion_headline_html: view_to_html_string('discussions/_headline', discussion: discussion)
......
...@@ -72,6 +72,8 @@ class Projects::NotesController < Projects::ApplicationController ...@@ -72,6 +72,8 @@ class Projects::NotesController < Projects::ApplicationController
note.resolve!(current_user) note.resolve!(current_user)
MergeRequests::AllDiscussionsResolvedService.new(project, current_user).execute(note.noteable)
discussion = note.discussion discussion = note.discussion
render json: { render json: {
......
...@@ -401,6 +401,11 @@ class MergeRequest < ActiveRecord::Base ...@@ -401,6 +401,11 @@ class MergeRequest < ActiveRecord::Base
discussions discussions
end end
def discussions_resolved?
all_discussions = discussions
all_discussions.any?(&:resolvable?) && all_discussions.none?(&:to_be_resolved?)
end
def hook_attrs def hook_attrs
attrs = { attrs = {
source: source_project.try(:hook_attrs), source: source_project.try(:hook_attrs),
......
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
...@@ -3,6 +3,10 @@ module Notes ...@@ -3,6 +3,10 @@ module Notes
def execute(note) def execute(note)
note.destroy note.destroy
note.reset_events_cache note.reset_events_cache
if note.resolvable?
MergeRequests::AllDiscussionsResolvedService.new(project, current_user).execute(note.noteable)
end
end end
end end
end end
...@@ -156,6 +156,12 @@ class SystemNoteService ...@@ -156,6 +156,12 @@ class SystemNoteService
create_note(noteable: noteable, project: project, author: author, note: body) create_note(noteable: noteable, project: project, author: author, note: body)
end 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 # Called when the title of a Noteable is changed
# #
# noteable - Noteable object that responds to `title` # noteable - Noteable object that responds to `title`
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment