Mercurial > psgxs
view modules/mod_manage.js @ 41:bc717575e66a
Much better handling of modules.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 20 Feb 2011 15:51:12 +0100 |
parents | 6697f394301f |
children | 023f767662d3 |
line wrap: on
line source
// SECTION 8.8.1: Retrieve Subscriptions List exports.manageRetrieveSub = { type: 'get', child: 'pubsub', ns: NS.PUBSUB_OWNER, child2: 'subscriptions', func: function(response, stanza, request, to) { if (!config.enabled('manage-subscriptions')) return makeError(response, errors.owner.manage_subscriptions.not_supported.n); var nodeID = request.getAttribute('node'); if (!nodeID || 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') return makeError(response, errors.forbidden.n); response.c('pubsub', {xmlns: NS.PUBSUB_OWNER}) .c('subscriptions', {node: nodeID}); var subs = storage.getSubscriptionsFromNodeID(nodeID) for (var jid in subs) response.c('subscription', {jid: jid, subscription: subs[jid].type, subid: subs[jid].subid}).up(); return response; } } // SECTION 8.9.1: Retrieve Affiliations List exports.manageRetrieveAff = { type: 'get', child: 'pubsub', ns: NS.PUBSUB_OWNER, child2: 'affiliations', func: function(response, stanza, request, to) { if (!config.enabled('modify-affiliations')) return makeError(response, errors.owner.manage_affiliations.not_supported.n); var nodeID = request.getAttribute('node'); if (!nodeID || nodeID == '') return makeError(response, errors.nodeid_required.n); if (!storage.existsNode(nodeID)) return makeError(response, errors.node_does_not_exist.n); var affils = storage.getAffiliationsFromNodeID(nodeID); var affil = affils[toBareJID(to)]; if (affil != 'super-owner' && affil != 'owner') return makeError(response, errors.owner.manage_affiliations.retrieve_list.entity_is_not_an_owner.n); response.c('pubsub', {xmlns: NS.PUBSUB_OWNER}) .c('affiliations', {node: nodeID}); for (var jid in affils) response.c('affiliation', {jid: jid, affiliation: affils[jid]}).up(); return response; } } // SECTION 8.8.2: Modify Subscriptions exports.modifySub = { type: 'set', child: 'pubsub', ns: NS.PUBSUB_OWNER, child2: 'subscriptions', func: function(response, stanza, request, to) { if (!config.enabled('manage-subscriptions')) return makeError(response, errors.owner.manage_subscriptions.not_supported.n); //XXX var nodeID = request.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') return makeError(response, errors.forbidden.n); var e = false; var tags2 = []; for (i in request.tags) { var tag = request.tags[i]; var jid = tag.getAttribute('jid'); var sub = tag.getAttribute('subscription'); if (sub == 'none' || sub == 'pending' || sub == 'subscribed' || sub == 'unconfigured') { var set = storage.subscribe(nodeID, jid, sub); if (typeof set == 'number') { e = true; tags2.push(tag); } else { // SECTION 8.8.4 notifs.send(jid, 'subscription', nodeID, {jid: jid, subscription: sub}); } } else { e = true; tags2.push(tag); } } request.tags = tags2; if (e) return makeError(response, errors.owner.manage_subscriptions.modify.multiple_simultaneous_modifications.n, pubsub); return response; } } // SECTION 8.9.2: Modify Affiliation exports.modifyAff = { type: 'set', child: 'pubsub', ns: NS.PUBSUB_OWNER, child2: 'affiliations', func: function(response, stanza, request, to) { if (!config.enabled('modify-affiliations')) return makeError(response, errors.owner.manage_affiliations.not_supported.n); //XXX var nodeID = request.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') return makeError(response, errors.forbidden.n); var e = false; for (i in request.children) { var jid = request.children[i].getAttribute('jid'); var affiliation = request.children[i].getAttribute('affiliation'); var set = storage.setAffiliation(nodeID, jid, affiliation); if (typeof set == 'number') e = true; else { // SECTION 8.9.4 notifs.send(jid, 'affiliations', nodeID, {jid: jid, affiliation: affiliation}); request.children.splice(i, 1); } } if (e) return makeError(response, errors.owner.manage_affiliations.modify.multiple_simultaneous_modifications.n, pubsub); return response; } }