rules.js 871 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. Rules = new Mongo.Collection('rules');
  2. Rules.attachSchema(new SimpleSchema({
  3. title: {
  4. type: String,
  5. optional: false,
  6. },
  7. triggerId: {
  8. type: String,
  9. optional: false,
  10. },
  11. actionId: {
  12. type: String,
  13. optional: false,
  14. },
  15. boardId: {
  16. type: String,
  17. optional: false,
  18. },
  19. }));
  20. Rules.mutations({
  21. rename(description) {
  22. return { $set: { description } };
  23. },
  24. });
  25. Rules.helpers({
  26. getAction(){
  27. return Actions.findOne({_id:this.actionId});
  28. },
  29. getTrigger(){
  30. return Triggers.findOne({_id:this.triggerId});
  31. }
  32. });
  33. Rules.allow({
  34. insert(userId, doc) {
  35. return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
  36. },
  37. update(userId, doc) {
  38. return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
  39. },
  40. remove(userId, doc) {
  41. return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
  42. }
  43. });