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 | 716c68f983333e3890a4deb0c5151af1b9d77b0e (patch) | |
tree | d8985888982d09a4f981abc3b295ae2f45ce4aab /util | |
parent | c6b4e592cf6c951464c5940bd33a02a87a875316 (diff) | |
download | prosody-716c68f983333e3890a4deb0c5151af1b9d77b0e.tar.gz prosody-716c68f983333e3890a4deb0c5151af1b9d77b0e.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"; |