Mercurial > psgxs
comparison modules/mod_owner.js @ 24:b80ab94da447
Add new modules files.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Mon, 01 Nov 2010 00:02:27 +0100 |
parents | |
children | b2faacfefb90 |
comparison
equal
deleted
inserted
replaced
23:5fc4ee90c1bc | 24:b80ab94da447 |
---|---|
1 var config = require('../configuration'); | |
2 var storage = require('../storage'); | |
3 var forms = require('../forms'); | |
4 var notifs = require('../notifs'); | |
5 var errors = require('../errors'); | |
6 var makeError = errors.makeError; | |
7 var toBareJID = require('../util').toBareJID; | |
8 var NS = require('../namespaces'); | |
9 | |
10 // SECTION 8.1: Create a Node | |
11 exports.getConfigure = { | |
12 type: 'set', | |
13 child: 'pubsub', | |
14 ns: NS.PUBSUB, | |
15 pschild: 'create', | |
16 func: function(response, stanza, request, to) { | |
17 if (!config.enabled('create-nodes')) | |
18 return makeError(response, errors.owner.create.node_creation_not_supported.n); | |
19 | |
20 var instant = false; | |
21 | |
22 var nodeID = request.getAttribute('node'); | |
23 if (!nodeID || nodeID == '') { | |
24 if (!config.enabled('instant-nodes')) | |
25 return makeError(response, errors.owner.create.instant_nodes_not_supported.n); | |
26 nodeID = utils.makeRandomId(); | |
27 instant = true; | |
28 } | |
29 if (storage.existsNode(nodeID)) | |
30 return makeError(response, errors.owner.create.nodeid_already_exists.n); | |
31 | |
32 var bare = toBareJID(to); | |
33 var right = false; | |
34 | |
35 // Check for super-owner | |
36 for (var i in config.owner) | |
37 if (config.owner[i] == bare) | |
38 right = true; | |
39 | |
40 // Check for authorized user | |
41 for (var i in config.allowCreateNode) | |
42 if (config.allowCreateNode[i].exec(bare)) | |
43 right = true; | |
44 | |
45 if (!right) | |
46 return makeError(response, errors.forbidden.n); | |
47 | |
48 var r = storage.createNode(nodeID); | |
49 if (typeof r == 'number') | |
50 return makeError(response, r); | |
51 | |
52 if (instant) | |
53 response.c('pubsub', {xmlns: NS.PUBSUB}) | |
54 .c('create', {node: nodeID}); | |
55 | |
56 return response; | |
57 } | |
58 } | |
59 | |
60 // SECTION 8.4: Delete a Node | |
61 exports['delete'] = { | |
62 type: 'set', | |
63 child: 'pubsub', | |
64 ns: NS.PUBSUB_OWNER, | |
65 pschild: 'delete', | |
66 func: function(response, stanza, request, to) { | |
67 if (!config.enabled('delete-nodes')) | |
68 return makeError(response, errors.feature_not_implemented.n); //XXX | |
69 | |
70 var nodeID = request.getAttribute('node'); | |
71 if (!nodeID) | |
72 return makeError(response, errors.nodeid_required.n); | |
73 if (!storage.existsNode(nodeID)) | |
74 return makeError(response, errors.node_does_not_exist.n); | |
75 | |
76 var affil = storage.getAffiliation(toBareJID(to), nodeID); | |
77 if (affil != 'super-owner' && affil != 'owner') | |
78 return makeError(response, errors.forbidden.n); | |
79 | |
80 var notifs = storage.deleteNode(nodeID); | |
81 if (typeof notifs == 'number') | |
82 return makeError(response, r); | |
83 | |
84 notifs.send(notifs, 'delete', nodeID); | |
85 | |
86 return response; | |
87 } | |
88 } | |
89 | |
90 // SECTION 8.5: Purge All Node Items | |
91 exports.purge = { | |
92 type: 'set', | |
93 child: 'pubsub', | |
94 ns: NS.PUBSUB_OWNER, | |
95 pschild: 'purge', | |
96 func: function(response, stanza, request, to) { | |
97 if (!config.enabled('purge-nodes')) | |
98 return makeError(response, errors.owner.purge.node_purging_not_supported.n); //XXX | |
99 | |
100 var nodeID = request.getAttribute('node'); | |
101 if (!nodeID) | |
102 return makeError(response, errors.nodeid_required.n); | |
103 if (!storage.existsNode(nodeID)) | |
104 return makeError(response, errors.node_does_not_exist.n); | |
105 | |
106 var affil = storage.getAffiliation(toBareJID(to), nodeID); | |
107 if (affil != 'super-owner' && affil != 'owner') | |
108 return makeError(response, errors.forbidden.n); | |
109 | |
110 if (!config.enabled('persistent-items')) //FIXME: autre condition, supporté par le node | |
111 return makeError(response, errors.owner.purge.node_does_not_persist_items.n); | |
112 | |
113 var notifs = storage.purgeNode(nodeID); | |
114 if (typeof notifs == 'number') | |
115 return makeError(response, r); | |
116 | |
117 notifs.send(notifs, 'purge', nodeID); | |
118 | |
119 return response; | |
120 } | |
121 } |