mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
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:
parent
1852420b98
commit
a35bcecf94
@ -183,11 +183,15 @@ class PermState(enum.Enum):
|
|||||||
|
|
||||||
ALLOWED_BY_HOOK = enum.auto()
|
ALLOWED_BY_HOOK = enum.auto()
|
||||||
"""This command has been actively allowed by a permission hook.
|
"""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()
|
DENIED_BY_HOOK = enum.auto()
|
||||||
"""This command has been actively denied by a permission hook
|
"""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
|
@classmethod
|
||||||
def from_bool(cls, value: Optional[bool]) -> "PermState":
|
def from_bool(cls, value: Optional[bool]) -> "PermState":
|
||||||
@ -263,6 +267,17 @@ PermStateAllowedStates = (
|
|||||||
|
|
||||||
|
|
||||||
def transition_permstate_to(prev: PermState, next_state: PermState) -> TransitionResult:
|
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]
|
return PermStateTransitions[prev][next_state]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user