Software /
code /
prosody
Changeset
9125:da7a2db01d6a
Merge with jonasw
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 06 Aug 2018 08:21:55 +0100 |
parents | 9124:dcc490f0044d (current diff) 9122:a69dc9c729ec (diff) |
children | 9126:3dd5034a3233 |
files | plugins/mod_pubsub/pubsub.lib.lua |
diffstat | 5 files changed, 61 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/mod_pubsub/mod_pubsub.lua Sun Aug 05 11:44:49 2018 +0200 +++ b/plugins/mod_pubsub/mod_pubsub.lua Mon Aug 06 08:21:55 2018 +0100 @@ -150,6 +150,10 @@ end end +function get_service() + return service; +end + function set_service(new_service) service = new_service; module.environment.service = service; @@ -196,6 +200,7 @@ publish = true; retract = true; get_nodes = true; + get_configuration = true; subscribe = true; unsubscribe = true; @@ -220,6 +225,7 @@ delete = true; get_nodes = true; configure = true; + get_configuration = true; subscribe = true; unsubscribe = true;
--- a/plugins/mod_pubsub/pubsub.lib.lua Sun Aug 05 11:44:49 2018 +0200 +++ b/plugins/mod_pubsub/pubsub.lib.lua Mon Aug 06 08:21:55 2018 +0100 @@ -642,18 +642,12 @@ return true; end - if not service:may(node, stanza.attr.from, "configure") then - origin.send(pubsub_error_reply(stanza, "forbidden")); + local ok, node_config = service:get_node_config(node, stanza.attr.from); + if not ok then + origin.send(pubsub_error_reply(stanza, node_config)); return true; end - local node_obj = service.nodes[node]; - if not node_obj then - origin.send(pubsub_error_reply(stanza, "item-not-found")); - return true; - end - - local node_config = node_obj.config; local pubsub_form_data = config_to_xep0060(node_config); local reply = st.reply(stanza) :tag("pubsub", { xmlns = xmlns_pubsub_owner }) @@ -678,7 +672,12 @@ origin.send(st.error_reply(stanza, "modify", "bad-request", "Missing dataform")); return true; end - local form_data, err = node_config_form:data(config_form); + local ok, old_config = service:get_node_config(node, stanza.attr.from); + if not ok then + origin.send(pubsub_error_reply(stanza, old_config)); + return true; + end + local form_data, err = node_config_form:data(config_form, old_config); if not form_data then origin.send(st.error_reply(stanza, "modify", "bad-request", err)); return true;
--- a/spec/util_dataforms_spec.lua Sun Aug 05 11:44:49 2018 +0200 +++ b/spec/util_dataforms_spec.lua Mon Aug 06 08:21:55 2018 +0100 @@ -347,5 +347,44 @@ assert.truthy(f:find("field/option")); end); end); + + describe("using current values in place of missing fields", function () + it("gets back the previous values when given an empty form", function () + local current = { + ["list-multi-field"] = { + "list-multi-option-value#2"; + }; + ["list-single-field"] = "list-single-value#2"; + ["hidden-field"] = "hidden-value"; + ["boolean-field"] = false; + ["text-multi-field"] = "words\ngo\nhere"; + ["jid-single-field"] = "alice@example.com"; + ["text-private-field"] = "hunter2"; + ["text-single-field"] = "text-single-value"; + ["jid-multi-field"] = { + "bob@example.net"; + }; + }; + local expect = { + -- FORM_TYPE = "xmpp:prosody.im/spec/util.dataforms#1"; -- does this need to be included? + ["list-multi-field"] = { + "list-multi-option-value#2"; + }; + ["list-single-field"] = "list-single-value#2"; + ["hidden-field"] = "hidden-value"; + ["boolean-field"] = false; + ["text-multi-field"] = "words\ngo\nhere"; + ["jid-single-field"] = "alice@example.com"; + ["text-private-field"] = "hunter2"; + ["text-single-field"] = "text-single-value"; + ["jid-multi-field"] = { + "bob@example.net"; + }; + }; + local data, err = some_form:data(st.stanza("x", {xmlns="jabber:x:data"}), current); + assert.is.table(data, err); + assert.same(expect, data, "got back the same data"); + end); + end); end);
--- a/util/dataforms.lua Sun Aug 05 11:44:49 2018 +0200 +++ b/util/dataforms.lua Mon Aug 06 08:21:55 2018 +0100 @@ -142,7 +142,7 @@ local field_readers = {}; -function form_t.data(layout, stanza) +function form_t.data(layout, stanza, current) local data = {}; local errors = {}; local present = {}; @@ -157,7 +157,9 @@ end if not tag then - if field.required then + if current and current[field.name] ~= nil then + data[field.name] = current[field.name]; + elseif field.required then errors[field.name] = "Required value missing"; end elseif field.name then
--- a/util/pubsub.lua Sun Aug 05 11:44:49 2018 +0200 +++ b/util/pubsub.lua Mon Aug 06 08:21:55 2018 +0100 @@ -565,6 +565,8 @@ return false, "item-not-found"; end + setmetatable(new_config, {__index=self.node_defaults}) + if self.config.check_node_config then local ok = self.config.check_node_config(node, actor, new_config); if not ok then @@ -573,7 +575,7 @@ end local old_config = node_obj.config; - node_obj.config = setmetatable(new_config, {__index=self.node_defaults}); + node_obj.config = new_config; if self.config.nodestore then local ok, err = save_node_to_store(self, node_obj);