Files
wekan/models/rules.js
T
Harry Adel 2e3fbf25db Meteor 3.4 migration: Convert allow/deny callbacks to async
Meteor 3.x supports async allow/deny callbacks. Convert all 25 sync
allow/deny callbacks across 23 model files to use async/await with
findOneAsync/fetchAsync instead of sync findOne/find().fetch().

Also converts helper functions in server/lib/utils.js:
- allowIsBoardMemberWithWriteAccessByCard -> async
- allowIsBoardMemberByCard -> async
- canUpdateCard (cards.js) -> async
- permissionHelper.allow (integrations.js) -> async
2026-03-22 17:44:29 +02:00

93 lines
2.0 KiB
JavaScript

import { ReactiveCache } from '/imports/reactiveCache';
import { Meteor } from 'meteor/meteor';
Rules = new Mongo.Collection('rules');
Rules.attachSchema(
new SimpleSchema({
title: {
type: String,
optional: false,
},
triggerId: {
type: String,
optional: false,
},
actionId: {
type: String,
optional: false,
},
boardId: {
type: String,
optional: false,
},
createdAt: {
type: Date,
optional: true,
// eslint-disable-next-line consistent-return
autoValue() {
if (this.isInsert) {
return new Date();
} else if (this.isUpsert) {
return { $setOnInsert: new Date() };
} else {
this.unset();
}
},
},
modifiedAt: {
type: Date,
denyUpdate: false,
// eslint-disable-next-line consistent-return
autoValue() {
if (this.isInsert || this.isUpsert || this.isUpdate) {
return new Date();
} else {
this.unset();
}
},
},
}),
);
Rules.helpers({
async rename(description) {
return await Rules.updateAsync(this._id, { $set: { description } });
},
getAction() {
return ReactiveCache.getAction(this.actionId);
},
getTrigger() {
return ReactiveCache.getTrigger(this.triggerId);
},
board() {
return ReactiveCache.getBoard(this.boardId);
},
trigger() {
return ReactiveCache.getTrigger(this.triggerId);
},
action() {
return ReactiveCache.getAction(this.actionId);
},
});
Rules.allow({
async insert(userId, doc) {
return allowIsBoardAdmin(userId, await Boards.findOneAsync(doc.boardId));
},
async update(userId, doc) {
return allowIsBoardAdmin(userId, await Boards.findOneAsync(doc.boardId));
},
async remove(userId, doc) {
return allowIsBoardAdmin(userId, await Boards.findOneAsync(doc.boardId));
},
});
if (Meteor.isServer) {
Meteor.startup(async () => {
await Rules._collection.createIndexAsync({ modifiedAt: -1 });
});
}
export default Rules;