From bbab5d014f10914b1e5d7a73dc0e85ea57344979 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Mon, 25 Jul 2016 22:37:22 -0600 Subject: [PATCH] Add methods to resolve diff notes and discussions --- app/models/diff_note.rb | 18 ++++++++++++++++++ app/models/discussion.rb | 12 ++++++++++++ 2 files changed, 30 insertions(+) diff --git a/app/models/diff_note.rb b/app/models/diff_note.rb index d76ac51af0f..3edbdf9f966 100644 --- a/app/models/diff_note.rb +++ b/app/models/diff_note.rb @@ -85,6 +85,24 @@ class DiffNote < Note self.resolved_at.present? end + def resolve!(current_user) + return unless resolvable? + return if resolved? + + self.resolved_at = Time.now + self.resolved_by = current_user + save! + end + + def unresolve! + return unless resolvable? + return unless resolved? + + self.resolved_at = nil + self.resolved_by = nil + save! + end + private def supported? diff --git a/app/models/discussion.rb b/app/models/discussion.rb index ff85e2038a7..64116d225ae 100644 --- a/app/models/discussion.rb +++ b/app/models/discussion.rb @@ -63,6 +63,18 @@ class Discussion notes.any?(&:to_be_resolved?) end + def resolve!(current_user) + notes.each do |note| + note.resolve!(current_user) if note.resolvable? + end + end + + def unresolve! + notes.each do |note| + note.unresolve! if note.resolvable? + end + end + def for_target?(target) self.noteable == target && !diff_discussion? end