1 function(newDoc, oldDoc, userCtx)
3 function require(doc, field, message)
5 message = message || "Document must have a " + field;
6 if (doc[field] == void 0 || doc[field] == null || doc[field].length == 0)
8 throw({forbidden: message});
12 function check(cond, message)
14 message = message || "Condition check failed";
17 throw({forbidden: message});
21 function checkPodcast(podcast)
23 last_timestamp = null;
24 if(podcast.subscribers)
26 for(var i=0, len=podcast.subscribers.length; sub=podcast.subscribers[i], i<len; i++)
28 check((last_timestamp == null) || (last_timestamp < sub.timestamp), "Subscriber Data must be sorted");
29 last_timestamp = sub.timestamp;
34 if(newDoc.doc_type == "PodcastGroup")
36 for(var n=0, len=newDoc.podcasts.length; podcast=newDoc.podcasts[n], n<len; n++)
40 oldpodcast = oldDoc.podcasts[n];
47 require(podcast, "id");
48 require(podcast, "group");
49 check(podcast.group == newDoc._id);
50 checkPodcast(podcast);
53 else if(newDoc.doc_type == "Podcast")