diff options
author | Matthew Wild <mwild1@gmail.com> | 2018-08-18 14:06:56 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2018-08-18 14:06:56 +0100 |
commit | e3daae729d23ed2514d313f38e37d4967460fdff (patch) | |
tree | d8985888982d09a4f981abc3b295ae2f45ce4aab /util | |
parent | 06ea54fb49dcaac5d4f8a781a31f4daf3e857aac (diff) | |
download | prosody-e3daae729d23ed2514d313f38e37d4967460fdff.tar.gz prosody-e3daae729d23ed2514d313f38e37d4967460fdff.zip |
pubsub.lib, util.pubsub: Move precondition checks to util.pubsub
Diffstat (limited to 'util')
-rw-r--r-- | util/pubsub.lua | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/util/pubsub.lua b/util/pubsub.lua index f9ae0998..628fdc59 100644 --- a/util/pubsub.lua +++ b/util/pubsub.lua @@ -464,7 +464,20 @@ function service:delete(node, actor) return true; end -function service:publish(node, actor, id, item) +-- Used to check that the config of a node is as expected (i.e. 'publish-options') +local function check_preconditions(node_config, required_config) + if not (node_config and required_config) then + return false; + end + for config_field, value in pairs(required_config) do + if node_config[config_field] ~= value then + return false; + end + end + return true; +end + +function service:publish(node, actor, id, item, required_config) -- Access checking local may_publish = false; @@ -487,11 +500,13 @@ function service:publish(node, actor, id, item) if not self.config.autocreate_on_publish then return false, "item-not-found"; end - local ok, err = self:create(node, true); + local ok, err = self:create(node, true, required_config); if not ok then return ok, err; end node_obj = self.nodes[node]; + elseif required_config and not check_preconditions(node_obj.config, required_config) then + return false, "precondition-not-met"; end if not self.config.itemcheck(item) then return nil, "internal-server-error"; |