Diff

util/pubsub.lua @ 9138:db47db788295

util.pubsub: Re-check all subscriptions on access_model change, unsubscribing those no longer allowed
author Kim Alvefur <zash@zash.se>
date Mon, 06 Aug 2018 17:04:11 +0200
parent 9129:7721794e9e93
child 9144:b40efef8ec99
line wrap: on
line diff
--- a/util/pubsub.lua	Mon Aug 06 17:16:42 2018 +0200
+++ b/util/pubsub.lua	Mon Aug 06 17:04:11 2018 +0200
@@ -598,6 +598,18 @@
 		end
 	end
 
+	if old_config["access_model"] ~= node_obj.config["access_model"] then
+		for subscriber in pairs(node_obj.subscribers) do
+			if not self:may(node, subscriber, "be_subscribed") then
+				local ok, err = self:remove_subscription(node, true, subscriber);
+				if not ok then
+					node_obj.config = old_config;
+					return ok, err;
+				end
+			end
+		end
+	end
+
 	if old_config["persist_items"] ~= node_obj.config["persist_items"] then
 		self.data[node] = self.config.itemstore(self.nodes[node].config, node);
 	elseif old_config["max_items"] ~= node_obj.config["max_items"] then