-
Notifications
You must be signed in to change notification settings - Fork 10
/
schema.js
473 lines (438 loc) · 9.88 KB
/
schema.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
/*
Posts schema
*/
import Users from "meteor/vulcan:users";
import { Utils, makeAutocomplete } from "meteor/vulcan:core";
import marked from "marked";
import { postStatusOptions } from "../data.js";
import { removeAtSymbol, getDefaultStatus } from "./helpers.js";
import get from "lodash/get";
import UrlInput from "../../components/posts/UrlInput";
import ScheduledAtInput from "../../components/posts/ScheduledAtInput";
const isOwnerOrAdmin = (user, document) =>
Users.owns(user, document) || Users.isAdmin(user);
const formGroups = {
sponsorship: {
name: "sponsorship",
order: 2,
},
admin: {
name: "admin",
order: 3,
},
};
/**
* @summary Posts schema
* @type {Object}
*/
export const schema = {
/*
ID
*/
_id: {
type: String,
optional: true,
canRead: ["guests"],
},
/*
Timetstamp of post creation
*/
createdAt: {
type: Date,
description: "Timetstamp of post creation",
optional: true,
canRead: ["guests"],
orderable: true,
onCreate: () => {
return new Date();
},
},
/*
Timestamp of post being actually published
*/
postedAt: {
type: Date,
description:
"Timestamp of post first appearing on the site (i.e. being approved)",
optional: true,
canRead: ["guests"],
// canCreate: ["admins"],
canUpdate: ["admins"],
input: "datetime",
sortable: true,
group: formGroups.admin,
onCreate: ({ data }) =>
data.scheduledAt ? data.scheduledAt : new Date(),
},
/**
Used to keep track of when a sponsor would like a post to be published
*/
scheduledAt: {
type: Date,
optional: true,
canRead: ["owners", "admins"],
canCreate: ["members", "admins"],
canUpdate: ["owners", "admins"],
input: ScheduledAtInput,
label: "Scheduled For",
query: `
query AvailableDatesQuery {
availableSponsorshipDates{
value
label
}
}
`,
options: (props) => get(props, "data.availableSponsorshipDates", []),
order: 50,
description:
"Note: if no date displayed here works for you, please pick the closest suitable date and contact us afterwards to change it to your desired date.",
},
/**
Used to keep track of when a post has been included in a newsletter
*/
sentAt: {
type: Date,
optional: true,
canRead: ["admins"],
canCreate: ["admins"],
canUpdate: ["admins"],
group: formGroups.admin,
},
/**
URL
*/
url: {
type: String,
optional: false,
max: 200,
canRead: ["guests"],
canCreate: ["members"],
canUpdate: ["owners", "admins"],
input: UrlInput,
label: "URL",
order: 10,
searchable: true,
},
domain: {
type: String,
optional: true,
canRead: ["guests"],
onCreate: ({ data }) => data.url && Utils.getDomain(data.url),
onUpdate: ({ data }) => data.url && Utils.getDomain(data.url),
},
/**
Title
*/
title: {
type: String,
optional: false,
max: 80,
canRead: ["guests"],
canCreate: ["members"],
canUpdate: ["owners", "admins"],
input: "text",
order: 20,
searchable: true,
},
/**
Credit
*/
credit: {
type: String,
optional: true,
max: 20,
canRead: ["guests"],
canCreate: ["members"],
canUpdate: ["owners", "admins"],
input: "text",
order: 35,
searchable: true,
onCreate: ({ data }) => data.credit && removeAtSymbol(data.credit),
onUpdate: ({ data }) => data.credit && removeAtSymbol(data.credit),
description:
"The Twitter username of the individual (or organization) that will receive credit for the resource being linked to.",
},
twitterName: {
type: String,
optional: true,
canRead: ["guests"],
description: "The full Twitter display name of the credited user",
},
twitterAvatarUrl: {
type: String,
optional: true,
canRead: ["guests"],
description: "The Twitter avatar URL of the credited user",
},
/**
Slug
*/
slug: {
type: String,
optional: true,
canRead: ["guests"],
onCreate: ({ data }) => {
return Utils.slugify(data.title);
},
onUpdate: ({ data }) => {
if (data.title) {
return Utils.slugify(data.title);
}
},
},
/**
Post body (markdown)
*/
body: {
type: String,
optional: false,
max: 150,
canRead: ["guests"],
canCreate: ["members"],
canUpdate: ["owners", "admins"],
input: "textarea",
description: "Markdown accepted.",
order: 30,
},
/**
HTML version of the post body
*/
htmlBody: {
type: String,
optional: true,
canRead: ["guests"],
onCreate: ({ data }) => {
if (data.body) {
return Utils.sanitize(marked(data.body));
}
},
onUpdate: ({ data }) => {
if (data.body) {
return Utils.sanitize(marked(data.body));
}
},
},
// /**
// Post Excerpt
// */
// excerpt: {
// type: String,
// optional: true,
// canRead: ['guests'],
// searchable: true,
// onCreate: ({document: post}) => {
// if (post.body) {
// return Utils.trimHTML(Utils.sanitize(marked(post.body)), excerptLength);
// }
// },
// onUpdate: ({ data }) => {
// if (data.body) {
// return Utils.trimHTML(
// Utils.sanitize(marked(data.body)),
// excerptLength
// );
// }
// },
// },
/**
Count of how many times the post's link was clicked
*/
clickCount: {
type: Number,
optional: true,
canRead: ["admins"],
defaultValue: 0,
sortable: true,
},
/**
The post's status.
*/
status: {
type: Number,
optional: true,
canRead: ["guests"],
canCreate: ["admins"],
canUpdate: ["admins"],
input: "radiogroup",
onCreate: ({ data, currentUser }) =>
getDefaultStatus(data, currentUser),
options: postStatusOptions,
group: formGroups.admin,
},
/**
Whether a post is scheduled in the future or not
*/
isFuture: {
type: Boolean,
optional: true,
canRead: ["guests"],
onCreate: ({ data }) => {
// Set the post's isFuture to true if necessary
if (data.postedAt) {
const postTime = new Date(data.postedAt).getTime();
const currentTime = new Date().getTime() + 1000;
return postTime > currentTime; // round up to the second
}
},
onUpdate: ({ data, document: post }) => {
// Set the post's isFuture to true if necessary
if (data.postedAt) {
const postTime = new Date(data.postedAt).getTime();
const currentTime = new Date().getTime() + 1000;
if (postTime > currentTime) {
// if a post's postedAt date is in the future, set isFuture to true
return true;
} else if (post.isFuture) {
// else if a post has isFuture to true but its date is in the past, set isFuture to false
return false;
}
}
},
},
/**
Save info for later spam checking on a post. We will use this for the akismet package
*/
userIP: {
type: String,
optional: true,
canRead: ["admins"],
},
userAgent: {
type: String,
optional: true,
canRead: ["admins"],
},
referrer: {
type: String,
optional: true,
canRead: ["admins"],
},
/**
The post author's `_id`.
*/
userId: makeAutocomplete(
{
type: String,
optional: true,
input: "select",
canRead: ["guests"],
canCreate: ["admins"],
canUpdate: ["admins"],
relation: {
fieldName: "user",
typeName: "User",
kind: "hasOne",
},
},
{ autocompletePropertyName: "displayName" }
),
newsletters: {
type: Object,
optional: true,
canRead: ["guests"],
// see server field definition
},
shortTitle: {
type: String,
optional: true,
canCreate: ["admins"],
canUpdate: ["admins"],
canRead: ["guests"],
group: formGroups.admin,
input: "text",
},
categoriesIds: makeAutocomplete(
{
type: Array,
arrayItem: {
type: String,
optional: true,
},
label: "Categories",
optional: true,
canCreate: ["members"],
canUpdate: ["owners", "admins"],
canRead: ["guests"],
relation: {
fieldName: "categories",
typeName: "[Category]",
kind: "hasMany",
},
order: 45,
description: "You can pick up to three categories.",
},
{ autocompletePropertyName: "name" }
),
/*
Sponsorships
*/
isSponsored: {
type: Boolean,
input: "checkbox",
optional: true,
defaultValue: false,
canCreate: ["members"],
canUpdate: ["admins"],
canRead: ["guests"],
group: formGroups.sponsorship,
// defaultValue doesn't seem to work with "false" so use onCreate instead
onCreate: ({ data }) => data.isSponsored || false,
},
discountCode: {
type: String,
label: "Discount Code",
optional: true,
canCreate: ["members"],
canUpdate: ["admins"],
canRead: isOwnerOrAdmin,
input: "statictext",
group: formGroups.sponsorship,
},
discountAmount: {
type: String,
label: "Discount Amount",
optional: true,
canRead: isOwnerOrAdmin,
canUpdate: ["admins"],
group: formGroups.sponsorship,
},
sponsorshipPrice: {
type: Number,
optional: true,
canRead: isOwnerOrAdmin,
canCreate: ["admins"],
canUpdate: ["admins"],
group: formGroups.sponsorship,
},
paidAt: {
type: Date,
optional: true,
canRead: isOwnerOrAdmin,
canUpdate: ["admins"],
input: "datetime",
group: formGroups.sponsorship,
},
tweetedAt: {
type: Date,
optional: true,
},
chargeIds: {
type: Array,
arrayItem: {
type: String,
optional: true,
},
optional: true,
},
webringSiteId: {
type: String,
optional: true,
canRead: ["guests"],
relation: {
fieldName: "webringSite",
typeName: "WebringSite",
kind: "hasOne",
}
}
};