Mercurial > psgxs
comparison modules/mod_configure.js @ 30:b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 04 Nov 2010 17:50:52 +0100 |
parents | b80ab94da447 |
children | 6697f394301f |
comparison
equal
deleted
inserted
replaced
29:e007a6364bf0 | 30:b2faacfefb90 |
---|---|
9 // SECTION 8.2: Configure a Node | 9 // SECTION 8.2: Configure a Node |
10 exports.getConfigure = { | 10 exports.getConfigure = { |
11 type: 'get', | 11 type: 'get', |
12 child: 'pubsub', | 12 child: 'pubsub', |
13 ns: NS.PUBSUB_OWNER, | 13 ns: NS.PUBSUB_OWNER, |
14 pschild: 'configure', | 14 child2: 'configure', |
15 func: function(response, stanza, request, to) { | 15 func: function(response, stanza, request, to) { |
16 if (!config.enabled('config-node')) | 16 if (!config.enabled('config-node')) |
17 return makeError(response, errors.owner.configure.node_configuration_not_supported.n); | 17 return makeError(response, errors.owner.configure.node_configuration_not_supported.n); |
18 | 18 |
19 var nodeID = request.getAttribute('node'); | 19 var nodeID = request.getAttribute('node'); |
24 | 24 |
25 var affil = storage.getAffiliation(toBareJID(to), nodeID); | 25 var affil = storage.getAffiliation(toBareJID(to), nodeID); |
26 if (affil != 'super-owner' && affil != 'owner' && affil != 'publish-only') | 26 if (affil != 'super-owner' && affil != 'owner' && affil != 'publish-only') |
27 return makeError(response, errors.pub.publish.insufficient_privileges.n); | 27 return makeError(response, errors.pub.publish.insufficient_privileges.n); |
28 | 28 |
29 var conf = storage.getConfiguration(nodeID); | |
30 if (!conf) | |
31 return makeError(response, 42); // FIXME | |
32 | |
29 response.c('pubsub', {xmlns: NS.PUBSUB_OWNER}); | 33 response.c('pubsub', {xmlns: NS.PUBSUB_OWNER}); |
30 response.c('configure', {node: nodeID}); | 34 response.c('configure', {node: nodeID}); |
31 | 35 |
32 var form = forms.build('form', 'node_config', 'default', true); | 36 var form = forms.build('form', 'node_config', conf, true); |
33 response.cnode(form); | 37 response.cnode(form); |
34 | 38 |
35 return response; | 39 return response; |
36 } | 40 } |
37 } | 41 } |
39 // SECTION 8.3: Request Default Node Configuration Options | 43 // SECTION 8.3: Request Default Node Configuration Options |
40 exports.default = { | 44 exports.default = { |
41 type: 'get', | 45 type: 'get', |
42 child: 'pubsub', | 46 child: 'pubsub', |
43 ns: NS.PUBSUB_OWNER, | 47 ns: NS.PUBSUB_OWNER, |
44 pschild: 'default', | 48 child2: 'default', |
45 func: function(response) { | 49 func: function(response) { |
46 if (!config.enabled('config-node')) | 50 if (!config.enabled('config-node')) |
47 return makeError(response, errors.owner.default_options.node_configuration_not_supported.n); | 51 return makeError(response, errors.owner.default_options.node_configuration_not_supported.n); |
48 | 52 |
49 response.c('pubsub', {xmlns: NS.PUBSUB_OWNER}); | 53 response.c('pubsub', {xmlns: NS.PUBSUB_OWNER}); |
59 // SECTION 8.2.4: Form Submission | 63 // SECTION 8.2.4: Form Submission |
60 exports.setConfigure = { | 64 exports.setConfigure = { |
61 type: 'set', | 65 type: 'set', |
62 child: 'pubsub', | 66 child: 'pubsub', |
63 ns: NS.PUBSUB_OWNER, | 67 ns: NS.PUBSUB_OWNER, |
64 pschild: 'configure', | 68 child2: 'configure', |
65 func: function(response, stanza, request, to) { | 69 func: function(response, stanza, request, to) { |
66 if (!config.enabled('config-node')) | 70 if (!config.enabled('config-node')) |
67 return makeError(response, errors.owner.configure.node_configuration_not_supported.n); | 71 return makeError(response, errors.owner.configure.node_configuration_not_supported.n); |
68 | 72 |
69 var nodeID = request.getAttribute('node'); | 73 var nodeID = request.getAttribute('node'); |
90 | 94 |
91 var form = forms.parse(x, true); | 95 var form = forms.parse(x, true); |
92 if (typeof form == 'number') | 96 if (typeof form == 'number') |
93 return makeError(response, form); | 97 return makeError(response, form); |
94 | 98 |
95 var conf = form; | 99 // TODO: verify the form. |
100 var conf = form.fields; | |
96 | 101 |
97 var set = storage.configure(nodeID, conf); | 102 var set = storage.configure(nodeID, conf); |
98 if (typeof set == 'number') | 103 if (typeof set == 'number') |
99 return makeError(response, set); | 104 return makeError(response, set); |
100 | 105 |
101 return response; | 106 return response; |
102 } | 107 } |
103 } | 108 } |
109 | |
110 // SECTION 8.1.3: Create and Configure a Node (configure) | |
111 exports.setConfigure2 = { | |
112 type: 'set', | |
113 child: 'pubsub', | |
114 ns: NS.PUBSUB, | |
115 child2: 'configure', | |
116 number: 1, | |
117 func: function(response, stanza, request, to) { | |
118 if (!config.enabled('config-node')) | |
119 return makeError(response, errors.owner.configure.node_configuration_not_supported.n); | |
120 | |
121 var nodeID = stanza.tags[0].tags[0].getAttribute('node'); | |
122 if (!nodeID) | |
123 return makeError(response, errors.nodeid_required.n); | |
124 if (!storage.existsNode(nodeID)) | |
125 return makeError(response, errors.node_does_not_exist.n); | |
126 | |
127 var affil = storage.getAffiliation(toBareJID(to), nodeID); | |
128 if (affil != 'super-owner' && affil != 'owner' && affil != 'publish-only') | |
129 return makeError(response, errors.forbidden.n); | |
130 | |
131 var x = request.getChild('x', 'jabber:x:data'); | |
132 if (!x) | |
133 return makeError(response, errors.bad_request.n); | |
134 | |
135 var type = x.getAttribute('type'); | |
136 if (type == 'cancel') { | |
137 conn.send(response); | |
138 return; | |
139 } | |
140 if (type != 'submit') | |
141 return makeError(response, errors.bad_request.n); | |
142 | |
143 var form = forms.parse(x, true); | |
144 if (typeof form == 'number') | |
145 return makeError(response, form); | |
146 | |
147 // TODO: verify the form. | |
148 var conf = form.fields; | |
149 | |
150 var set = storage.configure(nodeID, conf); | |
151 if (typeof set == 'number') | |
152 return makeError(response, set); | |
153 | |
154 return null; | |
155 } | |
156 } |