This is an automated email from the ASF dual-hosted git repository.
sbp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-trusted-release.git
The following commit(s) were added to refs/heads/main by this push:
new 3507701 Add a tool to delete files within a candidate draft
3507701 is described below
commit 3507701579c203c8df210645a77703539e47c3a9
Author: Sean B. Palmer <[email protected]>
AuthorDate: Tue Mar 25 19:37:40 2025 +0200
Add a tool to delete files within a candidate draft
---
atr/routes/files.py | 26 ++++++++++++++++++++++++--
atr/templates/files-tools.html | 2 +-
2 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/atr/routes/files.py b/atr/routes/files.py
index 2e064de..09f8fd7 100644
--- a/atr/routes/files.py
+++ b/atr/routes/files.py
@@ -503,6 +503,28 @@ async def root_files_tools(session: CommitterSession,
project_name: str, version
@committer_route("/files/delete/<project_name>/<version_name>/<path:file_path>",
methods=["POST"])
-async def root_files_delete(session: CommitterSession, project_name: str,
version_name: str, file_path: str) -> str:
+async def root_files_delete(
+ session: CommitterSession, project_name: str, version_name: str,
file_path: str
+) -> response.Response:
"""Delete a specific file from the release candidate."""
- return ""
+ # Check that the user has access to the project
+ if not any((p.name == project_name) for p in (await
session.user_projects)):
+ raise base.ASFQuartException("You do not have access to this project",
errorcode=403)
+
+ async with db.session() as data:
+ # Check that the release exists
+ await data.release(name=f"{project_name}-{version_name}",
_project=True).demand(
+ base.ASFQuartException("Release does not exist", errorcode=404)
+ )
+
+ full_path = str(util.get_candidate_draft_dir() / project_name /
version_name / file_path)
+
+ # Check that the file exists
+ if not await aiofiles.os.path.exists(full_path):
+ raise base.ASFQuartException("File does not exist", errorcode=404)
+
+ # Delete the file
+ await aiofiles.os.remove(full_path)
+
+ await quart.flash("File deleted successfully", "success")
+ return quart.redirect(quart.url_for("root_files_list",
project_name=project_name, version_name=version_name))
diff --git a/atr/templates/files-tools.html b/atr/templates/files-tools.html
index 25aac5e..8c813ac 100644
--- a/atr/templates/files-tools.html
+++ b/atr/templates/files-tools.html
@@ -30,6 +30,6 @@
<p>This tool deletes the file from the candidate draft.</p>
<form method="post"
action="{{ url_for('root_files_delete', project_name=project_name,
version_name=version_name, file_path=file_path) }}">
- <button type="submit" class="btn btn-danger" disabled>Delete file</button>
+ <button type="submit" class="btn btn-danger">Delete file</button>
</form>
{% endblock content %}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]