Mercurial > psgxs
diff 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 |
line wrap: on
line diff
--- a/modules/mod_configure.js +++ b/modules/mod_configure.js @@ -11,7 +11,7 @@ exports.getConfigure = { type: 'get', child: 'pubsub', ns: NS.PUBSUB_OWNER, - pschild: 'configure', + child2: 'configure', func: function(response, stanza, request, to) { if (!config.enabled('config-node')) return makeError(response, errors.owner.configure.node_configuration_not_supported.n); @@ -26,10 +26,14 @@ exports.getConfigure = { if (affil != 'super-owner' && affil != 'owner' && affil != 'publish-only') return makeError(response, errors.pub.publish.insufficient_privileges.n); + var conf = storage.getConfiguration(nodeID); + if (!conf) + return makeError(response, 42); // FIXME + response.c('pubsub', {xmlns: NS.PUBSUB_OWNER}); response.c('configure', {node: nodeID}); - var form = forms.build('form', 'node_config', 'default', true); + var form = forms.build('form', 'node_config', conf, true); response.cnode(form); return response; @@ -41,7 +45,7 @@ exports.default = { type: 'get', child: 'pubsub', ns: NS.PUBSUB_OWNER, - pschild: 'default', + child2: 'default', func: function(response) { if (!config.enabled('config-node')) return makeError(response, errors.owner.default_options.node_configuration_not_supported.n); @@ -61,7 +65,7 @@ exports.setConfigure = { type: 'set', child: 'pubsub', ns: NS.PUBSUB_OWNER, - pschild: 'configure', + child2: 'configure', func: function(response, stanza, request, to) { if (!config.enabled('config-node')) return makeError(response, errors.owner.configure.node_configuration_not_supported.n); @@ -92,7 +96,8 @@ exports.setConfigure = { if (typeof form == 'number') return makeError(response, form); - var conf = form; + // TODO: verify the form. + var conf = form.fields; var set = storage.configure(nodeID, conf); if (typeof set == 'number') @@ -101,3 +106,51 @@ exports.setConfigure = { return response; } } + +// SECTION 8.1.3: Create and Configure a Node (configure) +exports.setConfigure2 = { + type: 'set', + child: 'pubsub', + ns: NS.PUBSUB, + child2: 'configure', + number: 1, + func: function(response, stanza, request, to) { + if (!config.enabled('config-node')) + return makeError(response, errors.owner.configure.node_configuration_not_supported.n); + + var nodeID = stanza.tags[0].tags[0].getAttribute('node'); + if (!nodeID) + return makeError(response, errors.nodeid_required.n); + if (!storage.existsNode(nodeID)) + return makeError(response, errors.node_does_not_exist.n); + + var affil = storage.getAffiliation(toBareJID(to), nodeID); + if (affil != 'super-owner' && affil != 'owner' && affil != 'publish-only') + return makeError(response, errors.forbidden.n); + + var x = request.getChild('x', 'jabber:x:data'); + if (!x) + return makeError(response, errors.bad_request.n); + + var type = x.getAttribute('type'); + if (type == 'cancel') { + conn.send(response); + return; + } + if (type != 'submit') + return makeError(response, errors.bad_request.n); + + var form = forms.parse(x, true); + if (typeof form == 'number') + return makeError(response, form); + + // TODO: verify the form. + var conf = form.fields; + + var set = storage.configure(nodeID, conf); + if (typeof set == 'number') + return makeError(response, set); + + return null; + } +}