Permissions redesign #2149
No reviewers
Labels
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Mrcoolgamer11/Red-DiscordBot!2149
Loading…
Reference in a new issue
No description provided.
Delete branch "V3/redesign_permissions_model"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR proposes a complete redesign of how the permissions cog works, how our default check decorators work, amongst some other things.
One major difference is how default permissions are described. An instance of the new
Requiresclass in theredbot.core.commands.requireswill be attached to everycommands.Commandobject and everycommands.Cogobject at therequiresattribute. This object describes the bot's and user's required permissions for the command, the privilege level required, the overrides for the command/cog, and any checks which should be checked after overrides. In my opinion this improves the current design of how there are managed since it is a clear representation of everything related to the command's required permissions, and provides a simple and efficient API for modifying these requirements during runtime.How permissions rules are applied to
Requiresobjects is another question. One of the main motivations of this redesign was to resolve #1931 in a way which is sane, reliable, and doesn't impact performance. The main focus was trying to delegate complex tasks to the application and/or removal of rules, rather than having them be resolved every time a command is called. This is why now, when a rule is explicitly allowed or denied, rules for supercommands will have rules applied as well. Overrides are now resolved much like a state machine; see therequiresmodule for more info on how this works.This does mean rules stored in the config of the Permissions cog need to be loaded into these objects either when the permissions cog is loaded, or the receiving command/cog is loaded (whichever comes first). Events, setup and teardown tasks have been added to facilitate this accordingly.
API changes:
commands.Cog(see #2151 for discussion and more details)redbot.core.checksmodule are now deprecated in favour of their counterparts inredbot.core.utils.mod. This is to make this module more consistent and end the confusing naming convention.redbot.core.checks.check_overridesfunction is now gone, overrideable checks can now be created with the@commands.permissions_checkdecorator__permissions_check_beforeand__permissions_check_afterhave been replaced: A cog method named__permissions_hookwill be evaluated as permissions hooks in the same way__permissions_check_beforepreviously was. Permissions hooks can also be added/removed/verified through the new*_permissions_hook()methods on the bot object, and they will be verified even when permissions is unloaded.redbot.core.utils.chat_formatting.humanize_listschemaUser-facing changes:
@bot_has_permissionscheck fails, the bot will respond saying what permissions were actually missing.[p]permissionssubcommands now reside under the[p]permissions aclsub-group (tbh I still think the whole cog has too many top-level commands)Documentation:
redbot.core.commands.requiresandredbot.core.checksmodulessphinx.ext.doctestis now enabledNote: standard discord.py checks will still behave exactly the same way, in fact they are checked before
Requiresis looked at, so they are not overrideable.@ -317,3 +320,33 @@ def escape(text: str, *, mass_mentions: bool = False, formatting: bool = False)if formatting:This doctest looks like it isn't right....
humanize!=humanizedThis PR should now be ready for the first round of reviews! I've updated the header with the details. Sorry if I've missed some stuff.
I'll note on the removal of
__permissions_check_beforeand__permissions_check_after, that I don't think getting rid of them in entirety is a good thing. Getting rid of the after should be mostly fine, but the before did serve an important purpose.Neither the previous iteration or permissions, nor this one can properly support a negative condition. (i.e. deny to anyone not is a specific group, without modifying the rule for that specific group to do it ). An example of where this can be problematic actually shows up in how the docs are being modified to hedge the actual intent behind locking audio, and how using this method will actually prevent a discord server owner (not bot owner) from further restricting those commands. These extra hooks allowed for quick extra rules to be added for people with such cases, without needing to design an entire permission model to make that possible.
Setting via ACL appears to be working as intended. I've not found any major issues. I have found an inability to set rules via non-acl methods, (cause: converter, see comment).
This is a much more sustainable solution than before and seems to be performing well. With a fix for the converters that are problematic, this should be ready to go.
@ -0,0 +54,4 @@]_T = TypeVar("_T")GlobalPermissionModel = Union[This is being used as a union converter in a couple places, which isn't safe. There's no such converter for guild, breaking every attempt to add a rule not via acl, and also the error from this is not user facing (traceback in console, but silent bot response).
I'd suggest adding a guild converter in our subclassed commands to accommodate this.
All changes needed have been made.