From c16728f5c155cdf569eae960bb68e5d9d8e3683d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Wed, 12 Dec 2018 15:29:23 +0100 Subject: [PATCH] modules/{policy,view}: do not act if FAIL or DONE Not all actions are destructive, but it seems generally expected that if an earlier module or other code already transitioned the request into a FAIL or DONE state, we don't want to apply rules anymore. In particular, later rule actions would "overwrite" what previous actions did. --- modules/policy/policy.lua | 6 ++++++ modules/view/view.lua | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/policy/policy.lua b/modules/policy/policy.lua index 7a3fb6bbc..6e9492fb7 100644 --- a/modules/policy/policy.lua +++ b/modules/policy/policy.lua @@ -549,12 +549,18 @@ end -- as a dependency chain, e.g. r1,r2,r3 -> r3(r2(r1(state))) policy.layer = { begin = function(state, req) + -- Don't act on "resolved" cases. + if bit.band(state, bit.bor(kres.FAIL, kres.DONE)) ~= 0 then return state end + req = kres.request_t(req) return policy.evaluate(policy.rules, req, req:current(), state) or policy.evaluate(policy.special_names, req, req:current(), state) or state end, finish = function(state, req) + -- Don't act on "resolved" cases. + if bit.band(state, bit.bor(kres.FAIL, kres.DONE)) ~= 0 then return state end + req = kres.request_t(req) return policy.evaluate(policy.postrules, req, req:current(), state) or state end diff --git a/modules/view/view.lua b/modules/view/view.lua index 7e84ff29d..41157eb8d 100644 --- a/modules/view/view.lua +++ b/modules/view/view.lua @@ -106,7 +106,9 @@ end -- @function Module layers view.layer = { begin = function(state, req) - if state == kres.FAIL then return state end + -- Don't act on "resolved" cases. + if bit.band(state, bit.bor(kres.FAIL, kres.DONE)) ~= 0 then return state end + req = kres.request_t(req) evaluate(state, req) return req.state -- 2.47.2