Fix state transition for subcommands modified by permission hooks (#3956)

* [Permissions] Fix state transition for subcommands modified by
permission hooks

* docs
This commit is contained in:
Michael H 2020-07-18 15:40:23 -04:00 committed by GitHub
parent 1852420b98
commit a35bcecf94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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]