Merge 0.11->trunk
authorKim Alvefur <zash@zash.se>
Mon, 04 Mar 2019 13:46:09 +0100
changeset 9849 774b2ce62318
parent 9848 3de80fc511ab (current diff)
parent 9847 17060708d0eb (diff)
child 9850 9a0da809ed4a
Merge 0.11->trunk
plugins/mod_muc_mam.lua
--- a/plugins/mod_muc_mam.lua	Mon Mar 04 13:13:37 2019 +0100
+++ b/plugins/mod_muc_mam.lua	Mon Mar 04 13:46:09 2019 +0100
@@ -213,6 +213,7 @@
 		if not is_stanza(item) then
 			item = st.deserialize(item);
 		end
+		item.attr.to = nil;
 		item.attr.xmlns = "jabber:client";
 		fwd_st:add_child(item);
 
@@ -334,6 +335,7 @@
 
 	if stanza.name == "message" and self:get_whois() == "anyone" then
 		stored_stanza = st.clone(stanza);
+		stored_stanza.attr.to = nil;
 		local actor = jid_bare(self._occupants[stanza.attr.from].jid);
 		local affiliation = self:get_affiliation(actor) or "none";
 		local role = self:get_role(actor) or self:get_default_role(affiliation);
@@ -344,12 +346,13 @@
 	-- Policy check
 	if not archiving_enabled(self) then return end -- Don't log
 
-	-- And stash it
+	-- Save the type in the 'with' field, allows storing presence without conflicts
 	local with = stanza.name
 	if stanza.attr.type then
 		with = with .. "<" .. stanza.attr.type
 	end
 
+	-- And stash it
 	local id = archive:append(room_node, nil, stored_stanza, time_now(), with);
 
 	if id then
--- a/spec/util_pubsub_spec.lua	Mon Mar 04 13:13:37 2019 +0100
+++ b/spec/util_pubsub_spec.lua	Mon Mar 04 13:46:09 2019 +0100
@@ -436,4 +436,45 @@
 		end);
 	end);
 
+	describe("node config checking", function ()
+		local service;
+		before_each(function ()
+			service = pubsub.new({
+				check_node_config = function (node, actor, config) -- luacheck: ignore 212
+					return config["max_items"] <= 20;
+				end;
+			});
+		end);
+
+		it("defaults, then configure", function ()
+			local ok, err = service:create("node", true);
+			assert.is_true(ok, err);
+
+			local ok, err = service:set_node_config("node", true, { max_items = 10 });
+			assert.is_true(ok, err);
+
+			local ok, err = service:set_node_config("node", true, { max_items = 100 });
+			assert.falsy(ok, err);
+			assert.equals(err, "not-acceptable");
+		end);
+
+		it("create with ok config, then configure", function ()
+			local ok, err = service:create("node", true, { max_items = 10 });
+			assert.is_true(ok, err);
+
+			local ok, err = service:set_node_config("node", true, { max_items = 100 });
+			assert.falsy(ok, err);
+
+			local ok, err = service:set_node_config("node", true, { max_items = 10 });
+			assert.is_true(ok, err);
+		end);
+
+		it("create with unacceptable config", function ()
+			local ok, err = service:create("node", true, { max_items = 100 });
+			assert.falsy(ok, err);
+		end);
+
+
+	end);
+
 end);
--- a/util/pubsub.lua	Mon Mar 04 13:13:37 2019 +0100
+++ b/util/pubsub.lua	Mon Mar 04 13:46:09 2019 +0100
@@ -436,10 +436,19 @@
 		return false, "conflict";
 	end
 
+	local config = setmetatable(options or {}, {__index=self.node_defaults});
+
+	if self.config.check_node_config then
+		local ok = self.config.check_node_config(node, actor, config);
+		if not ok then
+			return false, "not-acceptable";
+		end
+	end
+
 	self.nodes[node] = {
 		name = node;
 		subscribers = {};
-		config = setmetatable(options or {}, {__index=self.node_defaults});
+		config = config;
 		affiliations = {};
 	};