actions.js 758 B

12345678910111213141516171819202122232425262728293031323334
  1. import { Meteor } from 'meteor/meteor';
  2. Actions = new Mongo.Collection('actions');
  3. Actions.allow({
  4. insert(userId, doc) {
  5. return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
  6. },
  7. update(userId, doc) {
  8. return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
  9. },
  10. remove(userId, doc) {
  11. return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
  12. },
  13. });
  14. Actions.helpers({
  15. description() {
  16. return this.desc;
  17. },
  18. });
  19. Actions.before.update((userId, doc, fieldNames, modifier, options) => {
  20. modifier.$set = modifier.$set || {};
  21. modifier.$set.modifiedAt = Date.now();
  22. });
  23. if (Meteor.isServer) {
  24. Meteor.startup(() => {
  25. Actions._collection._ensureIndex({ modifiedAt: -1 });
  26. });
  27. }
  28. export default Actions;