mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-18 11:15:12 +00:00
fix(console): distinct user grant searches and creates, project grant member edit, import cleanup (#342)
* project grant member edit * project grant member dialog, import cleanup * readd project roles * user login-methods cleanup * fix sw config, user grant context * delete user grants, context for creation, search * contributor box shadow * password to detail view * user detail notification * lint
This commit is contained in:
@@ -1,9 +1,21 @@
|
||||
import { DataSource } from '@angular/cdk/collections';
|
||||
import { BehaviorSubject, from, Observable, of } from 'rxjs';
|
||||
import { catchError, finalize, map } from 'rxjs/operators';
|
||||
import { UserGrant, UserGrantSearchKey, UserGrantSearchQuery } from 'src/app/proto/generated/management_pb';
|
||||
import {
|
||||
UserGrant,
|
||||
UserGrantSearchKey,
|
||||
UserGrantSearchQuery,
|
||||
UserGrantSearchResponse,
|
||||
} from 'src/app/proto/generated/management_pb';
|
||||
import { MgmtUserService } from 'src/app/services/mgmt-user.service';
|
||||
|
||||
export enum UserGrantContext {
|
||||
// AUTHUSER = 'authuser',
|
||||
USER = 'user',
|
||||
OWNED_PROJECT = 'owned',
|
||||
GRANTED_PROJECT = 'granted',
|
||||
}
|
||||
|
||||
export class UserGrantsDataSource extends DataSource<UserGrant.AsObject> {
|
||||
public totalResult: number = 0;
|
||||
public grantsSubject: BehaviorSubject<UserGrant.AsObject[]> = new BehaviorSubject<UserGrant.AsObject[]>([]);
|
||||
@@ -14,17 +26,54 @@ export class UserGrantsDataSource extends DataSource<UserGrant.AsObject> {
|
||||
super();
|
||||
}
|
||||
|
||||
public loadGrants(filter: UserGrantSearchKey, userId: string, pageIndex: number, pageSize: number): void {
|
||||
public loadGrants(
|
||||
context: UserGrantContext,
|
||||
pageIndex: number,
|
||||
pageSize: number,
|
||||
data: {
|
||||
projectId?: string;
|
||||
grantId?: string;
|
||||
userId?: string;
|
||||
},
|
||||
queries?: UserGrantSearchQuery[],
|
||||
): void {
|
||||
const offset = pageIndex * pageSize;
|
||||
|
||||
this.loadingSubject.next(true);
|
||||
|
||||
const query = new UserGrantSearchQuery();
|
||||
query.setKey(filter);
|
||||
query.setValue(userId);
|
||||
switch (context) {
|
||||
case UserGrantContext.USER:
|
||||
if (data && data.userId) {
|
||||
const userfilter = new UserGrantSearchQuery();
|
||||
userfilter.setKey(UserGrantSearchKey.USERGRANTSEARCHKEY_USER_ID);
|
||||
userfilter.setValue(data.userId);
|
||||
if (queries) {
|
||||
queries.push(userfilter);
|
||||
} else {
|
||||
queries = [userfilter];
|
||||
}
|
||||
|
||||
const queries: UserGrantSearchQuery[] = [query];
|
||||
from(this.userService.SearchUserGrants(10, 0, queries)).pipe(
|
||||
const promise = this.userService.SearchUserGrants(10, 0, queries);
|
||||
this.loadResponse(promise);
|
||||
}
|
||||
break;
|
||||
case UserGrantContext.OWNED_PROJECT:
|
||||
if (data && data.projectId) {
|
||||
const promise1 = this.userService.SearchProjectUserGrants(data.projectId, 10, 0, queries);
|
||||
this.loadResponse(promise1);
|
||||
}
|
||||
break;
|
||||
case UserGrantContext.GRANTED_PROJECT:
|
||||
if (data && data.grantId) {
|
||||
const promise2 = this.userService.SearchProjectGrantUserGrants(data.grantId, 10, 0, queries);
|
||||
this.loadResponse(promise2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private loadResponse(promise: Promise<UserGrantSearchResponse>): void {
|
||||
from(promise).pipe(
|
||||
map(resp => {
|
||||
this.totalResult = resp.toObject().totalResult;
|
||||
console.log(resp.toObject().resultList);
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
</div>
|
||||
<span class="fill-space"></span>
|
||||
<button color="warn" matTooltip="{{'GRANTS.DELETE' | translate}}" class="icon-button" mat-icon-button
|
||||
*ngIf="selection.hasValue() && allowDelete">
|
||||
(click)="deleteGrantSelection()" *ngIf="selection.hasValue() && allowDelete">
|
||||
<i class="las la-trash"></i>
|
||||
</button>
|
||||
<a *ngIf="allowCreate" matTooltip="{{'GRANTS.ADD' | translate}}" color="primary" class="add-button" color="primary"
|
||||
mat-raised-button [routerLink]="['/grant-create', {filter: filter, filterValue: filterValue}]">
|
||||
mat-raised-button [routerLink]="routerLink">
|
||||
<mat-icon class="icon">add</mat-icon>{{ 'GRANTS.ADD_BTN' | translate }}
|
||||
</a>
|
||||
</div>
|
||||
@@ -86,7 +86,7 @@
|
||||
</button>
|
||||
</ng-container>
|
||||
<ng-template #showOptions>
|
||||
<mat-form-field class="form-field" appearance="outline" *ngIf="filterValue">
|
||||
<mat-form-field class="form-field" appearance="outline" *ngIf="projectId">
|
||||
<mat-label>{{ 'PROJECT.GRANT.TITLE' | translate }}</mat-label>
|
||||
<mat-select [(ngModel)]="grant.roleKeysList" multiple [disabled]="allowCreate == false"
|
||||
(selectionChange)="updateRoles(grant, $event)">
|
||||
|
||||
@@ -4,12 +4,12 @@ import { MatPaginator } from '@angular/material/paginator';
|
||||
import { MatSelectChange } from '@angular/material/select';
|
||||
import { MatTable } from '@angular/material/table';
|
||||
import { tap } from 'rxjs/operators';
|
||||
import { ProjectGrant, ProjectRoleView, UserGrant, UserGrantSearchKey } from 'src/app/proto/generated/management_pb';
|
||||
import { ProjectGrant, ProjectRoleView, UserGrant } from 'src/app/proto/generated/management_pb';
|
||||
import { MgmtUserService } from 'src/app/services/mgmt-user.service';
|
||||
import { ProjectService } from 'src/app/services/project.service';
|
||||
import { ToastService } from 'src/app/services/toast.service';
|
||||
|
||||
import { UserGrantsDataSource } from './user-grants-datasource';
|
||||
import { UserGrantContext, UserGrantsDataSource } from './user-grants-datasource';
|
||||
|
||||
@Component({
|
||||
selector: 'app-user-grants',
|
||||
@@ -17,8 +17,9 @@ import { UserGrantsDataSource } from './user-grants-datasource';
|
||||
styleUrls: ['./user-grants.component.scss'],
|
||||
})
|
||||
export class UserGrantsComponent implements OnInit, AfterViewInit {
|
||||
@Input() filterValue: string = '';
|
||||
@Input() filter: UserGrantSearchKey = UserGrantSearchKey.USERGRANTSEARCHKEY_USER_ID;
|
||||
// @Input() filterValue: string = '';
|
||||
// @Input() filter: UserGrantSearchKey = UserGrantSearchKey.USERGRANTSEARCHKEY_USER_ID;
|
||||
@Input() context: UserGrantContext = UserGrantContext.USER;
|
||||
public grants: UserGrant.AsObject[] = [];
|
||||
|
||||
public dataSource!: UserGrantsDataSource;
|
||||
@@ -29,7 +30,12 @@ export class UserGrantsComponent implements OnInit, AfterViewInit {
|
||||
@Input() allowCreate: boolean = false;
|
||||
@Input() allowDelete: boolean = false;
|
||||
|
||||
@Input() userId: string = '';
|
||||
@Input() projectId: string = '';
|
||||
@Input() grantId: string = '';
|
||||
|
||||
public roleOptions: ProjectRoleView.AsObject[] = [];
|
||||
public routerLink: any = [''];
|
||||
|
||||
constructor(
|
||||
private userService: MgmtUserService,
|
||||
@@ -44,11 +50,35 @@ export class UserGrantsComponent implements OnInit, AfterViewInit {
|
||||
|
||||
public ngOnInit(): void {
|
||||
this.dataSource = new UserGrantsDataSource(this.userService);
|
||||
this.dataSource.loadGrants(this.filter, this.filterValue, 0, 25);
|
||||
const data = {
|
||||
projectId: this.projectId,
|
||||
grantId: this.grantId,
|
||||
userId: this.userId,
|
||||
};
|
||||
console.log(this.context);
|
||||
|
||||
if (this.filter === UserGrantSearchKey.USERGRANTSEARCHKEY_PROJECT_ID) {
|
||||
this.getRoleOptions(this.filterValue);
|
||||
switch (this.context) {
|
||||
case UserGrantContext.OWNED_PROJECT:
|
||||
if (this.projectId) {
|
||||
this.getRoleOptions(this.projectId);
|
||||
this.routerLink = ['/grant-create', 'project', this.projectId];
|
||||
}
|
||||
break;
|
||||
case UserGrantContext.GRANTED_PROJECT:
|
||||
if (data && data.grantId) {
|
||||
this.routerLink = ['/grant-create', 'project', this.projectId, 'grant', this.grantId];
|
||||
}
|
||||
break;
|
||||
case UserGrantContext.USER:
|
||||
if (this.userId) {
|
||||
this.routerLink = ['/grant-create', 'user', this.userId];
|
||||
}
|
||||
break;
|
||||
default:
|
||||
this.routerLink = ['/grant-create'];
|
||||
}
|
||||
console.log(data);
|
||||
this.dataSource.loadGrants(this.context, 0, 25, data);
|
||||
}
|
||||
|
||||
public ngAfterViewInit(): void {
|
||||
@@ -61,10 +91,13 @@ export class UserGrantsComponent implements OnInit, AfterViewInit {
|
||||
|
||||
private loadGrantsPage(): void {
|
||||
this.dataSource.loadGrants(
|
||||
this.filter,
|
||||
this.filterValue,
|
||||
this.context,
|
||||
this.paginator.pageIndex,
|
||||
this.paginator.pageSize,
|
||||
{
|
||||
projectId: this.projectId,
|
||||
grantId: this.grantId,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -81,7 +114,7 @@ export class UserGrantsComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
|
||||
public loadRoleOptions(projectId: string): void {
|
||||
if (this.filter === UserGrantSearchKey.USERGRANTSEARCHKEY_USER_ID) {
|
||||
if (this.context === UserGrantContext.USER) {
|
||||
this.getRoleOptions(projectId);
|
||||
}
|
||||
}
|
||||
@@ -103,4 +136,13 @@ export class UserGrantsComponent implements OnInit, AfterViewInit {
|
||||
this.toast.showError(error.message);
|
||||
});
|
||||
}
|
||||
|
||||
deleteGrantSelection(): void {
|
||||
this.userService.BulkRemoveUserGrant(this.selection.selected.map(grant => grant.id)).then(() => {
|
||||
this.toast.showInfo('Grants deleted');
|
||||
this.loadGrantsPage();
|
||||
}).catch(error => {
|
||||
this.toast.showError(error.message);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user