Skip to content

Commit

Permalink
Merge pull request #83 from TeamSevenWeb/admin-permissions-for-transa…
Browse files Browse the repository at this point in the history
…ctions

Add admin permissions to transactions and refactor styling in users page
  • Loading branch information
amechkarov authored Mar 18, 2024
2 parents 63434a4 + 7b727f0 commit 5adf73c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,14 @@ public String handleChangeProfilePhoto(@PathVariable String username, Model mode

@GetMapping("/transactions")
public String get(@ModelAttribute("transactionFilterOptions") TransactionFilterDto filterDto,
@RequestParam(defaultValue = "0") int page,@RequestParam(defaultValue = "10") int pageSize, Model model, HttpSession session,BindingResult errors) {
@RequestParam(defaultValue = "0") int page,@RequestParam(defaultValue = "10") int pageSize, Model model, HttpSession session) {

TransactionFilterOptions transactionFilterOptions = new TransactionFilterOptions(filterDto.getDate()
,filterDto.getSender(),filterDto.getReceiver(),filterDto.getDirection(),
filterDto.getSortBy(),filterDto.getSortOrder());

try {
User user = userService.getById(1);
User user = authenticationHelper.tryGetCurrentUser(session);
Pageable pageable = PageRequest.of(page, pageSize);
Page<Transaction> transactions = transactionService.getAll(user, transactionFilterOptions,pageable);
model.addAttribute("transactionFilterOptions", filterDto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public Transaction createTransaction(@RequestHeader(name = "Authentication")
try {
User sender = authenticationHelper.tryGetUser(authentication);
Transaction transaction = transactionMapper.fromDto(sender, transactionDto);

transactionService.create(transaction,sender.getWallet(),transaction.getReceiver().getWallet());
return transaction;
} catch (AuthenticationException | AuthorizationException e){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.telerikacademy.web.virtualwallet.models.User;
import com.telerikacademy.web.virtualwallet.repositories.contracts.TransactionRepository;
import com.telerikacademy.web.virtualwallet.repositories.contracts.UserRepository;
import com.telerikacademy.web.virtualwallet.services.contracts.UserService;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
Expand All @@ -28,10 +29,13 @@
public class TransactionRepositoryImpl extends AbstractCRUDRepository<Transaction> implements TransactionRepository {

private final UserRepository userRepository;

private final UserService userService;
@Autowired
public TransactionRepositoryImpl(SessionFactory sessionFactory, UserRepository userRepository) {
public TransactionRepositoryImpl(SessionFactory sessionFactory, UserRepository userRepository, UserService userService) {
super(Transaction.class,sessionFactory);
this.userRepository = userRepository;
this.userService = userService;
}

@Override
Expand All @@ -41,9 +45,10 @@ public Page<Transaction> filterAndSort(User user, TransactionFilterOptions filte
Map<String, Object> params = new HashMap<>();
StringBuilder queryString = new StringBuilder("from Transaction ");


filters.add("(sender = :user OR receiver = :user)");
params.put("user", user);
if(!userService.isAdmin(user)) {
filters.add("(sender = :user OR receiver = :user)");
params.put("user", user);
}

filterOptions.getReceiver().ifPresent(value -> {
if(value.isEmpty()||user.getUsername().equals(value)){
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/templates/TransactionsView.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h3 class="font-aquire" th:text="#{transactions.page.filters.title}">Filter Opti
<div class="table-header-cell">Sender</div>
<div class="table-header-cell">Receiver</div>
<div class="table-header-cell">Amount</div>
<div class="table-header-cell">Direction</div>
<div class="table-header-cell" th:unless="isAdmin">Direction</div>
<div class="table-header-cell">Date</div>
</div>
<div class="table-row" th:each="transaction : ${transactions}">
Expand All @@ -70,7 +70,7 @@ <h3 class="font-aquire" th:text="#{transactions.page.filters.title}">Filter Opti
<span class="cell-linebreak" th:text="${transaction.amount}"></span>
<br>
</div>
<div class="cell">
<div class="cell" th:unless="isAdmin">
<span th:unless="${transaction.receiver==currentUser}" class="cell-linebreak" th:text="OUTGOING"></span>
<span th:unless="${transaction.sender==currentUser}" class="cell-linebreak" th:text="INGOING"></span>
<br>
Expand Down
16 changes: 8 additions & 8 deletions src/main/resources/templates/UsersView.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@
<section class="page-section">
<header class="navigate">
<!-- Masthead Heading-->
<h1 class="text-uppercase mb-0" th:if="${allUsers.isEmpty()}" th:text="#{user.title.empty}">No
<h1 class="text-uppercase mb-0 font-aquire" th:if="${allUsers.isEmpty()}" th:text="#{user.title.empty}">No
Users</h1>
<h1 class="text-uppercase mb-0" th:unless="${allUsers.isEmpty()}" th:text="#{user.title.all}">All
<h1 class="text-uppercase mb-0 font-aquire" th:unless="${allUsers.isEmpty()}" th:text="#{user.title.all}">All
Users</h1>
</header>
</section>
<!-- Section 2-->
<section class="py-5">
<div class="navigate">
<form action="#" th:action="@{/users}" method="get" th:object="${userFilterOptionsDto}">
<h3 th:text="#{user.filter.label}">Filter Options</h3>
<h3 class="font-aquire" th:text="#{user.filter.label}">Filter Options</h3>
<br/><br/>
<div>
<input type="text" placeholder="Username" th:field="*{username}"/>
<input type="text" placeholder="Email" th:field="*{email}"/>
<input type="text" placeholder="Phone Number" th:field="*{phoneNumber}" />
<input class="simple-input-style" type="text" placeholder="Username" th:field="*{username}"/>
<input class="simple-input-style" type="text" placeholder="Email" th:field="*{email}"/>
<input class="simple-input-style" type="text" placeholder="Phone Number" th:field="*{phoneNumber}" />
</div>
<br/><br/>

<input class="py-3-create rounded" type="submit" value="Search"/>
<input class="py-3-create rounded font-aquire" type="submit" value="Search"/>
</form>
</div>
<div class="table text-center">
<div class="table-head">
<div class="table-head font-aquire">
<div class="table-header-cell">Username</div>
<div class="table-header-cell">Email</div>
<div class="table-header-cell">Phone</div>
Expand Down

0 comments on commit 5adf73c

Please sign in to comment.