Diff

util/pubsub.lua @ 9516:038446c50630

util.pubsub: Allow publishing with a config that should be used as defaults only
author Matthew Wild <mwild1@gmail.com>
date Thu, 18 Oct 2018 18:00:54 +0100
parent 9236:83375ec33619
child 9539:b30455212f89
line wrap: on
line diff
--- a/util/pubsub.lua	Thu Oct 18 13:33:19 2018 +0200
+++ b/util/pubsub.lua	Thu Oct 18 18:00:54 2018 +0100
@@ -493,7 +493,7 @@
 	return true;
 end
 
-function service:publish(node, actor, id, item, required_config) --> ok, err
+function service:publish(node, actor, id, item, requested_config) --> ok, err
 	-- Access checking
 	local may_publish = false;
 
@@ -516,13 +516,16 @@
 		if not self.config.autocreate_on_publish then
 			return false, "item-not-found";
 		end
-		local ok, err = self:create(node, true, required_config);
+		local ok, err = self:create(node, true, requested_config);
 		if not ok then
 			return ok, err;
 		end
 		node_obj = self.nodes[node];
-	elseif required_config and not check_preconditions(node_obj.config, required_config) then
-		return false, "precondition-not-met";
+	elseif requested_config and not requested_config._defaults_only then
+		-- Check that node has the requested config before we publish
+		if not check_preconditions(node_obj.config, requested_config) then
+			return false, "precondition-not-met";
+		end
 	end
 	if not self.config.itemcheck(item) then
 		return nil, "invalid-item";