Mercurial > psgxs
view modules/mod_owner.js @ 56:99bd1d1ac071
Migration to node-xmpp, done!
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Wed, 10 Aug 2011 15:11:22 -0700 |
parents | 7e421278b31b |
children |
line wrap: on
line source
/* * Copyright (C) 2010 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> * * This file is part of PSĜS, a PubSub server written in JavaScript. * * PSĜS is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License. * * PSĜS is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with PSĜS. If not, see <http://www.gnu.org/licenses/>. */ 'use strict'; // SECTION 8.1: Create a Node exports.create = { type: 'set', child: 'pubsub', ns: NS.PUBSUB, child2: 'create', func: function(response, stanza, request, to) { if (!config.enabled('create-nodes')) return makeError(response, errors.owner.create.node_creation_not_supported.n); var instant = false; var nodeID = request.getAttribute('node'); if (!nodeID || nodeID == '') { if (!config.enabled('instant-nodes')) return makeError(response, errors.owner.create.instant_nodes_not_supported.n); nodeID = uuid(); instant = true; } if (storage.existsNode(nodeID)) return makeError(response, errors.owner.create.nodeid_already_exists.n); var bare = JID.toBare(to); var right = false; // Check for super-owner for (var i in config.owner) if (config.owner[i] == bare) right = true; // Check for authorized user for (var i in config.allowCreateNode) if (config.allowCreateNode[i].exec(bare)) right = true; if (!right) return makeError(response, errors.forbidden.n); var conf = {}; conf['pubsub#creator'] = bare; var r = storage.createNode(nodeID, conf); if (typeof r == 'number') return makeError(response, r); if (instant) response.c('pubsub', {xmlns: NS.PUBSUB}) .c('create', {node: nodeID}); return response; } } // SECTION 8.4: Delete a Node exports['delete'] = { type: 'set', child: 'pubsub', ns: NS.PUBSUB_OWNER, child2: 'delete', func: function(response, stanza, request, to) { if (!config.enabled('delete-nodes')) return makeError(response, errors.feature_not_implemented.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(JID.toBare(to), nodeID); if (affil != 'super-owner' && affil != 'owner') return makeError(response, errors.forbidden.n); var notifications = storage.deleteNode(nodeID); if (typeof notifications == 'number') return makeError(response, r); notifs.send(notifications, 'delete', nodeID); return response; } } // SECTION 8.5: Purge All Node Items exports.purge = { type: 'set', child: 'pubsub', ns: NS.PUBSUB_OWNER, child2: 'purge', func: function(response, stanza, request, to) { if (!config.enabled('purge-nodes')) return makeError(response, errors.owner.purge.node_purging_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(JID.toBare(to), nodeID); if (affil != 'super-owner' && affil != 'owner') return makeError(response, errors.forbidden.n); if (!config.enabled('persistent-items')) //FIXME: autre condition, supporté par le node return makeError(response, errors.owner.purge.node_does_not_persist_items.n); var notifications = storage.purgeNode(nodeID); if (typeof notifications == 'number') return makeError(response, r); notifs.send(notifications, 'purge', nodeID); return response; } }