Commit graph

1,087 commits

Author SHA1 Message Date
Simon Willison
e7c7e21277 Ran blacken-docs 2025-10-25 15:38:07 -07:00
Simon Willison
d7d7ead0ef Ran cog 2025-10-25 15:38:07 -07:00
Simon Willison
fabcfd68ad Add datasette.ensure_permission() method, refs #2525, refs #2528
Implements a new ensure_permission() method that is a convenience wrapper
around allowed() that raises Forbidden instead of returning False.

Changes:
- Added ensure_permission() method to datasette/app.py
- Updated all views to use ensure_permission() instead of the pattern:
  if not await self.ds.allowed(...): raise Forbidden(...)
- Updated docs/internals.rst to document the new method
- Removed old ensure_permissions() documentation (that method was already removed)

The new method simplifies permission enforcement in views and makes the
code more concise and consistent.
2025-10-25 15:38:07 -07:00
Simon Willison
6df364cb2c Ran cog 2025-10-25 15:38:07 -07:00
Simon Willison
4be7eece8c just prettier, just format shortcuts 2025-10-25 09:04:04 -07:00
Simon Willison
a2994cc5bb Remove automatic parameter namespacing from permission plugins
Simplifies the permission system by removing automatic parameter namespacing.
Plugins are now responsible for using unique parameter names. The recommended
convention is to prefix parameters with the plugin source name (e.g.,
:myplugin_user_id). System reserves :actor, :actor_id, :action, :filter_parent.

- Remove _namespace_params() function from datasette/utils/permissions.py
- Update build_rules_union() to use plugin params directly
- Document parameter naming convention in plugin_hooks.rst
- Update example plugins to use prefixed parameters
- Add test_multiple_plugins_with_own_parameters() to verify convention works
2025-10-24 11:44:43 -07:00
Simon Willison
a21a1b6c14 Ran blacken-docs 2025-10-24 10:32:18 -07:00
Simon Willison
c0b5ce04c3 Ran cog 2025-10-24 10:32:18 -07:00
Simon Willison
b8d26754df Document datasette.allowed(), PermissionSQL class, and SQL parameters
- Added documentation for datasette.allowed() method with keyword-only arguments
- Added comprehensive PermissionSQL class documentation with examples
- Documented the three SQL parameters available: :actor, :actor_id, :action
- Included examples of using json_extract() to access actor fields
- Explained permission resolution rules (specificity, deny over allow, implicit deny)
- Fixed RST formatting warnings (escaped asterisk, fixed underline length)
2025-10-24 10:32:18 -07:00
Simon Willison
c06e05b7db New --root mechanism with datasette.root_enabled, closes #2521 2025-10-24 10:32:18 -07:00
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
27084caa04
New allowed_resources_sql plugin hook and debug tools (#2505)
* allowed_resources_sql plugin hook and infrastructure
* New methods for checking permissions with the new system
* New /-/allowed and /-/check and /-/rules special endpoints

Still needs to be integrated more deeply into Datasette, especially for listing visible tables.

Refs: #2502

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-08 14:27:51 -07:00
Simon Willison
85da8474d4
Python 3.14, drop Python 3.9
Closes #2506
2025-10-08 13:11:32 -07:00
Simon Willison
9dc2a3ffe5 Removed broken refs to Glitch, closes #2503 2025-09-28 21:15:58 -07:00
Simon Willison
7a602140df catalog_views table, closes #2495
Refs https://github.com/datasette/datasette-queries/issues/1#issuecomment-3074491003
2025-07-15 10:22:56 -07:00
Simon Willison
e2497fdb59 Replace Glitch with Codespaces, closes #2488 2025-05-28 19:17:22 -07:00
Simon Willison
1c77a7e33f Fix global-power-points references
Refs https://github.com/simonw/datasette.io/issues/167
2025-05-28 19:07:46 -07:00
Simon Willison
6f7f4c7d89 Release 1.0a19
Refs #2479
2025-04-21 22:38:53 -07:00
Simon Willison
271aa09056 Release 1.0a18
Refs #2466, #2468, #2470, #2476, #2477
2025-04-16 22:16:25 -07:00
Simon Willison
f6446b3095 Further wording tweaks 2025-04-16 08:25:03 -07:00
Simon Willison
d03273e205
Wording tweak 2025-04-16 08:19:22 -07:00
Simon Willison
d021ce97aa
Note that only first actor_from_request value is respected
https://github.com/datasette/datasette-profiles/issues/4#issuecomment-2758588167
2025-03-27 09:09:57 -07:00
Simon Willison
7945f4fbf2 Improved docs for db.get_all_foreign_keys() 2025-03-12 15:42:11 -07:00
Simon Willison
333f786cb0 Correct syntax for link headers, closes #2470 2025-03-09 20:05:43 -05:00
Simon Willison
209bdee0e8 Don't run prepare_connection() on internal database, closes #2468 2025-02-18 10:23:23 -08:00
Simon Willison
e59fd01757 Fix for incorrect REFERENCES in internal DB
Refs #2466
2025-02-12 19:40:43 -08:00
Simon Willison
cd9182a551 Release 1.0a17
Refs #1690, #1943, #2422, #2424, #2441, #2454, #2455, #2458, #2460, #2465
2025-02-06 11:12:34 -08:00
Simon Willison
308c243cfd datasette.set_actor_cookie() and datasette.delete_actor_cookie(), closes #1690 2025-01-15 17:37:25 -08:00
Solomon Himelbloom
1902735c63
docs: fix time travel bug via changelog.rst (#2449) 2025-01-01 15:41:42 -08:00
Simon Willison
7077b8b1ba Changelog for 0.65.1, refs #2443 2024-11-28 17:14:27 -08:00
Simon Willison
e85517dab3 blacken-docs, refs #2441 2024-11-15 13:34:45 -08:00
Simon Willison
dce718961c Async support for magic parameters
Closes #2441
2024-11-15 13:17:45 -08:00
Simon Willison
b0b600b79f Release notes for 0.65 in main branch
Refs #2434
2024-10-07 10:40:57 -07:00
Simon Willison
832f76ce26 Documentation for datasette serve environment variables
Refs #2422, #2424
2024-09-09 09:18:47 -07:00
Simon Willison
0bc6a2af89 Release 1.0a16
Refs #2320, #2342, #2398, #2399, #2400, #2403, #2404, #2405, #2406, #2407, #2408, #2414, #2415, #2420
2024-09-05 20:56:46 -07:00
Simon Willison
2170269258
New .core CSS class for inputs and buttons
* Initial .core input/button classes, refs #2415
* Docs for the new .core CSS class, refs #2415
* Applied .core class everywhere that needs it, closes #2415
2024-09-03 08:37:26 -07:00
Simon Willison
92c4d41ca6 results.dicts() method, closes #2414 2024-09-01 17:20:41 -07:00
Tiago Ilieve
1f3fb5f96b
debugger: load 'ipdb' if present
* debugger: load 'ipdb' if present

Transparently chooses between the IPython-enhanced 'ipdb' or the
standard 'pdb'.

* datasette install ipdb

---------

Co-authored-by: Simon Willison <swillison@gmail.com>
2024-08-20 20:02:35 -07:00
Simon Willison
39dfc7d7d7
Removed units functionality and Pint dependency
Closes #2400, unblocks #2320
2024-08-20 19:03:33 -07:00
Simon Willison
7d8dd2ac7f Release 1.0a15
Refs #2296, #2326, #2384, #2386, #2389, #2390, #2393, #2394
2024-08-15 22:04:04 -07:00
Simon Willison
93067668fe /-/ alternative URL for homepage, closes #2393 2024-08-14 17:57:13 -07:00
Simon Willison
2e82eb108c Group docs on get_/set_ metadata methods, refs #2381 2024-08-05 14:16:34 -07:00
Simon Willison
ff710ed7eb Typo fix, refs #2381 2024-08-05 14:09:12 -07:00
Simon Willison
5bd6853bf4 Release notes for 1.0a14, refs #2381
Refs #2306, #2307, #2311, #2319, #2341, #2348, #2352, #2353, #2358, #2359, #2360, #2375
2024-08-05 14:08:15 -07:00
Simon Willison
78ce105413 Markup fix 2024-08-05 14:07:16 -07:00
Simon Willison
2b0a61ee19 Rename metadata tables and add schema to docs, refs #2382 2024-08-05 13:53:55 -07:00
Simon Willison
8dc9bfa2ab Markup tweak for track_event docs 2024-08-05 12:58:10 -07:00
Simon Willison
2ad51baa31 Move /db?sql= redirect to top of changes
Refs #2381
2024-08-05 12:16:30 -07:00
Simon Willison
bd7d3bb70f Tweaks and improvements to upgrade guide, refs ##2374
Also refs #2381
2024-08-05 12:11:17 -07:00
Alex Garcia
169ee5d710
Initial upgrade guide for v0.XX to v1 2024-08-05 10:35:38 -07:00