2019-06-26 17:47:27 -05:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
|
2018-08-03 19:47:20 +02:00
|
|
|
Rules = new Mongo.Collection('rules');
|
|
|
|
|
2019-06-26 17:47:27 -05:00
|
|
|
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 {
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2019-06-28 12:52:09 -05:00
|
|
|
}),
|
2019-06-26 17:47:27 -05:00
|
|
|
);
|
2018-08-03 19:47:20 +02:00
|
|
|
|
|
|
|
Rules.mutations({
|
|
|
|
rename(description) {
|
|
|
|
return { $set: { description } };
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2018-08-16 00:32:31 +02:00
|
|
|
Rules.helpers({
|
2019-06-26 17:47:27 -05:00
|
|
|
getAction() {
|
|
|
|
return Actions.findOne({ _id: this.actionId });
|
2018-08-16 00:32:31 +02:00
|
|
|
},
|
2019-06-26 17:47:27 -05:00
|
|
|
getTrigger() {
|
|
|
|
return Triggers.findOne({ _id: this.triggerId });
|
2018-09-16 01:50:36 +03:00
|
|
|
},
|
2018-08-16 00:32:31 +02:00
|
|
|
});
|
2018-08-03 20:43:37 +02:00
|
|
|
|
2018-08-03 19:47:20 +02:00
|
|
|
Rules.allow({
|
2018-09-12 00:52:29 +02:00
|
|
|
insert(userId, doc) {
|
|
|
|
return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
|
2018-08-03 19:47:20 +02:00
|
|
|
},
|
2018-09-12 00:52:29 +02:00
|
|
|
update(userId, doc) {
|
|
|
|
return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
|
2018-08-03 20:43:37 +02:00
|
|
|
},
|
2018-09-12 00:52:29 +02:00
|
|
|
remove(userId, doc) {
|
|
|
|
return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
|
2018-09-16 01:50:36 +03:00
|
|
|
},
|
2018-08-03 19:47:20 +02:00
|
|
|
});
|
2019-06-26 17:47:27 -05:00
|
|
|
|
|
|
|
if (Meteor.isServer) {
|
|
|
|
Meteor.startup(() => {
|
|
|
|
Rules._collection._ensureIndex({ modifiedAt: -1 });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Rules;
|