Comparison

util/pubsub.lua @ 9129:7721794e9e93

util.pubsub: Add support for publish_model config option
author Matthew Wild <mwild1@gmail.com>
date Mon, 06 Aug 2018 11:23:09 +0100
parent 9117:a19fdc6e4f09
child 9138:db47db788295
comparison
equal deleted inserted replaced
9128:a4a923e493da 9129:7721794e9e93
15 15
16 local default_node_config = { 16 local default_node_config = {
17 ["persist_items"] = false; 17 ["persist_items"] = false;
18 ["max_items"] = 20; 18 ["max_items"] = 20;
19 ["access_model"] = "open"; 19 ["access_model"] = "open";
20 ["publish_model"] = "publishers";
20 }; 21 };
21 local default_node_config_mt = { __index = default_node_config }; 22 local default_node_config_mt = { __index = default_node_config };
22 23
23 -- Storage helper functions 24 -- Storage helper functions
24 25
363 return true; 364 return true;
364 end 365 end
365 366
366 function service:publish(node, actor, id, item) 367 function service:publish(node, actor, id, item)
367 -- Access checking 368 -- Access checking
368 if not self:may(node, actor, "publish") then 369 local may_publish = false;
370
371 if self:may(node, actor, "publish") then
372 may_publish = true;
373 else
374 local node_obj = self.nodes[node];
375 local publish_model = node_obj and node_obj.config.publish_model;
376 if publish_model == "open"
377 or (publish_model == "subscribers" and node_obj.subscribers[actor]) then
378 may_publish = true;
379 end
380 end
381 if not may_publish then
369 return false, "forbidden"; 382 return false, "forbidden";
370 end 383 end
371 -- 384 --
372 local node_obj = self.nodes[node]; 385 local node_obj = self.nodes[node];
373 if not node_obj then 386 if not node_obj then