diff options
Diffstat (limited to 'models')
-rw-r--r-- | models/cards.js | 115 | ||||
-rw-r--r-- | models/users.js | 36 |
2 files changed, 80 insertions, 71 deletions
diff --git a/models/cards.js b/models/cards.js index e1d48653..2e297d63 100644 --- a/models/cards.js +++ b/models/cards.js @@ -368,30 +368,36 @@ Cards.allow({ Cards.helpers({ copy(boardId, swimlaneId, listId) { - const oldBoard = Boards.findOne(this.boardId); - const oldBoardLabels = oldBoard.labels; - // Get old label names - const oldCardLabels = _.pluck( - _.filter(oldBoardLabels, label => { - return _.contains(this.labelIds, label._id); - }), - 'name', - ); - - const newBoard = Boards.findOne(boardId); - const newBoardLabels = newBoard.labels; - const newCardLabels = _.pluck( - _.filter(newBoardLabels, label => { - return _.contains(oldCardLabels, label.name); - }), - '_id', - ); - const oldId = this._id; const oldCard = Cards.findOne(oldId); - // Copy Custom Fields - if (oldBoard._id !== boardId) { + // we must only copy the labels and custom fields if the target board + // differs from the source board + if (this.boardId !== boardId) { + const oldBoard = Boards.findOne(this.boardId); + const oldBoardLabels = oldBoard.labels; + + // Get old label names + const oldCardLabels = _.pluck( + _.filter(oldBoardLabels, label => { + return _.contains(this.labelIds, label._id); + }), + 'name', + ); + + const newBoard = Boards.findOne(boardId); + const newBoardLabels = newBoard.labels; + const newCardLabels = _.pluck( + _.filter(newBoardLabels, label => { + return _.contains(oldCardLabels, label.name); + }), + '_id', + ); + // now set the new label ids + delete this.labelIds; + this.labelIds = newCardLabels; + + // Copy Custom Fields CustomFields.find({ _id: { $in: oldCard.customFields.map(cf => { @@ -404,8 +410,6 @@ Cards.helpers({ } delete this._id; - delete this.labelIds; - this.labelIds = newCardLabels; this.boardId = boardId; this.swimlaneId = swimlaneId; this.listId = listId; @@ -1298,8 +1302,40 @@ Cards.mutations({ }, move(boardId, swimlaneId, listId, sort) { - // Copy Custom Fields + const mutatedFields = { + boardId, + swimlaneId, + listId, + sort, + }; + + // we must only copy the labels and custom fields if the target board + // differs from the source board if (this.boardId !== boardId) { + // Get label names + const oldBoard = Boards.findOne(this.boardId); + const oldBoardLabels = oldBoard.labels; + const oldCardLabels = _.pluck( + _.filter(oldBoardLabels, label => { + return _.contains(this.labelIds, label._id); + }), + 'name', + ); + + const newBoard = Boards.findOne(boardId); + const newBoardLabels = newBoard.labels; + const newCardLabelIds = _.pluck( + _.filter(newBoardLabels, label => { + return label.name && _.contains(oldCardLabels, label.name); + }), + '_id', + ); + + Object.assign(mutatedFields, { + labelIds: newCardLabelIds, + }); + + // Copy custom fields CustomFields.find({ _id: { $in: this.customFields.map(cf => { @@ -1311,33 +1347,6 @@ Cards.mutations({ }); } - // Get label names - const oldBoard = Boards.findOne(this.boardId); - const oldBoardLabels = oldBoard.labels; - const oldCardLabels = _.pluck( - _.filter(oldBoardLabels, label => { - return _.contains(this.labelIds, label._id); - }), - 'name', - ); - - const newBoard = Boards.findOne(boardId); - const newBoardLabels = newBoard.labels; - const newCardLabelIds = _.pluck( - _.filter(newBoardLabels, label => { - return label.name && _.contains(oldCardLabels, label.name); - }), - '_id', - ); - - const mutatedFields = { - boardId, - swimlaneId, - listId, - sort, - labelIds: newCardLabelIds, - }; - Cards.update(this._id, { $set: mutatedFields, }); @@ -2169,7 +2178,7 @@ if (Meteor.isServer) { description: doc.description, listId: doc.listId, receivedAt: doc.receivedAt, - startAt:doc.startAt, + startAt: doc.startAt, dueAt: doc.dueAt, endAt: doc.endAt, assignees: doc.assignees, @@ -2210,7 +2219,7 @@ if (Meteor.isServer) { title: doc.title, description: doc.description, receivedAt: doc.receivedAt, - startAt:doc.startAt, + startAt: doc.startAt, dueAt: doc.dueAt, endAt: doc.endAt, assignees: doc.assignees, diff --git a/models/users.js b/models/users.js index 976e5068..f3fc1046 100644 --- a/models/users.js +++ b/models/users.js @@ -95,7 +95,7 @@ Users.attachSchema( autoValue() { if (this.isInsert && !this.isSet) { return { - boardView: 'board-view-lists', + boardView: 'board-view-swimlanes', }; } }, @@ -218,8 +218,8 @@ Users.attachSchema( type: String, optional: true, allowedValues: [ - 'board-view-lists', 'board-view-swimlanes', + 'board-view-lists', 'board-view-cal', ], }, @@ -903,7 +903,7 @@ if (Meteor.isServer) { user.profile = { initials, fullname: user.services.oidc.fullname, - boardView: 'board-view-lists', + boardView: 'board-view-swimlanes', }; user.authenticationMethod = 'oauth2'; @@ -961,7 +961,7 @@ if (Meteor.isServer) { ); } else { user.profile = { icode: options.profile.invitationcode }; - user.profile.boardView = 'board-view-lists'; + user.profile.boardView = 'board-view-swimlanes'; // Deletes the invitation code after the user was created successfully. setTimeout( @@ -1109,10 +1109,10 @@ if (Meteor.isServer) { }); */ - const Future = require('fibers/future'); - let future1 = new Future(); - let future2 = new Future(); - let future3 = new Future(); + const Future = require('fibers/future'); + let future1 = new Future(); + let future2 = new Future(); + let future3 = new Future(); Boards.insert( { title: TAPi18n.__('templates'), @@ -1140,7 +1140,7 @@ if (Meteor.isServer) { Users.update(fakeUserId.get(), { $set: { 'profile.cardTemplatesSwimlaneId': swimlaneId }, }); - future1.return(); + future1.return(); }, ); @@ -1158,7 +1158,7 @@ if (Meteor.isServer) { Users.update(fakeUserId.get(), { $set: { 'profile.listTemplatesSwimlaneId': swimlaneId }, }); - future2.return(); + future2.return(); }, ); @@ -1176,22 +1176,22 @@ if (Meteor.isServer) { Users.update(fakeUserId.get(), { $set: { 'profile.boardTemplatesSwimlaneId': swimlaneId }, }); - future3.return(); + future3.return(); }, ); }, ); - // HACK - future1.wait(); - future2.wait(); - future3.wait(); + // HACK + future1.wait(); + future2.wait(); + future3.wait(); }); }); } - Users.after.insert((userId, doc) => { - // HACK - doc = Users.findOne({_id: doc._id}); + Users.after.insert((userId, doc) => { + // HACK + doc = Users.findOne({ _id: doc._id }); if (doc.createdThroughApi) { // The admin user should be able to create a user despite disabling registration because // it is two different things (registration and creation). |