From 2b8327099ad7aa5db62cccb1e4381d394b5519e3 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 5 Aug 2018 15:17:00 +0200 Subject: util.pubsub: Apply defaults metatable before config check (thanks pep.) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Makes it so that the callback sees the default if it’s not in the form, which makes it easier to validate. --- util/pubsub.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'util') diff --git a/util/pubsub.lua b/util/pubsub.lua index 381c449a..964b26c7 100644 --- a/util/pubsub.lua +++ b/util/pubsub.lua @@ -565,6 +565,8 @@ function service:set_node_config(node, actor, new_config) 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 @@ function service:set_node_config(node, actor, new_config) 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); -- cgit v1.2.3 From 876b96659c284c4ab0cb3bbbfe0f8abb7b634562 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 5 Aug 2018 15:50:06 +0200 Subject: util.dataforms: Allow passing the current values to be used in stead of omitted fields --- util/dataforms.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'util') diff --git a/util/dataforms.lua b/util/dataforms.lua index a75e8db0..a5733b83 100644 --- a/util/dataforms.lua +++ b/util/dataforms.lua @@ -142,7 +142,7 @@ end 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 @@ function form_t.data(layout, stanza) 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 -- cgit v1.2.3