-
Notifications
You must be signed in to change notification settings - Fork 1
/
validate_doc_update.js
38 lines (32 loc) · 1.21 KB
/
validate_doc_update.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
function(newDoc, oldDoc, userCtx) {
var version = require('views/lib/version').fn(newDoc._id);
if (!userCtx || userCtx.roles.indexOf('builds-admin') === -1) {
throw({ forbidden: 'Invalid user' });
}
if (!version) {
throw({ forbidden: 'Document _id format invalid' });
}
if (newDoc._deleted) {
if (version.branch || version.pre) {
// You are allowed to delete branches, alphas, and betas.
// Don't worry worry about validating anything.
return;
}
// You're not allowed to delete anything else (eg: final releases)
throw({ forbidden: 'You are not allowed to delete releases' });
}
var meta = newDoc.build_info;
if (meta) {
if (meta.schema_version !== 1) {
throw({ forbidden: 'Incompatible schema_version'});
}
if (!(meta.application && meta.namespace && meta.version && meta.time && meta.author && meta.node_modules) ) {
throw({ forbidden: 'You must have a complete build_info property' });
}
} else if (!newDoc.kanso) {
throw({ forbidden: 'neither legacy kanso property nor build_info property exist'});
}
if (!version.branch && oldDoc) {
throw({ forbidden: 'You are not allowed to overwrite existing releases or pre-releases' });
}
}