Software /
code /
prosody
Changeset
9845:774b2ce62318
Merge 0.11->trunk
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 04 Mar 2019 13:46:09 +0100 |
parents | 9844:3de80fc511ab (current diff) 9843:17060708d0eb (diff) |
children | 9846:9a0da809ed4a |
files | plugins/mod_muc_mam.lua |
diffstat | 3 files changed, 55 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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 = {}; };