summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2016-07-28 20:09:36 -0600
committerDouwe Maan <douwe@selenight.nl>2016-07-28 20:09:36 -0600
commit1c2eefef3f67d9d221b6465ec77907940732e789 (patch)
tree36c66b062f5d328ea3cd41aea5d8ea483f08efe8
parent6d9715d8777265737c076abe06362d2a8e9e498d (diff)
downloadgitlab-ce-1c2eefef3f67d9d221b6465ec77907940732e789.tar.gz
Backend tweaks
-rw-r--r--app/controllers/projects/discussions_controller.rb4
-rw-r--r--app/controllers/projects/notes_controller.rb10
-rw-r--r--app/models/diff_note.rb15
-rw-r--r--app/views/discussions/_jump_to_next.html.haml2
-rw-r--r--app/views/discussions/_resolve_all.html.haml4
5 files changed, 23 insertions, 12 deletions
diff --git a/app/controllers/projects/discussions_controller.rb b/app/controllers/projects/discussions_controller.rb
index 47f301a08d9..11c8f714a95 100644
--- a/app/controllers/projects/discussions_controller.rb
+++ b/app/controllers/projects/discussions_controller.rb
@@ -11,7 +11,7 @@ class Projects::DiscussionsController < Projects::ApplicationController
render json: {
resolved_by: discussion.resolved_by.try(:name),
- updated_html: view_to_html_string('discussions/_headline', discussion: discussion)
+ discussion_headline_html: view_to_html_string('discussions/_headline', discussion: discussion)
}
end
@@ -21,7 +21,7 @@ class Projects::DiscussionsController < Projects::ApplicationController
discussion.unresolve!
render json: {
- updated_html: view_to_html_string('discussions/_headline', discussion: discussion)
+ discussion_headline_html: view_to_html_string('discussions/_headline', discussion: discussion)
}
end
diff --git a/app/controllers/projects/notes_controller.rb b/app/controllers/projects/notes_controller.rb
index 59b8e88c8d7..027a2d7dcb2 100644
--- a/app/controllers/projects/notes_controller.rb
+++ b/app/controllers/projects/notes_controller.rb
@@ -72,11 +72,11 @@ class Projects::NotesController < Projects::ApplicationController
note.resolve!(current_user)
- discussion = note.noteable.discussions.find { |d| d.id == note.discussion_id } || render_404
+ discussion = note.discussion
render json: {
resolved_by: note.resolved_by.try(:name),
- updated_html: view_to_html_string('discussions/_headline', discussion: discussion)
+ discussion_headline_html: (view_to_html_string('discussions/_headline', discussion: discussion) if discussion)
}
end
@@ -85,10 +85,10 @@ class Projects::NotesController < Projects::ApplicationController
note.unresolve!
- discussion = note.noteable.discussions.find { |d| d.id == note.discussion_id } || render_404
+ discussion = note.discussion
render json: {
- updated_html: view_to_html_string('discussions/_headline', discussion: discussion)
+ discussion_headline_html: (view_to_html_string('discussions/_headline', discussion: discussion) if discussion)
}
end
@@ -164,7 +164,7 @@ class Projects::NotesController < Projects::ApplicationController
}
if note.diff_note?
- discussion = Discussion.new([note])
+ discussion = note.as_discussion
attrs.merge!(
diff_discussion_html: diff_discussion_html(discussion),
diff --git a/app/models/diff_note.rb b/app/models/diff_note.rb
index 8c99be7df8a..e0c58b74380 100644
--- a/app/models/diff_note.rb
+++ b/app/models/diff_note.rb
@@ -76,7 +76,7 @@ class DiffNote < Note
end
def resolvable?
- !system? && !for_commit?
+ !system? && for_merge_request?
end
def resolved?
@@ -103,10 +103,21 @@ class DiffNote < Note
save!
end
+ def discussion
+ return unless resolvable?
+
+ discussion_notes = self.noteable.notes.fresh.select { |n| n.discussion_id == self.discussion_id }
+ Discussion.new(discussion_notes)
+ end
+
+ def as_discussion
+ Discussion.new([self])
+ end
+
private
def supported?
- !self.for_merge_request? || self.noteable.support_new_diff_notes?
+ for_commit? || self.noteable.support_new_diff_notes?
end
def set_original_position
diff --git a/app/views/discussions/_jump_to_next.html.haml b/app/views/discussions/_jump_to_next.html.haml
index dfdf6e60051..571e43b7594 100644
--- a/app/views/discussions/_jump_to_next.html.haml
+++ b/app/views/discussions/_jump_to_next.html.haml
@@ -1,4 +1,4 @@
-- discussion = local_assigns.fetch(:discussion, false)
+- discussion = local_assigns.fetch(:discussion, nil)
%jump-to-discussion{ "inline-template" => true, ":discussion-id" => "'#{discussion.try(:id)}'" }
.btn-group{ role: "group",
"v-show" => "!allResolved" }
diff --git a/app/views/discussions/_resolve_all.html.haml b/app/views/discussions/_resolve_all.html.haml
index ae222205c4e..9a75a573828 100644
--- a/app/views/discussions/_resolve_all.html.haml
+++ b/app/views/discussions/_resolve_all.html.haml
@@ -1,8 +1,8 @@
-- if discussion.can_resolve?(current_user) && discussion.resolvable?
+- if discussion.can_resolve?(current_user)
%resolve-all-btn{ ":namespace-path" => "'#{discussion.project.namespace.path}'",
":project-path" => "'#{discussion.project.path}'",
":discussion-id" => "'#{discussion.id}'",
- ":merge-request-id" => "#{discussion.first_note.noteable.try(:iid)}",
+ ":merge-request-id" => "#{discussion.noteable.iid}",
"inline-template" => true,
"v-cloak" => true }
%button.btn.btn-default{ type: "button", "@click" => "resolve", ":disabled" => "loading" }