forked from couchone/pages
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathvalidate_doc_update.js
More file actions
29 lines (25 loc) · 808 Bytes
/
validate_doc_update.js
File metadata and controls
29 lines (25 loc) · 808 Bytes
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
function (newDoc, oldDoc, userCtx, secObj) {
var v = require("vendor/couchapp/lib/validate").init(newDoc, oldDoc, userCtx, secObj);
if (v.isAdmin()) {
return true; // admin can do anything
}
if (!userCtx.name) {
// this could be configurable based on secObj
v.unauthorized("please login to make changes");
}
// only admin may delete
if (newDoc._deleted) {
v.unauthorized("only admin may delete docs");
}
// attached versions must be preserved
if (oldDoc && oldDoc._attachments) {
for (var n in oldDoc._attachments) {
if (n.indexOf("rev") == 0) {
if (!(newDoc._attachments && newDoc._attachments[n]
&& newDoc._attachments[n].stub === true)) {
v.forbidden("old versions may not be deleted")
}
}
}
}
}