summaryrefslogtreecommitdiffstats
path: root/models/users.js
diff options
context:
space:
mode:
Diffstat (limited to 'models/users.js')
-rw-r--r--models/users.js57
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,