Add the get_permissions plugin hook (contract 0.10.0)
Plugins declare their own RBAC permissions instead of core accumulating them: 36 permissions moved out of the core catalog into the 9 owning plugins (core keeps the 19 its own blueprints enforce). The catalog is resolved dynamically (core + enabled plugins) and feeds the roles grid, the token scope picker and ceiling, and flask seed permissions; installing or enabling a plugin seeds its permissions automatically. A disabled plugin drops out of the assignable catalog while existing role links keep working. New plugins - bundled or external - now bring their permissions with zero core edits. 781 tests pass; live-verified with a machines.edit-scoped token. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -209,6 +209,40 @@ class BasePlugin(ABC):
|
||||
"""
|
||||
return []
|
||||
|
||||
def get_permissions(self) -> List:
|
||||
"""
|
||||
Return the RBAC permissions this plugin owns.
|
||||
|
||||
Each entry is a (name, description, category) tuple, matching the core
|
||||
permission catalog shape (dicts with those keys are also accepted):
|
||||
|
||||
[
|
||||
('machines.view', 'View machines', 'machines'),
|
||||
('machines.create', 'Create machines', 'machines'),
|
||||
('machines.edit', 'Edit machines', 'machines'),
|
||||
('machines.delete', 'Delete machines', 'machines'),
|
||||
]
|
||||
|
||||
A plugin owns the permission names its own routes enforce via
|
||||
require_permission; core no longer accumulates them. The names must
|
||||
follow the naming convention (lowercase dotted, e.g. `machines.edit`).
|
||||
|
||||
Consumed by full_permission_catalog(): core permissions plus every
|
||||
ENABLED plugin's get_permissions(). That catalog backs `flask seed
|
||||
permissions`, the role-management grid (GET /api/users/permissions),
|
||||
and API-token scope validation. Plugin install/enable also seeds the
|
||||
plugin's own permissions idempotently.
|
||||
|
||||
Disabled plugins are skipped by the catalog, so their permissions are
|
||||
no longer offered for new scope grants or new role assignments. The
|
||||
Permission ROWS already in the database are NOT deleted, so roles that
|
||||
already reference them keep working until an admin edits the role. A
|
||||
broken plugin is isolated in prod and re-raised in dev/test.
|
||||
|
||||
Return [] (the default) if the plugin needs no permissions.
|
||||
"""
|
||||
return []
|
||||
|
||||
def get_reports(self) -> List[Dict]:
|
||||
"""
|
||||
Return report card definitions for the Reports hub.
|
||||
|
||||
Reference in New Issue
Block a user