2023-01-14 13:29:57 +01:00
|
|
|
import { ReactiveCache } from '/imports/reactiveCache';
|
2021-03-03 15:23:43 +02:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
|
2018-08-15 18:47:09 +02:00
|
|
|
Actions = new Mongo.Collection('actions');
|
|
|
|
|
|
|
|
Actions.allow({
|
2018-09-16 01:50:36 +03:00
|
|
|
insert(userId, doc) {
|
2023-01-14 13:29:57 +01:00
|
|
|
return allowIsBoardAdmin(userId, ReactiveCache.getBoard(doc.boardId));
|
2018-09-16 01:50:36 +03:00
|
|
|
},
|
|
|
|
update(userId, doc) {
|
2023-01-14 13:29:57 +01:00
|
|
|
return allowIsBoardAdmin(userId, ReactiveCache.getBoard(doc.boardId));
|
2018-09-16 01:50:36 +03:00
|
|
|
},
|
|
|
|
remove(userId, doc) {
|
2023-01-14 13:29:57 +01:00
|
|
|
return allowIsBoardAdmin(userId, ReactiveCache.getBoard(doc.boardId));
|
2018-09-16 01:50:36 +03:00
|
|
|
},
|
2018-09-14 16:49:06 +02:00
|
|
|
});
|
|
|
|
|
2019-09-05 12:29:45 -05:00
|
|
|
Actions.before.insert((userId, doc) => {
|
|
|
|
doc.createdAt = new Date();
|
|
|
|
doc.modifiedAt = doc.createdAt;
|
|
|
|
});
|
|
|
|
|
|
|
|
Actions.before.update((userId, doc, fieldNames, modifier) => {
|
|
|
|
modifier.$set = modifier.$set || {};
|
|
|
|
modifier.$set.modifiedAt = new Date();
|
|
|
|
});
|
|
|
|
|
2018-09-14 16:49:06 +02:00
|
|
|
Actions.helpers({
|
2018-09-16 01:50:36 +03:00
|
|
|
description() {
|
|
|
|
return this.desc;
|
|
|
|
},
|
|
|
|
});
|
2019-06-26 17:47:27 -05:00
|
|
|
|
|
|
|
if (Meteor.isServer) {
|
|
|
|
Meteor.startup(() => {
|
2021-10-09 15:56:16 +03:00
|
|
|
Actions._collection.createIndex({ modifiedAt: -1 });
|
2019-06-26 17:47:27 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Actions;
|