Conversation
…debugger Nothing answered 'why can/can't user X do P at org O / on object R?'. The new command re-asks the canonical predicate for the mode (can at an org, can_obj on a row, can_anywhere with no scope) so the verdict can never disagree with enforcement, then walks the arms behind it: global tier (superuser / global Role / user_permissions), direct grant, delegated grant (permission-matched), object grant (not wired until the clients cutover), and legacy PermissionGroup rows with the domain's live/inert posture — the last one doubles as a cutover-progress view: notes/clients still authorize through it, and the verdict shown is what enforcement becomes after cutover. Exits 0 on ALLOWED, 1 on DENIED — script-friendly. Tests pin the load-bearing property (verdict == can/can_obj/can_anywhere in every scenario) plus arm attribution per arm. Docs: permissions.md 'Debugging authority' + Key Files.
Contributor
Reviewer's GuideIntroduces a canonical-predicate-backed permission authority debugger as both a reusable explanation API and manage.py command, with arm-level diagnostics for global, direct, delegated, object, and legacy authorization paths, comprehensive parity-focused tests, and documentation. Sequence diagram for permission authority explanationsequenceDiagram
actor Operator
participant Command as explain_permission
participant Explain as permissions.explain.explain
participant Predicate as Canonical selectors
participant Database as Authorization data
Operator->>Command: provide user, perm, org or object
Command->>Explain: explain(user, perm, org, obj)
Explain->>Predicate: can(), can_obj(), or can_anywhere()
Predicate->>Database: evaluate effective authority
Database-->>Predicate: verdict
Explain->>Database: inspect global, direct, delegated, object, legacy arms
Database-->>Explain: arm diagnostics and cutover posture
Explain-->>Command: Explanation
Command-->>Operator: ALLOWED or DENIED, arms, notes
alt verdict is denied
Command-->>Operator: exit code 1
else verdict is allowed
Command-->>Operator: exit code 0
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The DX gap flagged in the grant-model audit: nothing answered "why can/can't user X do P at org O / on object R?" — you had to read predicate code and run ad-hoc shell queries. This adds
manage.py explain_permissionplus its pure corecommon.permissions.explain.explain().Design — the verdict can never disagree with enforcement
The explanation re-asks the canonical predicate for the mode —
can()at an org,can_obj()on a row,can_anywhere()with no scope — then walks the arms behind it:PermissionGroupmembership with the domain's live/inert posture (LEGACY_INERT_APPS)The legacy arm doubles as a cutover-progress view: for notes/clients it shows the arm that actually authorizes today and the grant-model verdict (what enforcement becomes after cutover); for cut-over domains it proves leftover rows are inert.
Exits 0 on ALLOWED, 1 on DENIED — script-friendly.
Verified
verdict == can/can_obj/can_anywhereper scenario, plus arm attribution (direct, delegated matched/unmatched, global role, superuser, legacy live vs inert, ORG vs SHARED write tier, command output + exit code).common/testsfull suite: 245 passed; ruff check/format clean; mypy clean on the new files (only the pre-existingaccounts/managers.pyno-any-returnpair remains, untouched).apps/betterangels-backend/docs/permissions.md— new Debugging authority section + Key Files rows.Stacked on #2453 (the ungated-mutation tripwire).
Summary by Sourcery
Add an authority debugger that explains canonical permission decisions and identifies the grant or legacy sources behind them.
New Features:
manage.py explain_permissioncommand for diagnosing a user's authority at an organization, on an object, or globally.Enhancements:
Documentation:
Tests: