# HG changeset patch # User Kim Alvefur # Date 1551703569 -3600 # Node ID 774b2ce62318249c6ded418fc572de9fcaa5c48d # Parent 3de80fc511abe4caf3ad2040432769ee17705240# Parent 17060708d0eb36cacd8f4590dc9b883e08f874cf Merge 0.11->trunk diff -r 3de80fc511ab -r 774b2ce62318 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 diff -r 3de80fc511ab -r 774b2ce62318 spec/util_pubsub_spec.lua --- 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); diff -r 3de80fc511ab -r 774b2ce62318 util/pubsub.lua --- 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 = {}; };