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];
},
showButton: function () {
if (!this.discussion) {
return false;
} else {
return this.discussion.canResolve();
if (this.discussion) {
return this.discussion.isResolvable();
}
},
isDiscussionResolved: function () {

View file

@ -8,6 +8,7 @@
mergeRequestId: Number,
namespacePath: String,
projectPath: String,
canResolve: Boolean,
},
data: function() {
return {
@ -18,6 +19,11 @@
discussion: function () {
return this.discussions[this.discussionId];
},
showButton: function () {
if (this.discussion) {
return this.discussion.isResolvable();
}
},
allResolved: function () {
if (this.discussion) {
return this.discussion.isResolved();
@ -40,6 +46,9 @@
resolve: function () {
ResolveService.toggleResolveForDiscussion(this.namespace, this.mergeRequestId, this.discussionId);
}
},
created: function () {
CommentsStore.createDiscussion(this.discussionId, this.canResolve);
}
});
})(window);

View file

@ -3,6 +3,7 @@ class DiscussionModel {
this.id = discussionId;
this.notes = {};
this.loading = false;
this.canResolve = false;
}
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) {
const note = this.notes[noteId];

View file

@ -4,13 +4,22 @@
get: function (discussionId, noteId) {
return this.state[discussionId].getNote(noteId);
},
create: function (discussionId, noteId, canResolve, resolved, resolved_by) {
createDiscussion: function (discussionId, canResolve) {
let discussion = this.state[discussionId];
if (!this.state[discussionId]) {
discussion = new DiscussionModel(discussionId);
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);
},
update: function (discussionId, noteId, resolved, resolved_by) {

View file

@ -1,11 +1,11 @@
- if discussion.can_resolve?(current_user)
.btn-group{ role: "group" }
%resolve-discussion-btn{ ":namespace-path" => "'#{discussion.project.namespace.path}'",
":project-path" => "'#{discussion.project.path}'",
":discussion-id" => "'#{discussion.id}'",
":merge-request-id" => "#{discussion.noteable.iid}",
"inline-template" => true,
"v-cloak" => true }
- if discussion.for_merge_request?
%resolve-discussion-btn{ ":namespace-path" => "'#{discussion.project.namespace.path}'",
":project-path" => "'#{discussion.project.path}'",
":discussion-id" => "'#{discussion.id}'",
":merge-request-id" => discussion.noteable.iid,
":can-resolve" => discussion.can_resolve?(current_user),
"inline-template" => true }
.btn-group{ role: "group", "v-if" => "showButton" }
%button.btn.btn-default{ type: "button", "@click" => "resolve", ":disabled" => "loading" }
= icon("spinner spin", "v-show" => "loading")
{{ buttonText }}