diff storage.js @ 1:c2954a9e5665

Add a super-owner that has power over all nodes; add support for affiliation changes; support pubsub#creator metadata; change pubsub#digest_frequency default; and use better default config values.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Mon, 28 Jun 2010 21:55:30 +0200
parents 9ee956af41e3
children d8a98540d749
line wrap: on
line diff
--- a/storage.js
+++ b/storage.js
@@ -294,8 +294,10 @@ storage.getItem = function(nodeID, itemI
 	var items = storage.existsItem(nodeID, itemID);
 	if (typeof items == 'number')
 		return items;
+
 	if (items)
 		return items.content;
+
 	return errors.item_not_found;
 };
 
@@ -388,6 +390,9 @@ storage.getAffiliation = function(jid, n
 	} else
 		node = nodeID;
 
+	for (var affil in config.owner)
+		if (typeof affil == 'string' && node.owner[affil] == jid)
+			return 'super-owner';
 	for (var affil in node.owner)
 		if (typeof affil == 'string' && node.owner[affil] == jid)
 			return 'owner';
@@ -408,29 +413,34 @@ storage.getAffiliation = function(jid, n
 
 storage.getAffiliationsFromJID = function(jid) {
 	var affils = {};
-	for (var node in list) {
-		var n = list[node];
-		for (var affil in n.owner)
-			if (typeof affil == 'string' && n.owner[affil] == jid) {
-				affils[node] = 'owner';
+	for (var nodeID in list) {
+		var node = list[nodeID];
+		for (var affil in config.owner)
+			if (typeof affil == 'string' && config.owner[affil] == jid) {
+				affils[nodeID] = 'super-owner';
+				break;
+			}
+		for (var affil in node.owner)
+			if (typeof affil == 'string' && node.owner[affil] == jid) {
+				affils[nodeID] = 'owner';
 				break;
 			}
 		if (config.enabled('publisher-affiliation'))
-			for (var affil in n.publisher)
-				if (typeof affil == 'string' && n.publisher[affil] == jid) {
-					affils[node] = 'publisher';
+			for (var affil in node.publisher)
+				if (typeof affil == 'string' && node.publisher[affil] == jid) {
+					affils[nodeID] = 'publisher';
 					break;
 				}
 		if (config.enabled('publish-only-affiliation'))
-			for (var affil in n.publishOnly)
-				if (typeof affil == 'string' && n.publishOnly[affil] == jid) {
-					affils[node] = 'publish-only';
+			for (var affil in node.publishOnly)
+				if (typeof affil == 'string' && node.publishOnly[affil] == jid) {
+					affils[nodeID] = 'publish-only';
 					break;
 				}
 		if (config.enabled('outcast-affiliation'))
-			for (var affil in n.outcast)
-				if (typeof affil == 'string' && n.outcast[affil] == jid) {
-					affils[node] = 'outcast';
+			for (var affil in node.outcast)
+				if (typeof affil == 'string' && node.outcast[affil] == jid) {
+					affils[nodeID] = 'outcast';
 					break;
 				}
 	}
@@ -447,6 +457,9 @@ storage.getAffiliationsFromNodeID = func
 		node = nodeID;
 
 	var affils = {};
+	for (var jid in config.owner)
+		if (typeof jid == 'string')
+			affils[config.owner[jid]] = 'super-owner';
 	for (var jid in node.owner)
 		if (typeof jid == 'string')
 			affils[node.owner[jid]] = 'owner';