diff psgxs.js @ 6:2bcadb0531f4

A few changes.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Mon, 23 Aug 2010 14:41:55 +0200
parents 4c93e76fa371
children 781ac4f1e304
line wrap: on
line diff
--- a/psgxs.js
+++ b/psgxs.js
@@ -86,7 +86,7 @@ function onIq(stanza) {
 				if (conf['pubsub#node_type'])
 					type = conf['pubsub#node_type'];
 
-				var q = xmpp.stanza('query', {xmlns: 'http://jabber.org/protocol/disco#info'})
+				var q = xmpp.stanza('query', {xmlns: 'http://jabber.org/protocol/disco#info', node: nodeID})
 				q.s('identity', {category: 'pubsub', type: type});
 				q.s('feature', {'var': 'http://jabber.org/protocol/pubsub'});
 
@@ -191,12 +191,15 @@ function onIq(stanza) {
 				if (nodeID && nodeID != '') {
 					if (!storage.existsNode(nodeID))
 						return makeError(response, errors.node_does_not_exist.n);
-					affils = storage.getAffiliation(toBareJID(to), nodeID);
+					affils = {};
+					affils[nodeID] = storage.getAffiliation(toBareJID(to), nodeID);
 				} else
 					affils = storage.getAffiliationsFromJID(toBareJID(to));
+
 				var s = xmpp.stanza('affiliations');
 				for (i in affils)
 					s.s('affiliation', {node: i, affiliation: affils[i]});
+
 				var p = xmpp.stanza('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'});
 				p.cx(s);
 				response.cx(p);
@@ -267,9 +270,12 @@ function onIq(stanza) {
 				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 != 'publisher' && affil != 'member')
-					return makeError(response, errors.pub.publish.insufficient_privileges.n);
+				var configuration = storage.getConfiguration(nodeID);
+				if (configuration['pubsub#access_model'] == 'whitelist') {
+					var affil = storage.getAffiliation(toBareJID(to), nodeID);
+					if (affil != 'super-owner' && affil != 'owner' && affil != 'publisher' && affil != 'member')
+						return makeError(response, errors.pub.publish.insufficient_privileges.n);
+				}
 
 				var item = [];
 				for (var i=0; i<items.children.length; i++) {
@@ -563,10 +569,18 @@ function onIq(stanza) {
 				if (!nodeID || nodeID == '')
 					return makeError(response, errors.nodeid_required.n);
 
+				var autocreate = false;
+				if (!storage.existsNode(nodeID)) {
+					if (config.enabled('auto-create'))
+						autocreate = true;
+					else
+						return makeError(response, errors.node_does_not_exist.n);
+				}
+
 				var affil = storage.getAffiliation(toBareJID(to), nodeID);
-				if (typeof affil == 'number')
+				if (typeof affil == 'number' && affil != errors.node_does_not_exist.n)
 					return makeError(response, affil);
-				if (affil != 'super-owner' && affil != 'owner' && affil != 'publisher' && affil != 'publish-only')
+				if (!autocreate && affil != 'super-owner' && affil != 'owner' && affil != 'publisher' && affil != 'publish-only')
 					return makeError(response, errors.forbidden.n);
 
 				var item = publish.getChild('item');
@@ -578,14 +592,6 @@ function onIq(stanza) {
 				if (item.tags.length != 1)
 					return makeError(response, errors.pub.publish.bad_payload.n);
 
-				var autocreate = false;
-				if (!storage.existsNode(nodeID)) {
-					if (config.enabled('auto-create'))
-						autocreate = true;
-					else
-						return makeError(response, errors.node_does_not_exist.n);
-				}
-
 				var conf = storage.getConfiguration(nodeID);
 				var publishOptions = pubsub.getChild('publish-options');
 				if (publishOptions && config.enabled('publish-options')) {
@@ -652,6 +658,10 @@ function onIq(stanza) {
 				if (!itemID || itemID == '')
 					return makeError(response, errors.pub.retract.item_or_itemid_required.n);
 
+				var affil = storage.getAffiliation(toBareJID(to), nodeID);
+				if (affil != 'super-owner' && affil != 'owner' && affil != 'publish-only')
+					return makeError(response, errors.forbidden.n);
+
 				var subscribers = storage.deleteItem(nodeID, itemID);
 				if (typeof subscribers == 'number')
 					return makeError(response, subscribers);