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

This commit is contained in:
Douwe Maan 2016-08-12 15:10:05 -05:00
parent c80f5e0a1c
commit 33edde50ab
5 changed files with 35 additions and 14 deletions

View file

@ -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 () {

View file

@ -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 @@
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 @@
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);

View file

@ -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 {
} }
} }
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];

View file

@ -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) {

View file

@ -1,11 +1,11 @@
- 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}", ":can-resolve" => discussion.can_resolve?(current_user),
"inline-template" => true, "inline-template" => true }
"v-cloak" => 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 }}