|
@@ -1,7 +1,7 @@
|
|
// Sandstorm context is detected using the METEOR_SETTINGS environment variable
|
|
// Sandstorm context is detected using the METEOR_SETTINGS environment variable
|
|
// in the package definition.
|
|
// in the package definition.
|
|
const isSandstorm = Meteor.settings && Meteor.settings.public &&
|
|
const isSandstorm = Meteor.settings && Meteor.settings.public &&
|
|
- Meteor.settings.public.sandstorm;
|
|
|
|
|
|
+ Meteor.settings.public.sandstorm;
|
|
Users = Meteor.users;
|
|
Users = Meteor.users;
|
|
|
|
|
|
Users.attachSchema(new SimpleSchema({
|
|
Users.attachSchema(new SimpleSchema({
|
|
@@ -148,32 +148,32 @@ Users.helpers({
|
|
},
|
|
},
|
|
|
|
|
|
starredBoards() {
|
|
starredBoards() {
|
|
- const {starredBoards = []} = this.profile;
|
|
|
|
- return Boards.find({archived: false, _id: {$in: starredBoards}});
|
|
|
|
|
|
+ const { starredBoards = [] } = this.profile;
|
|
|
|
+ return Boards.find({ archived: false, _id: { $in: starredBoards } });
|
|
},
|
|
},
|
|
|
|
|
|
hasStarred(boardId) {
|
|
hasStarred(boardId) {
|
|
- const {starredBoards = []} = this.profile;
|
|
|
|
|
|
+ const { starredBoards = [] } = this.profile;
|
|
return _.contains(starredBoards, boardId);
|
|
return _.contains(starredBoards, boardId);
|
|
},
|
|
},
|
|
|
|
|
|
invitedBoards() {
|
|
invitedBoards() {
|
|
- const {invitedBoards = []} = this.profile;
|
|
|
|
- return Boards.find({archived: false, _id: {$in: invitedBoards}});
|
|
|
|
|
|
+ const { invitedBoards = [] } = this.profile;
|
|
|
|
+ return Boards.find({ archived: false, _id: { $in: invitedBoards } });
|
|
},
|
|
},
|
|
|
|
|
|
isInvitedTo(boardId) {
|
|
isInvitedTo(boardId) {
|
|
- const {invitedBoards = []} = this.profile;
|
|
|
|
|
|
+ const { invitedBoards = [] } = this.profile;
|
|
return _.contains(invitedBoards, boardId);
|
|
return _.contains(invitedBoards, boardId);
|
|
},
|
|
},
|
|
|
|
|
|
hasTag(tag) {
|
|
hasTag(tag) {
|
|
- const {tags = []} = this.profile;
|
|
|
|
|
|
+ const { tags = [] } = this.profile;
|
|
return _.contains(tags, tag);
|
|
return _.contains(tags, tag);
|
|
},
|
|
},
|
|
|
|
|
|
hasNotification(activityId) {
|
|
hasNotification(activityId) {
|
|
- const {notifications = []} = this.profile;
|
|
|
|
|
|
+ const { notifications = [] } = this.profile;
|
|
return _.contains(notifications, activityId);
|
|
return _.contains(notifications, activityId);
|
|
},
|
|
},
|
|
|
|
|
|
@@ -183,7 +183,7 @@ Users.helpers({
|
|
},
|
|
},
|
|
|
|
|
|
getEmailBuffer() {
|
|
getEmailBuffer() {
|
|
- const {emailBuffer = []} = this.profile;
|
|
|
|
|
|
+ const { emailBuffer = [] } = this.profile;
|
|
return emailBuffer;
|
|
return emailBuffer;
|
|
},
|
|
},
|
|
|
|
|
|
@@ -308,7 +308,7 @@ Users.mutations({
|
|
},
|
|
},
|
|
|
|
|
|
setAvatarUrl(avatarUrl) {
|
|
setAvatarUrl(avatarUrl) {
|
|
- return { $set: { 'profile.avatarUrl': avatarUrl }};
|
|
|
|
|
|
+ return { $set: { 'profile.avatarUrl': avatarUrl } };
|
|
},
|
|
},
|
|
|
|
|
|
setShowCardsCountAt(limit) {
|
|
setShowCardsCountAt(limit) {
|
|
@@ -323,7 +323,7 @@ Meteor.methods({
|
|
if (nUsersWithUsername > 0) {
|
|
if (nUsersWithUsername > 0) {
|
|
throw new Meteor.Error('username-already-taken');
|
|
throw new Meteor.Error('username-already-taken');
|
|
} else {
|
|
} else {
|
|
- Users.update(this.userId, {$set: { username }});
|
|
|
|
|
|
+ Users.update(this.userId, { $set: { username } });
|
|
}
|
|
}
|
|
},
|
|
},
|
|
toggleSystemMessages() {
|
|
toggleSystemMessages() {
|
|
@@ -346,19 +346,19 @@ if (Meteor.isServer) {
|
|
const inviter = Meteor.user();
|
|
const inviter = Meteor.user();
|
|
const board = Boards.findOne(boardId);
|
|
const board = Boards.findOne(boardId);
|
|
const allowInvite = inviter &&
|
|
const allowInvite = inviter &&
|
|
- board &&
|
|
|
|
- board.members &&
|
|
|
|
- _.contains(_.pluck(board.members, 'userId'), inviter._id) &&
|
|
|
|
- _.where(board.members, {userId: inviter._id})[0].isActive &&
|
|
|
|
- _.where(board.members, {userId: inviter._id})[0].isAdmin;
|
|
|
|
|
|
+ board &&
|
|
|
|
+ board.members &&
|
|
|
|
+ _.contains(_.pluck(board.members, 'userId'), inviter._id) &&
|
|
|
|
+ _.where(board.members, { userId: inviter._id })[0].isActive &&
|
|
|
|
+ _.where(board.members, { userId: inviter._id })[0].isAdmin;
|
|
if (!allowInvite) throw new Meteor.Error('error-board-notAMember');
|
|
if (!allowInvite) throw new Meteor.Error('error-board-notAMember');
|
|
|
|
|
|
this.unblock();
|
|
this.unblock();
|
|
|
|
|
|
const posAt = username.indexOf('@');
|
|
const posAt = username.indexOf('@');
|
|
let user = null;
|
|
let user = null;
|
|
- if (posAt>=0) {
|
|
|
|
- user = Users.findOne({emails: {$elemMatch: {address: username}}});
|
|
|
|
|
|
+ if (posAt >= 0) {
|
|
|
|
+ user = Users.findOne({ emails: { $elemMatch: { address: username } } });
|
|
} else {
|
|
} else {
|
|
user = Users.findOne(username) || Users.findOne({ username });
|
|
user = Users.findOne(username) || Users.findOne({ username });
|
|
}
|
|
}
|
|
@@ -409,7 +409,7 @@ if (Meteor.isServer) {
|
|
});
|
|
});
|
|
Accounts.onCreateUser((options, user) => {
|
|
Accounts.onCreateUser((options, user) => {
|
|
const userCount = Users.find().count();
|
|
const userCount = Users.find().count();
|
|
- if (!isSandstorm && userCount === 0 ){
|
|
|
|
|
|
+ if (!isSandstorm && userCount === 0) {
|
|
user.isAdmin = true;
|
|
user.isAdmin = true;
|
|
return user;
|
|
return user;
|
|
}
|
|
}
|
|
@@ -421,11 +421,11 @@ if (Meteor.isServer) {
|
|
if (!options || !options.profile) {
|
|
if (!options || !options.profile) {
|
|
throw new Meteor.Error('error-invitation-code-blank', 'The invitation code is required');
|
|
throw new Meteor.Error('error-invitation-code-blank', 'The invitation code is required');
|
|
}
|
|
}
|
|
- const invitationCode = InvitationCodes.findOne({code: options.profile.invitationcode, email: options.email, valid: true});
|
|
|
|
|
|
+ const invitationCode = InvitationCodes.findOne({ code: options.profile.invitationcode, email: options.email, valid: true });
|
|
if (!invitationCode) {
|
|
if (!invitationCode) {
|
|
throw new Meteor.Error('error-invitation-code-not-exist', 'The invitation code doesn\'t exist');
|
|
throw new Meteor.Error('error-invitation-code-not-exist', 'The invitation code doesn\'t exist');
|
|
- }else{
|
|
|
|
- user.profile = {icode: options.profile.invitationcode};
|
|
|
|
|
|
+ } else {
|
|
|
|
+ user.profile = { icode: options.profile.invitationcode };
|
|
}
|
|
}
|
|
|
|
|
|
return user;
|
|
return user;
|
|
@@ -445,7 +445,7 @@ if (Meteor.isServer) {
|
|
// counter.
|
|
// counter.
|
|
// We need to run this code on the server only, otherwise the incrementation
|
|
// We need to run this code on the server only, otherwise the incrementation
|
|
// will be done twice.
|
|
// will be done twice.
|
|
- Users.after.update(function(userId, user, fieldNames) {
|
|
|
|
|
|
+ Users.after.update(function (userId, user, fieldNames) {
|
|
// The `starredBoards` list is hosted on the `profile` field. If this
|
|
// The `starredBoards` list is hosted on the `profile` field. If this
|
|
// field hasn't been modificated we don't need to run this hook.
|
|
// field hasn't been modificated we don't need to run this hook.
|
|
if (!_.contains(fieldNames, 'profile'))
|
|
if (!_.contains(fieldNames, 'profile'))
|
|
@@ -464,7 +464,7 @@ if (Meteor.isServer) {
|
|
// direction and then in the other.
|
|
// direction and then in the other.
|
|
function incrementBoards(boardsIds, inc) {
|
|
function incrementBoards(boardsIds, inc) {
|
|
boardsIds.forEach((boardId) => {
|
|
boardsIds.forEach((boardId) => {
|
|
- Boards.update(boardId, {$inc: {stars: inc}});
|
|
|
|
|
|
+ Boards.update(boardId, { $inc: { stars: inc } });
|
|
});
|
|
});
|
|
}
|
|
}
|
|
incrementBoards(_.difference(oldIds, newIds), -1);
|
|
incrementBoards(_.difference(oldIds, newIds), -1);
|
|
@@ -505,10 +505,10 @@ if (Meteor.isServer) {
|
|
//invite user to corresponding boards
|
|
//invite user to corresponding boards
|
|
const disableRegistration = Settings.findOne().disableRegistration;
|
|
const disableRegistration = Settings.findOne().disableRegistration;
|
|
if (disableRegistration) {
|
|
if (disableRegistration) {
|
|
- const invitationCode = InvitationCodes.findOne({code: doc.profile.icode, valid:true});
|
|
|
|
|
|
+ const invitationCode = InvitationCodes.findOne({ code: doc.profile.icode, valid: true });
|
|
if (!invitationCode) {
|
|
if (!invitationCode) {
|
|
throw new Meteor.Error('error-invitation-code-not-exist');
|
|
throw new Meteor.Error('error-invitation-code-not-exist');
|
|
- }else{
|
|
|
|
|
|
+ } else {
|
|
invitationCode.boardsToBeInvited.forEach((boardId) => {
|
|
invitationCode.boardsToBeInvited.forEach((boardId) => {
|
|
const board = Boards.findOne(boardId);
|
|
const board = Boards.findOne(boardId);
|
|
board.addMember(doc._id);
|
|
board.addMember(doc._id);
|
|
@@ -517,9 +517,55 @@ if (Meteor.isServer) {
|
|
doc.profile = {};
|
|
doc.profile = {};
|
|
}
|
|
}
|
|
doc.profile.invitedBoards = invitationCode.boardsToBeInvited;
|
|
doc.profile.invitedBoards = invitationCode.boardsToBeInvited;
|
|
- Users.update(doc._id, {$set:{profile: doc.profile}});
|
|
|
|
- InvitationCodes.update(invitationCode._id, {$set: {valid:false}});
|
|
|
|
|
|
+ Users.update(doc._id, { $set: { profile: doc.profile } });
|
|
|
|
+ InvitationCodes.update(invitationCode._id, { $set: { valid: false } });
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+// USERS REST API
|
|
|
|
+if (Meteor.isServer) {
|
|
|
|
+ JsonRoutes.add('GET', '/api/users', function (req, res, next) {
|
|
|
|
+ JsonRoutes.sendResult(res, {
|
|
|
|
+ code: 200,
|
|
|
|
+ data: Meteor.users.find({}).map(function (doc) {
|
|
|
|
+ return { _id: doc._id, username: doc.username };
|
|
|
|
+ }),
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ JsonRoutes.add('GET', '/api/users/:id', function (req, res, next) {
|
|
|
|
+ const id = req.params.id;
|
|
|
|
+ JsonRoutes.sendResult(res, {
|
|
|
|
+ code: 200,
|
|
|
|
+ data: Meteor.users.findOne({ _id: id }),
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ JsonRoutes.add('POST', '/api/users/', function (req, res, next) {
|
|
|
|
+ const id = Accounts.createUser({
|
|
|
|
+ username: req.body.username,
|
|
|
|
+ email: req.body.email,
|
|
|
|
+ password: 'default',
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ JsonRoutes.sendResult(res, {
|
|
|
|
+ code: 200,
|
|
|
|
+ data: {
|
|
|
|
+ _id: id,
|
|
|
|
+ },
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ JsonRoutes.add('DELETE', '/api/users/:id', function (req, res, next) {
|
|
|
|
+ const id = req.params.id;
|
|
|
|
+ Meteor.users.remove({ _id: id });
|
|
|
|
+ JsonRoutes.sendResult(res, {
|
|
|
|
+ code: 200,
|
|
|
|
+ data: {
|
|
|
|
+ _id: id,
|
|
|
|
+ },
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+}
|
|
|
|
+
|