diff options
author | Maxime Quandalle <maxime@quandalle.com> | 2015-10-31 10:27:20 +0100 |
---|---|---|
committer | Maxime Quandalle <maxime@quandalle.com> | 2015-10-31 12:49:58 +0100 |
commit | 2b134ff7a986eb97f8ec360321be284a7a8ea11e (patch) | |
tree | 0ff579909b402db5916b66ec7bc7469534881a15 /models/users.js | |
parent | 3507c6565bb16b5f45c6f269f7376902f8b1ff37 (diff) | |
parent | 41b23f88aea0f421226f92b081cdb1b61c64bde4 (diff) | |
download | wekan-2b134ff7a986eb97f8ec360321be284a7a8ea11e.tar.gz wekan-2b134ff7a986eb97f8ec360321be284a7a8ea11e.tar.bz2 wekan-2b134ff7a986eb97f8ec360321be284a7a8ea11e.zip |
Merge branch 'devel' into minicard-editor
Conflicts:
client/components/lists/listBody.js
Diffstat (limited to 'models/users.js')
-rw-r--r-- | models/users.js | 57 |
1 files changed, 38 insertions, 19 deletions
diff --git a/models/users.js b/models/users.js index 4260dc56..1e69564d 100644 --- a/models/users.js +++ b/models/users.js @@ -1,4 +1,4 @@ -Users = Meteor.users; +Users = Meteor.users; // eslint-disable-line meteor/collections // Search a user in the complete server database by its name or username. This // is used for instance to add a new user to a board. @@ -8,31 +8,50 @@ Users.initEasySearch(searchInFields, { returnFields: [...searchInFields, 'profile.avatarUrl'], }); +if (Meteor.isClient) { + Users.helpers({ + isBoardMember() { + const board = Boards.findOne(Session.get('currentBoard')); + return board && + _.contains(_.pluck(board.members, 'userId'), this._id) && + _.where(board.members, {userId: this._id})[0].isActive; + }, + + isBoardAdmin() { + const board = Boards.findOne(Session.get('currentBoard')); + return board && + this.isBoardMember(board) && + _.where(board.members, {userId: this._id})[0].isAdmin; + }, + }); +} + Users.helpers({ boards() { return Boards.find({ userId: this._id }); }, starredBoards() { - const starredBoardIds = this.profile.starredBoards || []; - return Boards.find({archived: false, _id: {$in: starredBoardIds}}); + const {starredBoards = []} = this.profile; + return Boards.find({archived: false, _id: {$in: starredBoards}}); }, hasStarred(boardId) { - const starredBoardIds = this.profile.starredBoards || []; - return _.contains(starredBoardIds, boardId); + const {starredBoards = []} = this.profile; + return _.contains(starredBoards, boardId); }, - isBoardMember() { - const board = Boards.findOne(Session.get('currentBoard')); - return board && _.contains(_.pluck(board.members, 'userId'), this._id) && - _.where(board.members, {userId: this._id})[0].isActive; - }, - - isBoardAdmin() { - const board = Boards.findOne(Session.get('currentBoard')); - return board && this.isBoardMember(board) && - _.where(board.members, {userId: this._id})[0].isAdmin; + getAvatarUrl() { + // Although we put the avatar picture URL in the `profile` object, we need + // to support Sandstorm which put in the `picture` attribute by default. + // XXX Should we move both cases to `picture`? + if (this.picture) { + return this.picture; + } else if (this.profile && this.profile.avatarUrl) { + return this.profile.avatarUrl; + } else { + return null; + } }, getInitials() { @@ -41,9 +60,9 @@ Users.helpers({ return profile.initials; else if (profile.fullname) { - return _.reduce(profile.fullname.split(/\s+/), (memo, word) => { + return profile.fullname.split(/\s+/).reduce((memo = '', word) => { return memo + word[0]; - }, '').toUpperCase(); + }).toUpperCase(); } else { return this.username[0].toUpperCase(); @@ -117,7 +136,7 @@ if (Meteor.isServer) { // b. We use it to find deleted and newly inserted ids by using it in one // direction and then in the other. function incrementBoards(boardsIds, inc) { - _.forEach(boardsIds, (boardId) => { + boardsIds.forEach((boardId) => { Boards.update(boardId, {$inc: {stars: inc}}); }); } @@ -136,7 +155,7 @@ if (Meteor.isServer) { // Insert the Welcome Board Boards.insert(ExampleBoard, (err, boardId) => { - _.forEach(['Basics', 'Advanced'], (title) => { + ['Basics', 'Advanced'].forEach((title) => { const list = { title, boardId, |