summaryrefslogtreecommitdiffstats
path: root/models/rules.js
blob: 7d97198041ff59cb5f44f815a6d640fc7aab9df3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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,
  },
}));

Rules.mutations({
  rename(description) {
    return { $set: { description } };
  },
});

Rules.helpers({
  getAction(){
    return Actions.findOne({_id:this.actionId});
  },
  getTrigger(){
    return Triggers.findOne({_id:this.triggerId});
  },
});


Rules.allow({
  insert(userId, doc) {
    return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
  },
  update(userId, doc) {
    return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
  },
  remove(userId, doc) {
    return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
  },
});