mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
confirm: true mechanism for drop table API, closes #1887
This commit is contained in:
parent
db796771e2
commit
612da8eae6
4 changed files with 64 additions and 8 deletions
|
|
@ -336,7 +336,7 @@ class ApiExplorerView(BaseView):
|
|||
{
|
||||
"path": self.ds.urls.table(name, table) + "/-/drop",
|
||||
"label": "Drop table {}".format(table),
|
||||
"json": {},
|
||||
"json": {"confirm": False},
|
||||
"method": "POST",
|
||||
}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1236,6 +1236,26 @@ class TableDropView(BaseView):
|
|||
request.actor, "drop-table", resource=(database_name, table_name)
|
||||
):
|
||||
return _error(["Permission denied"], 403)
|
||||
|
||||
confirm = False
|
||||
try:
|
||||
data = json.loads(await request.post_body())
|
||||
confirm = data.get("confirm")
|
||||
except json.JSONDecodeError as e:
|
||||
pass
|
||||
|
||||
if not confirm:
|
||||
return Response.json(
|
||||
{
|
||||
"ok": True,
|
||||
"row_count": (
|
||||
await db.execute("select count(*) from [{}]".format(table_name))
|
||||
).single_value(),
|
||||
"message": 'Pass "confirm": true to confirm',
|
||||
},
|
||||
status=200,
|
||||
)
|
||||
|
||||
# Drop table
|
||||
def drop_table(conn):
|
||||
sqlite_utils.Database(conn)[table_name].drop()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue