root/resilient#2 Change the User selection control to a 'on type' combo.
Also restricted the user list to only users that have NO association to org yet
This commit is contained in:
parent
4890950952
commit
2aa75f0e13
8 changed files with 174 additions and 82 deletions
|
@ -9,6 +9,7 @@ import org.springframework.data.domain.Page;
|
|||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.EntityGraph;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.oguerreiro.resilient.domain.User;
|
||||
|
@ -43,4 +44,13 @@ public interface UserRepository extends JpaRepository<User, Long> {
|
|||
Optional<User> findOneWithAuthoritiesByEmailIgnoreCase(String email);
|
||||
|
||||
Page<User> findAllByIdNotNullAndActivatedIsTrue(Pageable pageable);
|
||||
|
||||
@Query("""
|
||||
SELECT u
|
||||
FROM User u
|
||||
WHERE u.id IS NOT NULL
|
||||
AND u.activated = TRUE
|
||||
AND u.id NOT IN (SELECT o.user.id FROM Organization o WHERE o.user IS NOT NULL)
|
||||
""")
|
||||
Page<User> findActiveUsersNotInOrganization(Pageable pageable);
|
||||
}
|
||||
|
|
|
@ -274,6 +274,11 @@ public class UserService {
|
|||
return userRepository.findAllByIdNotNullAndActivatedIsTrue(pageable).map(UserDTO::new);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Page<UserDTO> getAllPublicUsersForOrganization(Pageable pageable) {
|
||||
return userRepository.findActiveUsersNotInOrganization(pageable).map(UserDTO::new);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Optional<User> getUserWithAuthoritiesByLogin(String login) {
|
||||
return userRepository.findOneWithAuthoritiesByLogin(login);
|
||||
|
|
|
@ -1,69 +1,83 @@
|
|||
package com.oguerreiro.resilient.service.dto;
|
||||
|
||||
import com.oguerreiro.resilient.domain.User;
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.oguerreiro.resilient.domain.User;
|
||||
|
||||
/**
|
||||
* A DTO representing a user, with only the public attributes.
|
||||
*/
|
||||
public class UserDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long id;
|
||||
private Long id;
|
||||
|
||||
private String login;
|
||||
private String login;
|
||||
|
||||
public UserDTO() {
|
||||
// Empty constructor needed for Jackson.
|
||||
private String email;
|
||||
|
||||
public UserDTO() {
|
||||
// Empty constructor needed for Jackson.
|
||||
}
|
||||
|
||||
public UserDTO(User user) {
|
||||
this.id = user.getId();
|
||||
this.login = user.getLogin();
|
||||
this.email = user.getEmail();
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getLogin() {
|
||||
return login;
|
||||
}
|
||||
|
||||
public void setLogin(String login) {
|
||||
this.login = login;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public UserDTO(User user) {
|
||||
this.id = user.getId();
|
||||
// Customize it here if you need, or not, firstName/lastName/etc
|
||||
this.login = user.getLogin();
|
||||
UserDTO userDTO = (UserDTO) o;
|
||||
if (userDTO.getId() == null || getId() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
return Objects.equals(getId(), userDTO.getId()) && Objects.equals(getLogin(), userDTO.getLogin());
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getLogin() {
|
||||
return login;
|
||||
}
|
||||
|
||||
public void setLogin(String login) {
|
||||
this.login = login;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
UserDTO userDTO = (UserDTO) o;
|
||||
if (userDTO.getId() == null || getId() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Objects.equals(getId(), userDTO.getId()) && Objects.equals(getLogin(), userDTO.getLogin());
|
||||
}
|
||||
|
||||
// prettier-ignore
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UserDTO{" +
|
||||
"id='" + id + '\'' +
|
||||
", login='" + login + '\'' +
|
||||
"}";
|
||||
}
|
||||
// prettier-ignore
|
||||
@Override
|
||||
public String toString() {
|
||||
//@formatter:off
|
||||
return "UserDTO{"
|
||||
+ "id='" + id + '\''
|
||||
+ ", login='" + login + '\''
|
||||
+ ", email='" + email + '\''
|
||||
+ "}";
|
||||
//@formatter:on
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package com.oguerreiro.resilient.web.rest;
|
||||
|
||||
import com.oguerreiro.resilient.service.UserService;
|
||||
import com.oguerreiro.resilient.service.dto.UserDTO;
|
||||
import java.util.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.Page;
|
||||
|
@ -12,45 +12,72 @@ import org.springframework.data.domain.Sort;
|
|||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
||||
|
||||
import com.oguerreiro.resilient.service.UserService;
|
||||
import com.oguerreiro.resilient.service.dto.UserDTO;
|
||||
|
||||
import tech.jhipster.web.util.PaginationUtil;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
public class PublicUserResource {
|
||||
|
||||
private static final List<String> ALLOWED_ORDERED_PROPERTIES = Collections.unmodifiableList(
|
||||
Arrays.asList("id", "login", "firstName", "lastName", "email", "activated", "langKey")
|
||||
);
|
||||
private static final List<String> ALLOWED_ORDERED_PROPERTIES = Collections.unmodifiableList(
|
||||
Arrays.asList("id", "login", "firstName", "lastName", "email", "activated", "langKey"));
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(PublicUserResource.class);
|
||||
private final Logger log = LoggerFactory.getLogger(PublicUserResource.class);
|
||||
|
||||
private final UserService userService;
|
||||
private final UserService userService;
|
||||
|
||||
public PublicUserResource(UserService userService) {
|
||||
this.userService = userService;
|
||||
public PublicUserResource(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code GET /users} : get all users with only public information - calling this method is allowed for anyone.
|
||||
*
|
||||
* @param pageable the pagination information.
|
||||
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body all users.
|
||||
*/
|
||||
@GetMapping("/users")
|
||||
public ResponseEntity<List<UserDTO>> getAllPublicUsers(
|
||||
@org.springdoc.core.annotations.ParameterObject Pageable pageable) {
|
||||
log.debug("REST request to get all public User names");
|
||||
if (!onlyContainsAllowedProperties(pageable)) {
|
||||
return ResponseEntity.badRequest().build();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code GET /users} : get all users with only public information - calling this method is allowed for anyone.
|
||||
*
|
||||
* @param pageable the pagination information.
|
||||
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body all users.
|
||||
*/
|
||||
@GetMapping("/users")
|
||||
public ResponseEntity<List<UserDTO>> getAllPublicUsers(@org.springdoc.core.annotations.ParameterObject Pageable pageable) {
|
||||
log.debug("REST request to get all public User names");
|
||||
if (!onlyContainsAllowedProperties(pageable)) {
|
||||
return ResponseEntity.badRequest().build();
|
||||
}
|
||||
final Page<UserDTO> page = userService.getAllPublicUsers(pageable);
|
||||
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(ServletUriComponentsBuilder.fromCurrentRequest(),
|
||||
page);
|
||||
return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
|
||||
}
|
||||
|
||||
final Page<UserDTO> page = userService.getAllPublicUsers(pageable);
|
||||
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(ServletUriComponentsBuilder.fromCurrentRequest(), page);
|
||||
return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
|
||||
/**
|
||||
* {@code GET /users} : get all users with only public information - calling this method is allowed for anyone.
|
||||
*
|
||||
* @param pageable the pagination information.
|
||||
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body all users.
|
||||
*/
|
||||
@GetMapping("/users/for/organization")
|
||||
public ResponseEntity<List<UserDTO>> getAllPublicUsersForOrganization(
|
||||
@org.springdoc.core.annotations.ParameterObject Pageable pageable) {
|
||||
log.debug("REST request to get all public User names, restricted to users not yet associated in the organization");
|
||||
if (!onlyContainsAllowedProperties(pageable)) {
|
||||
return ResponseEntity.badRequest().build();
|
||||
}
|
||||
|
||||
private boolean onlyContainsAllowedProperties(Pageable pageable) {
|
||||
return pageable.getSort().stream().map(Sort.Order::getProperty).allMatch(ALLOWED_ORDERED_PROPERTIES::contains);
|
||||
}
|
||||
final Page<UserDTO> page = userService.getAllPublicUsersForOrganization(pageable);
|
||||
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(ServletUriComponentsBuilder.fromCurrentRequest(),
|
||||
page);
|
||||
return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
|
||||
}
|
||||
|
||||
private boolean onlyContainsAllowedProperties(Pageable pageable) {
|
||||
return pageable.getSort().stream().map(Sort.Order::getProperty).allMatch(ALLOWED_ORDERED_PROPERTIES::contains);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -186,12 +186,36 @@
|
|||
<!-- User property applies only to OrganizationNature.PERSON -->
|
||||
<div class="mb-3" *ngIf="editForm.get('organizationType')?.value?.nature === organizationNature.PERSON">
|
||||
<label class="form-label" for="field_user" jhiTranslate="resilientApp.organization.user">User</label>
|
||||
<select class="form-control" id="field_user" data-cy="user" name="user" formControlName="user" [compareWith]="compareUser">
|
||||
<!--
|
||||
<select
|
||||
class="form-control"
|
||||
id="field_user"
|
||||
data-cy="user"
|
||||
name="user"
|
||||
formControlName="user"
|
||||
[compareWith]="compareUser">
|
||||
<option [ngValue]="null"></option>
|
||||
@for (userOption of usersSharedCollection; track $index) {
|
||||
<option [ngValue]="userOption">{{ userOption.login }}</option>
|
||||
}
|
||||
</select>
|
||||
-->
|
||||
|
||||
<ng-select
|
||||
class="form-control drop-down-panel"
|
||||
formControlName="user"
|
||||
[items]="usersSharedCollection"
|
||||
[compareWith]="compareUser"
|
||||
[clearable]="true"
|
||||
[searchFn]="userSearchFn"
|
||||
>
|
||||
<ng-template ng-label-tmp let-item="item">
|
||||
{{ item.login }} ( {{ item.email }} )
|
||||
</ng-template>
|
||||
<ng-template ng-option-tmp let-item="item">
|
||||
{{ item.login }} ( {{ item.email }} )
|
||||
</ng-template>
|
||||
</ng-select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import { finalize, map } from 'rxjs/operators';
|
|||
|
||||
import SharedModule from 'app/shared/shared.module';
|
||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
import { NgSelectModule } from '@ng-select/ng-select';
|
||||
|
||||
import { AlertError } from 'app/shared/alert/alert-error.model';
|
||||
import { EventManager, EventWithContent } from 'app/core/util/event-manager.service';
|
||||
|
@ -23,7 +24,7 @@ import { OrganizationNature } from 'app/entities/enumerations/organization-natur
|
|||
standalone: true,
|
||||
selector: 'jhi-organization-update',
|
||||
templateUrl: './organization-update.component.html',
|
||||
imports: [SharedModule, FormsModule, ReactiveFormsModule],
|
||||
imports: [SharedModule, FormsModule, ReactiveFormsModule, NgSelectModule],
|
||||
})
|
||||
export class OrganizationUpdateComponent implements OnInit {
|
||||
// Properties with defaults by router
|
||||
|
@ -181,7 +182,7 @@ export class OrganizationUpdateComponent implements OnInit {
|
|||
|
||||
protected loadRelationshipsOptionsUser(): void {
|
||||
this.userService
|
||||
.query()
|
||||
.queryForOrganization()
|
||||
.pipe(map((res: HttpResponse<IUser[]>) => res.body ?? []))
|
||||
.pipe(map((users: IUser[]) => this.userService.addUserToCollectionIfMissing<IUser>(users, this.organization?.user)))
|
||||
.subscribe((users: IUser[]) => (this.usersSharedCollection = users));
|
||||
|
@ -227,4 +228,9 @@ export class OrganizationUpdateComponent implements OnInit {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
userSearchFn = (term: string, item: any) => {
|
||||
term = term.toLowerCase();
|
||||
return (item.login + "( " + item.email + " )").toLowerCase().includes(term);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -26,6 +26,11 @@ export class UserService {
|
|||
return this.http.get<IUser[]>(this.resourceUrl, { params: options, observe: 'response' });
|
||||
}
|
||||
|
||||
queryForOrganization(req?: any): Observable<EntityArrayResponseType> {
|
||||
const options = createRequestOption(req);
|
||||
return this.http.get<IUser[]>(`${this.resourceUrl}/for/organization`, { params: options, observe: 'response' });
|
||||
}
|
||||
|
||||
getUserIdentifier(user: Pick<IUser, 'id'>): number {
|
||||
return user.id;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
export interface IUser {
|
||||
id: number;
|
||||
login?: string | null;
|
||||
email?: string | null;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue