Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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", "");
Expand All @@ -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 {
Expand All @@ -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);

Expand All @@ -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());
Expand All @@ -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) {

Expand All @@ -85,7 +86,7 @@ public String recipientEdit(@RequestParam(value = "recipientName") String recipi
return "recipient";
}

@RequestMapping(value = "/recipient/delete", method = RequestMethod.GET)
@PostMapping("/recipient/delete")

Copy link
Copy Markdown

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. Because deleteRecipientByName uses 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 recipient as 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/recipient after the deletion instead of rendering recipient. The existing GET handler loads the updated list; refreshing its response will only repeat the GET.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown

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 asserts status().isOk() + view().name("recipient") for delete, so switching to a redirect would change that recorded contract. On master, 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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 recipientDelete and remove that recipient. deleteRecipientByName deletes globally by name; listing recipients afterward does not limit the deletion.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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. master already had it on the GET mapping: TransactionServiceImpl.deleteRecipientByName → recipientDao.deleteByName deletes by name globally. This happens with findRecipientByName too (edit, and toSomeoneElse transfers). COG-1155 is limited to changing the HTTP method (a W1 behaviour-neutral refactor), and the money smoke suite (#106) records current behaviour, so I have not scoped the service/DAO by owner here. I'm reporting it to the coordinator so it can get its own ticket.

@Transactional
public String recipientDelete(@RequestParam(value = "recipientName") String recipientName, Model model,
Principal principal) {
Expand All @@ -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);

Expand All @@ -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) {
Expand Down
7 changes: 6 additions & 1 deletion UserFront/src/main/resources/templates/recipient.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ <h3>List of Recipients</h3>
<td data-th-text="${eachRecipient.phone}">...</td>
<td data-th-text="${eachRecipient.accountNumber}">...</td>
<td data-th-text="${eachRecipient.description}">...</td>
<td><a th:href="@{/transfer/recipient/delete?recipientName=}+${eachRecipient.name}">delete</a></td>
<td>
<form th:action="@{/transfer/recipient/delete}" method="post" style="margin: 0;">
<input type="hidden" name="recipientName" th:value="${eachRecipient.name}"/>
<button type="submit" class="btn btn-link" style="padding: 0; border: 0; vertical-align: baseline;">delete</button>
</form>
</td>
</tr>
</tbody>
</table>
Expand Down