Diff

util/pubsub.lua @ 9129:7721794e9e93

util.pubsub: Add support for publish_model config option
author Matthew Wild <mwild1@gmail.com>
date Mon, 06 Aug 2018 11:23:09 +0100
parent 9117:a19fdc6e4f09
child 9138:db47db788295
line wrap: on
line diff
--- a/util/pubsub.lua	Mon Aug 06 11:22:05 2018 +0100
+++ b/util/pubsub.lua	Mon Aug 06 11:23:09 2018 +0100
@@ -17,6 +17,7 @@
 	["persist_items"] = false;
 	["max_items"] = 20;
 	["access_model"] = "open";
+	["publish_model"] = "publishers";
 };
 local default_node_config_mt = { __index = default_node_config };
 
@@ -365,7 +366,19 @@
 
 function service:publish(node, actor, id, item)
 	-- Access checking
-	if not self:may(node, actor, "publish") then
+	local may_publish = false;
+
+	if self:may(node, actor, "publish") then
+		may_publish = true;
+	else
+		local node_obj = self.nodes[node];
+		local publish_model = node_obj and node_obj.config.publish_model;
+		if publish_model == "open"
+		or (publish_model == "subscribers" and node_obj.subscribers[actor]) then
+			may_publish = true;
+		end
+	end
+	if not may_publish then
 		return false, "forbidden";
 	end
 	--