diff options
Diffstat (limited to 'models')
-rw-r--r-- | models/cards.js | 2 | ||||
-rw-r--r-- | models/lists.js | 42 | ||||
-rw-r--r-- | models/settings.js | 2 | ||||
-rw-r--r-- | models/users.js | 86 | ||||
-rw-r--r-- | models/wekanCreator.js | 48 |
5 files changed, 95 insertions, 85 deletions
diff --git a/models/cards.js b/models/cards.js index 5b752ec3..5de17c6f 100644 --- a/models/cards.js +++ b/models/cards.js @@ -182,7 +182,7 @@ Cards.helpers({ canBeRestored() { const list = Lists.findOne({_id: this.listId}); - if(list.getWipLimit() && list.getWipLimit('enabled') && list.getWipLimit('value') === list.cards().count()){ + if(!list.getWipLimit('soft') && list.getWipLimit('enabled') && list.getWipLimit('value') === list.cards().count()){ return false; } return true; diff --git a/models/lists.js b/models/lists.js index 75c39d2a..a5f4791b 100644 --- a/models/lists.js +++ b/models/lists.js @@ -49,23 +49,15 @@ Lists.attachSchema(new SimpleSchema({ 'wipLimit.value': { type: Number, decimal: false, - autoValue() { - if(this.isInsert){ - return 0; - } - return this.value; - }, - optional: true, + defaultValue: 1, }, - 'wipLimit.enabled':{ + 'wipLimit.enabled': { type: Boolean, - autoValue() { - if(this.isInsert){ - return false; - } - return this.value; - }, - optional: true, + defaultValue: false, + }, + 'wipLimit.soft': { + type: Boolean, + defaultValue: false, }, })); @@ -123,6 +115,10 @@ Lists.mutations({ return { $set: { archived: false } }; }, + toggleSoftLimit(toggle) { + return { $set: { 'wipLimit.soft': toggle } }; + }, + toggleWipLimit(toggle) { return { $set: { 'wipLimit.enabled': toggle } }; }, @@ -136,17 +132,25 @@ Meteor.methods({ applyWipLimit(listId, limit){ check(listId, String); check(limit, Number); + if(limit === 0){ + limit = 1; + } Lists.findOne({ _id: listId }).setWipLimit(limit); }, enableWipLimit(listId) { check(listId, String); const list = Lists.findOne({ _id: listId }); - if(list.getWipLimit()){ // Necessary check to avoid exceptions for the case where the doc doesn't have the wipLimit field yet set - list.toggleWipLimit(!list.getWipLimit('enabled')); - } else { - list.toggleWipLimit(true); // First time toggle is always to 'true' because default is 'false' + if(list.getWipLimit('value') === 0){ + list.setWipLimit(1); } + list.toggleWipLimit(!list.getWipLimit('enabled')); + }, + + enableSoftLimit(listId) { + check(listId, String); + const list = Lists.findOne({ _id: listId }); + list.toggleSoftLimit(!list.getWipLimit('soft')); }, }); diff --git a/models/settings.js b/models/settings.js index a490d9c5..a02bb3fb 100644 --- a/models/settings.js +++ b/models/settings.js @@ -105,7 +105,7 @@ if (Meteor.isServer) { inviter: Users.findOne(icode.authorId).username, user: icode.email.split('@')[0], icode: icode.code, - url: FlowRouter.url('sign-in'), + url: FlowRouter.url('sign-up'), }; const lang = author.getLanguage(); Email.send({ diff --git a/models/users.js b/models/users.js index 5ba0131f..11a53ce6 100644 --- a/models/users.js +++ b/models/users.js @@ -118,6 +118,13 @@ Users.attachSchema(new SimpleSchema({ }, })); +Users.allow({ + update(userId) { + const user = Users.findOne(userId); + return user && Meteor.user().isAdmin; + }, +}); + // 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. const searchInFields = ['username', 'profile.fullname']; @@ -152,36 +159,36 @@ if (Meteor.isClient) { Users.helpers({ boards() { - return Boards.find({ userId: this._id }); + return Boards.find({ 'members.userId': this._id }); }, 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) { - const { starredBoards = [] } = this.profile; + const {starredBoards = []} = this.profile; return _.contains(starredBoards, boardId); }, 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) { - const { invitedBoards = [] } = this.profile; + const {invitedBoards = []} = this.profile; return _.contains(invitedBoards, boardId); }, hasTag(tag) { - const { tags = [] } = this.profile; + const {tags = []} = this.profile; return _.contains(tags, tag); }, hasNotification(activityId) { - const { notifications = [] } = this.profile; + const {notifications = []} = this.profile; return _.contains(notifications, activityId); }, @@ -191,7 +198,7 @@ Users.helpers({ }, getEmailBuffer() { - const { emailBuffer = [] } = this.profile; + const {emailBuffer = []} = this.profile; return emailBuffer; }, @@ -316,22 +323,22 @@ Users.mutations({ }, setAvatarUrl(avatarUrl) { - return { $set: { 'profile.avatarUrl': avatarUrl } }; + return {$set: {'profile.avatarUrl': avatarUrl}}; }, setShowCardsCountAt(limit) { - return { $set: { 'profile.showCardsCountAt': limit } }; + return {$set: {'profile.showCardsCountAt': limit}}; }, }); Meteor.methods({ - setUsername(username) { + setUsername(username, userId) { check(username, String); - const nUsersWithUsername = Users.find({ username }).count(); + const nUsersWithUsername = Users.find({username}).count(); if (nUsersWithUsername > 0) { throw new Meteor.Error('username-already-taken'); } else { - Users.update(this.userId, { $set: { username } }); + Users.update(userId, {$set: {username}}); } }, toggleSystemMessages() { @@ -342,13 +349,13 @@ Meteor.methods({ check(limit, Number); Meteor.user().setShowCardsCountAt(limit); }, - setEmail(email) { + setEmail(email, userId) { check(email, String); - const existingUser = Users.findOne({ 'emails.address': email }, { fields: { _id: 1 } }); + const existingUser = Users.findOne({'emails.address': email}, {fields: {_id: 1}}); if (existingUser) { throw new Meteor.Error('email-already-taken'); } else { - Users.update(this.userId, { + Users.update(userId, { $set: { emails: [{ address: email, @@ -358,11 +365,12 @@ Meteor.methods({ }); } }, - setUsernameAndEmail(username, email) { + setUsernameAndEmail(username, email, userId) { check(username, String); check(email, String); - Meteor.call('setUsername', username); - Meteor.call('setEmail', email); + check(userId, String); + Meteor.call('setUsername', username, userId); + Meteor.call('setEmail', email, userId); }, }); @@ -379,8 +387,8 @@ if (Meteor.isServer) { 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; + _.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'); this.unblock(); @@ -388,9 +396,9 @@ if (Meteor.isServer) { const posAt = username.indexOf('@'); let user = null; if (posAt >= 0) { - user = Users.findOne({ emails: { $elemMatch: { address: username } } }); + user = Users.findOne({emails: {$elemMatch: {address: username}}}); } else { - user = Users.findOne(username) || Users.findOne({ username }); + user = Users.findOne(username) || Users.findOne({username}); } if (user) { if (user._id === inviter._id) throw new Meteor.Error('error-user-notAllowSelf'); @@ -400,7 +408,7 @@ if (Meteor.isServer) { // Set in lowercase email before creating account const email = username.toLowerCase(); username = email.substring(0, posAt); - const newUserId = Accounts.createUser({ username, email }); + const newUserId = Accounts.createUser({username, email}); if (!newUserId) throw new Meteor.Error('error-user-notCreated'); // assume new user speak same language with inviter if (inviter.profile && inviter.profile.language) { @@ -434,7 +442,7 @@ if (Meteor.isServer) { } catch (e) { throw new Meteor.Error('email-fail', e.message); } - return { username: user.username, email: user.emails[0].address }; + return {username: user.username, email: user.emails[0].address}; }, }); Accounts.onCreateUser((options, user) => { @@ -457,11 +465,15 @@ if (Meteor.isServer) { if (!options || !options.profile) { 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) { throw new Meteor.Error('error-invitation-code-not-exist', 'The invitation code doesn\'t exist'); } else { - user.profile = { icode: options.profile.invitationcode }; + user.profile = {icode: options.profile.invitationcode}; } return user; @@ -473,7 +485,7 @@ if (Meteor.isServer) { Meteor.startup(() => { Users._collection._ensureIndex({ username: 1, - }, { unique: true }); + }, {unique: true}); }); // Each board document contains the de-normalized number of users that have @@ -492,6 +504,7 @@ if (Meteor.isServer) { function getStarredBoardsIds(doc) { return doc.profile && doc.profile.starredBoards; } + const oldIds = getStarredBoardsIds(this.previous); const newIds = getStarredBoardsIds(user); @@ -500,9 +513,10 @@ if (Meteor.isServer) { // direction and then in the other. function incrementBoards(boardsIds, inc) { boardsIds.forEach((boardId) => { - Boards.update(boardId, { $inc: { stars: inc } }); + Boards.update(boardId, {$inc: {stars: inc}}); }); } + incrementBoards(_.difference(oldIds, newIds), -1); incrementBoards(_.difference(newIds, oldIds), +1); }); @@ -529,7 +543,7 @@ if (Meteor.isServer) { }, fakeUser, (err, boardId) => { ['welcome-list1', 'welcome-list2'].forEach((title) => { - Lists.insert({ title: TAPi18n.__(title), boardId }, fakeUser); + Lists.insert({title: TAPi18n.__(title), boardId}, fakeUser); }); }); }); @@ -545,14 +559,14 @@ if (Meteor.isServer) { // the disableRegistration check. // Issue : https://github.com/wekan/wekan/issues/1232 // PR : https://github.com/wekan/wekan/pull/1251 - Users.update(doc._id, { $set: { createdThroughApi: '' } }); + Users.update(doc._id, {$set: {createdThroughApi: ''}}); return; } //invite user to corresponding boards const disableRegistration = Settings.findOne().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) { throw new Meteor.Error('error-invitation-code-not-exist'); } else { @@ -564,8 +578,8 @@ if (Meteor.isServer) { doc.profile = {}; } 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}}); } } }); diff --git a/models/wekanCreator.js b/models/wekanCreator.js index 3cd65fd7..ae8e32ca 100644 --- a/models/wekanCreator.js +++ b/models/wekanCreator.js @@ -133,47 +133,39 @@ export class WekanCreator { } // You must call parseActions before calling this one. - createBoardAndLabels(wekanBoard) { + createBoardAndLabels(boardToImport) { const boardToCreate = { - archived: wekanBoard.archived, - color: wekanBoard.color, + archived: boardToImport.archived, + color: boardToImport.color, // very old boards won't have a creation activity so no creation date - createdAt: this._now(wekanBoard.createdAt), + createdAt: this._now(boardToImport.createdAt), labels: [], members: [{ userId: Meteor.userId(), - isAdmin: true, + wekanId: Meteor.userId(), isActive: true, + isAdmin: true, isCommentOnly: false, }], // Standalone Export has modifiedAt missing, adding modifiedAt to fix it - modifiedAt: this._now(wekanBoard.modifiedAt), - permission: wekanBoard.permission, - slug: getSlug(wekanBoard.title) || 'board', + modifiedAt: this._now(boardToImport.modifiedAt), + permission: boardToImport.permission, + slug: getSlug(boardToImport.title) || 'board', stars: 0, - title: wekanBoard.title, + title: boardToImport.title, }; // now add other members - if(wekanBoard.members) { - wekanBoard.members.forEach((wekanMember) => { - const wekanId = wekanMember.userId; - // do we have a mapping? - if(this.members[wekanId]) { - const wekanId = this.members[wekanId]; - // do we already have it in our list? - const wekanMember = boardToCreate.members.find((wekanMember) => wekanMember.userId === wekanId); - if(!wekanMember) { - boardToCreate.members.push({ - userId: wekanId, - isAdmin: wekanMember.isAdmin, - isActive: true, - isCommentOnly: false, - }); - } - } + if(boardToImport.members) { + boardToImport.members.forEach((wekanMember) => { + // do we already have it in our list? + if(!boardToCreate.members.some((member) => member.wekanId === wekanMember.wekanId)) + boardToCreate.members.push({ + ... wekanMember, + userId: wekanMember.wekanId, + }); }); } - wekanBoard.labels.forEach((label) => { + boardToImport.labels.forEach((label) => { const labelToCreate = { _id: Random.id(6), color: label.color, @@ -192,7 +184,7 @@ export class WekanCreator { boardId, createdAt: this._now(), source: { - id: wekanBoard.id, + id: boardToImport.id, system: 'Wekan', }, // We attribute the import to current user, |