Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to set permissions on a per-table and per-enrichment basis #24

Open
simonw opened this issue Nov 25, 2023 · 1 comment
Open
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Collaborator

simonw commented Nov 25, 2023

I shipped a enrichments permission that can be coupled to a database.

There are actually two cases to consider here:

  • What enrichments is the current user allowed to use?
  • What databases and tables are they allowed to enrich?

We may have enrichments (e.g. ones with expensive API keys) that are restricted to some users, independent of which tables they are allowed to run them against.

Maybe enrichment is the permission for selecting which enrichments they can use and enrich-table is the one for specific tables?

Originally posted by @simonw in #12 (comment)

@simonw simonw added this to the First stable release milestone Nov 25, 2023
@simonw simonw added the enhancement New feature or request label Nov 25, 2023
@simonw simonw removed this from the First non-alpha release milestone Nov 29, 2023
@simonw simonw changed the title Ability to set permissions on a per-table basis Ability to set permissions on a per-table and per-enrichment basis Nov 30, 2023
@simonw
Copy link
Collaborator Author

simonw commented Nov 30, 2023

Here's the code that checks permissions:

async def check_permissions(datasette, request, database):
if not await datasette.permission_allowed(
request.actor, "enrichments", resource=database, default=False
):
raise Forbidden("Permission denied for enrichments")

And:

@hookimpl
def table_actions(datasette, actor, database, table, request):
async def inner():
if await datasette.permission_allowed(
actor, "enrichments", resource=database, default=False
):
return [
{
"href": datasette.urls.path(
"/-/enrich/{}/{}{}".format(
database,
tilde_encode(table),
"?{}".format(request.query_string)
if request.query_string
else "",
)
),
"label": "Enrich selected data",
}
]
return inner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant