changeset 42:07ca0263a53f

Add an option to hide non-accessible nodes.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 26 Feb 2011 17:39:49 +0100
parents bc717575e66a
children 023f767662d3
files configuration.js modules/mod_disco.js
diffstat 2 files changed, 17 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/configuration.js
+++ b/configuration.js
@@ -28,6 +28,7 @@ config.allowCreateNode = [/@example\.com
 config.backend = 'directory'; // Put backends in “backends” directory.
 config.access = 'open'; // values include open, whitelist (by members) and authorize (owners of the node receive notification). presence and roster aren’t implemented yet.
 config.pluginsDir = 'modules';
+config.hideNonAccessibleNodes = true;
 
 config.activated = [
 	'auto-create',
--- a/modules/mod_disco.js
+++ b/modules/mod_disco.js
@@ -54,7 +54,7 @@ exports.disco_items = {
 	type: 'get',
 	child: 'query',
 	ns: NS.DISCO_ITEMS,
-	func: function(response, stanza, request) {
+	func: function(response, stanza, request, to) {
 		var children;
 		var nodeID = request.getAttribute('node');
 		if (nodeID && nodeID != '') {
@@ -84,19 +84,29 @@ exports.disco_items = {
 				return makeError(response, children);
 		}
 
-		for (var i in children) {
+		for (var nodeID in children) {
 			var attr = {jid: config.jid};
-			if (children[i] == 'node') {
+			if (children[nodeID] == 'node') {
 				if (config.enabled('meta-data')) {
-					var metadata = storage.getMetadata(i);
+					var metadata = storage.getMetadata(nodeID);
 					if (metadata['pubsub#title'])
 						attr.name = metadata['pubsub#title'];
+
+					if (config.hideNonAccessibleNodes) {
+						var configuration = storage.getConfiguration(nodeID);
+						if (configuration['pubsub#access_model'] == 'whitelist') {
+							var affils = storage.getAffiliationsFromNodeID(nodeID);
+							var affil = affils[toBareJID(to)];
+							if (!affil || affil == 'outcast')
+								continue;
+						}
+					}
 				}
-				attr.node = i;
+				attr.node = nodeID;
 
 			// SECTION 5.5: Discover Items for a Node
 			} else
-				attr.name = i;
+				attr.name = nodeID;
 
 			response.c('item', attr).up();
 		}