Commit graph

84 commits

Author SHA1 Message Date
Simon Willison
5705ce0d95
Move takes_child/takes_parent information from Action to Resource (#2567)
Simplified Action by moving takes_child/takes_parent logic to Resource

- Removed InstanceResource - global actions are now simply those with resource_class=None
- Resource.parent_class - Replaced parent_name: str with parent_class: type[Resource] | None for direct class references
- Simplified Action dataclass - No more redundant fields, everything is derived from the Resource class structure
- Validation - The __init_subclass__ method now checks parent_class.parent_class to enforce the 2-level hierarchy

Closes #2563
2025-11-01 11:35:08 -07:00
Simon Willison
6a71bde37f
Permissions SQL API improvements (#2558)
* Neater design for PermissionSQL class, refs #2556
  - source is now automatically set to the source plugin
  - params is optional
* PermissionSQL.allow() and PermissionSQL.deny() shortcuts

Closes #2556

* Filter out temp database from attached_databases()

Refs https://github.com/simonw/datasette/issues/2557#issuecomment-3470510837
2025-10-30 15:48:46 -07:00
Simon Willison
5feb5fcf5d Remove permission_allowed hook entirely, refs #2528
The permission_allowed hook has been fully replaced by permission_resources_sql.
This commit removes:
- hookspec definition from hookspecs.py
- 4 implementations from default_permissions.py
- implementations from test plugins (my_plugin.py, my_plugin_2.py)
- hook monitoring infrastructure from conftest.py
- references from fixtures.py
- Also fixes test_get_permission to use ds.get_action() instead of ds.get_permission()
- Removes 5th column (source_plugin) from PermissionSQL queries

This completes the migration to the SQL-based permission system.
2025-10-25 15:38:07 -07:00
Simon Willison
60a38cee85 Run black formatter 2025-10-25 15:38:07 -07:00
Simon Willison
fe2084df66 Update test infrastructure to use register_actions hook
- Consolidated register_permissions and register_actions hooks in my_plugin.py
- Added permission_resources_sql hook to provide SQL-based permission rules
- Updated conftest.py to reference datasette.actions instead of datasette.permissions
- Updated fixtures.py to include permission_resources_sql hook and remove register_permissions
- Added backwards compatibility support for old datasette-register-permissions config
- Converted test actions (this_is_allowed, this_is_denied, etc.) to use permission_resources_sql

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-25 15:38:07 -07:00
Simon Willison
d73b6f169f Add register_actions hook to test plugin and improve test 2025-10-24 10:32:18 -07:00
Simon Willison
308c243cfd datasette.set_actor_cookie() and datasette.delete_actor_cookie(), closes #1690 2025-01-15 17:37:25 -08:00
Simon Willison
dce718961c Async support for magic parameters
Closes #2441
2024-11-15 13:17:45 -08:00
Simon Willison
39dfc7d7d7
Removed units functionality and Pint dependency
Closes #2400, unblocks #2320
2024-08-20 19:03:33 -07:00
Alex Garcia
a23c2aee00
Introduce new /$DB/-/query endpoint, soft replaces /$DB?sql=... (#2363)
* Introduce new default /$DB/-/query endpoint
* Fix a lot of tests
* Update pyodide test to use query endpoint
* Link to /fixtures/-/query in a few places
* Documentation for QueryView

---------

Co-authored-by: Simon Willison <swillison@gmail.com>
2024-07-15 10:33:51 -07:00
Simon Willison
b8711988b9 row_actions() plugin hook, closes #2299 2024-03-12 16:16:05 -07:00
Simon Willison
909c85cd2b view_actions plugin hook, closes #2297 2024-03-12 14:25:28 -07:00
Simon Willison
daf5ca02ca homepage_actions() plugin hook, closes #2298 2024-03-12 13:46:06 -07:00
Simon Willison
090dff542b
Action menu descriptions
* Refactor tests to extract get_actions_links() helper
* Table, database and query action menu items now support optional descriptions

Closes #2294
2024-03-06 22:54:06 -05:00
Simon Willison
4d24bf6b34 Don't explain an explain even in the demo, refs #2293 2024-03-05 18:14:55 -08:00
Simon Willison
5de6797d4a Better demo plugin for query_actions, refs #2293 2024-03-05 18:06:38 -08:00
Simon Willison
6ec0081f5d
query_actions plugin hook
* New query_actions plugin hook, closes #2283
2024-02-27 21:55:16 -08:00
Simon Willison
5c64af6936 Upgrade to latest Black, closes #2239 2024-01-30 19:55:26 -08:00
Alex Garcia
92b8bf38c0
Add new --internal internal.db option, deprecate legacy _internal database
Refs:
- #2157 
---------

Co-authored-by: Simon Willison <swillison@gmail.com>
2023-08-28 20:24:23 -07:00
Simon Willison
0b4a286914 render_cell(..., request) argument, closes #2007 2023-01-27 19:34:14 -08:00
Simon Willison
d94d363ec0 Don't use pytest_asyncio.fixture(scope="session") any more, refs #1959
Also got rid of the weird memory=False hack:

https://github.com/simonw/datasette/pull/1960#issuecomment-1354053151
2022-12-17 13:47:55 -08:00
Simon Willison
425ac4357f Ported app_client to ds_client where possible in test_auth.py, refs #1959 2022-12-17 13:47:55 -08:00
Simon Willison
45979eb723 Rename permission created by demo plugin
It was showing up as 'new-permission' on https://latest.datasette.io/-/permissions
which I thought was confusing
2022-12-12 21:21:01 -08:00
Simon Willison
8bf06a76b5
register_permissions() plugin hook (#1940)
* Docs for permissions: in metadata, refs #1636
* Refactor default_permissions.py to help with implementation of #1636
* register_permissions() plugin hook, closes #1939 - also refs #1938
* Tests for register_permissions() hook, refs #1939
* Documentation for datasette.permissions, refs #1939
* permission_allowed() falls back on Permission.default, refs #1939
* Raise StartupError on duplicate permissions
* Allow dupe permisisons if exact matches
2022-12-12 18:05:54 -08:00
Simon Willison
d7e5e3c9f9 Fix for todomvc permission check
Refs https://github.com/simonw/todomvc-datasette/issues/2
2022-12-01 17:38:23 -08:00
Simon Willison
27efa8c381 todomvc permissions and fixed DATASETTE_SECRET for new demo
Refs https://github.com/simonw/todomvc-datasette/issues/2
2022-12-01 17:29:44 -08:00
Simon Willison
f3c8da7acd MAke the sign in as root button bigger on latest.datasette.io 2022-12-01 13:29:31 -08:00
Simon Willison
ddc999ad12 Async support for prepare_jinja2_environment, closes #1809 2022-09-16 20:38:24 -07:00
Simon Willison
b40872f5e5 prepare_jinja2_environment(datasette) argument, refs #1809 2022-09-14 14:31:54 -07:00
Simon Willison
c09c53f345 New handle_exception plugin hook, refs #1770
Also refs:
- https://github.com/simonw/datasette-sentry/issues/1
- https://github.com/simonw/datasette-show-errors/issues/2
2022-07-17 16:24:39 -07:00
Simon Willison
6373bb3414 Expose current SQLite row to render_cell hook, closes #1300 2022-07-07 09:30:49 -07:00
Simon Willison
8a25ea9bca Implemented import shortcuts, closes #957 2022-02-05 22:34:33 -08:00
Simon Willison
da53e0360d tracer.trace_child_tasks() for asyncio.gather tracing
Also added documentation for datasette.tracer module.

Closes #1576
2022-02-04 21:19:49 -08:00
Simon Willison
c35b84a2aa Remove undocumented sqlite_functions mechanism, closes #1567 2021-12-17 17:54:39 -08:00
Simon Willison
6e971b4ac1 Test confirming plugins can over-ride default routes, closes #1517 2021-11-18 19:07:21 -08:00
Simon Willison
3bb6409a6c render_cell() can now return an awaitable, refs 2021-08-08 16:05:00 -07:00
Simon Willison
a679d0de87 Fixed spelling of 'receive' in a bunch of places 2021-08-03 09:11:18 -07:00
Simon Willison
eccfeb0871 register_routes() plugin hook datasette argument, closes #1404 2021-07-26 16:16:46 -07:00
Simon Willison
b1fd24ac9f skip_csrf(datasette, scope) plugin hook, refs #1377 2021-06-23 15:40:09 -07:00
Simon Willison
d23a267138 Make request available to menu plugin hooks, closes #1371 2021-06-09 21:45:24 -07:00
Simon Willison
2bd9d54b27 Fix Jinja warnings, closes #1338, refs #1331 2021-05-23 18:41:50 -07:00
Simon Willison
d579fcf4f7 Applied some fixes suggested by @withshubh in #1260 2021-03-28 17:20:55 -07:00
Simon Willison
c38c42948c extra_body_script module support, closes #1187 2021-01-13 18:14:33 -08:00
Simon Willison
fa0c3777b8 script type=module support, closes #1186 2021-01-13 17:50:52 -08:00
Miroslav Šedivý
a882d67962
Modernize code to Python 3.6+ (#1158)
* Compact dict and set building
* Remove redundant parentheses
* Simplify chained conditions
* Change method name to lowercase
* Use triple double quotes for docstrings

Thanks, @eumiro!
2020-12-23 09:04:32 -08:00
Simon Willison
30e64c8d3b
Use f-strings in place of .format()
Code transformed like so:

    pip install flynt
    flynt .
    black .
2020-11-15 15:24:22 -08:00
Simon Willison
7b19492070 database_actions() plugin hook, closes #1077 2020-11-02 10:27:25 -08:00
Simon Willison
bf18b9ba17 Stop using plugin-example.com, closes #1074 2020-10-31 12:47:42 -07:00
Simon Willison
84bc7244c1 datasette.client now applies base_url, closes #1026 2020-10-31 12:29:42 -07:00
Simon Willison
d6db47f5c1 Deploy demo plugins to latest.datasette.io, refs #1074 2020-10-31 10:36:46 -07:00