Repository navigation
COG-1155: W1 · TransferController recipient delete → POST form (server + Thymeleaf) #339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,9 +7,10 @@ | |
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
| import org.springframework.ui.Model; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.ModelAttribute; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestMethod; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
|
|
||
| import com.userFront.domain.PrimaryAccount; | ||
|
|
@@ -29,7 +30,7 @@ public class TransferController { | |
| @Autowired | ||
| private UserService userService; | ||
|
|
||
| @RequestMapping(value = "/betweenAccounts", method = RequestMethod.GET) | ||
| @GetMapping("/betweenAccounts") | ||
| public String betweenAccounts(Model model) { | ||
| model.addAttribute("transferFrom", ""); | ||
| model.addAttribute("transferTo", ""); | ||
|
|
@@ -38,7 +39,7 @@ public String betweenAccounts(Model model) { | |
| return "betweenAccounts"; | ||
| } | ||
|
|
||
| @RequestMapping(value = "/betweenAccounts", method = RequestMethod.POST) | ||
| @PostMapping("/betweenAccounts") | ||
| public String betweenAccountsPost(@ModelAttribute("transferFrom") String transferFrom, | ||
| @ModelAttribute("transferTo") String transferTo, @ModelAttribute("amount") String amount, | ||
| Principal principal) throws Exception { | ||
|
|
@@ -50,7 +51,7 @@ public String betweenAccountsPost(@ModelAttribute("transferFrom") String transfe | |
| return "redirect:/userFront"; | ||
| } | ||
|
|
||
| @RequestMapping(value = "/recipient", method = RequestMethod.GET) | ||
| @GetMapping("/recipient") | ||
| public String recipient(Model model, Principal principal) { | ||
| List<Recipient> recipientList = transactionService.findRecipientList(principal); | ||
|
|
||
|
|
@@ -62,7 +63,7 @@ public String recipient(Model model, Principal principal) { | |
| return "recipient"; | ||
| } | ||
|
|
||
| @RequestMapping(value = "/recipient/save", method = RequestMethod.POST) | ||
| @PostMapping("/recipient/save") | ||
| public String recipientPost(@ModelAttribute("recipient") Recipient recipient, Principal principal) { | ||
|
|
||
| User user = userService.findByUsername(principal.getName()); | ||
|
|
@@ -72,7 +73,7 @@ public String recipientPost(@ModelAttribute("recipient") Recipient recipient, Pr | |
| return "redirect:/transfer/recipient"; | ||
| } | ||
|
|
||
| @RequestMapping(value = "/recipient/edit", method = RequestMethod.GET) | ||
| @GetMapping("/recipient/edit") | ||
| public String recipientEdit(@RequestParam(value = "recipientName") String recipientName, Model model, | ||
| Principal principal) { | ||
|
|
||
|
|
@@ -85,7 +86,7 @@ public String recipientEdit(@RequestParam(value = "recipientName") String recipi | |
| return "recipient"; | ||
| } | ||
|
|
||
| @RequestMapping(value = "/recipient/delete", method = RequestMethod.GET) | ||
| @PostMapping("/recipient/delete") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟥 Other users' recipients can be deleted An authenticated user can POST another user's name to Was this helpful? React with 👍 or 👎 to provide feedback. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confirmed, and it is a real problem, but it is not new in this PR. |
||
| @Transactional | ||
| public String recipientDelete(@RequestParam(value = "recipientName") String recipientName, Model model, | ||
| Principal principal) { | ||
|
|
@@ -101,7 +102,7 @@ public String recipientDelete(@RequestParam(value = "recipientName") String reci | |
| return "recipient"; | ||
| } | ||
|
|
||
| @RequestMapping(value = "/toSomeoneElse", method = RequestMethod.GET) | ||
| @GetMapping("/toSomeoneElse") | ||
| public String toSomeoneElse(Model model, Principal principal) { | ||
| List<Recipient> recipientList = transactionService.findRecipientList(principal); | ||
|
|
||
|
|
@@ -111,7 +112,7 @@ public String toSomeoneElse(Model model, Principal principal) { | |
| return "toSomeoneElse"; | ||
| } | ||
|
|
||
| @RequestMapping(value = "/toSomeoneElse", method = RequestMethod.POST) | ||
| @PostMapping("/toSomeoneElse") | ||
| public String toSomeoneElsePost(@ModelAttribute("recipientName") String recipientName, | ||
| @ModelAttribute("accountType") String accountType, @ModelAttribute("amount") String amount, | ||
| Principal principal) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Refreshing recipient page repeats deletion
After a delete POST, refreshing the returned page resubmits
recipientDelete. BecausedeleteRecipientByNameuses the name again, a newly added recipient with that name gets deleted.Learn more
The delete form now submits a POST, but the handler renders
recipientas its response. Browsers can resend that POST when refreshing the resulting page. deleteRecipientByName deletes by name rather than by a unique ID, so a second submission can remove a replacement recipient.Example: A user deletes a recipient named Alex, adds another Alex in a second tab, then refreshes the first tab and confirms resubmission. The new Alex disappears instead of remaining in the recipient list.
Recommended fix: Return
redirect:/transfer/recipientafter the deletion instead of renderingrecipient. The existing GET handler loads the updated list; refreshing its response will only repeat the GET.Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed that PRG (
redirect:/transfer/recipient) is the better pattern. I'm deliberately leaving it out of this PR: the W1 contract is behaviour-neutral, and the money smoke test in #106 assertsstatus().isOk()+view().name("recipient")for delete, so switching to a redirect would change that recorded contract. Onmaster, refreshing after a GET delete also repeated the delete. I'm flagging it to the coordinator as a follow-up, which should update the smoke assertion in the same change.