Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions docs/plugin_hooks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,25 @@ The fields of the ``Action`` dataclass are as follows:
- Implement a ``resources_sql()`` classmethod that returns SQL returning all resources as ``(parent, child)`` columns
- Have an ``__init__`` method that accepts appropriate parameters and calls ``super().__init__(parent=..., child=...)``

Checking a registered action
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To check one of these actions in your plugin code, call
``datasette.allowed()`` with both the action name and a resource instance.
For example, this checks if the current actor can view a specific
``DocumentResource``:

.. code-block:: python

async def can_view_document(
datasette, actor, collection, document_id
):
return await datasette.allowed(
actor,
"view-document",
resource=DocumentResource(collection, document_id),
)

The ``resources_sql()`` method
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down