Changeset

9125:da7a2db01d6a

Merge with jonasw
author Matthew Wild <mwild1@gmail.com>
date Mon, 06 Aug 2018 08:21:55 +0100
parents 9124:dcc490f0044d (diff) 9122:a69dc9c729ec (current diff)
children 9126:3dd5034a3233
files plugins/mod_pubsub/pubsub.lib.lua
diffstat 1 files changed, 13 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_pubsub/pubsub.lib.lua	Sun Aug 05 15:52:19 2018 +0200
+++ b/plugins/mod_pubsub/pubsub.lib.lua	Mon Aug 06 08:21:55 2018 +0100
@@ -156,7 +156,7 @@
 				config_value = tonumber(config_value);
 			end
 			ret[mapped_name] = config_value;
-		elseif strict then
+		elseif strict and config_field ~= "FORM_TYPE" then
 			return nil, "unknown-field", config_field;
 		end
 	end
@@ -552,8 +552,18 @@
 		-- Ensure that the node configuration matches the values in publish-options
 		local publish_options_form = publish_options:get_child("x", "jabber:x:data");
 		local required_config = config_from_xep0060(node_config_form:data(publish_options_form), true);
-		local node_config = service:get_node_config(node, stanza.attr.from);
-		if not check_preconditions(node_config, required_config) then
+		local node_accessible, node_config = service:get_node_config(node, stanza.attr.from);
+		if node_accessible == false and service.config.autocreate_on_publish then
+			module:log("debug", "creating node %s with publish-options", node)
+			-- we need to create the node here so that it is configured
+			-- correctly
+			local created, err = service:create(node, stanza.attr.from, required_config)
+			if not created then
+				local reply = pubsub_error_reply(stanza, err);
+				origin.send(reply);
+				return true;
+			end
+		elseif not check_preconditions(node_config, required_config) then
 			local reply = pubsub_error_reply(stanza, "precondition-not-met");
 			origin.send(reply);
 			return true;