Commit graph

20 commits

Author SHA1 Message Date
Simon Willison
2b879e462f Implement resource-based permission system with SQL-driven access control
This introduces a new hierarchical permission system that uses SQL queries
for efficient permission checking across resources. The system replaces the
older permission_allowed() pattern with a more flexible resource-based
approach.

Core changes:

- New Resource ABC and Action dataclass in datasette/permissions.py
  * Resources represent hierarchical entities (instance, database, table)
  * Each resource type implements resources_sql() to list all instances
  * Actions define operations on resources with cascading rules

- New plugin hook: register_actions(datasette)
  * Plugins register actions with their associated resource types
  * Replaces register_permissions() and register_resource_types()
  * See docs/plugin_hooks.rst for full documentation

- Three new Datasette methods for permission checks:
  * allowed_resources(action, actor) - returns list[Resource]
  * allowed_resources_with_reasons(action, actor) - for debugging
  * allowed(action, resource, actor) - checks single resource
  * All use SQL for filtering, never Python iteration

- New /-/tables endpoint (TablesView)
  * Returns JSON list of tables user can view
  * Supports ?q= parameter for regex filtering
  * Format: {"matches": [{"name": "db/table", "url": "/db/table"}]}
  * Respects all permission rules from configuration and plugins

- SQL-based permission evaluation (datasette/utils/actions_sql.py)
  * Cascading rules: child-level → parent-level → global-level
  * DENY beats ALLOW at same specificity
  * Uses CTEs for efficient SQL-only filtering
  * Combines permission_resources_sql() hook results

- Default actions in datasette/default_actions.py
  * InstanceResource, DatabaseResource, TableResource, QueryResource
  * Core actions: view-instance, view-database, view-table, etc.

- Fixed default_permissions.py to handle database-level allow blocks
  * Now creates parent-level rules for view-table action
  * Fixes: datasette ... -s databases.fixtures.allow.id root

Documentation:

- Comprehensive register_actions() hook documentation
- Detailed resources_sql() method explanation
- /-/tables endpoint documentation in docs/introspection.rst
- Deprecated register_permissions() with migration guide

Tests:

- tests/test_actions_sql.py: 7 tests for core permission API
- tests/test_tables_endpoint.py: 13 tests for /-/tables endpoint
- All 118 documentation tests pass
- Tests verify SQL does filtering (not Python)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-24 10:32:18 -07:00
Simon Willison
5d21057cf1 /-/config example, refs #2254 2024-02-06 15:22:03 -08:00
Simon Willison
1e901aa690 /-/config page, closes #2254 2024-02-06 12:33:46 -08:00
Simon Willison
fae3983c51 Drop support for Python 3.6, closes #1577
Refs #1606
2022-01-19 20:31:22 -08:00
Simon Willison
5a77f7a649 Updated docs renaming config to settings
- config.html is now settings.html
- ConfigOption in app.py is now Setting
- updated documentation unit tests

Refs #1106
2020-11-24 13:22:33 -08:00
Simon Willison
2a3d5b720b Redirect /-/config to /-/settings, closes #1103 2020-11-24 12:19:14 -08:00
Simon Willison
d6f9ff7137 Docs on Designing URLs for your plugin - closes #1053 2020-10-29 12:35:25 -07:00
Simon Willison
a7137dfe06 /-/plugins now shows details of hooks, closes #794
Also added /-/plugins?all=1 parameter to see default plugins.
2020-06-02 14:49:28 -07:00
Simon Willison
4fa7cf6853 Flash messages mechanism, closes #790 2020-06-02 14:12:18 -07:00
Simon Willison
1fc6ceefb9 Added /-/actor.json - refs #699
Also added JSON highlighting to introspection documentation.
2020-05-31 18:16:42 -07:00
Simon Willison
d6b6c9171f Include asyncio task information in /-/threads debug page 2019-12-04 22:47:17 -08:00
Simon Willison
a314b76186 Added /-/threads debugging page 2019-10-02 08:35:25 -07:00
Simon Willison
0dad111d24 New introspection endpoint: /-/databases - closes #470
Refs #419 and #465
2019-05-16 07:49:34 -07:00
Simon Willison
c0d1b4c322 "datasette inspect foo.db" now just calculates table counts
Refs #462

* inspect command now just outputs table counts
* test_inspect.py is now only tests for that CLI command
* Updated some relevant documentation
* Removed docs for /-/inspect since that is about to change
2019-05-11 14:36:57 -07:00
Simon Willison
53bf875483 expand_foreign_keys() no longer uses inspect, refs #420 2019-04-06 19:56:07 -07:00
Simon Willison
8ce7866312 compile_options output in /-/versions, closes #396 2019-01-10 16:44:50 -08:00
Simon Willison
8da6b0d542
Added labels so unit tests can detect docs, refs #299 2018-07-27 20:26:18 -07:00
Simon Willison
d59366d36e
Link to /-/plugins example 2018-05-20 21:07:26 -07:00
Simon Willison
0b8e5981a3
Typo fix 2018-05-20 14:30:48 -07:00
Simon Willison
bd3353a31f
Added docs for introspection endpoints
https://datasette.readthedocs.io/en/latest/introspection.html
2018-05-20 14:28:53 -07:00