Software /
code /
prosody
Comparison
util/pubsub.lua @ 9516:038446c50630
util.pubsub: Allow publishing with a config that should be used as defaults only
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 18 Oct 2018 18:00:54 +0100 |
parent | 9236:83375ec33619 |
child | 9539:b30455212f89 |
comparison
equal
deleted
inserted
replaced
9515:2571c65b972f | 9516:038446c50630 |
---|---|
491 end | 491 end |
492 end | 492 end |
493 return true; | 493 return true; |
494 end | 494 end |
495 | 495 |
496 function service:publish(node, actor, id, item, required_config) --> ok, err | 496 function service:publish(node, actor, id, item, requested_config) --> ok, err |
497 -- Access checking | 497 -- Access checking |
498 local may_publish = false; | 498 local may_publish = false; |
499 | 499 |
500 if self:may(node, actor, "publish") then | 500 if self:may(node, actor, "publish") then |
501 may_publish = true; | 501 may_publish = true; |
514 local node_obj = self.nodes[node]; | 514 local node_obj = self.nodes[node]; |
515 if not node_obj then | 515 if not node_obj then |
516 if not self.config.autocreate_on_publish then | 516 if not self.config.autocreate_on_publish then |
517 return false, "item-not-found"; | 517 return false, "item-not-found"; |
518 end | 518 end |
519 local ok, err = self:create(node, true, required_config); | 519 local ok, err = self:create(node, true, requested_config); |
520 if not ok then | 520 if not ok then |
521 return ok, err; | 521 return ok, err; |
522 end | 522 end |
523 node_obj = self.nodes[node]; | 523 node_obj = self.nodes[node]; |
524 elseif required_config and not check_preconditions(node_obj.config, required_config) then | 524 elseif requested_config and not requested_config._defaults_only then |
525 return false, "precondition-not-met"; | 525 -- Check that node has the requested config before we publish |
526 if not check_preconditions(node_obj.config, requested_config) then | |
527 return false, "precondition-not-met"; | |
528 end | |
526 end | 529 end |
527 if not self.config.itemcheck(item) then | 530 if not self.config.itemcheck(item) then |
528 return nil, "invalid-item"; | 531 return nil, "invalid-item"; |
529 end | 532 end |
530 local node_data = self.data[node]; | 533 local node_data = self.data[node]; |