diff options
author | Kim Alvefur <zash@zash.se> | 2019-03-04 13:46:09 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2019-03-04 13:46:09 +0100 |
commit | 2326bed3c7b2386aa1706ad0e760827ef2e165ce (patch) | |
tree | e47cbfb67c4f98b179baec19c2f4fd66e62f7132 | |
parent | 9c9d32e7e69af9aa59c1937b91bc41525d584144 (diff) | |
parent | 09a662026a3fc4c69eda9d8ef8862abac5569625 (diff) | |
download | prosody-2326bed3c7b2386aa1706ad0e760827ef2e165ce.tar.gz prosody-2326bed3c7b2386aa1706ad0e760827ef2e165ce.zip |
Merge 0.11->trunk
-rw-r--r-- | plugins/mod_muc_mam.lua | 5 | ||||
-rw-r--r-- | spec/util_pubsub_spec.lua | 41 | ||||
-rw-r--r-- | util/pubsub.lua | 11 |
3 files changed, 55 insertions, 2 deletions
diff --git a/plugins/mod_muc_mam.lua b/plugins/mod_muc_mam.lua index 963e5255..d414a449 100644 --- a/plugins/mod_muc_mam.lua +++ b/plugins/mod_muc_mam.lua @@ -213,6 +213,7 @@ module:hook("iq-set/bare/"..xmlns_mam..":query", function(event) 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 @@ local function save_to_history(self, stanza) 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 @@ local function save_to_history(self, stanza) -- 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 --git a/spec/util_pubsub_spec.lua b/spec/util_pubsub_spec.lua index 551aedd6..c982fb36 100644 --- a/spec/util_pubsub_spec.lua +++ b/spec/util_pubsub_spec.lua @@ -436,4 +436,45 @@ describe("util.pubsub", function () 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 --git a/util/pubsub.lua b/util/pubsub.lua index a53e8b95..e5e0cb7c 100644 --- a/util/pubsub.lua +++ b/util/pubsub.lua @@ -436,10 +436,19 @@ function service:create(node, actor, options) --> ok, err 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 = {}; }; |