Merge pull request #925 from rhelsing/comment-permissions

Comment permissions
This commit is contained in:
Lauri Ojansivu 2017-03-28 20:55:02 +03:00 committed by GitHub
commit 578619d409
22 changed files with 177 additions and 63 deletions

View file

@ -107,6 +107,7 @@ Boards.attachSchema(new SimpleSchema({
userId: this.userId,
isAdmin: true,
isActive: true,
isCommentOnly: false,
}];
}
},
@ -120,6 +121,9 @@ Boards.attachSchema(new SimpleSchema({
'members.$.isActive': {
type: Boolean,
},
'members.$.isCommentOnly': {
type: Boolean,
},
permission: {
type: String,
allowedValues: ['public', 'private'],
@ -219,6 +223,10 @@ Boards.helpers({
return !!_.findWhere(this.members, {userId: memberId, isActive: true, isAdmin: true});
},
hasCommentOnly(memberId) {
return !!_.findWhere(this.members, {userId: memberId, isActive: true, isAdmin: false, isCommentOnly: true});
},
absoluteUrl() {
return FlowRouter.url('board', { id: this._id, slug: this.slug });
},
@ -332,7 +340,7 @@ Boards.mutations({
};
},
setMemberPermission(memberId, isAdmin) {
setMemberPermission(memberId, isAdmin, isCommentOnly) {
const memberIndex = this.memberIndex(memberId);
// do not allow change permission of self
@ -343,6 +351,7 @@ Boards.mutations({
return {
$set: {
[`members.${memberIndex}.isAdmin`]: isAdmin,
[`members.${memberIndex}.isCommentOnly`]: isCommentOnly,
},
};
},

View file

@ -46,13 +46,13 @@ Lists.attachSchema(new SimpleSchema({
Lists.allow({
insert(userId, doc) {
return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
return allowIsBoardMemberNonComment(userId, Boards.findOne(doc.boardId));
},
update(userId, doc) {
return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
return allowIsBoardMemberNonComment(userId, Boards.findOne(doc.boardId));
},
remove(userId, doc) {
return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
return allowIsBoardMemberNonComment(userId, Boards.findOne(doc.boardId));
},
fetch: ['boardId'],
});

View file

@ -121,6 +121,16 @@ if (Meteor.isClient) {
return board && board.hasMember(this._id);
},
isNotCommentOnly() {
const board = Boards.findOne(Session.get('currentBoard'));
return board && board.hasMember(this._id) && !board.hasCommentOnly(this._id);
},
isCommentOnly() {
const board = Boards.findOne(Session.get('currentBoard'));
return board && board.hasCommentOnly(this._id);
},
isBoardAdmin() {
const board = Boards.findOne(Session.get('currentBoard'));
return board && board.hasAdmin(this._id);