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:
@@ -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
|
||||
{
|
||||
|
||||
22
src/main/resources/templates/confirm-delete.html
Normal file
22
src/main/resources/templates/confirm-delete.html
Normal 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>
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user