Commit 33edde50 authored by Douwe Maan's avatar Douwe Maan

Don’t show “Resolve discussion” for non-author/members

parent c80f5e0a
...@@ -9,10 +9,8 @@ ...@@ -9,10 +9,8 @@
return CommentsStore.state[this.discussionId]; return CommentsStore.state[this.discussionId];
}, },
showButton: function () { showButton: function () {
if (!this.discussion) { if (this.discussion) {
return false; return this.discussion.isResolvable();
} else {
return this.discussion.canResolve();
} }
}, },
isDiscussionResolved: function () { isDiscussionResolved: function () {
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
mergeRequestId: Number, mergeRequestId: Number,
namespacePath: String, namespacePath: String,
projectPath: String, projectPath: String,
canResolve: Boolean,
}, },
data: function() { data: function() {
return { return {
...@@ -18,6 +19,11 @@ ...@@ -18,6 +19,11 @@
discussion: function () { discussion: function () {
return this.discussions[this.discussionId]; return this.discussions[this.discussionId];
}, },
showButton: function () {
if (this.discussion) {
return this.discussion.isResolvable();
}
},
allResolved: function () { allResolved: function () {
if (this.discussion) { if (this.discussion) {
return this.discussion.isResolved(); return this.discussion.isResolved();
...@@ -40,6 +46,9 @@ ...@@ -40,6 +46,9 @@
resolve: function () { resolve: function () {
ResolveService.toggleResolveForDiscussion(this.namespace, this.mergeRequestId, this.discussionId); ResolveService.toggleResolveForDiscussion(this.namespace, this.mergeRequestId, this.discussionId);
} }
},
created: function () {
CommentsStore.createDiscussion(this.discussionId, this.canResolve);
} }
}); });
})(window); })(window);
...@@ -3,6 +3,7 @@ class DiscussionModel { ...@@ -3,6 +3,7 @@ class DiscussionModel {
this.id = discussionId; this.id = discussionId;
this.notes = {}; this.notes = {};
this.loading = false; this.loading = false;
this.canResolve = false;
} }
createNote (noteId, canResolve, resolved, resolved_by) { createNote (noteId, canResolve, resolved, resolved_by) {
...@@ -68,7 +69,11 @@ class DiscussionModel { ...@@ -68,7 +69,11 @@ class DiscussionModel {
} }
} }
canResolve () { isResolvable () {
if (!this.canResolve) {
return false;
}
for (const noteId in this.notes) { for (const noteId in this.notes) {
const note = this.notes[noteId]; const note = this.notes[noteId];
......
...@@ -4,13 +4,22 @@ ...@@ -4,13 +4,22 @@
get: function (discussionId, noteId) { get: function (discussionId, noteId) {
return this.state[discussionId].getNote(noteId); return this.state[discussionId].getNote(noteId);
}, },
create: function (discussionId, noteId, canResolve, resolved, resolved_by) { createDiscussion: function (discussionId, canResolve) {
let discussion = this.state[discussionId]; let discussion = this.state[discussionId];
if (!this.state[discussionId]) { if (!this.state[discussionId]) {
discussion = new DiscussionModel(discussionId); discussion = new DiscussionModel(discussionId);
Vue.set(this.state, discussionId, discussion); Vue.set(this.state, discussionId, discussion);
} }
if (canResolve !== undefined) {
discussion.canResolve = canResolve;
}
return discussion;
},
create: function (discussionId, noteId, canResolve, resolved, resolved_by) {
const discussion = this.createDiscussion(discussionId);
discussion.createNote(noteId, canResolve, resolved, resolved_by); discussion.createNote(noteId, canResolve, resolved, resolved_by);
}, },
update: function (discussionId, noteId, resolved, resolved_by) { update: function (discussionId, noteId, resolved, resolved_by) {
......
- if discussion.can_resolve?(current_user) - if discussion.for_merge_request?
.btn-group{ role: "group" }
%resolve-discussion-btn{ ":namespace-path" => "'#{discussion.project.namespace.path}'", %resolve-discussion-btn{ ":namespace-path" => "'#{discussion.project.namespace.path}'",
":project-path" => "'#{discussion.project.path}'", ":project-path" => "'#{discussion.project.path}'",
":discussion-id" => "'#{discussion.id}'", ":discussion-id" => "'#{discussion.id}'",
":merge-request-id" => "#{discussion.noteable.iid}", ":merge-request-id" => discussion.noteable.iid,
"inline-template" => true, ":can-resolve" => discussion.can_resolve?(current_user),
"v-cloak" => true } "inline-template" => true }
.btn-group{ role: "group", "v-if" => "showButton" }
%button.btn.btn-default{ type: "button", "@click" => "resolve", ":disabled" => "loading" } %button.btn.btn-default{ type: "button", "@click" => "resolve", ":disabled" => "loading" }
= icon("spinner spin", "v-show" => "loading") = icon("spinner spin", "v-show" => "loading")
{{ buttonText }} {{ buttonText }}
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