add user roles listing filter

This commit is contained in:
amentis 2023-12-01 13:18:20 +02:00
parent 04d97fc2e2
commit 3ea60a4b43
8 changed files with 86 additions and 17 deletions

View File

@ -165,7 +165,8 @@ public class ReferenceQuery extends QueryBase<ReferenceEntity> {
}
if (this.like != null && !this.like.isEmpty()) {
predicates.add(queryContext.CriteriaBuilder.or(queryContext.CriteriaBuilder.like(queryContext.Root.get(ReferenceEntity._label), this.like),
queryContext.CriteriaBuilder.like(queryContext.Root.get(ReferenceEntity._description), this.like)
queryContext.CriteriaBuilder.like(queryContext.Root.get(ReferenceEntity._description), this.like),
queryContext.CriteriaBuilder.like(queryContext.Root.get(ReferenceEntity._source), this.like)
));
}
if (this.isActives != null) {

View File

@ -4,13 +4,9 @@ import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.authorization.Permission;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.DescriptionReferenceEntity;
import eu.eudat.data.UserContactInfoEntity;
import eu.eudat.data.UserEntity;
import eu.eudat.data.*;
import eu.eudat.model.User;
import eu.eudat.model.PublicUser;
import eu.eudat.model.UserContactInfo;
import eu.eudat.query.utils.BuildSubQueryInput;
import eu.eudat.query.utils.QueryUtilsService;
import gr.cite.commons.web.authz.service.AuthorizationService;
@ -36,6 +32,7 @@ public class UserQuery extends QueryBase<UserEntity> {
private Collection<String> emails;
private Collection<UUID> excludedIds;
private Collection<IsActive> isActives;
private UserRoleQuery userRoleQuery;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@ -113,6 +110,11 @@ public class UserQuery extends QueryBase<UserEntity> {
return this;
}
public UserQuery userRoleSubQuery(UserRoleQuery userRoleSubQuery) {
this.userRoleQuery = userRoleSubQuery;
return this;
}
public UserQuery authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
@ -124,7 +126,8 @@ public class UserQuery extends QueryBase<UserEntity> {
this.isEmpty(this.ids) ||
this.isEmpty(this.isActives) ||
this.isEmpty(this.emails) ||
this.isEmpty(this.excludedIds);
this.isEmpty(this.excludedIds) ||
this.isFalseQuery(this.userRoleQuery);
}
@Override
@ -190,6 +193,11 @@ public class UserQuery extends QueryBase<UserEntity> {
));
predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(UserEntity._id)).value(userContactInfoSubquery));
}
if (this.userRoleQuery != null) {
Subquery<UserRoleEntity> subQuery = queryContext.Query.subquery(this.userRoleQuery.entityClass());
this.applySubQuery(this.userRoleQuery, queryContext.CriteriaBuilder, subQuery);
predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(UserEntity._id)).value(subQuery));
}
if (!predicates.isEmpty()) {

View File

@ -1,15 +1,10 @@
package eu.eudat.query.lookup;
import eu.eudat.commons.enums.DescriptionStatus;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.elastic.query.DescriptionElasticQuery;
import eu.eudat.elastic.query.InnerObjectDmpElasticQuery;
import eu.eudat.query.DescriptionQuery;
import eu.eudat.query.UserQuery;
import gr.cite.tools.data.query.Lookup;
import gr.cite.tools.data.query.QueryFactory;
import java.time.Instant;
import java.util.List;
import java.util.UUID;
@ -22,6 +17,7 @@ public class UserLookup extends Lookup {
private List<UUID> excludedIds;
private List<IsActive> isActive;
private UserRoleLookup userRoleSubQuery;
public String getLike() {
return like;
@ -55,11 +51,28 @@ public class UserLookup extends Lookup {
this.isActive = isActive;
}
public List<String> getEmails() {
return emails;
}
public void setEmails(List<String> emails) {
this.emails = emails;
}
public UserRoleLookup getUserRoleSubQuery() {
return userRoleSubQuery;
}
public void setUserRoleSubQuery(UserRoleLookup userRoleSubQuery) {
this.userRoleSubQuery = userRoleSubQuery;
}
public UserQuery enrich(QueryFactory queryFactory) {
UserQuery query = queryFactory.query(UserQuery.class);
if (this.like != null) query.like(this.like);
if (this.ids != null) query.ids(this.ids);
if (this.emails != null) query.emails(this.emails);
if (this.userRoleSubQuery != null) query.userRoleSubQuery(this.userRoleSubQuery.enrich(queryFactory));
if (this.excludedIds != null) query.excludedIds(this.excludedIds);
if (this.isActive != null) query.isActive(this.isActive);

View File

@ -0,0 +1,20 @@
import { Lookup } from "@common/model/lookup";
import { Guid } from "@common/types/guid";
export class UserRoleLookup extends Lookup implements UserRoleFilter {
ids: Guid[];
excludedIds: Guid[];
userIds: Guid[];
roles: string[]
constructor() {
super();
}
}
export interface UserRoleFilter {
ids: Guid[];
excludedIds: Guid[];
userIds: Guid[];
roles: string[];
}

View File

@ -1,6 +1,7 @@
import { Lookup } from '@common/model/lookup';
import { Guid } from '@common/types/guid';
import { IsActive } from '../common/enum/is-active.enum';
import { UserRoleLookup } from './user-role.lookup';
export class UserLookup extends Lookup implements UserFilter {
ids: Guid[];
@ -8,6 +9,7 @@ export class UserLookup extends Lookup implements UserFilter {
like: string;
emails: string[];
isActive: IsActive[];
userRoleSubQuery: UserRoleLookup;
constructor() {
super();
@ -20,4 +22,5 @@ export interface UserFilter {
like: string;
emails: string[];
isActive: IsActive[];
userRoleSubQuery: UserRoleLookup;
}

View File

@ -20,6 +20,14 @@
{{'USER-LISTING.FILTER.IS-ACTIVE' | translate}}
</mat-slide-toggle>
<div>
<mat-label>{{'USER-LISTING.FILTER.ROLES' | translate}}
<mat-select multiple [(ngModel)]="internalFilters.userRoleSubQuery.roles">
<mat-option *ngFor="let appRole of appRoleEnumValues" [value]="appRole">{{enumUtils.toAppRoleString(appRole)}}</mat-option>
</mat-select>
</mat-label>
</div>
<div class="d-flex justify-content-end align-items-center mt-4 gap-1-rem">
<button mat-stroked-button color="primary" (click)="filterMenuTrigger?.closeMenu()">
{{'USER-LISTING.FILTER.CANCEL' | translate}}

View File

@ -1,5 +1,7 @@
import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core';
import { AppRole } from '@app/core/common/enum/app-role';
import { IsActive } from '@app/core/common/enum/is-active.enum';
import { UserRoleLookup } from '@app/core/query/user-role.lookup';
import { UserFilter } from '@app/core/query/user.lookup';
import { EnumUtils } from '@app/core/services/utilities/enum-utils.service';
import { BaseComponent } from '@common/base/base.component';
@ -15,6 +17,9 @@ export class UserListingFiltersComponent extends BaseComponent implements OnInit
@Input() readonly filter: UserFilter;
@Output() filterChange = new EventEmitter<UserFilter>();
roles: string[] = []
appRoleEnumValues = this.enumUtils.getEnumValues<AppRole>(AppRole);
// * State
internalFilters: UserListingFilters = this._getEmptyFilters();
@ -45,11 +50,12 @@ export class UserListingFiltersComponent extends BaseComponent implements OnInit
}
protected applyFilters(): void {
const { isActive, like } = this.internalFilters ?? {}
const { isActive, like, userRoleSubQuery } = this.internalFilters ?? {}
this.filterChange.emit({
...this.filter,
like,
isActive: isActive ? [IsActive.Active] : [IsActive.Inactive]
isActive: isActive ? [IsActive.Active] : [IsActive.Inactive],
userRoleSubQuery
})
}
@ -59,11 +65,12 @@ export class UserListingFiltersComponent extends BaseComponent implements OnInit
return this._getEmptyFilters();
}
let { excludedIds, ids, isActive, like } = inputFilter;
let { excludedIds, ids, isActive, like, userRoleSubQuery } = inputFilter;
return {
isActive: (isActive ?? [])?.includes(IsActive.Active) || !isActive?.length,
like: like
like: like,
userRoleSubQuery: userRoleSubQuery ?? new UserRoleLookup()
}
}
@ -72,6 +79,7 @@ export class UserListingFiltersComponent extends BaseComponent implements OnInit
return {
isActive: true,
like: null,
userRoleSubQuery: new UserRoleLookup()
}
}
@ -91,4 +99,5 @@ export class UserListingFiltersComponent extends BaseComponent implements OnInit
interface UserListingFilters {
isActive: boolean;
like: string;
userRoleSubQuery: UserRoleLookup;
}

View File

@ -13,6 +13,7 @@ import { QueryParamsService } from '@app/core/services/utilities/query-params.se
import { BaseListingComponent } from '@common/base/base-listing-component';
import { PipeService } from '@common/formatting/pipe.service';
import { DataTableDateTimeFormatPipe } from '@common/formatting/pipes/date-time-format.pipe';
import { IsActiveTypePipe } from '@common/formatting/pipes/is-active-type.pipe';
import { QueryResult } from '@common/model/query-result';
import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component';
import { HttpErrorHandlingService } from '@common/modules/errors/error-handling/http-error-handling.service';
@ -124,7 +125,13 @@ export class UserListingComponent extends BaseListingComponent<User, UserLookup>
alwaysShown: true,
maxWidth: 300,
cellTemplate: this.roleCellTemplate
}
},
{
prop: nameof<User>(x => x.isActive),
sortable: true,
languageName: 'USER-LISTING.FIELDS.IS-ACTIVE',
pipe: this.pipeService.getPipe<IsActiveTypePipe>(IsActiveTypePipe)
},
]);
this.propertiesAvailableForOrder = this.gridColumns.filter(x => x.sortable);
}