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
6 changes: 6 additions & 0 deletions UserFront/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
<artifactId>spring-boot-starter-security</artifactId>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
Comment on lines +58 to +61

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👁️ TD Information Security: Critically vulnerable H2 test dependency

h2 inherits version 1.4.195 from Spring Boot 1.5.4.RELEASE, introducing critical CVE-2021-42392 against the Dependencies criterion. The vulnerability permits remote code execution when an H2 Console accepts untrusted remote connections. Test scope excludes production packaging; these tests do not expose that console.

View in Devin Review · Custom reviewer

Devin Review


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

</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
Expand All @@ -16,6 +17,7 @@
import com.userFront.domain.SavingsTransaction;
import com.userFront.domain.User;
import com.userFront.service.AccountService;
import com.userFront.service.TransactionFilter;
import com.userFront.service.TransactionService;
import com.userFront.service.UserService;

Expand All @@ -33,9 +35,10 @@ public class AccountController {
private TransactionService transactionService;

@RequestMapping("/primaryAccount")
public String primaryAccount(Model model, Principal principal) {
public String primaryAccount(@ModelAttribute("filter") TransactionFilter filter, BindingResult filterErrors,
Model model, Principal principal) {
List<PrimaryTransaction> primaryTransactionList = transactionService
.findPrimaryTransactionList(principal.getName());
.findPrimaryTransactionList(principal.getName(), filter);

User user = userService.findByUsername(principal.getName());
PrimaryAccount primaryAccount = user.getPrimaryAccount();
Expand All @@ -47,9 +50,10 @@ public String primaryAccount(Model model, Principal principal) {
}

@RequestMapping("/savingsAccount")
public String savingsAccount(Model model, Principal principal) {
public String savingsAccount(@ModelAttribute("filter") TransactionFilter filter, BindingResult filterErrors,
Model model, Principal principal) {
List<SavingsTransaction> savingsTransactionList = transactionService
.findSavingsTransactionList(principal.getName());
.findSavingsTransactionList(principal.getName(), filter);
User user = userService.findByUsername(principal.getName());
SavingsAccount savingsAccount = user.getSavingsAccount();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.CrudRepository;

import com.userFront.domain.PrimaryTransaction;

public interface PrimaryTransactionDao extends CrudRepository<PrimaryTransaction, Long> {
public interface PrimaryTransactionDao extends CrudRepository<PrimaryTransaction, Long>,
JpaSpecificationExecutor<PrimaryTransaction> {

List<PrimaryTransaction> findAll();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.CrudRepository;

import com.userFront.domain.SavingsTransaction;

public interface SavingsTransactionDao extends CrudRepository<SavingsTransaction, Long> {
public interface SavingsTransactionDao extends CrudRepository<SavingsTransaction, Long>,
JpaSpecificationExecutor<SavingsTransaction> {

List<SavingsTransaction> findAll();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.userFront.service;

import java.time.LocalDate;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.util.StringUtils;

public class TransactionFilter {

public static final String TYPE_DEPOSIT = "deposit";
public static final String TYPE_WITHDRAW = "withdraw";
public static final String TYPE_TRANSFER = "transfer";

@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
private LocalDate from;

@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
private LocalDate to;

private String type;
private Double minAmount;
private Double maxAmount;
private String q;

public boolean isActive() {
return from != null || to != null || StringUtils.hasText(type) || minAmount != null || maxAmount != null
|| StringUtils.hasText(q);
}

public LocalDate getFrom() {
return from;
}

public void setFrom(LocalDate from) {
this.from = from;
}

public LocalDate getTo() {
return to;
}

public void setTo(LocalDate to) {
this.to = to;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public Double getMinAmount() {
return minAmount;
}

public void setMinAmount(Double minAmount) {
this.minAmount = minAmount;
}

public Double getMaxAmount() {
return maxAmount;
}

public void setMaxAmount(Double maxAmount) {
this.maxAmount = maxAmount;
}

public String getQ() {
return q;
}

public void setQ(String q) {
this.q = q;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public interface TransactionService {

List<SavingsTransaction> findSavingsTransactionList(String username);

List<PrimaryTransaction> findPrimaryTransactionList(String username, TransactionFilter filter);

List<SavingsTransaction> findSavingsTransactionList(String username, TransactionFilter filter);

void savePrimaryDepositTransaction(PrimaryTransaction primaryTransaction);

void saveSavingsDepositTransaction(SavingsTransaction savingsTransaction);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.userFront.service;

import java.time.LocalDate;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Predicate;

import org.springframework.data.jpa.domain.Specification;
import org.springframework.util.StringUtils;

/**
* Builds the server-side query for the account pages' transaction filters.
* The stored {@code type} column is not consistent (deposits, withdrawals and
* some transfers are all stored as "Account"), so the type filter matches on
* the description the app writes for each kind of transaction.
*/
public final class TransactionSpecifications {

private static final char ESCAPE = '\\';

private TransactionSpecifications() {
}

public static <T> Specification<T> forAccount(String accountField, Object account, TransactionFilter filter) {
return (root, query, cb) -> {
List<Predicate> predicates = new ArrayList<>();
predicates.add(cb.equal(root.get(accountField), account));

if (filter == null) {
return cb.and(predicates.toArray(new Predicate[0]));
}

if (filter.getFrom() != null) {
predicates.add(cb.greaterThanOrEqualTo(root.<Date>get("date"), startOfDay(filter.getFrom(), 0)));
}
if (filter.getTo() != null) {
predicates.add(cb.lessThan(root.<Date>get("date"), startOfDay(filter.getTo(), 1)));
}
if (filter.getMinAmount() != null) {
predicates.add(cb.greaterThanOrEqualTo(root.<Double>get("amount"), filter.getMinAmount()));
}
if (filter.getMaxAmount() != null) {
predicates.add(cb.lessThanOrEqualTo(root.<Double>get("amount"), filter.getMaxAmount()));
}

Expression<String> description = cb.lower(root.<String>get("description"));
String typePattern = typePattern(filter.getType());
if (typePattern != null) {
predicates.add(cb.like(description, typePattern));
}
if (StringUtils.hasText(filter.getQ())) {
String text = escapeLike(filter.getQ().trim().toLowerCase(Locale.ROOT));
predicates.add(cb.like(description, "%" + text + "%", ESCAPE));
}

return cb.and(predicates.toArray(new Predicate[0]));
};
}

static String typePattern(String type) {
if (type == null) {
return null;
}
switch (type.trim().toLowerCase(Locale.ROOT)) {
case TransactionFilter.TYPE_DEPOSIT:
return "deposit%";
case TransactionFilter.TYPE_WITHDRAW:
return "withdraw%";
case TransactionFilter.TYPE_TRANSFER:
return "%transfer%";
default:
return null;
}
}

private static String escapeLike(String text) {
return text.replace("\\", "\\\\").replace("%", "\\%").replace("_", "\\_");
}

static Date startOfDay(LocalDate day, int plusDays) {
return Date.from(day.plusDays(plusDays).atStartOfDay(ZoneId.systemDefault()).toInstant());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import com.userFront.dao.PrimaryAccountDao;
Expand All @@ -20,12 +21,16 @@
import com.userFront.domain.SavingsAccount;
import com.userFront.domain.SavingsTransaction;
import com.userFront.domain.User;
import com.userFront.service.TransactionFilter;
import com.userFront.service.TransactionService;
import com.userFront.service.TransactionSpecifications;
import com.userFront.service.UserService;

@Service
public class TransactionServiceImpl implements TransactionService {

private static final Sort BY_DATE = new Sort(Sort.Direction.ASC, "date", "id");

@Autowired
private UserService userService;

Expand Down Expand Up @@ -58,6 +63,20 @@ public List<SavingsTransaction> findSavingsTransactionList(String username) {
return savingsTransactionList;
}

public List<PrimaryTransaction> findPrimaryTransactionList(String username, TransactionFilter filter) {
User user = userService.findByUsername(username);
return primaryTransactionDao.findAll(
TransactionSpecifications.forAccount("primaryAccount", user.getPrimaryAccount(), filter),
BY_DATE);
}

public List<SavingsTransaction> findSavingsTransactionList(String username, TransactionFilter filter) {
User user = userService.findByUsername(username);
return savingsTransactionDao.findAll(
TransactionSpecifications.forAccount("savingsAccount", user.getSavingsAccount(), filter),
BY_DATE);
}

public void savePrimaryDepositTransaction(PrimaryTransaction primaryTransaction) {
primaryTransactionDao.save(primaryTransaction);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<body>

<div th:fragment="filterForm(actionUrl)" class="panel panel-default transaction-filter">
<div class="panel-heading">
<strong><i class="fa fa-filter" aria-hidden="true"></i> Search transactions</strong>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧠 TD French Language (Bill 96): Transaction search copy stays English

On both account pages, filterForm displays “Search transactions” and other English labels without locale keys. emptyState and result counts also stay English. Add transactionSearch.title with fr-CA “Rechercher des opérations” and localize the remaining filter, count, and empty-state copy.

View in Devin Review · Custom reviewer

Devin Review


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

</div>
<div class="panel-body">
<form method="get" th:action="@{${actionUrl}}" th:object="${filter}">
<div class="row">
<div class="form-group col-sm-6 col-md-2">
<label for="from">From</label>
<input type="date" class="form-control" id="from" th:field="*{from}" />
</div>
<div class="form-group col-sm-6 col-md-2">
<label for="to">To</label>
<input type="date" class="form-control" id="to" th:field="*{to}" />
</div>
<div class="form-group col-sm-4 col-md-2">
<label for="type">Type</label>
<select class="form-control" id="type" th:field="*{type}">
<option value="">All types</option>
<option value="deposit">Deposit</option>
<option value="withdraw">Withdraw</option>
<option value="transfer">Transfer</option>
</select>
</div>
<div class="form-group col-sm-4 col-md-2">
<label for="minAmount">Min amount</label>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-usd" aria-hidden="true"></i></span>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧠 TD French Language (Bill 96): French amount filters show leading dollars

For fr-CA, minAmount and maxAmount display a dollar sign before the value. Place the sign after the input for French currency order, as in 1 250,00 $.

View in Devin Review · Custom reviewer

Devin Review


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

<input type="number" step="0.01" min="0" class="form-control" id="minAmount"
th:field="*{minAmount}" />
</div>
</div>
<div class="form-group col-sm-4 col-md-2">
<label for="maxAmount">Max amount</label>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-usd" aria-hidden="true"></i></span>
<input type="number" step="0.01" min="0" class="form-control" id="maxAmount"
th:field="*{maxAmount}" />
</div>
</div>
<div class="form-group col-sm-12 col-md-2">
<label for="q">Description</label>
<input type="text" class="form-control" id="q" placeholder="e.g. recipient"
th:field="*{q}" />
</div>
</div>
<div class="row">
<div class="col-sm-12">
<button type="submit" class="btn btn-primary"><i class="fa fa-search" aria-hidden="true"></i> Filter</button>
<a class="btn btn-link" th:href="@{${actionUrl}}" th:if="${filter.active}">Clear filters</a>
</div>
</div>
</form>
</div>
</div>

<div th:fragment="emptyState(actionUrl)" class="well text-center transaction-empty">
<h4><i class="fa fa-search" aria-hidden="true"></i>
<span th:text="${filter.active} ? 'No transactions match these filters.' : 'No transactions yet.'">No transactions yet.</span>
</h4>
<p th:if="${filter.active}">Try a wider date range or amount, or
<a th:href="@{${actionUrl}}">clear filters</a> to see every transaction.</p>
</div>

</body>
</html>
Loading