Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Made user search case-insensitive (not well optimized, sadly)
* Added a few tests for search
* Removed some extraneous import in TenantTechnicalUserDto

Signed-off-by: Menahem Julien Raccah Lisei <[email protected]>
  • Loading branch information
menajrl committed Dec 23, 2019
1 parent 416f3d5 commit 70de7f3
Show file tree
Hide file tree
Showing 5 changed files with 438 additions and 388 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public interface IUserRepository extends CrudRepository<User, Long> {
* @param partial
* @return
*/
@Query("SELECT u from User u WHERE u.username LIKE %?1%")
@Query("SELECT u from User u WHERE LOWER(u.username) LIKE %?1%")
Collection<User> findUserByPartial(String partial);

@Query("SELECT u from User u, TenantUser tu, UserRole r " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,14 @@ public ResponseEntity<Boolean> createTechnicalUserForTenant(
}

try {
LOGGER.info("Creating technical user [" + userId + "] and adding to tenant [" + tenantId + "] with role(s) [" + Arrays.toString(user.getRoles().toArray()) + "]");
LOGGER.info(
String.format(
"Creating technical user [%s] and adding to tenant [%s] with role(s) [%s]",
userId,
tenantId,
user.getRoles()
)
);
if (userId.equals(SecurityContextHolder.getContext().getAuthentication().getName())) {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
Expand Down Expand Up @@ -290,7 +297,7 @@ public ResponseEntity<UserDto> getUser(
public ResponseEntity<Collection<UserDto>> findUsers(
@ApiParam(value = "Username", required = true) @PathVariable String partial) {

Collection<User> users = accountService.findUsers(ControllerUtils.sanitize(partial));
Collection<User> users = accountService.findUsers(ControllerUtils.sanitize(partial.toLowerCase()));
if (users != null) {
return new ResponseEntity<>(users.stream().map(UserDto::fromUser).collect(Collectors.toList()), HttpStatus.OK);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
*/
package org.eclipse.vorto.repository.web.account.dto;

import org.eclipse.vorto.repository.domain.User;

/**
* Represents a payload for requests to perform both:
* <ul>
Expand Down
Loading

0 comments on commit 70de7f3

Please sign in to comment.