mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Fix view-database-download permission handling
Two fixes for database download permissions:
1. Added also_requires="view-database" to view-database-download action
- You should only be able to download a database if you can view it
2. Added view-database-download to default_allow_actions list
- This action should be allowed by default, like view-database
3. Implemented also_requires checking in allowed() method
- The allowed() method now checks action.also_requires before
checking the action itself
- This ensures execute-sql requires view-database, etc.
Fixes test_database_download_for_immutable and
test_database_download_disallowed_for_memory.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
ad00bb11f6
commit
b5f41772ca
3 changed files with 13 additions and 0 deletions
|
|
@ -1249,6 +1249,17 @@ class Datasette:
|
|||
if resource is None:
|
||||
resource = InstanceResource()
|
||||
|
||||
# Check if this action has also_requires - if so, check that action first
|
||||
action_obj = self.actions.get(action)
|
||||
if action_obj and action_obj.also_requires:
|
||||
# Must have the required action first
|
||||
if not await self.allowed(
|
||||
action=action_obj.also_requires,
|
||||
resource=resource,
|
||||
actor=actor,
|
||||
):
|
||||
return False
|
||||
|
||||
result = await check_permission_for_resource(
|
||||
datasette=self,
|
||||
actor=actor,
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ def register_actions():
|
|||
takes_parent=True,
|
||||
takes_child=False,
|
||||
resource_class=DatabaseResource,
|
||||
also_requires="view-database",
|
||||
),
|
||||
Action(
|
||||
name="view-table",
|
||||
|
|
|
|||
|
|
@ -122,6 +122,7 @@ async def permission_resources_sql(datasette, actor, action):
|
|||
default_allow_actions = {
|
||||
"view-instance",
|
||||
"view-database",
|
||||
"view-database-download",
|
||||
"view-table",
|
||||
"execute-sql",
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue