util.pubsub: Comments describing the return values of methods

This commit is contained in:
Kim Alvefur 2018-08-22 13:27:36 +02:00
parent 8799bd0293
commit df5360e6a3

View file

@ -172,12 +172,12 @@ end
local service = {}; local service = {};
service_mt.__index = service; service_mt.__index = service;
function service:jids_equal(jid1, jid2) function service:jids_equal(jid1, jid2) --> boolean
local normalize = self.config.normalize_jid; local normalize = self.config.normalize_jid;
return normalize(jid1) == normalize(jid2); return normalize(jid1) == normalize(jid2);
end end
function service:may(node, actor, action) function service:may(node, actor, action) --> boolean
if actor == true then return true; end if actor == true then return true; end
local node_obj = self.nodes[node]; local node_obj = self.nodes[node];
@ -212,7 +212,7 @@ function service:may(node, actor, action)
return false; return false;
end end
function service:get_default_affiliation(node, actor) function service:get_default_affiliation(node, actor) --> affiliation
local node_obj = self.nodes[node]; local node_obj = self.nodes[node];
local access_model = node_obj and node_obj.config.access_model local access_model = node_obj and node_obj.config.access_model
or self.node_defaults.access_model; or self.node_defaults.access_model;
@ -234,7 +234,7 @@ function service:get_default_affiliation(node, actor)
end end
end end
function service:set_affiliation(node, actor, jid, affiliation) function service:set_affiliation(node, actor, jid, affiliation) --> ok, err
-- Access checking -- Access checking
if not self:may(node, actor, "set_affiliation") then if not self:may(node, actor, "set_affiliation") then
return false, "forbidden"; return false, "forbidden";
@ -271,7 +271,7 @@ function service:set_affiliation(node, actor, jid, affiliation)
return true; return true;
end end
function service:add_subscription(node, actor, jid, options) function service:add_subscription(node, actor, jid, options) --> ok, err
-- Access checking -- Access checking
local cap; local cap;
if actor == true or jid == actor or self:jids_equal(actor, jid) then if actor == true or jid == actor or self:jids_equal(actor, jid) then
@ -325,7 +325,7 @@ function service:add_subscription(node, actor, jid, options)
return true; return true;
end end
function service:remove_subscription(node, actor, jid) function service:remove_subscription(node, actor, jid) --> ok, err
-- Access checking -- Access checking
local cap; local cap;
if actor == true or jid == actor or self:jids_equal(actor, jid) then if actor == true or jid == actor or self:jids_equal(actor, jid) then
@ -377,7 +377,7 @@ function service:remove_subscription(node, actor, jid)
return true; return true;
end end
function service:get_subscription(node, actor, jid) function service:get_subscription(node, actor, jid) --> (true, subscription) or (false, err)
-- Access checking -- Access checking
local cap; local cap;
if actor == true or jid == actor or self:jids_equal(actor, jid) then if actor == true or jid == actor or self:jids_equal(actor, jid) then
@ -396,7 +396,7 @@ function service:get_subscription(node, actor, jid)
return true, node_obj.subscribers[jid]; return true, node_obj.subscribers[jid];
end end
function service:create(node, actor, options) function service:create(node, actor, options) --> ok, err
-- Access checking -- Access checking
if not self:may(node, actor, "create") then if not self:may(node, actor, "create") then
return false, "forbidden"; return false, "forbidden";
@ -435,7 +435,7 @@ function service:create(node, actor, options)
return true; return true;
end end
function service:delete(node, actor) function service:delete(node, actor) --> ok, err
-- Access checking -- Access checking
if not self:may(node, actor, "delete") then if not self:may(node, actor, "delete") then
return false, "forbidden"; return false, "forbidden";
@ -477,7 +477,7 @@ local function check_preconditions(node_config, required_config)
return true; return true;
end end
function service:publish(node, actor, id, item, required_config) function service:publish(node, actor, id, item, required_config) --> ok, err
-- Access checking -- Access checking
local may_publish = false; local may_publish = false;
@ -524,7 +524,7 @@ function service:publish(node, actor, id, item, required_config)
return true; return true;
end end
function service:retract(node, actor, id, retract) function service:retract(node, actor, id, retract) --> ok, err
-- Access checking -- Access checking
if not self:may(node, actor, "retract") then if not self:may(node, actor, "retract") then
return false, "forbidden"; return false, "forbidden";
@ -545,7 +545,7 @@ function service:retract(node, actor, id, retract)
return true return true
end end
function service:purge(node, actor, notify) function service:purge(node, actor, notify) --> ok, err
-- Access checking -- Access checking
if not self:may(node, actor, "retract") then if not self:may(node, actor, "retract") then
return false, "forbidden"; return false, "forbidden";
@ -567,7 +567,7 @@ function service:purge(node, actor, notify)
return true return true
end end
function service:get_items(node, actor, id) function service:get_items(node, actor, id) --> ok, err
-- Access checking -- Access checking
if not self:may(node, actor, "get_items") then if not self:may(node, actor, "get_items") then
return false, "forbidden"; return false, "forbidden";
@ -593,7 +593,7 @@ function service:get_items(node, actor, id)
end end
end end
function service:get_last_item(node, actor) function service:get_last_item(node, actor) --> (true, id, node) or (false, err)
-- Access checking -- Access checking
if not self:may(node, actor, "get_items") then if not self:may(node, actor, "get_items") then
return false, "forbidden"; return false, "forbidden";
@ -609,7 +609,7 @@ function service:get_last_item(node, actor)
return true, self.data[node]:head(); return true, self.data[node]:head();
end end
function service:get_nodes(actor) function service:get_nodes(actor) --> (true, map) or (false, err)
-- Access checking -- Access checking
if not self:may(nil, actor, "get_nodes") then if not self:may(nil, actor, "get_nodes") then
return false, "forbidden"; return false, "forbidden";
@ -641,7 +641,7 @@ local function flatten_subscriptions(ret, serv, subs, node, node_obj)
end end
end end
function service:get_subscriptions(node, actor, jid) function service:get_subscriptions(node, actor, jid) --> (true, array) or (false, err)
-- Access checking -- Access checking
local cap; local cap;
if actor == true or jid == actor or self:jids_equal(actor, jid) then if actor == true or jid == actor or self:jids_equal(actor, jid) then
@ -678,7 +678,7 @@ function service:get_subscriptions(node, actor, jid)
end end
-- Access models only affect 'none' affiliation caps, service/default access level... -- Access models only affect 'none' affiliation caps, service/default access level...
function service:set_node_capabilities(node, actor, capabilities) function service:set_node_capabilities(node, actor, capabilities) --> ok, err
-- Access checking -- Access checking
if not self:may(node, actor, "configure") then if not self:may(node, actor, "configure") then
return false, "forbidden"; return false, "forbidden";
@ -692,7 +692,7 @@ function service:set_node_capabilities(node, actor, capabilities)
return true; return true;
end end
function service:set_node_config(node, actor, new_config) function service:set_node_config(node, actor, new_config) --> ok, err
if not self:may(node, actor, "configure") then if not self:may(node, actor, "configure") then
return false, "forbidden"; return false, "forbidden";
end end
@ -743,7 +743,7 @@ function service:set_node_config(node, actor, new_config)
return true; return true;
end end
function service:get_node_config(node, actor) function service:get_node_config(node, actor) --> ok, err
if not self:may(node, actor, "get_configuration") then if not self:may(node, actor, "get_configuration") then
return false, "forbidden"; return false, "forbidden";
end end