2020-05-13 14:41:43 +02:00
|
|
|
import { DataSource } from '@angular/cdk/collections';
|
|
|
|
|
import { BehaviorSubject, from, Observable, of } from 'rxjs';
|
|
|
|
|
import { catchError, finalize, map } from 'rxjs/operators';
|
2020-07-06 16:17:06 +02:00
|
|
|
import {
|
2020-07-30 16:54:15 +02:00
|
|
|
SearchMethod,
|
2020-07-06 16:17:06 +02:00
|
|
|
UserGrant,
|
|
|
|
|
UserGrantSearchKey,
|
|
|
|
|
UserGrantSearchQuery,
|
|
|
|
|
UserGrantSearchResponse,
|
fix(console): cleanup structure, role guard, paginated requests, cleanup policies, toast i18n, view timestamp, preloading strategy, maennchenfindings, fix passwordchange (#483)
* routes, move grid to list comopnent
* rename app list component, move to project sub
* add owned-project-detail child module
* seperate pipes
* set password validators only if needed
* create org initialize without pwd
* no caps
* self xss message
* fix user table
* fix project member paginator
* fix project members pagination, user grant pag
* move project grants, fix imports
* fix owned project detail imports
* use pipe and directives
* ng content bindings, rem custom schemas
* i18n, fix error toast parameter
* toast i18n
* side background
* fix: sequence, add timestamp
* audit
* fix metanav background
* org domain label
* cleanup policy component
* shorten user grant roles, mk cols visible as bind
* move user components, show otp only if available
* preload modules
* fix password change
* fix org create buttons
* class css
2020-07-16 15:13:36 +02:00
|
|
|
UserGrantView,
|
2020-07-06 16:17:06 +02:00
|
|
|
} from 'src/app/proto/generated/management_pb';
|
2020-05-13 14:41:43 +02:00
|
|
|
import { MgmtUserService } from 'src/app/services/mgmt-user.service';
|
|
|
|
|
|
2020-07-06 16:17:06 +02:00
|
|
|
export enum UserGrantContext {
|
|
|
|
|
// AUTHUSER = 'authuser',
|
|
|
|
|
USER = 'user',
|
|
|
|
|
OWNED_PROJECT = 'owned',
|
|
|
|
|
GRANTED_PROJECT = 'granted',
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-13 14:41:43 +02:00
|
|
|
export class UserGrantsDataSource extends DataSource<UserGrant.AsObject> {
|
|
|
|
|
public totalResult: number = 0;
|
fix(console): cleanup structure, role guard, paginated requests, cleanup policies, toast i18n, view timestamp, preloading strategy, maennchenfindings, fix passwordchange (#483)
* routes, move grid to list comopnent
* rename app list component, move to project sub
* add owned-project-detail child module
* seperate pipes
* set password validators only if needed
* create org initialize without pwd
* no caps
* self xss message
* fix user table
* fix project member paginator
* fix project members pagination, user grant pag
* move project grants, fix imports
* fix owned project detail imports
* use pipe and directives
* ng content bindings, rem custom schemas
* i18n, fix error toast parameter
* toast i18n
* side background
* fix: sequence, add timestamp
* audit
* fix metanav background
* org domain label
* cleanup policy component
* shorten user grant roles, mk cols visible as bind
* move user components, show otp only if available
* preload modules
* fix password change
* fix org create buttons
* class css
2020-07-16 15:13:36 +02:00
|
|
|
public grantsSubject: BehaviorSubject<UserGrantView.AsObject[]> = new BehaviorSubject<UserGrantView.AsObject[]>([]);
|
2020-05-13 14:41:43 +02:00
|
|
|
private loadingSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
|
|
|
|
public loading$: Observable<boolean> = this.loadingSubject.asObservable();
|
|
|
|
|
|
|
|
|
|
constructor(private userService: MgmtUserService) {
|
|
|
|
|
super();
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-06 16:17:06 +02:00
|
|
|
public loadGrants(
|
|
|
|
|
context: UserGrantContext,
|
|
|
|
|
pageIndex: number,
|
|
|
|
|
pageSize: number,
|
|
|
|
|
data: {
|
|
|
|
|
projectId?: string;
|
|
|
|
|
grantId?: string;
|
|
|
|
|
userId?: string;
|
|
|
|
|
},
|
|
|
|
|
queries?: UserGrantSearchQuery[],
|
|
|
|
|
): void {
|
2020-05-13 14:41:43 +02:00
|
|
|
const offset = pageIndex * pageSize;
|
|
|
|
|
|
2020-07-06 16:17:06 +02:00
|
|
|
switch (context) {
|
|
|
|
|
case UserGrantContext.USER:
|
|
|
|
|
if (data && data.userId) {
|
2020-07-08 10:00:15 +02:00
|
|
|
this.loadingSubject.next(true);
|
2020-07-06 16:17:06 +02:00
|
|
|
const userfilter = new UserGrantSearchQuery();
|
|
|
|
|
userfilter.setKey(UserGrantSearchKey.USERGRANTSEARCHKEY_USER_ID);
|
|
|
|
|
userfilter.setValue(data.userId);
|
|
|
|
|
if (queries) {
|
|
|
|
|
queries.push(userfilter);
|
|
|
|
|
} else {
|
|
|
|
|
queries = [userfilter];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const promise = this.userService.SearchUserGrants(10, 0, queries);
|
|
|
|
|
this.loadResponse(promise);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case UserGrantContext.OWNED_PROJECT:
|
|
|
|
|
if (data && data.projectId) {
|
2020-07-08 10:00:15 +02:00
|
|
|
this.loadingSubject.next(true);
|
2020-07-30 16:54:15 +02:00
|
|
|
const projectfilter = new UserGrantSearchQuery();
|
|
|
|
|
projectfilter.setKey(UserGrantSearchKey.USERGRANTSEARCHKEY_PROJECT_ID);
|
|
|
|
|
projectfilter.setValue(data.projectId);
|
|
|
|
|
if (queries) {
|
|
|
|
|
queries.push(projectfilter);
|
|
|
|
|
} else {
|
|
|
|
|
queries = [projectfilter];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const promise1 = this.userService.SearchUserGrants(10, 0, queries);
|
2020-07-06 16:17:06 +02:00
|
|
|
this.loadResponse(promise1);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case UserGrantContext.GRANTED_PROJECT:
|
2020-07-30 16:54:15 +02:00
|
|
|
if (data && data.grantId && data.projectId) {
|
2020-07-08 10:00:15 +02:00
|
|
|
this.loadingSubject.next(true);
|
2020-07-30 16:54:15 +02:00
|
|
|
|
|
|
|
|
const grantquery: UserGrantSearchQuery = new UserGrantSearchQuery();
|
|
|
|
|
grantquery.setKey(UserGrantSearchKey.USERGRANTSEARCHKEY_GRANT_ID);
|
|
|
|
|
grantquery.setMethod(SearchMethod.SEARCHMETHOD_EQUALS);
|
|
|
|
|
grantquery.setValue(data.grantId);
|
|
|
|
|
|
|
|
|
|
const projectfilter = new UserGrantSearchQuery();
|
|
|
|
|
projectfilter.setKey(UserGrantSearchKey.USERGRANTSEARCHKEY_PROJECT_ID);
|
|
|
|
|
projectfilter.setValue(data.projectId);
|
|
|
|
|
|
|
|
|
|
if (queries) {
|
|
|
|
|
queries.push(projectfilter);
|
|
|
|
|
queries.push(grantquery);
|
|
|
|
|
} else {
|
|
|
|
|
queries = [projectfilter, grantquery];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const promise2 = this.userService.SearchUserGrants(10, 0, queries);
|
2020-07-06 16:17:06 +02:00
|
|
|
this.loadResponse(promise2);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-01 17:48:34 +02:00
|
|
|
|
2020-07-06 16:17:06 +02:00
|
|
|
private loadResponse(promise: Promise<UserGrantSearchResponse>): void {
|
|
|
|
|
from(promise).pipe(
|
2020-05-13 14:41:43 +02:00
|
|
|
map(resp => {
|
|
|
|
|
this.totalResult = resp.toObject().totalResult;
|
|
|
|
|
return resp.toObject().resultList;
|
|
|
|
|
}),
|
|
|
|
|
catchError(() => of([])),
|
|
|
|
|
finalize(() => this.loadingSubject.next(false)),
|
|
|
|
|
).subscribe(grants => {
|
|
|
|
|
this.grantsSubject.next(grants);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Connect this data source to the table. The table will only update when
|
|
|
|
|
* the returned stream emits new items.
|
|
|
|
|
* @returns A stream of the items to be rendered.
|
|
|
|
|
*/
|
fix(console): cleanup structure, role guard, paginated requests, cleanup policies, toast i18n, view timestamp, preloading strategy, maennchenfindings, fix passwordchange (#483)
* routes, move grid to list comopnent
* rename app list component, move to project sub
* add owned-project-detail child module
* seperate pipes
* set password validators only if needed
* create org initialize without pwd
* no caps
* self xss message
* fix user table
* fix project member paginator
* fix project members pagination, user grant pag
* move project grants, fix imports
* fix owned project detail imports
* use pipe and directives
* ng content bindings, rem custom schemas
* i18n, fix error toast parameter
* toast i18n
* side background
* fix: sequence, add timestamp
* audit
* fix metanav background
* org domain label
* cleanup policy component
* shorten user grant roles, mk cols visible as bind
* move user components, show otp only if available
* preload modules
* fix password change
* fix org create buttons
* class css
2020-07-16 15:13:36 +02:00
|
|
|
public connect(): Observable<UserGrantView.AsObject[]> {
|
2020-05-13 14:41:43 +02:00
|
|
|
return this.grantsSubject.asObservable();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Called when the table is being destroyed. Use this function, to clean up
|
|
|
|
|
* any open connections or free any held resources that were set up during connect.
|
|
|
|
|
*/
|
|
|
|
|
public disconnect(): void {
|
|
|
|
|
this.grantsSubject.complete();
|
|
|
|
|
this.loadingSubject.complete();
|
|
|
|
|
}
|
|
|
|
|
}
|