From a35bcecf94d44860bc522f4eb865db86c9a04287 Mon Sep 17 00:00:00 2001 From: Michael H Date: Sat, 18 Jul 2020 15:40:23 -0400 Subject: [PATCH] Fix state transition for subcommands modified by permission hooks (#3956) * [Permissions] Fix state transition for subcommands modified by permission hooks * docs --- redbot/core/commands/requires.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/redbot/core/commands/requires.py b/redbot/core/commands/requires.py index a476e9c79..48b1697d0 100644 --- a/redbot/core/commands/requires.py +++ b/redbot/core/commands/requires.py @@ -183,11 +183,15 @@ class PermState(enum.Enum): ALLOWED_BY_HOOK = enum.auto() """This command has been actively allowed by a permission hook. - check validation doesn't need this, but is useful to developers""" + check validation swaps this out, but the information may be useful + to developers. It is treated as `ACTIVE_ALLOW` for the current command + and `PASSIVE_ALLOW` for subcommands.""" DENIED_BY_HOOK = enum.auto() """This command has been actively denied by a permission hook - check validation doesn't need this, but is useful to developers""" + check validation swaps this out, but the information may be useful + to developers. It is treated as `ACTIVE_DENY` for the current command + and any subcommands.""" @classmethod def from_bool(cls, value: Optional[bool]) -> "PermState": @@ -263,6 +267,17 @@ PermStateAllowedStates = ( def transition_permstate_to(prev: PermState, next_state: PermState) -> TransitionResult: + + # Transforms here are used so that the + # informational ALLOWED_BY_HOOK/DENIED_BY_HOOK + # remain, while retaining the behavior desired. + if prev is PermState.ALLOWED_BY_HOOK: + # As hook allows are extremely granular, + # we don't want this to allow every subcommand + prev = PermState.PASSIVE_ALLOW + elif prev is PermState.DENIED_BY_HOOK: + # However, denying should deny every subcommand + prev = PermState.ACTIVE_DENY return PermStateTransitions[prev][next_state]