-
Notifications
You must be signed in to change notification settings - Fork 2
/
stickies.js
executable file
·141 lines (139 loc) · 3.8 KB
/
stickies.js
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
Stickies = new Mongo.Collection('stickies');
Stickies.allow({
insert: scrumTeam,
update: scrumTeam,
remove: scrumTeam
});
Stickies.attachSchema(new SimpleSchema({
title: {
type: String,
label: "Title",
max: 20,
autoform: {
placeholder: "Name your sticky."
}
},
description: {
type: String,
label: "Description",
max: 50,
autoform: {
placeholder: "A clear and concise statement of work to do."
}
},
effort: {
type: Number,
label: "Effort (h)",
allowedValues: [2, 4, 6, 8]
},
storyId: {
type: String,
autoform: {
omit: true
}
},
status: {
type: Number,
allowedValues: [1, 2, 3, 4],
autoform: {
omit: true
},
autoValue: function () {
if (this.isInsert) {
if (!this.isFromTrustedCode) {
return 1;
}
}
}
},
assigneeId: {
type: String,
label: "Assignee",
optional: true,
autoform: {
options: function () {
/* Find corresponding product. */
let product = Products.findOne({slug: getRouteSlug()});
/* Get array with user IDs which have an invitation for the current product and accepted the invitation. */
if (product) {
let userIds = Invitations.find({
productId: product._id,
status: 1
}).map((invitation) => invitation.userId);
/* We add the current user's id to the array, because users can assign stickies to themselves. */
userIds.push(Meteor.userId());
/* Return all users as options which accepted an invitation incl. our own user ID. */
return Users.find({_id: {$in: userIds}}).map((user) => ({
label: user.username,
value: user._id
}));
}
}
}
},
userId: {
type: String,
autoValue: function () {
if (this.isInsert) {
if (!this.isFromTrustedCode) {
return this.userId;
}
} else
/* Prevent user from supplying their own user ID. */
this.unset();
},
denyUpdate: true,
autoform: {
omit: true
}
},
lastEditedBy: {
type: String,
autoValue: function () {
if (this.isUpdate) {
return this.userId;
} else
/* Prevent user from supplying their own user ID. */
this.unset();
},
denyInsert: true,
optional: true,
autoform: {
omit: true
}
},
lastMovedBy: {
type: String,
denyInsert: true,
optional: true,
autoform: {
omit: true
}
},
createdAt: {
type: Date,
autoValue: function () {
if (this.isInsert) return new Date;
else if (this.isUpsert) return {$setOnInsert: new Date};
else
/* Prevent user from supplying their own date. */
this.unset();
},
autoform: {
omit: true
}
},
updatedAt: {
type: Date,
autoValue: function () {
if (this.isInsert || this.isUpdate) return new Date;
else if (this.isUpsert) return {$setOnInsert: new Date};
else
/* Prevent user from supplying their own date. */
this.unset();
},
autoform: {
omit: true
}
}
}));