Add delete confirmation page before removing repository

The Delete Repository button now navigates to a confirmation page
asking 'Are you sure?' with Yes/No options. Only the Yes button
performs the actual delete POST. No JavaScript required.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-02-27 09:31:03 +01:00
parent 4458eb204b
commit 383864469d
4 changed files with 40 additions and 1 deletions

View File

@@ -114,6 +114,13 @@ public class RepoController
return "redirect:/repo/" + name + "/remote";
}
@GetMapping("/repo/{name}/confirm-delete")
public String confirmDelete(@PathVariable String name, Model model)
{
model.addAttribute("name", name);
return "confirm-delete";
}
@PostMapping("/repo/{name}/delete")
public String delete(@PathVariable String name) throws IOException
{

View File

@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title th:text="'Confirm Delete - ' + ${name}">Confirm Delete</title>
</head>
<body>
<h2>Are you sure?</h2>
<p>This will permanently delete the repository <b th:text="${name}"></b> and its working tree.</p>
<table border="0" cellpadding="4" cellspacing="0">
<tr>
<td>
<form method="post" th:action="@{/repo/{name}/delete(name=${name})}" target="_top">
<input type="submit" value="Yes">
</form>
</td>
<td>
<a th:href="@{/repo/{name}/manage(name=${name})}">No</a>
</td>
</tr>
</table>
</body>
</html>

View File

@@ -8,7 +8,7 @@
<h3>Danger Zone</h3>
<p>This will permanently delete the repository and its working tree.</p>
<form method="post" th:action="@{/repo/{name}/delete(name=${name})}" target="_top">
<form method="get" th:action="@{/repo/{name}/confirm-delete(name=${name})}">
<input type="submit" value="Delete Repository">
</form>

View File

@@ -194,6 +194,16 @@ class RepoControllerTest
verify(gitService).updateRemoteUrl("myrepo", "origin", "https://new-url.com/repo.git");
}
@Test
void confirmDeleteShowsConfirmation() throws Exception
{
mockMvc.perform(get("/repo/myrepo/confirm-delete"))
.andExpect(status().isOk())
.andExpect(view().name("confirm-delete"))
.andExpect(model().attribute("name", "myrepo"))
.andExpect(content().string(org.hamcrest.Matchers.containsString("Are you sure?")));
}
@Test
void deleteRedirectsToRoot() throws Exception
{