Comparison

util/pubsub.lua @ 4099:5c0b7947f0ef

util.pubsub: Some tidying/optimisation to service:may()
author Matthew Wild <mwild1@gmail.com>
date Sat, 08 Jan 2011 23:15:27 +0000
parent 3945:39e34cb4c491
child 4100:69e3f1e7111e
comparison
equal deleted inserted replaced
4098:7d687c348295 4099:5c0b7947f0ef
25 end 25 end
26 26
27 function service:may(node, actor, action) 27 function service:may(node, actor, action)
28 if actor == true then return true; end 28 if actor == true then return true; end
29 29
30
31 local node_obj = self.nodes[node]; 30 local node_obj = self.nodes[node];
32 local node_aff = node_obj and node_obj.affiliations[actor]; 31 local node_aff = node_obj and node_obj.affiliations[actor];
33 local service_aff = self.affiliations[actor] 32 local service_aff = self.affiliations[actor]
34 or self.config.get_affiliation(actor, node, action) 33 or self.config.get_affiliation(actor, node, action)
35 or "none"; 34 or "none";
36 35
36 -- Check if node allows/forbids it
37 local node_capabilities = node_obj and node_obj.capabilities; 37 local node_capabilities = node_obj and node_obj.capabilities;
38 local service_capabilities = self.config.capabilities;
39
40 -- Check if node allows/forbids it
41 if node_capabilities then 38 if node_capabilities then
42 local caps = node_capabilities[node_aff or service_aff]; 39 local caps = node_capabilities[node_aff or service_aff];
43 if caps then 40 if caps then
44 local can = caps[action]; 41 local can = caps[action];
45 if can ~= nil then 42 if can ~= nil then
46 return can; 43 return can;
47 end 44 end
48 end 45 end
49 end 46 end
47
50 -- Check service-wide capabilities instead 48 -- Check service-wide capabilities instead
49 local service_capabilities = self.config.capabilities;
51 local caps = service_capabilities[node_aff or service_aff]; 50 local caps = service_capabilities[node_aff or service_aff];
52 if caps then 51 if caps then
53 local can = caps[action]; 52 local can = caps[action];
54 if can ~= nil then 53 if can ~= nil then
55 return can; 54 return can;