From e77be37450df66b708bddeeaae7d40faf70f57f9 Mon Sep 17 00:00:00 2001 From: Harry Adel Date: Thu, 19 Feb 2026 00:26:47 +0200 Subject: [PATCH] Use sync code in allow/deny for 2.x --- METEOR3_MIGRATION.md | 187 +++++++++ models/accessibilitySettings.js | 4 +- models/accountSettings.js | 4 +- models/actions.js | 12 +- models/activities.js | 38 +- models/announcements.js | 4 +- models/attachments.js | 12 +- models/boards.js | 10 +- models/cardCommentReactions.js | 12 +- models/cardComments.js | 12 +- models/cards.js | 523 +++++++++++++------------- models/checklistItems.js | 12 +- models/checklists.js | 12 +- models/customFields.js | 18 +- models/integrations.js | 20 +- models/lists.js | 14 +- models/lockoutSettings.js | 4 +- models/org.js | 12 +- models/rules.js | 12 +- models/settings.js | 4 +- models/swimlanes.js | 12 +- models/tableVisibilityModeSettings.js | 4 +- models/team.js | 12 +- models/translation.js | 12 +- models/triggers.js | 12 +- server/cronMigrationManager.js | 4 +- server/lib/utils.js | 4 +- server/rulesHelper.js | 18 +- 28 files changed, 594 insertions(+), 410 deletions(-) create mode 100644 METEOR3_MIGRATION.md diff --git a/METEOR3_MIGRATION.md b/METEOR3_MIGRATION.md new file mode 100644 index 000000000..f933abe4e --- /dev/null +++ b/METEOR3_MIGRATION.md @@ -0,0 +1,187 @@ +# Meteor 3.0 Migration Guide + +Reference document capturing patterns, constraints, and lessons learned during the async migration of WeKan from Meteor 2.16 toward Meteor 3.0 readiness. + +--- + +## 1. Dual-Compatibility Strategy + +WeKan runs on **Meteor 2.16 with Blaze 2.x**. The goal is dual compatibility: changes must work on 2.16 now and remain compatible with a future Meteor 3.0 upgrade. + +**Key constraint:** Blaze 2.x does NOT support async template helpers. Client-side code must receive synchronous data. + +--- + +## 2. ReactiveCache Facade Pattern + +`ReactiveCache` dispatches to `ReactiveCacheServer` (async MongoDB) or `ReactiveCacheClient` (sync Minimongo). + +**Rule:** Facade methods must NOT be `async`. They return a Promise on the server and data on the client. Server callers `await`; client code uses the return value directly. + +```javascript +// CORRECT: +getBoard(boardId) { + if (Meteor.isServer) { + return ReactiveCacheServer.getBoard(boardId); // Returns Promise + } else { + return ReactiveCacheClient.getBoard(boardId); // Returns data + } +} + +// WRONG: +async getBoard(boardId) { ... } // Wraps client return in Promise too! +``` + +--- + +## 3. Model Helpers (Collection.helpers) + +Model helpers defined via `Collection.helpers({})` are used by Blaze templates. They must NOT be `async`. + +```javascript +// CORRECT: +Cards.helpers({ + board() { + return ReactiveCache.getBoard(this.boardId); // Promise on server, data on client + }, +}); + +// WRONG: +Cards.helpers({ + async board() { // Blaze gets Promise instead of data + return await ReactiveCache.getBoard(this.boardId); + }, +}); +``` + +**Server-side callers** of these helpers must `await` the result: +```javascript +// In a Meteor method or hook (server-only): +const board = await card.board(); +``` + +--- + +## 4. Allow/Deny Callbacks Must Be Synchronous + +Meteor 2.x evaluates allow/deny callbacks synchronously. An `async` callback returns a Promise: +- **allow** callback returning Promise (truthy) → always passes +- **deny** callback returning Promise (truthy) → always denies + +**Rule:** Never use `async` in allow/deny. Replace `ReactiveCache` calls with direct sync Mongo calls. + +```javascript +// CORRECT: +Cards.allow({ + insert(userId, doc) { + return allowIsBoardMemberWithWriteAccess(userId, Boards.findOne(doc.boardId)); + }, + fetch: ['boardId'], +}); + +// WRONG: +Cards.allow({ + async insert(userId, doc) { + return allowIsBoardMemberWithWriteAccess(userId, await ReactiveCache.getBoard(doc.boardId)); + }, +}); +``` + +### Sync alternatives for common patterns: + +| Async (broken in allow/deny) | Sync replacement | +|------------------------------|------------------| +| `await ReactiveCache.getBoard(id)` | `Boards.findOne(id)` | +| `await ReactiveCache.getCard(id)` | `Cards.findOne(id)` | +| `await ReactiveCache.getCurrentUser()` | `Meteor.users.findOne(userId)` | +| `await ReactiveCache.getBoards({...})` | `Boards.find({...}).fetch()` | +| `await card.board()` | `Boards.findOne(card.boardId)` | + +**Note:** These sync Mongo calls (`findOne`, `find().fetch()`) are available in Meteor 2.x. In Meteor 3.0, they will be replaced by `findOneAsync` / `find().fetchAsync()`, which will require allow/deny callbacks to be reworked again (or replaced by Meteor 3.0's new permission model). + +--- + +## 5. Server-Only Code CAN Be Async + +Code that runs exclusively on the server can safely use `async`/`await`: + +- `Meteor.methods({})` — method bodies +- `Meteor.publish()` — publication functions +- `JsonRoutes.add()` — REST API handlers +- `Collection.before.*` / `Collection.after.*` — collection hooks (via `matb33:collection-hooks`) +- Standalone server functions + +```javascript +Meteor.methods({ + async createCard(data) { + const board = await ReactiveCache.getBoard(data.boardId); // OK + // ... + }, +}); +``` + +--- + +## 6. forEach with await Anti-Pattern + +`Array.forEach()` does not handle async callbacks — iterations run concurrently without awaiting. + +```javascript +// WRONG: +items.forEach(async (item) => { + await processItem(item); // Runs all in parallel, not sequentially +}); + +// CORRECT: +for (const item of items) { + await processItem(item); // Runs sequentially +} +``` + +--- + +## 7. Client-Side Collection Updates + +Meteor requires client-side collection updates to use `_id` as the selector: + +```javascript +// CORRECT: +Lists.updateAsync(listId, { $set: { title: newTitle } }); + +// WRONG - fails with "Untrusted code may only update documents by ID": +Lists.updateAsync({ _id: listId, boardId: boardId }, { $set: { title: newTitle } }); +``` + +--- + +## 8. Sync Meteor 2.x APIs to Convert for 3.0 + +These Meteor 2.x sync APIs will need conversion when upgrading to Meteor 3.0: + +| Meteor 2.x (sync) | Meteor 3.0 (async) | +|--------------------|--------------------| +| `Collection.findOne()` | `Collection.findOneAsync()` | +| `Collection.find().fetch()` | `Collection.find().fetchAsync()` | +| `Collection.insert()` | `Collection.insertAsync()` | +| `Collection.update()` | `Collection.updateAsync()` | +| `Collection.remove()` | `Collection.removeAsync()` | +| `Collection.upsert()` | `Collection.upsertAsync()` | +| `Meteor.user()` | `Meteor.userAsync()` | +| `Meteor.userId()` | Remains sync | + +**Current status:** Server-side code already uses async patterns via `ReactiveCache`. The sync `findOne()` calls in allow/deny callbacks will need to be addressed when Meteor 3.0's allow/deny system supports async (or is replaced). + +--- + +## 9. Files Reference + +Key files involved in the async migration: + +| File | Role | +|------|------| +| `imports/reactiveCache.js` | ReactiveCache facade + Server/Client/Index implementations | +| `server/lib/utils.js` | Permission helper functions (`allowIsBoardMember*`) | +| `models/*.js` | Collection schemas, helpers, allow/deny, hooks, methods | +| `server/publications/*.js` | Meteor publications | +| `server/rulesHelper.js` | Rule trigger/action evaluation | +| `server/cronMigrationManager.js` | Cron-based migration jobs | diff --git a/models/accessibilitySettings.js b/models/accessibilitySettings.js index 12be6e2ad..0cc9260dc 100644 --- a/models/accessibilitySettings.js +++ b/models/accessibilitySettings.js @@ -46,8 +46,8 @@ AccessibilitySettings.attachSchema( ); AccessibilitySettings.allow({ - async update(userId) { - const user = await ReactiveCache.getUser(userId); + update(userId) { + const user = Meteor.users.findOne(userId); return user && user.isAdmin; }, }); diff --git a/models/accountSettings.js b/models/accountSettings.js index 38fed5c82..9030e56a9 100644 --- a/models/accountSettings.js +++ b/models/accountSettings.js @@ -45,8 +45,8 @@ AccountSettings.attachSchema( ); AccountSettings.allow({ - async update(userId) { - const user = await ReactiveCache.getUser(userId); + update(userId) { + const user = Meteor.users.findOne(userId); return user && user.isAdmin; }, }); diff --git a/models/actions.js b/models/actions.js index e8209febd..09dd501d5 100644 --- a/models/actions.js +++ b/models/actions.js @@ -4,14 +4,14 @@ import { Meteor } from 'meteor/meteor'; Actions = new Mongo.Collection('actions'); Actions.allow({ - async insert(userId, doc) { - return allowIsBoardAdmin(userId, await ReactiveCache.getBoard(doc.boardId)); + insert(userId, doc) { + return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId)); }, - async update(userId, doc) { - return allowIsBoardAdmin(userId, await ReactiveCache.getBoard(doc.boardId)); + update(userId, doc) { + return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId)); }, - async remove(userId, doc) { - return allowIsBoardAdmin(userId, await ReactiveCache.getBoard(doc.boardId)); + remove(userId, doc) { + return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId)); }, }); diff --git a/models/activities.js b/models/activities.js index 1ce7cc269..6594ef620 100644 --- a/models/activities.js +++ b/models/activities.js @@ -118,7 +118,7 @@ if (Meteor.isServer) { if (activity.userId) { // No need send notification to user of activity // participants = _.union(participants, [activity.userId]); - const user = activity.user(); + const user = await activity.user(); if (user) { if (user.getName()) { params.user = user.getName(); @@ -146,7 +146,7 @@ if (Meteor.isServer) { params.boardId = activity.boardId; } if (activity.oldBoardId) { - const oldBoard = activity.oldBoard(); + const oldBoard = await activity.oldBoard(); if (oldBoard) { watchers = _.union(watchers, oldBoard.watchers || []); params.oldBoard = oldBoard.title; @@ -155,10 +155,10 @@ if (Meteor.isServer) { } if (activity.memberId) { participants = _.union(participants, [activity.memberId]); - params.member = activity.member().getName(); + params.member = (await activity.member()).getName(); } if (activity.listId) { - const list = activity.list(); + const list = await activity.list(); if (list) { if (list.watchers !== undefined) { watchers = _.union(watchers, list.watchers || []); @@ -168,7 +168,7 @@ if (Meteor.isServer) { } } if (activity.oldListId) { - const oldList = activity.oldList(); + const oldList = await activity.oldList(); if (oldList) { watchers = _.union(watchers, oldList.watchers || []); params.oldList = oldList.title; @@ -176,7 +176,7 @@ if (Meteor.isServer) { } } if (activity.oldSwimlaneId) { - const oldSwimlane = activity.oldSwimlane(); + const oldSwimlane = await activity.oldSwimlane(); if (oldSwimlane) { watchers = _.union(watchers, oldSwimlane.watchers || []); params.oldSwimlane = oldSwimlane.title; @@ -184,7 +184,7 @@ if (Meteor.isServer) { } } if (activity.cardId) { - const card = activity.card(); + const card = await activity.card(); participants = _.union(participants, [card.userId], card.members || []); watchers = _.union(watchers, card.watchers || []); params.card = card.title; @@ -193,12 +193,12 @@ if (Meteor.isServer) { params.cardId = activity.cardId; } if (activity.swimlaneId) { - const swimlane = activity.swimlane(); + const swimlane = await activity.swimlane(); params.swimlane = swimlane.title; params.swimlaneId = activity.swimlaneId; } if (activity.commentId) { - const comment = activity.comment(); + const comment = await activity.comment(); params.comment = comment.text; let hasMentions = false; // Track if comment has @mentions if (board) { @@ -257,7 +257,7 @@ if (Meteor.isServer) { hasMentions = true; } else if (activity.cardId && username === 'card_members') { // mentions all card members if assigned - const card = activity.card(); + const card = await activity.card(); if (card && card.members && card.members.length > 0) { // Filter to only valid users who are board members const validMembers = []; @@ -273,7 +273,7 @@ if (Meteor.isServer) { hasMentions = true; } else if (activity.cardId && username === 'card_assignees') { // mentions all assignees of the current card - const card = activity.card(); + const card = await activity.card(); if (card && card.assignees && card.assignees.length > 0) { // Filter to only valid users who are board members const validAssignees = []; @@ -310,7 +310,7 @@ if (Meteor.isServer) { params.attachmentId = activity.attachmentId; } if (activity.checklistId) { - const checklist = activity.checklist(); + const checklist = await activity.checklist(); if (checklist) { if (checklist.title) { params.checklist = checklist.title; @@ -318,7 +318,7 @@ if (Meteor.isServer) { } } if (activity.checklistItemId) { - const checklistItem = activity.checklistItem(); + const checklistItem = await activity.checklistItem(); if (checklistItem) { if (checklistItem.title) { params.checklistItem = checklistItem.title; @@ -326,7 +326,7 @@ if (Meteor.isServer) { } } if (activity.customFieldId) { - const customField = activity.customField(); + const customField = await activity.customField(); if (customField) { if (customField.name) { params.customField = customField.name; @@ -338,7 +338,7 @@ if (Meteor.isServer) { } // Label activity did not work yet, unable to edit labels when tried this. if (activity.labelId) { - const label = activity.label(); + const label = await activity.label(); if (label) { if (label.name) { params.label = label.name; @@ -368,10 +368,8 @@ if (Meteor.isServer) { try { const atype = activity.activityType; if (new RegExp(BIGEVENTS).exec(atype)) { - watchers = _.union( - watchers, - board.activeMembers().map((member) => member.userId), - ); // notify all active members for important events + const activeMemberIds = _.filter(board.members, m => m.isActive === true).map(m => m.userId); + watchers = _.union(watchers, activeMemberIds); // notify all active members for important events } } catch (e) { // passed env var BIGEVENTS_PATTERN is not a valid regex @@ -396,7 +394,7 @@ if (Meteor.isServer) { ); } } - Notifications.getUsers(watchers).forEach((user) => { + (await Notifications.getUsers(watchers)).forEach((user) => { // Skip if user is undefined or doesn't have an _id (e.g., deleted user or invalid ID) if (!user || !user._id) return; diff --git a/models/announcements.js b/models/announcements.js index 1c3f60e7a..a4f3455b4 100644 --- a/models/announcements.js +++ b/models/announcements.js @@ -50,8 +50,8 @@ Announcements.attachSchema( ); Announcements.allow({ - async update(userId) { - const user = await ReactiveCache.getUser(userId); + update(userId) { + const user = Meteor.users.findOne(userId); return user && user.isAdmin; }, }); diff --git a/models/attachments.js b/models/attachments.js index a2e52e1fc..5e20cf993 100644 --- a/models/attachments.js +++ b/models/attachments.js @@ -196,11 +196,11 @@ Attachments = new FilesCollection({ if (Meteor.isServer) { Attachments.allow({ - async insert(userId, fileObj) { + insert(userId, fileObj) { // ReadOnly users cannot upload attachments - return allowIsBoardMemberWithWriteAccess(userId, await ReactiveCache.getBoard(fileObj.boardId)); + return allowIsBoardMemberWithWriteAccess(userId, Boards.findOne(fileObj.boardId)); }, - async update(userId, fileObj, fields) { + update(userId, fileObj, fields) { // SECURITY: The 'name' field is sanitized in onBeforeUpload and server-side methods, // but we block direct client-side $set operations on 'versions.*.path' to prevent // path traversal attacks via storage migration exploits. @@ -230,9 +230,9 @@ if (Meteor.isServer) { } // ReadOnly users cannot update attachments - return allowIsBoardMemberWithWriteAccess(userId, await ReactiveCache.getBoard(fileObj.boardId)); + return allowIsBoardMemberWithWriteAccess(userId, Boards.findOne(fileObj.boardId)); }, - async remove(userId, fileObj) { + remove(userId, fileObj) { // Additional security check: ensure the file belongs to the board the user has access to if (!fileObj || !fileObj.boardId) { if (process.env.DEBUG === 'true') { @@ -241,7 +241,7 @@ if (Meteor.isServer) { return false; } - const board = await ReactiveCache.getBoard(fileObj.boardId); + const board = Boards.findOne(fileObj.boardId); if (!board) { if (process.env.DEBUG === 'true') { console.warn('Blocked attachment removal: board not found'); diff --git a/models/boards.js b/models/boards.js index 97d7b58f0..223699e84 100644 --- a/models/boards.js +++ b/models/boards.js @@ -1828,7 +1828,7 @@ Boards.labelColors = () => { if (Meteor.isServer) { Boards.allow({ - async insert(userId, doc) { + insert(userId, doc) { // Check if user is logged in if (!userId) return false; @@ -1847,7 +1847,7 @@ if (Meteor.isServer) { // All logged in users are allowed to reorder boards by dragging at All Boards page and Public Boards page. Boards.allow({ - async update(userId, board, fieldNames) { + update(userId, board, fieldNames) { return canUpdateBoardSort(userId, board, fieldNames); }, // Need members to verify membership in policy @@ -1857,7 +1857,7 @@ if (Meteor.isServer) { // The number of users that have starred this board is managed by trusted code // and the user is not allowed to update it Boards.deny({ - async update(userId, board, fieldNames) { + update(userId, board, fieldNames) { return _.contains(fieldNames, 'stars'); }, fetch: [], @@ -1865,7 +1865,7 @@ if (Meteor.isServer) { // We can't remove a member if it is the last administrator Boards.deny({ - async update(userId, doc, fieldNames, modifier) { + update(userId, doc, fieldNames, modifier) { if (!_.contains(fieldNames, 'members')) return false; // We only care in case of a $pull operation, ie remove a member @@ -1891,7 +1891,7 @@ if (Meteor.isServer) { // Deny changing permission to public if allowPrivateOnly is enabled Boards.deny({ - async update(userId, doc, fieldNames, modifier) { + update(userId, doc, fieldNames, modifier) { if (!_.contains(fieldNames, 'permission')) return false; const allowPrivateOnly = TableVisibilityModeSettings.findOne('tableVisibilityMode-allowPrivateOnly')?.booleanValue; diff --git a/models/cardCommentReactions.js b/models/cardCommentReactions.js index 3a9a21608..8271a563f 100644 --- a/models/cardCommentReactions.js +++ b/models/cardCommentReactions.js @@ -50,14 +50,14 @@ CardCommentReactions.attachSchema( ); CardCommentReactions.allow({ - async insert(userId, doc) { - return allowIsBoardMember(userId, await ReactiveCache.getBoard(doc.boardId)); + insert(userId, doc) { + return allowIsBoardMember(userId, Boards.findOne(doc.boardId)); }, - async update(userId, doc) { - return allowIsBoardMember(userId, await ReactiveCache.getBoard(doc.boardId)); + update(userId, doc) { + return allowIsBoardMember(userId, Boards.findOne(doc.boardId)); }, - async remove(userId, doc) { - return allowIsBoardMember(userId, await ReactiveCache.getBoard(doc.boardId)); + remove(userId, doc) { + return allowIsBoardMember(userId, Boards.findOne(doc.boardId)); }, fetch: ['boardId'], }); diff --git a/models/cardComments.js b/models/cardComments.js index 0d4d4e763..a377083ed 100644 --- a/models/cardComments.js +++ b/models/cardComments.js @@ -81,15 +81,15 @@ CardComments.attachSchema( ); CardComments.allow({ - async insert(userId, doc) { + insert(userId, doc) { // ReadOnly users cannot add comments. Only members who can comment are allowed. - return allowIsBoardMemberCommentOnly(userId, await ReactiveCache.getBoard(doc.boardId)); + return allowIsBoardMemberCommentOnly(userId, Boards.findOne(doc.boardId)); }, - async update(userId, doc) { - return userId === doc.userId || allowIsBoardAdmin(userId, await ReactiveCache.getBoard(doc.boardId)); + update(userId, doc) { + return userId === doc.userId || allowIsBoardAdmin(userId, Boards.findOne(doc.boardId)); }, - async remove(userId, doc) { - return userId === doc.userId || allowIsBoardAdmin(userId, await ReactiveCache.getBoard(doc.boardId)); + remove(userId, doc) { + return userId === doc.userId || allowIsBoardAdmin(userId, Boards.findOne(doc.boardId)); }, fetch: ['userId', 'boardId'], }); diff --git a/models/cards.js b/models/cards.js index 5f606861c..290447ada 100644 --- a/models/cards.js +++ b/models/cards.js @@ -519,7 +519,7 @@ Cards.attachSchema( // Centralized update policy for Cards // Security: deny any direct client updates to 'vote' fields; require write access otherwise -canUpdateCard = async function(userId, doc, fields) { +canUpdateCard = function(userId, doc, fields) { if (!userId) return false; const fieldNames = fields || []; // Block direct updates to voting fields; voting must go through Meteor method 'cards.vote' @@ -531,21 +531,20 @@ canUpdateCard = async function(userId, doc, fields) { return false; } // ReadOnly users cannot edit cards - return allowIsBoardMemberWithWriteAccess(userId, await ReactiveCache.getBoard(doc.boardId)); + return allowIsBoardMemberWithWriteAccess(userId, Boards.findOne(doc.boardId)); }; Cards.allow({ - async insert(userId, doc) { + insert(userId, doc) { // ReadOnly users cannot create cards - return allowIsBoardMemberWithWriteAccess(userId, await ReactiveCache.getBoard(doc.boardId)); + return allowIsBoardMemberWithWriteAccess(userId, Boards.findOne(doc.boardId)); }, - - async update(userId, doc, fields) { - return await canUpdateCard(userId, doc, fields); + update(userId, doc, fields) { + return canUpdateCard(userId, doc, fields); }, - async remove(userId, doc) { + remove(userId, doc) { // ReadOnly users cannot delete cards - return allowIsBoardMemberWithWriteAccess(userId, await ReactiveCache.getBoard(doc.boardId)); + return allowIsBoardMemberWithWriteAccess(userId, Boards.findOne(doc.boardId)); }, fetch: ['boardId'], }); @@ -572,7 +571,7 @@ Cards.helpers({ }); }, - async mapCustomFieldsToBoard(boardId) { + mapCustomFieldsToBoard(boardId) { // Guard against undefined/null customFields if (!this.customFields || !Array.isArray(this.customFields)) { return []; @@ -580,7 +579,7 @@ Cards.helpers({ // Map custom fields to new board const result = []; for (const cf of this.customFields) { - const oldCf = await ReactiveCache.getCustomField(cf._id); + const oldCf = ReactiveCache.getCustomField(cf._id); // Check if oldCf is undefined or null if (!oldCf) { @@ -589,7 +588,7 @@ Cards.helpers({ continue; } - const newCf = await ReactiveCache.getCustomField({ + const newCf = ReactiveCache.getCustomField({ boardIds: boardId, name: oldCf.name, type: oldCf.type, @@ -598,7 +597,7 @@ Cards.helpers({ if (newCf) { cf._id = newCf._id; } else if (!_.contains(oldCf.boardIds, boardId)) { - await oldCf.addBoard(boardId); + oldCf.addBoard(boardId); } result.push(cf); @@ -607,9 +606,9 @@ Cards.helpers({ }, - async copy(boardId, swimlaneId, listId) { + copy(boardId, swimlaneId, listId) { const oldId = this._id; - const oldCard = await ReactiveCache.getCard(oldId); + const oldCard = ReactiveCache.getCard(oldId); // Work on a shallow copy to avoid mutating the source card in ReactiveCache const cardData = { ...this }; @@ -623,7 +622,7 @@ Cards.helpers({ // we must only copy the labels and custom fields if the target board // differs from the source board if (this.boardId !== boardId) { - const oldBoard = await ReactiveCache.getBoard(this.boardId); + const oldBoard = ReactiveCache.getBoard(this.boardId); const oldBoardLabels = oldBoard.labels; // Get old label names @@ -634,7 +633,7 @@ Cards.helpers({ 'name', ); - const newBoard = await ReactiveCache.getBoard(boardId); + const newBoard = ReactiveCache.getBoard(boardId); const newBoardLabels = newBoard.labels; const newCardLabels = _.pluck( _.filter(newBoardLabels, label => { @@ -644,16 +643,16 @@ Cards.helpers({ ); cardData.labelIds = newCardLabels; - this.customFields = await this.mapCustomFieldsToBoard(newBoard._id); + this.customFields = this.mapCustomFieldsToBoard(newBoard._id); } delete this._id; this.boardId = boardId; - const board = await ReactiveCache.getBoard(boardId); + const board = ReactiveCache.getBoard(boardId); this.cardNumber = board.getNextCardNumber(); this.swimlaneId = swimlaneId; this.listId = listId; - const _id = await Cards.insertAsync(this); + const _id = Cards.insertAsync(this); // Copy attachments oldCard.attachments() @@ -662,23 +661,23 @@ Cards.helpers({ }); // copy checklists - const checklists = await ReactiveCache.getChecklists({ cardId: oldId }); + const checklists = ReactiveCache.getChecklists({ cardId: oldId }); for (const ch of checklists) { - await ch.copy(_id); + ch.copy(_id); } // copy subtasks - const subtasks = await ReactiveCache.getCards({ parentId: oldId }); + const subtasks = ReactiveCache.getCards({ parentId: oldId }); for (const subtask of subtasks) { subtask.parentId = _id; subtask._id = null; - await Cards.insertAsync(subtask); + Cards.insertAsync(subtask); } // copy card comments - const comments = await ReactiveCache.getCardComments({ cardId: oldId }); + const comments = ReactiveCache.getCardComments({ cardId: oldId }); for (const cmt of comments) { - await cmt.copy(_id); + cmt.copy(_id); } // restore the id, otherwise new copies will fail this._id = oldId; @@ -1035,8 +1034,8 @@ Cards.helpers({ return ''; }, - async absoluteUrl() { - const board = await this.board(); + absoluteUrl() { + const board = this.board(); if (!board) return undefined; return FlowRouter.url('card', { boardId: board._id, @@ -1044,8 +1043,8 @@ Cards.helpers({ cardId: this._id, }); }, - async originRelativeUrl() { - const board = await this.board(); + originRelativeUrl() { + const board = this.board(); if (!board) return undefined; return FlowRouter.path('card', { boardId: board._id, @@ -1054,8 +1053,8 @@ Cards.helpers({ }); }, - async canBeRestored() { - const list = await ReactiveCache.getList(this.listId); + canBeRestored() { + const list = ReactiveCache.getList(this.listId); if ( !list.getWipLimit('soft') && list.getWipLimit('enabled') && @@ -1066,18 +1065,18 @@ Cards.helpers({ return true; }, - async parentCard() { + parentCard() { let ret = null; if (this.parentId) { - ret = await ReactiveCache.getCard(this.parentId); + ret = ReactiveCache.getCard(this.parentId); } return ret; }, - async parentCardName() { + parentCardName() { let result = ''; if (this.parentId) { - const card = await ReactiveCache.getCard(this.parentId); + const card = ReactiveCache.getCard(this.parentId); if (card) { result = card.title; } @@ -1085,11 +1084,11 @@ Cards.helpers({ return result; }, - async parentListId() { + parentListId() { const result = []; let crtParentId = this.parentId; while (crtParentId) { - const crt = await ReactiveCache.getCard(crtParentId); + const crt = ReactiveCache.getCard(crtParentId); if (crt === null || crt === undefined) { // maybe it has been deleted break; @@ -1104,12 +1103,12 @@ Cards.helpers({ return result; }, - async parentList() { + parentList() { const resultId = []; const result = []; let crtParentId = this.parentId; while (crtParentId) { - const crt = await ReactiveCache.getCard(crtParentId); + const crt = ReactiveCache.getCard(crtParentId); if (crt === null || crt === undefined) { // maybe it has been deleted break; @@ -1125,8 +1124,8 @@ Cards.helpers({ return result; }, - async parentString(sep) { - return (await this.parentList()) + parentString(sep) { + return (this.parentList()) .map(function(elem) { return elem.title; }) @@ -1161,13 +1160,13 @@ Cards.helpers({ } }, - async getDescription() { + getDescription() { if (this.isLinkedCard()) { - const card = await ReactiveCache.getCard(this.linkedId); + const card = ReactiveCache.getCard(this.linkedId); if (card && card.description) return card.description; else return null; } else if (this.isLinkedBoard()) { - const board = await ReactiveCache.getBoard(this.linkedId); + const board = ReactiveCache.getBoard(this.linkedId); if (board && board.description) return board.description; else return null; } else if (this.description) { @@ -1177,16 +1176,16 @@ Cards.helpers({ } }, - async getMembers() { + getMembers() { if (this.isLinkedCard()) { - const card = await ReactiveCache.getCard(this.linkedId); + const card = ReactiveCache.getCard(this.linkedId); if (card === undefined) { return null; } else { return card.members; } } else if (this.isLinkedBoard()) { - const board = await ReactiveCache.getBoard(this.linkedId); + const board = ReactiveCache.getBoard(this.linkedId); if (board === undefined) { return null; } else { @@ -1199,16 +1198,16 @@ Cards.helpers({ } }, - async getAssignees() { + getAssignees() { if (this.isLinkedCard()) { - const card = await ReactiveCache.getCard(this.linkedId); + const card = ReactiveCache.getCard(this.linkedId); if (card === undefined) { return null; } else { return card.assignees; } } else if (this.isLinkedBoard()) { - const board = await ReactiveCache.getBoard(this.linkedId); + const board = ReactiveCache.getBoard(this.linkedId); if (board === undefined) { return null; } else { @@ -1221,13 +1220,13 @@ Cards.helpers({ } }, - async assignMember(memberId) { + assignMember(memberId) { let ret; if (this.isLinkedBoard()) { - const board = await ReactiveCache.getBoard(this.linkedId); - ret = await board.addMember(memberId); + const board = ReactiveCache.getBoard(this.linkedId); + ret = board.addMember(memberId); } else { - ret = await Cards.updateAsync( + ret = Cards.updateAsync( { _id: this.getRealId() }, { $addToSet: { members: memberId } }, ); @@ -1235,82 +1234,82 @@ Cards.helpers({ return ret; }, - async assignAssignee(assigneeId) { + assignAssignee(assigneeId) { if (this.isLinkedCard()) { - return await Cards.updateAsync( + return Cards.updateAsync( { _id: this.linkedId }, { $addToSet: { assignees: assigneeId } }, ); } else if (this.isLinkedBoard()) { - const board = await ReactiveCache.getBoard(this.linkedId); + const board = ReactiveCache.getBoard(this.linkedId); return board.addAssignee(assigneeId); } else { - return await Cards.updateAsync( + return Cards.updateAsync( { _id: this._id }, { $addToSet: { assignees: assigneeId } }, ); } }, - async unassignMember(memberId) { + unassignMember(memberId) { if (this.isLinkedCard()) { - return await Cards.updateAsync( + return Cards.updateAsync( { _id: this.linkedId }, { $pull: { members: memberId } }, ); } else if (this.isLinkedBoard()) { - const board = await ReactiveCache.getBoard(this.linkedId); - return await board.removeMember(memberId); + const board = ReactiveCache.getBoard(this.linkedId); + return board.removeMember(memberId); } else { - return await Cards.updateAsync({ _id: this._id }, { $pull: { members: memberId } }); + return Cards.updateAsync({ _id: this._id }, { $pull: { members: memberId } }); } }, - async unassignAssignee(assigneeId) { + unassignAssignee(assigneeId) { if (this.isLinkedCard()) { - return await Cards.updateAsync( + return Cards.updateAsync( { _id: this.linkedId }, { $pull: { assignees: assigneeId } }, ); } else if (this.isLinkedBoard()) { - const board = await ReactiveCache.getBoard(this.linkedId); + const board = ReactiveCache.getBoard(this.linkedId); return board.removeAssignee(assigneeId); } else { - return await Cards.updateAsync( + return Cards.updateAsync( { _id: this._id }, { $pull: { assignees: assigneeId } }, ); } }, - async toggleMember(memberId) { - const members = await this.getMembers(); + toggleMember(memberId) { + const members = this.getMembers(); if (members && members.indexOf(memberId) > -1) { - return await this.unassignMember(memberId); + return this.unassignMember(memberId); } else { - return await this.assignMember(memberId); + return this.assignMember(memberId); } }, - async toggleAssignee(assigneeId) { - const assignees = await this.getAssignees(); + toggleAssignee(assigneeId) { + const assignees = this.getAssignees(); if (assignees && assignees.indexOf(assigneeId) > -1) { - return await this.unassignAssignee(assigneeId); + return this.unassignAssignee(assigneeId); } else { - return await this.assignAssignee(assigneeId); + return this.assignAssignee(assigneeId); } }, - async getReceived() { + getReceived() { if (this.isLinkedCard()) { - const card = await ReactiveCache.getCard(this.linkedId); + const card = ReactiveCache.getCard(this.linkedId); if (card === undefined) { return null; } else { return card.receivedAt; } } else if (this.isLinkedBoard()) { - const board = await ReactiveCache.getBoard(this.linkedId); + const board = ReactiveCache.getBoard(this.linkedId); if (board === undefined) { return null; } else { @@ -1329,16 +1328,16 @@ Cards.helpers({ } }, - async getStart() { + getStart() { if (this.isLinkedCard()) { - const card = await ReactiveCache.getCard(this.linkedId); + const card = ReactiveCache.getCard(this.linkedId); if (card === undefined) { return null; } else { return card.startAt; } } else if (this.isLinkedBoard()) { - const board = await ReactiveCache.getBoard(this.linkedId); + const board = ReactiveCache.getBoard(this.linkedId); if (board === undefined) { return null; } else { @@ -1357,16 +1356,16 @@ Cards.helpers({ } }, - async getDue() { + getDue() { if (this.isLinkedCard()) { - const card = await ReactiveCache.getCard(this.linkedId); + const card = ReactiveCache.getCard(this.linkedId); if (card === undefined) { return null; } else { return card.dueAt; } } else if (this.isLinkedBoard()) { - const board = await ReactiveCache.getBoard(this.linkedId); + const board = ReactiveCache.getBoard(this.linkedId); if (board === undefined) { return null; } else { @@ -1385,16 +1384,16 @@ Cards.helpers({ } }, - async getEnd() { + getEnd() { if (this.isLinkedCard()) { - const card = await ReactiveCache.getCard(this.linkedId); + const card = ReactiveCache.getCard(this.linkedId); if (card === undefined) { return null; } else { return card.endAt; } } else if (this.isLinkedBoard()) { - const board = await ReactiveCache.getBoard(this.linkedId); + const board = ReactiveCache.getBoard(this.linkedId); if (board === undefined) { return null; } else { @@ -1413,16 +1412,16 @@ Cards.helpers({ } }, - async getIsOvertime() { + getIsOvertime() { if (this.isLinkedCard()) { - const card = await ReactiveCache.getCard(this.linkedId); + const card = ReactiveCache.getCard(this.linkedId); if (card === undefined) { return null; } else { return card.isOvertime; } } else if (this.isLinkedBoard()) { - const board = await ReactiveCache.getBoard(this.linkedId); + const board = ReactiveCache.getBoard(this.linkedId); if (board === undefined) { return null; } else { @@ -1441,16 +1440,16 @@ Cards.helpers({ } }, - async getSpentTime() { + getSpentTime() { if (this.isLinkedCard()) { - const card = await ReactiveCache.getCard(this.linkedId); + const card = ReactiveCache.getCard(this.linkedId); if (card === undefined) { return null; } else { return card.spentTime; } } else if (this.isLinkedBoard()) { - const board = await ReactiveCache.getBoard(this.linkedId); + const board = ReactiveCache.getBoard(this.linkedId); if (board === undefined) { return null; } else { @@ -1469,9 +1468,9 @@ Cards.helpers({ } }, - async getVoteQuestion() { + getVoteQuestion() { if (this.isLinkedCard()) { - const card = await ReactiveCache.getCard(this.linkedId); + const card = ReactiveCache.getCard(this.linkedId); if (card === undefined) { return null; } else if (card && card.vote) { @@ -1480,7 +1479,7 @@ Cards.helpers({ return null; } } else if (this.isLinkedBoard()) { - const board = await ReactiveCache.getBoard(this.linkedId); + const board = ReactiveCache.getBoard(this.linkedId); if (board === undefined) { return null; } else if (board && board.vote) { @@ -1495,9 +1494,9 @@ Cards.helpers({ } }, - async getVotePublic() { + getVotePublic() { if (this.isLinkedCard()) { - const card = await ReactiveCache.getCard(this.linkedId); + const card = ReactiveCache.getCard(this.linkedId); if (card === undefined) { return null; } else if (card && card.vote) { @@ -1506,7 +1505,7 @@ Cards.helpers({ return null; } } else if (this.isLinkedBoard()) { - const board = await ReactiveCache.getBoard(this.linkedId); + const board = ReactiveCache.getBoard(this.linkedId); if (board === undefined) { return null; } else if (board && board.vote) { @@ -1521,9 +1520,9 @@ Cards.helpers({ } }, - async getVoteEnd() { + getVoteEnd() { if (this.isLinkedCard()) { - const card = await ReactiveCache.getCard(this.linkedId); + const card = ReactiveCache.getCard(this.linkedId); if (card === undefined) { return null; } else if (card && card.vote) { @@ -1532,7 +1531,7 @@ Cards.helpers({ return null; } } else if (this.isLinkedBoard()) { - const board = await ReactiveCache.getBoard(this.linkedId); + const board = ReactiveCache.getBoard(this.linkedId); if (board === undefined) { return null; } else if (board && board.vote) { @@ -1546,23 +1545,23 @@ Cards.helpers({ return null; } }, - async expiredVote() { - let end = await this.getVoteEnd(); + expiredVote() { + let end = this.getVoteEnd(); if (end) { end = new Date(end); return isBefore(end, new Date()); } return false; }, - async voteMemberPositive() { + voteMemberPositive() { if (this.vote && this.vote.positive) - return await ReactiveCache.getUsers({ _id: { $in: this.vote.positive } }); + return ReactiveCache.getUsers({ _id: { $in: this.vote.positive } }); return []; }, - async voteMemberNegative() { + voteMemberNegative() { if (this.vote && this.vote.negative) - return await ReactiveCache.getUsers({ _id: { $in: this.vote.negative } }); + return ReactiveCache.getUsers({ _id: { $in: this.vote.negative } }); return []; }, voteState() { @@ -1581,9 +1580,9 @@ Cards.helpers({ return null; }, - async getPokerQuestion() { + getPokerQuestion() { if (this.isLinkedCard()) { - const card = await ReactiveCache.getCard(this.linkedId); + const card = ReactiveCache.getCard(this.linkedId); if (card === undefined) { return null; } else if (card && card.poker) { @@ -1592,7 +1591,7 @@ Cards.helpers({ return null; } } else if (this.isLinkedBoard()) { - const board = await ReactiveCache.getBoard(this.linkedId); + const board = ReactiveCache.getBoard(this.linkedId); if (board === undefined) { return null; } else if (board && board.poker) { @@ -1615,9 +1614,9 @@ Cards.helpers({ } }, - async getPokerEnd() { + getPokerEnd() { if (this.isLinkedCard()) { - const card = await ReactiveCache.getCard(this.linkedId); + const card = ReactiveCache.getCard(this.linkedId); if (card === undefined) { return null; } else if (card && card.poker) { @@ -1626,7 +1625,7 @@ Cards.helpers({ return null; } } else if (this.isLinkedBoard()) { - const board = await ReactiveCache.getBoard(this.linkedId); + const board = ReactiveCache.getBoard(this.linkedId); if (board === undefined) { return null; } else if (board && board.poker) { @@ -1640,62 +1639,62 @@ Cards.helpers({ return null; } }, - async expiredPoker() { - let end = await this.getPokerEnd(); + expiredPoker() { + let end = this.getPokerEnd(); if (end) { end = new Date(end); return isBefore(end, new Date()); } return false; }, - async pokerMemberOne() { + pokerMemberOne() { if (this.poker && this.poker.one) - return await ReactiveCache.getUsers({ _id: { $in: this.poker.one } }); + return ReactiveCache.getUsers({ _id: { $in: this.poker.one } }); return []; }, - async pokerMemberTwo() { + pokerMemberTwo() { if (this.poker && this.poker.two) - return await ReactiveCache.getUsers({ _id: { $in: this.poker.two } }); + return ReactiveCache.getUsers({ _id: { $in: this.poker.two } }); return []; }, - async pokerMemberThree() { + pokerMemberThree() { if (this.poker && this.poker.three) - return await ReactiveCache.getUsers({ _id: { $in: this.poker.three } }); + return ReactiveCache.getUsers({ _id: { $in: this.poker.three } }); return []; }, - async pokerMemberFive() { + pokerMemberFive() { if (this.poker && this.poker.five) - return await ReactiveCache.getUsers({ _id: { $in: this.poker.five } }); + return ReactiveCache.getUsers({ _id: { $in: this.poker.five } }); return []; }, - async pokerMemberEight() { + pokerMemberEight() { if (this.poker && this.poker.eight) - return await ReactiveCache.getUsers({ _id: { $in: this.poker.eight } }); + return ReactiveCache.getUsers({ _id: { $in: this.poker.eight } }); return []; }, - async pokerMemberThirteen() { + pokerMemberThirteen() { if (this.poker && this.poker.thirteen) - return await ReactiveCache.getUsers({ _id: { $in: this.poker.thirteen } }); + return ReactiveCache.getUsers({ _id: { $in: this.poker.thirteen } }); return []; }, - async pokerMemberTwenty() { + pokerMemberTwenty() { if (this.poker && this.poker.twenty) - return await ReactiveCache.getUsers({ _id: { $in: this.poker.twenty } }); + return ReactiveCache.getUsers({ _id: { $in: this.poker.twenty } }); return []; }, - async pokerMemberForty() { + pokerMemberForty() { if (this.poker && this.poker.forty) - return await ReactiveCache.getUsers({ _id: { $in: this.poker.forty } }); + return ReactiveCache.getUsers({ _id: { $in: this.poker.forty } }); return []; }, - async pokerMemberOneHundred() { + pokerMemberOneHundred() { if (this.poker && this.poker.oneHundred) - return await ReactiveCache.getUsers({ _id: { $in: this.poker.oneHundred } }); + return ReactiveCache.getUsers({ _id: { $in: this.poker.oneHundred } }); return []; }, - async pokerMemberUnsure() { + pokerMemberUnsure() { if (this.poker && this.poker.unsure) - return await ReactiveCache.getUsers({ _id: { $in: this.poker.unsure } }); + return ReactiveCache.getUsers({ _id: { $in: this.poker.unsure } }); return []; }, pokerState() { @@ -1766,16 +1765,16 @@ Cards.helpers({ return null; }, - async getTitle() { + getTitle() { if (this.isLinkedCard()) { - const card = await ReactiveCache.getCard(this.linkedId); + const card = ReactiveCache.getCard(this.linkedId); if (card === undefined) { return null; } else { return card.title; } } else if (this.isLinkedBoard()) { - const board = await ReactiveCache.getBoard(this.linkedId); + const board = ReactiveCache.getBoard(this.linkedId); if (board === undefined) { return null; } else { @@ -1792,27 +1791,27 @@ Cards.helpers({ return this.cardNumber; }, - async getBoardTitle() { + getBoardTitle() { if (this.isLinkedCard()) { - const card = await ReactiveCache.getCard(this.linkedId); + const card = ReactiveCache.getCard(this.linkedId); if (card === undefined) { return null; } - const board = await ReactiveCache.getBoard(card.boardId); + const board = ReactiveCache.getBoard(card.boardId); if (board === undefined) { return null; } else { return board.title; } } else if (this.isLinkedBoard()) { - const board = await ReactiveCache.getBoard(this.linkedId); + const board = ReactiveCache.getBoard(this.linkedId); if (board === undefined) { return null; } else { return board.title; } } else { - const board = await ReactiveCache.getBoard(this.boardId); + const board = ReactiveCache.getBoard(this.boardId); if (board === undefined) { return null; } else { @@ -1839,16 +1838,16 @@ Cards.helpers({ } }, - async getArchived() { + getArchived() { if (this.isLinkedCard()) { - const card = await ReactiveCache.getCard(this.linkedId); + const card = ReactiveCache.getCard(this.linkedId); if (card === undefined) { return null; } else { return card.archived; } } else if (this.isLinkedBoard()) { - const board = await ReactiveCache.getBoard(this.linkedId); + const board = ReactiveCache.getBoard(this.linkedId); if (board === undefined) { return null; } else { @@ -1863,9 +1862,9 @@ Cards.helpers({ return Cards.update({ _id: this.getRealId() }, { $set: { requestedBy } }); }, - async getRequestedBy() { + getRequestedBy() { if (this.isLinkedCard()) { - const card = await ReactiveCache.getCard(this.linkedId); + const card = ReactiveCache.getCard(this.linkedId); if (card === undefined) { return null; } else { @@ -1880,9 +1879,9 @@ Cards.helpers({ return Cards.update({ _id: this.getRealId() }, { $set: { assignedBy } }); }, - async getAssignedBy() { + getAssignedBy() { if (this.isLinkedCard()) { - const card = await ReactiveCache.getCard(this.linkedId); + const card = ReactiveCache.getCard(this.linkedId); if (card === undefined) { return null; } else { @@ -1975,10 +1974,10 @@ Cards.helpers({ this.pokerCountUnsure() ); }, - async pokerWinner() { + pokerWinner() { const pokerListMaps = []; let pokerWinnersListMap = []; - if (await this.expiredPoker()) { + if (this.expiredPoker()) { const one = { count: this.pokerCountOne(), pokerCard: 1 }; const two = { count: this.pokerCountTwo(), pokerCard: 2 }; const three = { count: this.pokerCountThree(), pokerCard: 3 }; @@ -2012,38 +2011,38 @@ Cards.helpers({ return pokerWinnersListMap[0].pokerCard; }, - async applyToChildren(funct) { - const cards = await ReactiveCache.getCards({ parentId: this._id }); + applyToChildren(funct) { + const cards = ReactiveCache.getCards({ parentId: this._id }); for (const card of cards) { - await funct(card); + funct(card); } }, - async archive() { - await this.applyToChildren(async card => { - await card.archive(); + archive() { + this.applyToChildren(card => { + card.archive(); }); - return await Cards.updateAsync(this._id, { + return Cards.updateAsync(this._id, { $set: { archived: true, archivedAt: new Date() }, }); }, - async restore() { - await this.applyToChildren(async card => { - await card.restore(); + restore() { + this.applyToChildren(card => { + card.restore(); }); - return await Cards.updateAsync(this._id, { + return Cards.updateAsync(this._id, { $set: { archived: false }, }); }, - async moveToEndOfList({ listId, swimlaneId } = {}) { + moveToEndOfList({ listId, swimlaneId } = {}) { swimlaneId = swimlaneId || this.swimlaneId; const boardId = this.boardId; let sortIndex = 0; if (!swimlaneId) { - const board = await ReactiveCache.getBoard(boardId); + const board = ReactiveCache.getBoard(boardId); swimlaneId = board.getDefaultSwimline()._id; } let parentElementDom = $(`#swimlane-${swimlaneId}`).get(0); @@ -2054,7 +2053,7 @@ Cards.helpers({ .get(0); if (lastCardDom) sortIndex = Utils.calculateIndex(lastCardDom, null).base; - return await this.moveOptionalArgs({ + return this.moveOptionalArgs({ boardId, swimlaneId, listId, @@ -2062,19 +2061,19 @@ Cards.helpers({ }); }, - async moveOptionalArgs({ boardId, swimlaneId, listId, sort } = {}) { + moveOptionalArgs({ boardId, swimlaneId, listId, sort } = {}) { boardId = boardId || this.boardId; swimlaneId = swimlaneId || this.swimlaneId; if (!swimlaneId) { - const board = await ReactiveCache.getBoard(boardId); + const board = ReactiveCache.getBoard(boardId); swimlaneId = board.getDefaultSwimline()._id; } listId = listId || this.listId; if (sort === undefined || sort === null) sort = this.sort; - return await this.move(boardId, swimlaneId, listId, sort); + return this.move(boardId, swimlaneId, listId, sort); }, - async move(boardId, swimlaneId, listId, sort = null) { + move(boardId, swimlaneId, listId, sort = null) { const previousState = { boardId: this.boardId, swimlaneId: this.swimlaneId, @@ -2089,7 +2088,7 @@ Cards.helpers({ } if (this.boardId !== boardId) { - const oldBoard = await ReactiveCache.getBoard(this.boardId); + const oldBoard = ReactiveCache.getBoard(this.boardId); const oldBoardLabels = oldBoard.labels; const oldCardLabels = _.pluck( _.filter(oldBoardLabels, label => { @@ -2098,7 +2097,7 @@ Cards.helpers({ 'name', ); - const newBoard = await ReactiveCache.getBoard(boardId); + const newBoard = ReactiveCache.getBoard(boardId); const newBoardLabels = newBoard.labels; const newCardLabelIds = _.pluck( _.filter(newBoardLabels, label => { @@ -2114,7 +2113,7 @@ Cards.helpers({ cardNumber: newCardNumber }); - mutatedFields.customFields = await this.mapCustomFieldsToBoard(newBoard._id); + mutatedFields.customFields = this.mapCustomFieldsToBoard(newBoard._id); // Ensure customFields is always an array (guards against legacy {} data) if (!Array.isArray(mutatedFields.customFields)) { @@ -2122,7 +2121,7 @@ Cards.helpers({ } } - await Cards.updateAsync(this._id, { $set: mutatedFields }); + Cards.updateAsync(this._id, { $set: mutatedFields }); if (Meteor.isServer && Meteor.userId() && typeof UserPositionHistory !== 'undefined') { try { @@ -2153,7 +2152,7 @@ Cards.helpers({ if (Object.keys(updateMeta).length > 0) { try { - await Attachments.collection.updateAsync( + Attachments.collection.updateAsync( { 'meta.cardId': this._id }, { $set: updateMeta }, { multi: true }, @@ -2165,147 +2164,147 @@ Cards.helpers({ } }, - async addLabel(labelId) { + addLabel(labelId) { this.labelIds.push(labelId); - return await Cards.updateAsync(this._id, { $addToSet: { labelIds: labelId } }); + return Cards.updateAsync(this._id, { $addToSet: { labelIds: labelId } }); }, - async removeLabel(labelId) { + removeLabel(labelId) { this.labelIds = _.without(this.labelIds, labelId); - return await Cards.updateAsync(this._id, { $pull: { labelIds: labelId } }); + return Cards.updateAsync(this._id, { $pull: { labelIds: labelId } }); }, - async toggleLabel(labelId) { + toggleLabel(labelId) { if (this.labelIds && this.labelIds.indexOf(labelId) > -1) { - return await this.removeLabel(labelId); + return this.removeLabel(labelId); } else { - return await this.addLabel(labelId); + return this.addLabel(labelId); } }, - async setColor(newColor) { + setColor(newColor) { if (newColor === 'white') { newColor = null; } - return await Cards.updateAsync(this._id, { $set: { color: newColor } }); + return Cards.updateAsync(this._id, { $set: { color: newColor } }); }, - async assignMember(memberId) { - return await Cards.updateAsync(this._id, { $addToSet: { members: memberId } }); + assignMember(memberId) { + return Cards.updateAsync(this._id, { $addToSet: { members: memberId } }); }, - async assignAssignee(assigneeId) { - return await Cards.updateAsync(this._id, { $addToSet: { assignees: assigneeId } }); + assignAssignee(assigneeId) { + return Cards.updateAsync(this._id, { $addToSet: { assignees: assigneeId } }); }, - async unassignMember(memberId) { - return await Cards.updateAsync(this._id, { $pull: { members: memberId } }); + unassignMember(memberId) { + return Cards.updateAsync(this._id, { $pull: { members: memberId } }); }, - async unassignAssignee(assigneeId) { - return await Cards.updateAsync(this._id, { $pull: { assignees: assigneeId } }); + unassignAssignee(assigneeId) { + return Cards.updateAsync(this._id, { $pull: { assignees: assigneeId } }); }, - async toggleMember(memberId) { + toggleMember(memberId) { if (this.members && this.members.indexOf(memberId) > -1) { - return await this.unassignMember(memberId); + return this.unassignMember(memberId); } else { - return await this.assignMember(memberId); + return this.assignMember(memberId); } }, - async toggleAssignee(assigneeId) { + toggleAssignee(assigneeId) { if (this.assignees && this.assignees.indexOf(assigneeId) > -1) { - return await this.unassignAssignee(assigneeId); + return this.unassignAssignee(assigneeId); } else { - return await this.assignAssignee(assigneeId); + return this.assignAssignee(assigneeId); } }, - async assignCustomField(customFieldId) { - return await Cards.updateAsync(this._id, { + assignCustomField(customFieldId) { + return Cards.updateAsync(this._id, { $addToSet: { customFields: { _id: customFieldId, value: null } }, }); }, - async unassignCustomField(customFieldId) { - return await Cards.updateAsync(this._id, { + unassignCustomField(customFieldId) { + return Cards.updateAsync(this._id, { $pull: { customFields: { _id: customFieldId } }, }); }, - async toggleCustomField(customFieldId) { + toggleCustomField(customFieldId) { if (this.customFields && this.customFieldIndex(customFieldId) > -1) { - return await this.unassignCustomField(customFieldId); + return this.unassignCustomField(customFieldId); } else { - return await this.assignCustomField(customFieldId); + return this.assignCustomField(customFieldId); } }, - async toggleShowActivities() { - return await Cards.updateAsync(this._id, { + toggleShowActivities() { + return Cards.updateAsync(this._id, { $set: { showActivities: !this.showActivities }, }); }, - async toggleShowChecklistAtMinicard() { - return await Cards.updateAsync(this._id, { + toggleShowChecklistAtMinicard() { + return Cards.updateAsync(this._id, { $set: { showChecklistAtMinicard: !this.showChecklistAtMinicard }, }); }, - async setCustomField(customFieldId, value) { + setCustomField(customFieldId, value) { const index = this.customFieldIndex(customFieldId); if (index > -1) { const update = { $set: {} }; update.$set[`customFields.${index}.value`] = value; - return await Cards.updateAsync(this._id, update); + return Cards.updateAsync(this._id, update); } return null; }, - async setCover(coverId) { - return await Cards.updateAsync(this._id, { $set: { coverId } }); + setCover(coverId) { + return Cards.updateAsync(this._id, { $set: { coverId } }); }, - async unsetCover() { - return await Cards.updateAsync(this._id, { $unset: { coverId: '' } }); + unsetCover() { + return Cards.updateAsync(this._id, { $unset: { coverId: '' } }); }, - async unsetReceived() { - return await Cards.updateAsync(this._id, { $unset: { receivedAt: '' } }); + unsetReceived() { + return Cards.updateAsync(this._id, { $unset: { receivedAt: '' } }); }, - async unsetStart() { - return await Cards.updateAsync(this._id, { $unset: { startAt: '' } }); + unsetStart() { + return Cards.updateAsync(this._id, { $unset: { startAt: '' } }); }, - async unsetDue() { - return await Cards.updateAsync(this._id, { $unset: { dueAt: '' } }); + unsetDue() { + return Cards.updateAsync(this._id, { $unset: { dueAt: '' } }); }, - async unsetEnd() { - return await Cards.updateAsync(this._id, { $unset: { endAt: '' } }); + unsetEnd() { + return Cards.updateAsync(this._id, { $unset: { endAt: '' } }); }, - async setOvertime(isOvertime) { - return await Cards.updateAsync(this._id, { $set: { isOvertime } }); + setOvertime(isOvertime) { + return Cards.updateAsync(this._id, { $set: { isOvertime } }); }, - async setSpentTime(spentTime) { - return await Cards.updateAsync(this._id, { $set: { spentTime } }); + setSpentTime(spentTime) { + return Cards.updateAsync(this._id, { $set: { spentTime } }); }, - async unsetSpentTime() { - return await Cards.updateAsync(this._id, { $unset: { spentTime: '', isOvertime: false } }); + unsetSpentTime() { + return Cards.updateAsync(this._id, { $unset: { spentTime: '', isOvertime: false } }); }, - async setParentId(parentId) { - return await Cards.updateAsync(this._id, { $set: { parentId } }); + setParentId(parentId) { + return Cards.updateAsync(this._id, { $set: { parentId } }); }, - async setVoteQuestion(question, publicVote, allowNonBoardMembers) { - return await Cards.updateAsync(this._id, { + setVoteQuestion(question, publicVote, allowNonBoardMembers) { + return Cards.updateAsync(this._id, { $set: { vote: { question, @@ -2318,39 +2317,39 @@ Cards.helpers({ }); }, - async unsetVote() { - return await Cards.updateAsync(this._id, { $unset: { vote: '' } }); + unsetVote() { + return Cards.updateAsync(this._id, { $unset: { vote: '' } }); }, - async setVoteEnd(end) { - return await Cards.updateAsync(this._id, { $set: { 'vote.end': end } }); + setVoteEnd(end) { + return Cards.updateAsync(this._id, { $set: { 'vote.end': end } }); }, - async unsetVoteEnd() { - return await Cards.updateAsync(this._id, { $unset: { 'vote.end': '' } }); + unsetVoteEnd() { + return Cards.updateAsync(this._id, { $unset: { 'vote.end': '' } }); }, - async setVote(userId, forIt) { + setVote(userId, forIt) { switch (forIt) { case true: - return await Cards.updateAsync(this._id, { + return Cards.updateAsync(this._id, { $pull: { 'vote.negative': userId }, $addToSet: { 'vote.positive': userId }, }); case false: - return await Cards.updateAsync(this._id, { + return Cards.updateAsync(this._id, { $pull: { 'vote.positive': userId }, $addToSet: { 'vote.negative': userId }, }); default: - return await Cards.updateAsync(this._id, { + return Cards.updateAsync(this._id, { $pull: { 'vote.positive': userId, 'vote.negative': userId }, }); } }, - async setPokerQuestion(question, allowNonBoardMembers) { - return await Cards.updateAsync(this._id, { + setPokerQuestion(question, allowNonBoardMembers) { + return Cards.updateAsync(this._id, { $set: { poker: { question, @@ -2370,44 +2369,44 @@ Cards.helpers({ }); }, - async setPokerEstimation(estimation) { - return await Cards.updateAsync(this._id, { $set: { 'poker.estimation': estimation } }); + setPokerEstimation(estimation) { + return Cards.updateAsync(this._id, { $set: { 'poker.estimation': estimation } }); }, - async unsetPokerEstimation() { - return await Cards.updateAsync(this._id, { $unset: { 'poker.estimation': '' } }); + unsetPokerEstimation() { + return Cards.updateAsync(this._id, { $unset: { 'poker.estimation': '' } }); }, - async unsetPoker() { - return await Cards.updateAsync(this._id, { $unset: { poker: '' } }); + unsetPoker() { + return Cards.updateAsync(this._id, { $unset: { poker: '' } }); }, - async setPokerEnd(end) { - return await Cards.updateAsync(this._id, { $set: { 'poker.end': end } }); + setPokerEnd(end) { + return Cards.updateAsync(this._id, { $set: { 'poker.end': end } }); }, - async unsetPokerEnd() { - return await Cards.updateAsync(this._id, { $unset: { 'poker.end': '' } }); + unsetPokerEnd() { + return Cards.updateAsync(this._id, { $unset: { 'poker.end': '' } }); }, - async setPoker(userId, state) { + setPoker(userId, state) { const pokerFields = ['one', 'two', 'three', 'five', 'eight', 'thirteen', 'twenty', 'forty', 'oneHundred', 'unsure']; const pullFields = {}; pokerFields.forEach(f => { pullFields[`poker.${f}`] = userId; }); if (pokerFields.includes(state)) { delete pullFields[`poker.${state}`]; - return await Cards.updateAsync(this._id, { + return Cards.updateAsync(this._id, { $pull: pullFields, $addToSet: { [`poker.${state}`]: userId }, }); } else { - return await Cards.updateAsync(this._id, { $pull: pullFields }); + return Cards.updateAsync(this._id, { $pull: pullFields }); } }, - async replayPoker() { - return await Cards.updateAsync(this._id, { + replayPoker() { + return Cards.updateAsync(this._id, { $set: { 'poker.one': [], 'poker.two': [], diff --git a/models/checklistItems.js b/models/checklistItems.js index a6eb524aa..3b7573ee4 100644 --- a/models/checklistItems.js +++ b/models/checklistItems.js @@ -69,17 +69,17 @@ ChecklistItems.attachSchema( ); ChecklistItems.allow({ - async insert(userId, doc) { + insert(userId, doc) { // ReadOnly users cannot create checklist items - return allowIsBoardMemberWithWriteAccessByCard(userId, await ReactiveCache.getCard(doc.cardId)); + return allowIsBoardMemberWithWriteAccessByCard(userId, Cards.findOne(doc.cardId)); }, - async update(userId, doc) { + update(userId, doc) { // ReadOnly users cannot edit checklist items - return allowIsBoardMemberWithWriteAccessByCard(userId, await ReactiveCache.getCard(doc.cardId)); + return allowIsBoardMemberWithWriteAccessByCard(userId, Cards.findOne(doc.cardId)); }, - async remove(userId, doc) { + remove(userId, doc) { // ReadOnly users cannot delete checklist items - return allowIsBoardMemberWithWriteAccessByCard(userId, await ReactiveCache.getCard(doc.cardId)); + return allowIsBoardMemberWithWriteAccessByCard(userId, Cards.findOne(doc.cardId)); }, fetch: ['userId', 'cardId'], }); diff --git a/models/checklists.js b/models/checklists.js index 9f0cbc333..77196984c 100644 --- a/models/checklists.js +++ b/models/checklists.js @@ -195,17 +195,17 @@ Checklists.helpers({ }); Checklists.allow({ - async insert(userId, doc) { + insert(userId, doc) { // ReadOnly users cannot create checklists - return allowIsBoardMemberWithWriteAccessByCard(userId, await ReactiveCache.getCard(doc.cardId)); + return allowIsBoardMemberWithWriteAccessByCard(userId, Cards.findOne(doc.cardId)); }, - async update(userId, doc) { + update(userId, doc) { // ReadOnly users cannot edit checklists - return allowIsBoardMemberWithWriteAccessByCard(userId, await ReactiveCache.getCard(doc.cardId)); + return allowIsBoardMemberWithWriteAccessByCard(userId, Cards.findOne(doc.cardId)); }, - async remove(userId, doc) { + remove(userId, doc) { // ReadOnly users cannot delete checklists - return allowIsBoardMemberWithWriteAccessByCard(userId, await ReactiveCache.getCard(doc.cardId)); + return allowIsBoardMemberWithWriteAccessByCard(userId, Cards.findOne(doc.cardId)); }, fetch: ['userId', 'cardId'], }); diff --git a/models/customFields.js b/models/customFields.js index 7fa31d9ae..f9535d76a 100644 --- a/models/customFields.js +++ b/models/customFields.js @@ -164,28 +164,28 @@ CustomFields.helpers({ }); CustomFields.allow({ - async insert(userId, doc) { + insert(userId, doc) { return allowIsAnyBoardMember( userId, - await ReactiveCache.getBoards({ + Boards.find({ _id: { $in: doc.boardIds }, - }), + }).fetch(), ); }, - async update(userId, doc) { + update(userId, doc) { return allowIsAnyBoardMember( userId, - await ReactiveCache.getBoards({ + Boards.find({ _id: { $in: doc.boardIds }, - }), + }).fetch(), ); }, - async remove(userId, doc) { + remove(userId, doc) { return allowIsAnyBoardMember( userId, - await ReactiveCache.getBoards({ + Boards.find({ _id: { $in: doc.boardIds }, - }), + }).fetch(), ); }, fetch: ['userId', 'boardIds'], diff --git a/models/integrations.js b/models/integrations.js index fed283f95..d3c7aee5b 100644 --- a/models/integrations.js +++ b/models/integrations.js @@ -101,21 +101,21 @@ Integrations.Const = { }, }; const permissionHelper = { - async allow(userId, doc) { - const user = await ReactiveCache.getUser(userId); - const isAdmin = user && (await ReactiveCache.getCurrentUser()).isAdmin; - return isAdmin || allowIsBoardAdmin(userId, await ReactiveCache.getBoard(doc.boardId)); + allow(userId, doc) { + const user = Meteor.users.findOne(userId); + const isAdmin = user && user.isAdmin; + return isAdmin || allowIsBoardAdmin(userId, Boards.findOne(doc.boardId)); }, }; Integrations.allow({ - async insert(userId, doc) { - return await permissionHelper.allow(userId, doc); + insert(userId, doc) { + return permissionHelper.allow(userId, doc); }, - async update(userId, doc) { - return await permissionHelper.allow(userId, doc); + update(userId, doc) { + return permissionHelper.allow(userId, doc); }, - async remove(userId, doc) { - return await permissionHelper.allow(userId, doc); + remove(userId, doc) { + return permissionHelper.allow(userId, doc); }, fetch: ['boardId'], }); diff --git a/models/lists.js b/models/lists.js index c2df2acd9..a974bcbd4 100644 --- a/models/lists.js +++ b/models/lists.js @@ -180,17 +180,17 @@ Lists.attachSchema( ); Lists.allow({ - async insert(userId, doc) { + insert(userId, doc) { // ReadOnly and CommentOnly users cannot create lists - return allowIsBoardMemberWithWriteAccess(userId, await ReactiveCache.getBoard(doc.boardId)); + return allowIsBoardMemberWithWriteAccess(userId, Boards.findOne(doc.boardId)); }, - async update(userId, doc) { + update(userId, doc) { // ReadOnly and CommentOnly users cannot edit lists - return allowIsBoardMemberWithWriteAccess(userId, await ReactiveCache.getBoard(doc.boardId)); + return allowIsBoardMemberWithWriteAccess(userId, Boards.findOne(doc.boardId)); }, - async remove(userId, doc) { + remove(userId, doc) { // ReadOnly and CommentOnly users cannot delete lists - return allowIsBoardMemberWithWriteAccess(userId, await ReactiveCache.getBoard(doc.boardId)); + return allowIsBoardMemberWithWriteAccess(userId, Boards.findOne(doc.boardId)); }, fetch: ['boardId'], }); @@ -540,7 +540,7 @@ Meteor.methods({ } await Lists.updateAsync( - { _id: listId, boardId }, + listId, { $set: { ...updateData, diff --git a/models/lockoutSettings.js b/models/lockoutSettings.js index 5bd6dbdf3..454b64481 100644 --- a/models/lockoutSettings.js +++ b/models/lockoutSettings.js @@ -48,8 +48,8 @@ LockoutSettings.attachSchema( ); LockoutSettings.allow({ - async update(userId) { - const user = await ReactiveCache.getUser(userId); + update(userId) { + const user = Meteor.users.findOne(userId); return user && user.isAdmin; }, }); diff --git a/models/org.js b/models/org.js index 21ac40f76..eeb5cb6c3 100644 --- a/models/org.js +++ b/models/org.js @@ -87,8 +87,8 @@ Org.attachSchema( if (Meteor.isServer) { Org.allow({ - async insert(userId, doc) { - const user = await ReactiveCache.getUser(userId) || await ReactiveCache.getCurrentUser(); + insert(userId, doc) { + const user = Meteor.users.findOne(userId); if (user?.isAdmin) return true; if (!user) { @@ -96,8 +96,8 @@ if (Meteor.isServer) { } return doc._id === userId; }, - async update(userId, doc) { - const user = await ReactiveCache.getUser(userId) || await ReactiveCache.getCurrentUser(); + update(userId, doc) { + const user = Meteor.users.findOne(userId); if (user?.isAdmin) return true; if (!user) { @@ -105,8 +105,8 @@ if (Meteor.isServer) { } return doc._id === userId; }, - async remove(userId, doc) { - const user = await ReactiveCache.getUser(userId) || await ReactiveCache.getCurrentUser(); + remove(userId, doc) { + const user = Meteor.users.findOne(userId); if (user?.isAdmin) return true; if (!user) { diff --git a/models/rules.js b/models/rules.js index 9a5d052e4..5d533372b 100644 --- a/models/rules.js +++ b/models/rules.js @@ -72,14 +72,14 @@ Rules.helpers({ }); Rules.allow({ - async insert(userId, doc) { - return allowIsBoardAdmin(userId, await ReactiveCache.getBoard(doc.boardId)); + insert(userId, doc) { + return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId)); }, - async update(userId, doc) { - return allowIsBoardAdmin(userId, await ReactiveCache.getBoard(doc.boardId)); + update(userId, doc) { + return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId)); }, - async remove(userId, doc) { - return allowIsBoardAdmin(userId, await ReactiveCache.getBoard(doc.boardId)); + remove(userId, doc) { + return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId)); }, }); diff --git a/models/settings.js b/models/settings.js index 04b5ee0e9..00dd1b653 100644 --- a/models/settings.js +++ b/models/settings.js @@ -223,8 +223,8 @@ Settings.helpers({ }, }); Settings.allow({ - async update(userId) { - const user = await ReactiveCache.getUser(userId); + update(userId) { + const user = Meteor.users.findOne(userId); return user && user.isAdmin; }, }); diff --git a/models/swimlanes.js b/models/swimlanes.js index beebaefb6..8b41a0292 100644 --- a/models/swimlanes.js +++ b/models/swimlanes.js @@ -131,17 +131,17 @@ Swimlanes.attachSchema( ); Swimlanes.allow({ - async insert(userId, doc) { + insert(userId, doc) { // ReadOnly and CommentOnly users cannot create swimlanes - return allowIsBoardMemberWithWriteAccess(userId, await ReactiveCache.getBoard(doc.boardId)); + return allowIsBoardMemberWithWriteAccess(userId, Boards.findOne(doc.boardId)); }, - async update(userId, doc) { + update(userId, doc) { // ReadOnly and CommentOnly users cannot edit swimlanes - return allowIsBoardMemberWithWriteAccess(userId, await ReactiveCache.getBoard(doc.boardId)); + return allowIsBoardMemberWithWriteAccess(userId, Boards.findOne(doc.boardId)); }, - async remove(userId, doc) { + remove(userId, doc) { // ReadOnly and CommentOnly users cannot delete swimlanes - return allowIsBoardMemberWithWriteAccess(userId, await ReactiveCache.getBoard(doc.boardId)); + return allowIsBoardMemberWithWriteAccess(userId, Boards.findOne(doc.boardId)); }, fetch: ['boardId'], }); diff --git a/models/tableVisibilityModeSettings.js b/models/tableVisibilityModeSettings.js index e6b10566e..157152783 100644 --- a/models/tableVisibilityModeSettings.js +++ b/models/tableVisibilityModeSettings.js @@ -45,8 +45,8 @@ TableVisibilityModeSettings.attachSchema( ); TableVisibilityModeSettings.allow({ - async update(userId) { - const user = await ReactiveCache.getUser(userId); + update(userId) { + const user = Meteor.users.findOne(userId); return user && user.isAdmin; }, }); diff --git a/models/team.js b/models/team.js index a38f703cd..38f819aba 100644 --- a/models/team.js +++ b/models/team.js @@ -78,8 +78,8 @@ Team.attachSchema( if (Meteor.isServer) { Team.allow({ - async insert(userId, doc) { - const user = await ReactiveCache.getUser(userId) || await ReactiveCache.getCurrentUser(); + insert(userId, doc) { + const user = Meteor.users.findOne(userId); if (user?.isAdmin) return true; if (!user) { @@ -87,8 +87,8 @@ if (Meteor.isServer) { } return doc._id === userId; }, - async update(userId, doc) { - const user = await ReactiveCache.getUser(userId) || await ReactiveCache.getCurrentUser(); + update(userId, doc) { + const user = Meteor.users.findOne(userId); if (user?.isAdmin) return true; if (!user) { @@ -96,8 +96,8 @@ if (Meteor.isServer) { } return doc._id === userId; }, - async remove(userId, doc) { - const user = await ReactiveCache.getUser(userId) || await ReactiveCache.getCurrentUser(); + remove(userId, doc) { + const user = Meteor.users.findOne(userId); if (user?.isAdmin) return true; if (!user) { diff --git a/models/translation.js b/models/translation.js index b71099628..4a12c5389 100644 --- a/models/translation.js +++ b/models/translation.js @@ -58,8 +58,8 @@ Translation.attachSchema( if (Meteor.isServer) { Translation.allow({ - async insert(userId, doc) { - const user = await ReactiveCache.getUser(userId) || await ReactiveCache.getCurrentUser(); + insert(userId, doc) { + const user = Meteor.users.findOne(userId); if (user?.isAdmin) return true; if (!user) { @@ -67,8 +67,8 @@ if (Meteor.isServer) { } return doc._id === userId; }, - async update(userId, doc) { - const user = await ReactiveCache.getUser(userId) || await ReactiveCache.getCurrentUser(); + update(userId, doc) { + const user = Meteor.users.findOne(userId); if (user?.isAdmin) return true; if (!user) { @@ -76,8 +76,8 @@ if (Meteor.isServer) { } return doc._id === userId; }, - async remove(userId, doc) { - const user = await ReactiveCache.getUser(userId) || await ReactiveCache.getCurrentUser(); + remove(userId, doc) { + const user = Meteor.users.findOne(userId); if (user?.isAdmin) return true; if (!user) { diff --git a/models/triggers.js b/models/triggers.js index 8c46ced06..fd8dc045b 100644 --- a/models/triggers.js +++ b/models/triggers.js @@ -14,14 +14,14 @@ Triggers.before.update((userId, doc, fieldNames, modifier) => { }); Triggers.allow({ - async insert(userId, doc) { - return allowIsBoardAdmin(userId, await ReactiveCache.getBoard(doc.boardId)); + insert(userId, doc) { + return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId)); }, - async update(userId, doc) { - return allowIsBoardAdmin(userId, await ReactiveCache.getBoard(doc.boardId)); + update(userId, doc) { + return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId)); }, - async remove(userId, doc) { - return allowIsBoardAdmin(userId, await ReactiveCache.getBoard(doc.boardId)); + remove(userId, doc) { + return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId)); }, }); diff --git a/server/cronMigrationManager.js b/server/cronMigrationManager.js index 3600d2129..7ae295ffb 100644 --- a/server/cronMigrationManager.js +++ b/server/cronMigrationManager.js @@ -1646,8 +1646,8 @@ class CronMigrationManager { SyncedCron.add({ name: step.cronName, schedule: (parser) => parser.text(step.schedule), - job: () => { - this.runMigrationStep(step); + job: async () => { + await this.runMigrationStep(step); }, }); } diff --git a/server/lib/utils.js b/server/lib/utils.js index a19456b1a..d4f5667bb 100644 --- a/server/lib/utils.js +++ b/server/lib/utils.js @@ -27,12 +27,12 @@ allowIsBoardMemberWithWriteAccess = function(userId, board) { // Check if user has write access via a card's board allowIsBoardMemberWithWriteAccessByCard = function(userId, card) { - const board = card && card.board && card.board(); + const board = card && Boards.findOne(card.boardId); return allowIsBoardMemberWithWriteAccess(userId, board); }; allowIsBoardMemberByCard = function(userId, card) { - const board = card.board(); + const board = card && Boards.findOne(card.boardId); return board && board.hasMember(userId); }; diff --git a/server/rulesHelper.js b/server/rulesHelper.js index 47af33fbb..0df49dff1 100644 --- a/server/rulesHelper.js +++ b/server/rulesHelper.js @@ -2,9 +2,9 @@ import { ReactiveCache } from '/imports/reactiveCache'; RulesHelper = { async executeRules(activity) { - const matchingRules = this.findMatchingRules(activity); + const matchingRules = await this.findMatchingRules(activity); for (let i = 0; i < matchingRules.length; i++) { - const action = matchingRules[i].getAction(); + const action = await matchingRules[i].getAction(); if (action !== undefined) { await this.performAction(activity, action); } @@ -19,14 +19,14 @@ RulesHelper = { const matchingMap = await this.buildMatchingFieldsMap(activity, matchingFields); const matchingTriggers = await ReactiveCache.getTriggers(matchingMap); const matchingRules = []; - matchingTriggers.forEach(function(trigger) { - const rule = trigger.getRule(); + for (const trigger of matchingTriggers) { + const rule = await trigger.getRule(); // Check that for some unknown reason there are some leftover triggers // not connected to any rules if (rule !== undefined) { - matchingRules.push(trigger.getRule()); + matchingRules.push(rule); } - }); + } return matchingRules; }, async buildMatchingFieldsMap(activity, matchingFields) { @@ -67,7 +67,7 @@ RulesHelper = { let list; let listId; if (action.listName === '*') { - list = card.list(); + list = await card.list(); if (boardId !== action.boardId) { list = await ReactiveCache.getList({ title: list.title, boardId: action.boardId }); } @@ -110,12 +110,12 @@ RulesHelper = { if (action.actionType === 'moveCardToTop') { const minOrder = _.min( - list.cardsUnfiltered(swimlaneId).map(c => c.sort), + (await list.cardsUnfiltered(swimlaneId)).map(c => c.sort), ); await card.move(action.boardId, swimlaneId, listId, minOrder - 1); } else { const maxOrder = _.max( - list.cardsUnfiltered(swimlaneId).map(c => c.sort), + (await list.cardsUnfiltered(swimlaneId)).map(c => c.sort), ); await card.move(action.boardId, swimlaneId, listId, maxOrder + 1); }