[455] | 1 | module.exports = { |
---|
[464] | 2 | |
---|
[455] | 3 | "_users/qed_admin": { |
---|
| 4 | __configAction: "ignore", |
---|
| 5 | _id: "org.couchdb.user:qed_admin", |
---|
| 6 | name: "qed_admin", |
---|
| 7 | password: "Welkom01", |
---|
| 8 | roles: [ "qed_admin" ], |
---|
| 9 | type: "user" |
---|
| 10 | }, |
---|
[464] | 11 | |
---|
[480] | 12 | "qed/schemaInfo": { |
---|
[508] | 13 | version: "4" |
---|
[480] | 14 | }, |
---|
| 15 | |
---|
[455] | 16 | "qed/_security": { |
---|
| 17 | __configAction: "ignore", |
---|
| 18 | admins: { |
---|
| 19 | names: [], |
---|
| 20 | roles: ["qed_admin"] |
---|
| 21 | }, |
---|
| 22 | readers: { |
---|
| 23 | names: [], |
---|
| 24 | roles: ["qed_user"] |
---|
| 25 | } |
---|
| 26 | }, |
---|
[464] | 27 | |
---|
[516] | 28 | "qed/_design/protectPublished": { |
---|
[455] | 29 | __configAction: "replace", |
---|
[516] | 30 | _id: "_design/protectPublished", |
---|
[455] | 31 | language: "javascript", |
---|
| 32 | validate_doc_update: function(newDoc, oldDoc, userCtx, secObj) { |
---|
[487] | 33 | if ( oldDoc && oldDoc.publicationDate ) { |
---|
| 34 | throw({forbidden:'Published documents cannot be modified.'}); |
---|
| 35 | } |
---|
[516] | 36 | } |
---|
| 37 | }, |
---|
| 38 | |
---|
| 39 | "qed/_design/default": { |
---|
| 40 | __configAction: "replace", |
---|
| 41 | _id: "_design/default", |
---|
| 42 | language: "javascript", |
---|
[455] | 43 | views: { |
---|
| 44 | by_type: { |
---|
| 45 | map: function(doc){ |
---|
| 46 | emit(doc.type, doc); |
---|
| 47 | } |
---|
[477] | 48 | }, |
---|
| 49 | typeless: { |
---|
| 50 | map: function(doc){ |
---|
| 51 | if ( !doc.type ) { |
---|
| 52 | emit(doc._id, doc); |
---|
| 53 | } |
---|
| 54 | } |
---|
[455] | 55 | } |
---|
| 56 | } |
---|
| 57 | }, |
---|
[464] | 58 | |
---|
[455] | 59 | "qed/_design/questions": { |
---|
| 60 | __configAction: "replace", |
---|
| 61 | _id: "_design/questions", |
---|
| 62 | language: "javascript", |
---|
| 63 | views: { |
---|
| 64 | all: { |
---|
| 65 | map: function(doc){ |
---|
| 66 | if ( doc.type !== 'Question' ) { return; } |
---|
| 67 | if ( doc.categories && doc.categories.length > 0 ) { |
---|
| 68 | for ( var i = 0; i < doc.categories.length; i++ ) { |
---|
[487] | 69 | emit([doc.categories[i],doc.topic||"(default)"],1); |
---|
[455] | 70 | } |
---|
| 71 | } else { |
---|
[487] | 72 | emit(["(default)","(default)"],1); |
---|
[455] | 73 | } |
---|
| 74 | }, |
---|
| 75 | reduce: function(keys,values){ return sum(values); } |
---|
| 76 | }, |
---|
| 77 | published: { |
---|
| 78 | map: function(doc){ |
---|
| 79 | if ( doc.type!=='Question' || !doc.publicationDate ) { return; } |
---|
| 80 | if ( doc.categories && doc.categories.length > 0 ) { |
---|
| 81 | for ( var i = 0; i < doc.categories.length; i++ ) { |
---|
[487] | 82 | emit([doc.categories[i],doc.topic||"(default)"],1); |
---|
[455] | 83 | } |
---|
| 84 | } else { |
---|
[487] | 85 | emit(["(default)","(default)"],1); |
---|
[455] | 86 | } |
---|
| 87 | }, |
---|
| 88 | reduce: function(keys,values){ return sum(values); } |
---|
| 89 | }, |
---|
| 90 | all_topics: { |
---|
| 91 | map: function(doc){ |
---|
| 92 | if( doc.type !== 'Question' ){ return; } |
---|
[487] | 93 | emit(doc.topic||"(default)",1); |
---|
[455] | 94 | }, |
---|
[487] | 95 | reduce: function(key, values, rereduce) { return sum(values); } |
---|
[455] | 96 | }, |
---|
| 97 | published_topics: { |
---|
| 98 | map: function(doc){ |
---|
| 99 | if ( doc.type !== 'Question' || !doc.publicationDate ) { return; } |
---|
[487] | 100 | emit(doc.topic||"(default)",1); |
---|
[455] | 101 | }, |
---|
[487] | 102 | reduce: function(key, values, rereduce) { return sum(values); } |
---|
| 103 | }, |
---|
[501] | 104 | all_by_code: { |
---|
[487] | 105 | map: function(doc){ |
---|
| 106 | if ( doc.type !== 'Question' ) { return; } |
---|
| 107 | emit(doc.code,doc); |
---|
| 108 | } |
---|
[501] | 109 | }, |
---|
| 110 | published_by_code: { |
---|
| 111 | map: function(doc){ |
---|
| 112 | if ( doc.type !== 'Question' || !doc.publicationDate ) { return; } |
---|
| 113 | emit(doc.code,doc); |
---|
| 114 | } |
---|
[455] | 115 | } |
---|
| 116 | } |
---|
| 117 | }, |
---|
[464] | 118 | |
---|
[455] | 119 | "qed/_design/surveys": { |
---|
| 120 | __configAction: "replace", |
---|
| 121 | _id: "_design/surveys", |
---|
| 122 | language: "javascript", |
---|
| 123 | views: { |
---|
| 124 | drafts: { |
---|
| 125 | map: function(doc){ |
---|
| 126 | if ( doc.type !== 'Survey' || doc.publicationDate ) { return; } |
---|
| 127 | emit(doc._id,doc); |
---|
| 128 | } |
---|
| 129 | }, |
---|
| 130 | published: { |
---|
| 131 | map: function(doc){ |
---|
| 132 | if ( doc.type !== 'Survey' || !doc.publicationDate ) { return; } |
---|
| 133 | emit(doc._id,doc); |
---|
| 134 | } |
---|
| 135 | } |
---|
| 136 | } |
---|
| 137 | }, |
---|
[464] | 138 | |
---|
[492] | 139 | "qed/_design/surveyRuns": { |
---|
| 140 | __configAction: "replace", |
---|
| 141 | _id: "_design/surveys", |
---|
| 142 | language: "javascript", |
---|
| 143 | views: { |
---|
| 144 | by_dates: { |
---|
| 145 | map: function(doc){ |
---|
| 146 | if ( doc.type !== 'SurveyRun' ) { return; } |
---|
| 147 | var startDate = doc.startDate || ""; |
---|
| 148 | var endDate = doc.endDate || {}; |
---|
| 149 | emit([startDate,endDate,doc.liveName||null],doc); |
---|
| 150 | } |
---|
| 151 | } |
---|
| 152 | } |
---|
| 153 | }, |
---|
| 154 | |
---|
[455] | 155 | "qed/_design/responses": { |
---|
| 156 | __configAction: "replace", |
---|
| 157 | _id: "_design/responses", |
---|
| 158 | language: "javascript", |
---|
| 159 | views: { |
---|
| 160 | by_surveyrun: { |
---|
| 161 | map: function(doc){ |
---|
| 162 | if ( doc.type !== 'Response' ) { return; } |
---|
| 163 | emit(doc.surveyRunId, doc); |
---|
| 164 | } |
---|
| 165 | } |
---|
| 166 | } |
---|
| 167 | } |
---|
[464] | 168 | |
---|
[455] | 169 | }; |
---|