bugfix: only care active members, also optimize some code

This commit is contained in:
floatinghotpot 2015-12-08 16:03:31 +08:00
parent b719968df5
commit 672c21bfe0
9 changed files with 62 additions and 78 deletions

View file

@ -279,7 +279,7 @@ BlazeComponent.extendComponent({
'click .js-select-member'() {
const userId = this.currentData()._id;
const currentBoard = Boards.findOne(Session.get('currentBoard'));
if (currentBoard.memberIndex(userId)<0) {
if (!currentBoard.hasMember(userId)) {
this.inviteUser(userId);
}
},
@ -305,16 +305,12 @@ Template.changePermissionsPopup.events({
Template.changePermissionsPopup.helpers({
isAdmin() {
const user = Users.findOne(this.userId);
return user.isBoardAdmin();
const currentBoard = Boards.findOne(Session.get('currentBoard'));
return currentBoard.hasAdmin(this.userId);
},
isLastAdmin() {
const user = Users.findOne(this.userId);
if (!user.isBoardAdmin())
return false;
const currentBoard = Boards.findOne(Session.get('currentBoard'));
const nbAdmins = _.where(currentBoard.members, { isAdmin: true }).length;
return nbAdmins === 1;
return currentBoard.hasAdmin(this.userId) && (currentBoard.activeAdmins() === 1);
},
});