diff --git a/generators/server/files.js b/generators/server/files.js index cad2d8ae677f..ff923976c61c 100644 --- a/generators/server/files.js +++ b/generators/server/files.js @@ -1635,6 +1635,10 @@ const serverFiles = { file: 'package/service/dto/package-info.java', renameTo: generator => `${generator.javaDir}service/dto/package-info.java`, }, + { + file: 'package/service/dto/PublicUserDTO.java', + renameTo: generator => `${generator.javaDir}service/dto/${generator.asDto('PublicUser')}.java`, + }, { file: 'package/service/dto/UserDTO.java', renameTo: generator => `${generator.javaDir}service/dto/${generator.asDto('User')}.java`, @@ -1779,6 +1783,10 @@ const serverFiles = { file: 'package/service/dto/UserDTO.java', renameTo: generator => `${generator.javaDir}service/dto/${generator.asDto('User')}.java`, }, + { + file: 'package/service/dto/PublicUserDTO.java', + renameTo: generator => `${generator.javaDir}service/dto/${generator.asDto('PublicUser')}.java`, + }, { file: 'package/service/dto/PasswordChangeDTO.java', renameTo: generator => `${generator.javaDir}service/dto/PasswordChangeDTO.java`, diff --git a/generators/server/templates/src/main/java/package/repository/UserRepository.java.ejs b/generators/server/templates/src/main/java/package/repository/UserRepository.java.ejs index c0d454489e5b..e5be907dd6df 100644 --- a/generators/server/templates/src/main/java/package/repository/UserRepository.java.ejs +++ b/generators/server/templates/src/main/java/package/repository/UserRepository.java.ejs @@ -168,8 +168,9 @@ public interface UserRepository extends <% if (databaseType === 'sql') { %>JpaRe <%_ } _%> <%_ if (authenticationType !== 'oauth2') { _%> - <% if (reactive) { %>Flux<% } else { %>List<% } %><<%= asEntity('User') %>> findAllByActivatedIsFalseAndActivationKeyIsNotNullAndCreatedDateBefore(Instant dateTime); + <%= listOrFlux %><<%= asEntity('User') %>> findAllByActivatedIsFalseAndActivationKeyIsNotNullAndCreatedDateBefore(Instant dateTime); <%_ } _%> + <%_ if (authenticationType !== 'oauth2') { _%> <%= optionalOrMono %><<%= asEntity('User') %>> findOneByResetKey(String resetKey); @@ -221,12 +222,17 @@ public interface UserRepository extends <% if (databaseType === 'sql') { %>JpaRe <%_ } _%> <%_ } _%> + <% if (reactive) { %> Flux<<%= asEntity('User') %>>findAllByIdNotNull(Pageable pageable); + Flux<<%= asEntity('User') %>>findAllByIdNotNullAndActivatedIsTrue(Pageable pageable); + Mono count(); <% } else { %> - Page<<%= asEntity('User') %>>findAll(Pageable pageable); + Page<<%= asEntity('User') %>> findAll(Pageable pageable); + + Page<<%= asEntity('User') %>> findAllByIdNotNullAndActivatedIsTrue(Pageable pageable); <% } %> } <%_ } else if (databaseType === 'sql' && reactive) { _%> @@ -247,6 +253,8 @@ public interface UserRepository extends R2dbcRepository findAllByIdNotNull(Pageable pageable); + Flux findAllByIdNotNullAndActivatedIsTrue(Pageable pageable); + Mono count(); @Query("INSERT INTO <%= jhiTablePrefix %>_user_authority VALUES(:userId, :authority)") diff --git a/generators/server/templates/src/main/java/package/service/UserService.java.ejs b/generators/server/templates/src/main/java/package/service/UserService.java.ejs index e3e2a4e64771..4d8d6e999ecb 100644 --- a/generators/server/templates/src/main/java/package/service/UserService.java.ejs +++ b/generators/server/templates/src/main/java/package/service/UserService.java.ejs @@ -39,6 +39,7 @@ import <%= packageName %>.security.AuthoritiesConstants; <%_ } _%> import <%= packageName %>.security.SecurityUtils; <%_ } _%> +import <%= packageName %>.service.dto.<%= asDto('PublicUser') %>; import <%= packageName %>.service.dto.<%= asDto('User') %>; <%_ if (authenticationType !== 'oauth2') { _%> @@ -740,6 +741,14 @@ public class UserService { public <% if (reactive) { %>Flux<% } else { %>Page<% } %><<%= asDto('User') %>> getAllManagedUsers(Pageable pageable) { return userRepository.findAll<% if (reactive) { %>ByIdNotNull<% } %>(pageable).map(<%= asDto('User') %>::new); } + + <%_ if (databaseType === 'sql') { _%> + @Transactional(readOnly = true) + <%_ } _%> + public <% if (reactive) { %>Flux<% } else { %>Page<% } %><<%= asDto('PublicUser') %>> getAllPublicUsers(Pageable pageable) { + return userRepository.findAllByIdNotNullAndActivatedIsTrue(pageable).map(<%= asDto('PublicUser') %>::new); + } + <%_ if (reactive) { _%> <%_ if (databaseType === 'sql') { _%> @@ -755,6 +764,13 @@ public class UserService { .map(<%= asDto('User') %>::new)<% if (!reactive) { %> .collect(Collectors.toList())<% } %>; } + + public <% if (reactive) { %>Flux<% } else { %>List<% } %><<%= asDto('PublicUser') %>> getAllPublicUsers() { + return userRepository.findAll()<% if (!reactive) { %>.stream()<% } %> + .filter(user -> user.isActivated()) + .map(<%= asDto('PublicUser') %>::new)<% if (!reactive) { %> + .collect(Collectors.toList())<% } %>; + } <%_ } _%> <%_ if (databaseType === 'sql') { _%> diff --git a/generators/server/templates/src/main/java/package/service/dto/PublicUserDTO.java.ejs b/generators/server/templates/src/main/java/package/service/dto/PublicUserDTO.java.ejs new file mode 100644 index 000000000000..35a430a37e66 --- /dev/null +++ b/generators/server/templates/src/main/java/package/service/dto/PublicUserDTO.java.ejs @@ -0,0 +1,95 @@ +<%# + Copyright 2013-2020 the original author or authors from the JHipster project. + + This file is part of the JHipster project, see https://www.jhipster.tech/ + for more information. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +-%> +package <%= packageName %>.service.dto; + +<%_ + let userPk = (databaseType === 'mongodb' || databaseType === 'neo4j' || databaseType === 'couchbase' || databaseType === 'cassandra' || authenticationType === 'oauth2') ? "String" : "Long"; +_%> +<%_ if (databaseType !== 'no') { _%> +import <%= packageName %>.domain.<%= asEntity('User') %>; +<%_ } _%> + +/** + * A DTO representing a user, with all the public attributes. + */ +public class <%= asDto('PublicUser') %> { + + private <%= userPk %> id; + private String login; + + private String firstName; + + private String lastName; + + <%_ if (databaseType !== 'no') { _%> + public <%= asDto('PublicUser') %>() { + // Empty constructor needed for Jackson. + } + + public <%= asDto('PublicUser') %>(User user) { + this.id = user.getId(); + this.login = user.getLogin(); + this.firstName = user.getFirstName(); + this.lastName = user.getLastName(); + } + + <%_ } _%> + public <%= userPk %> getId() { + return id; + } + + public void setId(<%= userPk %> id) { + this.id = id; + } + + public String getLogin() { + return login; + } + + public void setLogin(String login) { + this.login = login; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + // prettier-ignore + @Override + public String toString() { + return "<%= asDto('PublicUser') %>{" + + "login='" + login + '\'' + + ", firstName='" + firstName + '\'' + + ", lastName='" + lastName + '\'' + + "}"; + } + +} diff --git a/generators/server/templates/src/main/java/package/service/dto/UserDTO.java.ejs b/generators/server/templates/src/main/java/package/service/dto/UserDTO.java.ejs index b96ce595ff49..4ece6de1f1ca 100644 --- a/generators/server/templates/src/main/java/package/service/dto/UserDTO.java.ejs +++ b/generators/server/templates/src/main/java/package/service/dto/UserDTO.java.ejs @@ -18,6 +18,9 @@ -%> package <%= packageName %>.service.dto; +<%_ + let userPk = (databaseType === 'mongodb' || databaseType === 'neo4j' || databaseType === 'couchbase' || databaseType === 'cassandra' || authenticationType === 'oauth2') ? "String" : "Long"; + _%> import <%= packageName %>.config.Constants; <% if (databaseType === 'sql' || databaseType === 'mongodb' || databaseType === 'neo4j') { %> import <%= packageName %>.domain.Authority;<% } %> @@ -39,7 +42,7 @@ import java.util.stream.Collectors; */ public class <%= asDto('User') %> { - private <% if (databaseType === 'mongodb' || databaseType === 'neo4j' || databaseType === 'couchbase' || databaseType === 'cassandra' || authenticationType === 'oauth2') { %>String<% } else { %>Long<% } %> id; + private <%= userPk %> id; @NotBlank @Pattern(regexp = Constants.LOGIN_REGEX) @@ -110,11 +113,11 @@ public class <%= asDto('User') %> { } <%_ } _%> - public <% if (databaseType === 'mongodb' || databaseType === 'neo4j' || databaseType === 'couchbase' || databaseType === 'cassandra' || authenticationType === 'oauth2') { %>String<% } else { %>Long<% } %> getId() { + public <%= userPk %> getId() { return id; } - public void setId(<% if (databaseType === 'mongodb' || databaseType === 'neo4j' || databaseType === 'couchbase' || databaseType === 'cassandra' || authenticationType === 'oauth2') { %>String<% } else { %>Long<% } %> id) { + public void setId(<%= userPk %> id) { this.id = id; } diff --git a/generators/server/templates/src/main/java/package/web/rest/UserResource.java.ejs b/generators/server/templates/src/main/java/package/web/rest/UserResource.java.ejs index 0348fb99b3ee..c48ddbd450a2 100644 --- a/generators/server/templates/src/main/java/package/web/rest/UserResource.java.ejs +++ b/generators/server/templates/src/main/java/package/web/rest/UserResource.java.ejs @@ -35,6 +35,7 @@ import org.springframework.data.domain.Sort; import java.util.Collections; <%_ } _%> import <%= packageName %>.service.UserService; +import <%= packageName %>.service.dto.<%= asDto('PublicUser') %>; import <%= packageName %>.service.dto.<%= asDto('User') %>; <%_ if (authenticationType !== 'oauth2') { _%> import <%= packageName %>.web.rest.errors.BadRequestAlertException; @@ -163,7 +164,7 @@ public class UserResource { <%_ if (authenticationType !== 'oauth2') { _%> /** - * {@code POST /users} : Creates a new user. + * {@code POST /admin/users} : Creates a new user. *

* Creates a new user if the login and email are not already used, and sends an * mail with an activation link. @@ -176,7 +177,7 @@ public class UserResource { <%_ } _%> * @throws BadRequestAlertException {@code 400 (Bad Request)} if the login or email is already in use. */ - @PostMapping("/users") + @PostMapping("/admin/users") @PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")") public <% if (reactive) { %>Mono>><% } else { %>ResponseEntity<<%= asEntity('User') %>><% } %> createUser(@Valid @RequestBody <%= asDto('User') %> userDTO)<% if (!reactive) { %> throws URISyntaxException<% } %> { log.debug("REST request to save User : {}", userDTO); @@ -192,7 +193,7 @@ public class UserResource { } else { <%= asEntity('User') %> newUser = userService.createUser(userDTO); mailService.sendCreationEmail(newUser); - return ResponseEntity.created(new URI("/api/users/" + newUser.getLogin())) + return ResponseEntity.created(new URI("/api/admin/users/" + newUser.getLogin())) .headers(HeaderUtil.createAlert(applicationName, <% if (enableTranslation) { %> "userManagement.created"<% } else { %> "A user is created with identifier " + newUser.getLogin()<% } %>, newUser.getLogin())) .body(newUser); } @@ -216,7 +217,7 @@ public class UserResource { .doOnSuccess(mailService::sendCreationEmail) .map(user -> { try { - return ResponseEntity.created(new URI("/api/users/" + user.getLogin())) + return ResponseEntity.created(new URI("/api/admin/users/" + user.getLogin())) .headers(HeaderUtil.createAlert(applicationName, "userManagement.created", user.getLogin())) .body(user); } catch (URISyntaxException e) { @@ -227,14 +228,14 @@ public class UserResource { } /** - * {@code PUT /users} : Updates an existing User. + * {@code PUT /admin/users} : Updates an existing User. * * @param userDTO the user to update. * @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated user. * @throws EmailAlreadyUsedException {@code 400 (Bad Request)} if the email is already in use. * @throws LoginAlreadyUsedException {@code 400 (Bad Request)} if the login is already in use. */ - @PutMapping("/users") + @PutMapping("/admin/users") @PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")") <%_ if (!reactive) { _%> public ResponseEntity<<%= asDto('User') %>> updateUser(@Valid @RequestBody <%= asDto('User') %> userDTO) { @@ -281,7 +282,7 @@ public class UserResource { <%_ } _%> /** - * {@code GET /users} : get all users. + * {@code GET /admin/users} : get all users with all the details - calling this are only allowed for the administrators. *<% if (databaseType === 'sql' || databaseType === 'mongodb' || databaseType == 'neo4j' || databaseType === 'couchbase') { %> <%_ if (reactive) { _%> * @param request a {@link ServerHttpRequest} request. @@ -289,7 +290,8 @@ public class UserResource { * @param pageable the pagination information.<% } %> * @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body all users. */ - @GetMapping("/users") + @GetMapping("/admin/users") + @PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")") <%_ if (databaseType === 'sql' || databaseType === 'mongodb' || databaseType === 'neo4j' || databaseType === 'couchbase') { _%> <%_ if (!reactive) { _%> public ResponseEntity>> getAllUsers(Pageable pageable) { @@ -317,6 +319,44 @@ public class UserResource { <%_ } _%> } + + /** + * {@code GET /users} : get all users with only the public informations - calling this are allowed for anyone. + *<% if (databaseType === 'sql' || databaseType === 'mongodb' || databaseType == 'neo4j' || databaseType === 'couchbase') { %> + <%_ if (reactive) { _%> + * @param request a {@link ServerHttpRequest} request. + <%_ } _%> + * @param pageable the pagination information.<% } %> + * @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body all users. + */ + @GetMapping("/users") + <%_ if (!reactive) { _%> + public ResponseEntity>> getAllPublicUsers(Pageable pageable) { + <%_ if (authenticationType !== 'oauth2') { _%> + if (!onlyContainsAllowedProperties(pageable)) { + return ResponseEntity.badRequest().build(); + } + <%_ } _%> + + final Page<<%= asDto('PublicUser') %>> page = userService.getAllPublicUsers(pageable); + HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(ServletUriComponentsBuilder.fromCurrentRequest(), page); + return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK); + } + <%_ } else { _%> + public Mono>>> getAllPublicUsers(ServerHttpRequest request, Pageable pageable) { + <%_ if (authenticationType !== 'oauth2') { _%> + if (!onlyContainsAllowedProperties(pageable)) { + return Mono.just(ResponseEntity.badRequest().build()); + } + <%_ } _%> + + return userService.countManagedUsers() + .map(total -> new PageImpl<>(new ArrayList<>(), pageable, total)) + .map(page -> PaginationUtil.generatePaginationHttpHeaders(UriComponentsBuilder.fromHttpRequest(request), page)) + .map(headers -> ResponseEntity.ok().headers(headers).body(userService.getAllManagedUsers(pageable))); + } + <%_ } _%> + <%_ if (authenticationType !== 'oauth2') { _%> private boolean onlyContainsAllowedProperties(Pageable pageable) { return pageable.getSort().stream().map(Sort.Order::getProperty).allMatch(ALLOWED_ORDERED_PROPERTIES::contains); @@ -336,15 +376,21 @@ public class UserResource { public <% if (reactive) { %>Flux<% } else { %>List<% } %><<%= asDto('User') %>> getAllUsers() { return userService.getAllManagedUsers(); } + + public <% if (reactive) { %>Flux<% } else { %>List<% } %><<%= asDto('PublicUser') %>> getAllPublicUsers() { + return userService.getAllPublicUsers(); + } + <%_ } _%> /** - * {@code GET /users/:login} : get the "login" user. + * {@code GET /admin/users/:login} : get the "login" user. * * @param login the login of the user to find. * @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the "login" user, or with status {@code 404 (Not Found)}. */ - @GetMapping("/users/{login}") + @GetMapping("/admin/users/{login}") + @PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")") <%_ if (!reactive) { _%> public ResponseEntity<<%= asDto('User') %>> getUser(@PathVariable @Pattern(regexp = Constants.LOGIN_REGEX) String login) { log.debug("REST request to get User : {}", login); @@ -362,12 +408,12 @@ public class UserResource { <%_ if (authenticationType !== 'oauth2') { _%> /** - * {@code DELETE /users/:login} : delete the "login" User. + * {@code DELETE /admin/users/:login} : delete the "login" User. * * @param login the login of the user to delete. * @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)}. */ - @DeleteMapping("/users/{login}") + @DeleteMapping("/admin/users/{login}") @PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")") <%_ if (!reactive) { _%> public ResponseEntity deleteUser(@PathVariable @Pattern(regexp = Constants.LOGIN_REGEX) String login) { diff --git a/generators/server/templates/src/test/java/package/web/rest/UserResourceIT.java.ejs b/generators/server/templates/src/test/java/package/web/rest/UserResourceIT.java.ejs index 17cac3fffcdb..c20df1c4fbac 100644 --- a/generators/server/templates/src/test/java/package/web/rest/UserResourceIT.java.ejs +++ b/generators/server/templates/src/test/java/package/web/rest/UserResourceIT.java.ejs @@ -46,6 +46,7 @@ import <%= packageName %>.repository.UserRepository; import <%= packageName %>.repository.search.UserSearchRepository; <%_ } _%> import <%= packageName %>.security.AuthoritiesConstants; +import <%= packageName %>.service.dto.<%= asDto('PublicUser') %>; import <%= packageName %>.service.dto.<%= asDto('User') %>; <%_ if (databaseType === 'sql' && reactive) { _%> import <%= packageName %>.service.EntityManager; @@ -333,13 +334,13 @@ class UserResourceIT <% if (databaseType === 'cassandra') { %>extends AbstractCa managedUserVM.setAuthorities(Collections.singleton(AuthoritiesConstants.USER)); <%_ if (!reactive) { _%> - restUserMockMvc.perform(post("/api/users") + restUserMockMvc.perform(post("/api/admin/users") .contentType(MediaType.APPLICATION_JSON) .content(TestUtil.convertObjectToJsonBytes(managedUserVM))<% if (testsNeedCsrf) { %> .with(csrf())<% } %>) .andExpect(status().isCreated()); <%_ } else { _%> - webTestClient.post().uri("/api/users") + webTestClient.post().uri("/api/admin/users") .contentType(MediaType.APPLICATION_JSON) .bodyValue(TestUtil.convertObjectToJsonBytes(managedUserVM)) .exchange() @@ -391,13 +392,13 @@ class UserResourceIT <% if (databaseType === 'cassandra') { %>extends AbstractCa // An entity with an existing ID cannot be created, so this API call must fail <%_ if (!reactive) { _%> - restUserMockMvc.perform(post("/api/users") + restUserMockMvc.perform(post("/api/admin/users") .contentType(MediaType.APPLICATION_JSON) .content(TestUtil.convertObjectToJsonBytes(managedUserVM))<% if (testsNeedCsrf) { %> .with(csrf())<% } %>) .andExpect(status().isBadRequest()); <%_ } else { _%> - webTestClient.post().uri("/api/users") + webTestClient.post().uri("/api/admin/users") .contentType(MediaType.APPLICATION_JSON) .bodyValue(TestUtil.convertObjectToJsonBytes(managedUserVM)) .exchange() @@ -436,13 +437,13 @@ class UserResourceIT <% if (databaseType === 'cassandra') { %>extends AbstractCa // Create the User <%_ if (!reactive) { _%> - restUserMockMvc.perform(post("/api/users") + restUserMockMvc.perform(post("/api/admin/users") .contentType(MediaType.APPLICATION_JSON) .content(TestUtil.convertObjectToJsonBytes(managedUserVM))<% if (testsNeedCsrf) { %> .with(csrf())<% } %>) .andExpect(status().isBadRequest()); <%_ } else { _%> - webTestClient.post().uri("/api/users") + webTestClient.post().uri("/api/admin/users") .contentType(MediaType.APPLICATION_JSON) .bodyValue(TestUtil.convertObjectToJsonBytes(managedUserVM)) .exchange() @@ -481,13 +482,13 @@ class UserResourceIT <% if (databaseType === 'cassandra') { %>extends AbstractCa // Create the User <%_ if (!reactive) { _%> - restUserMockMvc.perform(post("/api/users") + restUserMockMvc.perform(post("/api/admin/users") .contentType(MediaType.APPLICATION_JSON) .content(TestUtil.convertObjectToJsonBytes(managedUserVM))<% if (testsNeedCsrf) { %> .with(csrf())<% } %>) .andExpect(status().isBadRequest()); <%_ } else { _%> - webTestClient.post().uri("/api/users") + webTestClient.post().uri("/api/admin/users") .contentType(MediaType.APPLICATION_JSON) .bodyValue(TestUtil.convertObjectToJsonBytes(managedUserVM)) .exchange() @@ -509,7 +510,7 @@ class UserResourceIT <% if (databaseType === 'cassandra') { %>extends AbstractCa // Get all the users <%_ if (!reactive) { _%> - restUserMockMvc.perform(get("/api/users<% if (databaseType === 'sql') { %>?sort=id,desc<% } %>") + restUserMockMvc.perform(get("/api/admin/users<% if (databaseType === 'sql') { %>?sort=id,desc<% } %>") .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) @@ -522,7 +523,7 @@ class UserResourceIT <% if (databaseType === 'cassandra') { %>extends AbstractCa <%_ } _%> .andExpect(jsonPath("$.[*].langKey").value(hasItem(DEFAULT_LANGKEY))); <%_ } else { _%> - <%= asDto('User') %> foundUser = webTestClient.get().uri("/api/users?sort=id,DESC") + <%= asDto('User') %> foundUser = webTestClient.get().uri("/api/admin/users?sort=id,DESC") .accept(MediaType.APPLICATION_JSON) .exchange() .expectStatus().isOk() @@ -540,6 +541,42 @@ class UserResourceIT <% if (databaseType === 'cassandra') { %>extends AbstractCa <%_ } _%> } + @Test + <%_ if (databaseType === 'sql' && !reactive) { _%> + @Transactional + <%_ } _%> + void getAllPublicUsers()<% if (!reactive) { %> throws Exception<% } %> { + // Initialize the database + userRepository.<% if (databaseType === 'sql' && reactive && authenticationType === 'oauth2') { %>create<% } else { %>save<% } %><% if (databaseType === 'sql' && !reactive) { %>AndFlush<% } %>(user)<% if (reactive) { %>.block()<% } %>; + + // Get all the users + <%_ if (!reactive) { _%> + restUserMockMvc.perform(get("/api/users<% if (databaseType === 'sql') { %>?sort=id,desc<% } %>") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(jsonPath("$.[*].login").value(hasItem(DEFAULT_LOGIN))) + .andExpect(jsonPath("$.[*].firstName").value(hasItem(DEFAULT_FIRSTNAME))) + .andExpect(jsonPath("$.[*].lastName").value(hasItem(DEFAULT_LASTNAME))) + .andExpect(jsonPath("$.[*].email").doesNotExist()) + <%_ if (databaseType !== 'cassandra') { _%> + .andExpect(jsonPath("$.[*].imageUrl").doesNotExist()) + <%_ } _%> + .andExpect(jsonPath("$.[*].langKey").doesNotExist()); + <%_ } else { _%> + <%= asDto('PublicUser') %> foundUser = webTestClient.get().uri("/api/users?sort=id,DESC") + .accept(MediaType.APPLICATION_JSON) + .exchange() + .expectStatus().isOk() + .expectHeader().contentType(MediaType.APPLICATION_JSON) + .returnResult(<%= asDto('User') %>.class).getResponseBody().blockFirst(); + + assertThat(foundUser.getLogin()).isEqualTo(DEFAULT_LOGIN); + assertThat(foundUser.getFirstName()).isEqualTo(DEFAULT_FIRSTNAME); + assertThat(foundUser.getLastName()).isEqualTo(DEFAULT_LASTNAME); + <% } _%> + } + <%_ if (databaseType === 'sql' && authenticationType !== 'oauth2') { _%> @Test <%_ if (!reactive) { _%> @@ -580,7 +617,7 @@ class UserResourceIT <% if (databaseType === 'cassandra') { %>extends AbstractCa // Get the user <%_ if (!reactive) { _%> - restUserMockMvc.perform(get("/api/users/{login}", user.getLogin())) + restUserMockMvc.perform(get("/api/admin/users/{login}", user.getLogin())) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) .andExpect(jsonPath("$.login").value(user.getLogin())) @@ -592,7 +629,7 @@ class UserResourceIT <% if (databaseType === 'cassandra') { %>extends AbstractCa <%_ } _%> .andExpect(jsonPath("$.langKey").value(DEFAULT_LANGKEY)); <%_ } else { _%> - webTestClient.get().uri("/api/users/{login}", user.getLogin()) + webTestClient.get().uri("/api/admin/users/{login}", user.getLogin()) .exchange() .expectStatus().isOk() .expectHeader().contentType(MediaType.APPLICATION_JSON) @@ -622,10 +659,10 @@ class UserResourceIT <% if (databaseType === 'cassandra') { %>extends AbstractCa <%_ } _%> void getNonExistingUser()<% if (!reactive) { %> throws Exception<% } %> { <%_ if (!reactive) { _%> - restUserMockMvc.perform(get("/api/users/unknown")) + restUserMockMvc.perform(get("/api/admin/users/unknown")) .andExpect(status().isNotFound()); <%_ } else { _%> - webTestClient.get().uri("/api/users/unknown") + webTestClient.get().uri("/api/admin/users/unknown") .exchange() .expectStatus().isNotFound(); <%_ } _%> @@ -671,13 +708,13 @@ class UserResourceIT <% if (databaseType === 'cassandra') { %>extends AbstractCa managedUserVM.setAuthorities(Collections.singleton(AuthoritiesConstants.USER)); <%_ if (!reactive) { _%> - restUserMockMvc.perform(put("/api/users") + restUserMockMvc.perform(put("/api/admin/users") .contentType(MediaType.APPLICATION_JSON) .content(TestUtil.convertObjectToJsonBytes(managedUserVM))<% if (testsNeedCsrf) { %> .with(csrf())<% } %>) .andExpect(status().isOk()); <%_ } else { _%> - webTestClient.put().uri("/api/users") + webTestClient.put().uri("/api/admin/users") .contentType(MediaType.APPLICATION_JSON) .bodyValue(TestUtil.convertObjectToJsonBytes(managedUserVM)) .exchange() @@ -737,13 +774,13 @@ class UserResourceIT <% if (databaseType === 'cassandra') { %>extends AbstractCa managedUserVM.setAuthorities(Collections.singleton(AuthoritiesConstants.USER)); <%_ if (!reactive) { _%> - restUserMockMvc.perform(put("/api/users") + restUserMockMvc.perform(put("/api/admin/users") .contentType(MediaType.APPLICATION_JSON) .content(TestUtil.convertObjectToJsonBytes(managedUserVM))<% if (testsNeedCsrf) { %> .with(csrf())<% } %>) .andExpect(status().isOk()); <%_ } else { _%> - webTestClient.put().uri("/api/users") + webTestClient.put().uri("/api/admin/users") .contentType(MediaType.APPLICATION_JSON) .bodyValue(TestUtil.convertObjectToJsonBytes(managedUserVM)) .exchange() @@ -822,13 +859,13 @@ class UserResourceIT <% if (databaseType === 'cassandra') { %>extends AbstractCa managedUserVM.setAuthorities(Collections.singleton(AuthoritiesConstants.USER)); <%_ if (!reactive) { _%> - restUserMockMvc.perform(put("/api/users") + restUserMockMvc.perform(put("/api/admin/users") .contentType(MediaType.APPLICATION_JSON) .content(TestUtil.convertObjectToJsonBytes(managedUserVM))<% if (testsNeedCsrf) { %> .with(csrf())<% } %>) .andExpect(status().isBadRequest()); <%_ } else { _%> - webTestClient.put().uri("/api/users") + webTestClient.put().uri("/api/admin/users") .contentType(MediaType.APPLICATION_JSON) .bodyValue(TestUtil.convertObjectToJsonBytes(managedUserVM)) .exchange() @@ -893,13 +930,13 @@ class UserResourceIT <% if (databaseType === 'cassandra') { %>extends AbstractCa managedUserVM.setAuthorities(Collections.singleton(AuthoritiesConstants.USER)); <%_ if (!reactive) { _%> - restUserMockMvc.perform(put("/api/users") + restUserMockMvc.perform(put("/api/admin/users") .contentType(MediaType.APPLICATION_JSON) .content(TestUtil.convertObjectToJsonBytes(managedUserVM))<% if (testsNeedCsrf) { %> .with(csrf())<% } %>) .andExpect(status().isBadRequest()); <%_ } else { _%> - webTestClient.put().uri("/api/users") + webTestClient.put().uri("/api/admin/users") .contentType(MediaType.APPLICATION_JSON) .bodyValue(TestUtil.convertObjectToJsonBytes(managedUserVM)) .exchange() @@ -923,12 +960,12 @@ class UserResourceIT <% if (databaseType === 'cassandra') { %>extends AbstractCa // Delete the user <%_ if (!reactive) { _%> - restUserMockMvc.perform(delete("/api/users/{login}", user.getLogin()) + restUserMockMvc.perform(delete("/api/admin/users/{login}", user.getLogin()) .accept(MediaType.APPLICATION_JSON)<% if (testsNeedCsrf) { %> .with(csrf())<% } %>) .andExpect(status().isNoContent()); <%_ } else { _%> - webTestClient.delete().uri("/api/users/{login}", user.getLogin()) + webTestClient.delete().uri("/api/admin/users/{login}", user.getLogin()) .accept(MediaType.APPLICATION_JSON) .exchange() .expectStatus().isNoContent();