Skip to content

Commit 7fae25a

Browse files
committed
ADDED listPersonsByUsers.html
1 parent 1f46fce commit 7fae25a

File tree

6 files changed

+106
-7
lines changed

6 files changed

+106
-7
lines changed

src/main/java/io/github/anantharajuc/sbat/example/crm/user/services/PersonQueryServiceImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.springframework.data.domain.PageImpl;
1111
import org.springframework.data.domain.PageRequest;
1212
import org.springframework.data.domain.Pageable;
13+
import org.springframework.security.core.Authentication;
14+
import org.springframework.security.core.context.SecurityContextHolder;
1315
import org.springframework.stereotype.Service;
1416

1517
import io.github.anantharajuc.sbat.core_backend.exception.ResourceNotFoundException;
@@ -91,6 +93,11 @@ public Page<Person> findPaginated(Pageable pageable)
9193

9294
List<Person> list;
9395

96+
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
97+
String currentPrincipalName = authentication.getName();
98+
99+
log.info("currentPrincipalName : "+currentPrincipalName);
100+
94101
List<Person> persons = personRepository.findAll();
95102

96103
if (persons.size() < startItem)

src/main/java/io/github/anantharajuc/sbat/web/controllers/SpringBootApplicationTemplateController.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
import org.springframework.core.env.Environment;
1111
import org.springframework.data.domain.Page;
1212
import org.springframework.data.domain.PageRequest;
13-
import org.springframework.security.access.prepost.PreAuthorize;
13+
import org.springframework.security.core.Authentication;
14+
import org.springframework.security.core.context.SecurityContextHolder;
1415
import org.springframework.stereotype.Controller;
1516
import org.springframework.ui.Model;
1617
import org.springframework.web.bind.annotation.GetMapping;
@@ -34,7 +35,7 @@
3435
*/
3536
@Log4j2
3637
@Controller
37-
@RequestMapping(value=ResourcePaths.SBAT.V1.ROOT)
38+
@RequestMapping(value=ResourcePaths.SBAT.V1.ROOT)
3839
public class SpringBootApplicationTemplateController
3940
{
4041
@Autowired
@@ -156,15 +157,27 @@ public String close()
156157
return "pages/close";
157158
}
158159

160+
@GetMapping("/listPersonsByUsers")
161+
public String listPersons(Model model)
162+
{
163+
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
164+
String currentPrincipalName = authentication.getName();
165+
166+
log.info("currentPrincipalName : "+currentPrincipalName);
167+
168+
model.addAttribute("personPage", personQueryServiceImpl.getPersonByUsername(currentPrincipalName));
169+
170+
return "pages/listPersonsByUsers";
171+
}
172+
159173
@GetMapping("/listPersons")
160-
//@PreAuthorize("#username == authentication.principal.username")
161174
public String listPersons(Model model, @RequestParam("page") Optional<Integer> page, @RequestParam("size") Optional<Integer> size)
162175
{
163176
final int currentPage = page.orElse(1);
164177
final int pageSize = size.orElse(10);
165-
178+
166179
Page<Person> personPage = personQueryServiceImpl.findPaginated(PageRequest.of(currentPage - 1, pageSize));
167-
180+
168181
model.addAttribute("personPage", personPage);
169182

170183
int totalPages = personPage.getTotalPages();

src/main/resources/i18n/messages.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ navbar.logout.text=Logout
1515
navbar.dark-mode.text=Dark Mode
1616
navbar.close-app.text=Shutdown
1717
navbar.settings.text=Settings
18-
navbar.persons.text=Persons
18+
navbar.persons.text=CRM Admin
19+
navbar.persons-user.text=CRM User
1920

2021
# Settings Page - settings.html
2122
settings.h1.text=settings1

src/main/resources/i18n/messages_es.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ navbar.logout.text=cerrar sesi
1515
navbar.dark-mode.text=modo oscuro
1616
navbar.close-app.text=apagar
1717
navbar.settings.text=Settings
18-
navbar.persons.text=Persons
18+
navbar.persons.text=CRM Admin
19+
navbar.persons-user.text=CRM User
1920

2021
# Settings Page - settings.html
2122
settings.h1.text=settings1

src/main/resources/templates/fragments/navigation.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
<li class="nav-item" sec:authorize="isAuthenticated()">
2828
<a sec:authorize="hasRole('ROLE_ADMIN')" class="nav-link" href="/sbat/listPersons" th:text="#{navbar.persons.text}"></span></a>
2929
</li>
30+
<li class="nav-item" sec:authorize="isAuthenticated()">
31+
<a sec:authorize="hasRole('ROLE_PERSON')" class="nav-link" href="/sbat/listPersonsByUsers" th:text="#{navbar.persons-user.text}"></span></a>
32+
</li>
3033

3134
<li class="nav-item dropdown">
3235
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" th:text="Help"></a>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<!DOCTYPE html>
2+
<html lang="en" xmlns:th="http://www.thymeleaf.org"
3+
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
4+
xmlns:with="http://www.thymeleaf.org/extras/with"
5+
layout:decorate="~{layout}"
6+
with:title="'Persons'">
7+
8+
<th:block layout:fragment="content">
9+
10+
<h1>Persons List</h1>
11+
12+
<div class="card-block">
13+
14+
<table
15+
border="1"
16+
class="table table-hover table-striped table-sm"
17+
id="table"
18+
data-buttons="btn btn-sm"
19+
data-buttons-class="link btn-sm"
20+
data-advanced-search="true"
21+
data-id-table="advancedTable"
22+
data-resizable="true"
23+
data-filter-control="true"
24+
data-show-fullscreen="true"
25+
data-show-search-clear-button="true"
26+
data-show-button-text="true"
27+
data-show-columns-search="true"
28+
data-show-toggle="true"
29+
data-show-refresh="true"
30+
data-show-pagination-switch="true"
31+
data-toolbar="#toolbar"
32+
data-toggle="table"
33+
data-flat="true"
34+
data-search="true"
35+
data-search-align="left"
36+
data-show-columns="true"
37+
data-show-columns-toggle-all="true"
38+
data-pagination="true"
39+
data-pagination-v-align="both"
40+
data-pagination-pre-text="Previous"
41+
data-pagination-next-text="Next"
42+
data-page-list="[5, 10, 25, All]">
43+
<caption>Persons List</caption>
44+
<thead>
45+
<tr>
46+
<th scope="col" data-resizable-column-id="id" class="text-center" data-sortable="true" data-field="id" data-filter-control="select" data-visible="false">id</th>
47+
<th scope="col" data-resizable-column-id="name" class="text-center" data-sortable="true" data-field="name" data-filter-control="input">name</th>
48+
<th scope="col" data-resizable-column-id="username" class="text-center" data-sortable="true" data-field="username" data-filter-control="input">username</th>
49+
<th scope="col" data-resizable-column-id="emailPrimary" class="text-center" data-sortable="true" data-field="emailPrimary" data-filter-control="input">emailPrimary</th>
50+
<th scope="col" data-resizable-column-id="emailSecondary" class="text-center" data-sortable="true" data-field="emailSecondary" data-filter-control="input" data-visible="false">emailSecondary</th>
51+
<th scope="col" data-resizable-column-id="phone" class="text-center" data-sortable="true" data-field="phone" data-filter-control="input">phone</th>
52+
</tr>
53+
</thead>
54+
<tbody>
55+
<tr th:each="person :${personPage}">
56+
<td th:text="${person.id}" />
57+
<td th:text="${person.name}" />
58+
<td th:text="${person.username}" />
59+
<td th:text="${person.emailPrimary}" />
60+
<td th:text="${person.emailSecondary}" />
61+
<td th:text="${person.phone}" />
62+
</tr>
63+
</tbody>
64+
</table>
65+
66+
</div>
67+
68+
<div th:if="${personPage.totalPages > 0}" class="pagination" th:each="pageNumber : ${pageNumbers}">
69+
<a th:href="@{/sbat/listPersons(size=${personPage.size}, page=${pageNumber})}" th:text=${pageNumber} th:class="${pageNumber==personPage.number + 1} ? active"></a>
70+
</div>
71+
72+
</th:block>
73+
74+
</html>

0 commit comments

Comments
 (0)