mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-03 21:02:15 +00:00
fix(console): general fixes, project grants for owned and granted context (#425)
* update and delete project grants * fix: user grant id (#421) * fix: verboser logging on sql err (#412) * fix(eventstore): improve insert statement * fix: verbose logging on error * fix: simplify insertEvents * fix: project grant delete (#417) * fix: add grant id to user grant if needed * fix: add grant id to user grant if needed Co-authored-by: Silvan <[email protected]> * fix user grant context * lint * role validators * fix: usergrantid (#424) * fix: verboser logging on sql err (#412) * fix(eventstore): improve insert statement * fix: verbose logging on error * fix: simplify insertEvents * fix: project grant delete (#417) * fix: add grant id to user grant if needed * fix: add grant id to user grant if needed * fix: add bulk remove * fix: merge Co-authored-by: Silvan <[email protected]> Co-authored-by: Fabi <[email protected]> Co-authored-by: Silvan <[email protected]>
This commit is contained in:
co-authored by
Silvan
Fabi
parent
cf51bbc36d
commit
0b012f2fa2
@@ -34,10 +34,15 @@ export class UserGrantsComponent implements OnInit, AfterViewInit {
|
||||
@Input() projectId: string = '';
|
||||
@Input() grantId: string = '';
|
||||
|
||||
public roleOptions: ProjectRoleView.AsObject[] = [];
|
||||
public grantRoleOptions: string[] = [];
|
||||
public projectRoleOptions: ProjectRoleView.AsObject[] = [];
|
||||
public routerLink: any = [''];
|
||||
|
||||
public loadedGrantId: string = '';
|
||||
public loadedProjectId: string = '';
|
||||
|
||||
public UserGrantContext: any = UserGrantContext;
|
||||
|
||||
constructor(
|
||||
private userService: MgmtUserService,
|
||||
private projectService: ProjectService,
|
||||
@@ -50,6 +55,7 @@ export class UserGrantsComponent implements OnInit, AfterViewInit {
|
||||
'projectId', 'creationDate', 'changeDate', 'roleNamesList'];
|
||||
|
||||
public ngOnInit(): void {
|
||||
console.log(this.context);
|
||||
this.dataSource = new UserGrantsDataSource(this.userService);
|
||||
const data = {
|
||||
projectId: this.projectId,
|
||||
@@ -60,13 +66,14 @@ export class UserGrantsComponent implements OnInit, AfterViewInit {
|
||||
switch (this.context) {
|
||||
case UserGrantContext.OWNED_PROJECT:
|
||||
if (this.projectId) {
|
||||
this.getRoleOptions(this.projectId);
|
||||
this.getProjectRoleOptions(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];
|
||||
this.getGrantRoleOptions(this.grantId, this.projectId);
|
||||
}
|
||||
break;
|
||||
case UserGrantContext.USER:
|
||||
@@ -112,26 +119,49 @@ export class UserGrantsComponent implements OnInit, AfterViewInit {
|
||||
this.dataSource.grantsSubject.value.forEach(row => this.selection.select(row));
|
||||
}
|
||||
|
||||
public loadRoleOptions(projectId: string): void {
|
||||
if (this.context === UserGrantContext.USER) {
|
||||
this.getRoleOptions(projectId);
|
||||
}
|
||||
public getGrantRoleOptions(grantId: string, projectId: string): void {
|
||||
console.log(grantId, projectId);
|
||||
|
||||
this.projectService.GetGrantedProjectByID(projectId, grantId).then(resp => {
|
||||
this.loadedGrantId = projectId;
|
||||
this.grantRoleOptions = resp.toObject().roleKeysList;
|
||||
}).catch(error => {
|
||||
this.toast.showError(error);
|
||||
});
|
||||
}
|
||||
|
||||
public getRoleOptions(projectId: string): void {
|
||||
public getProjectRoleOptions(projectId: string): void {
|
||||
console.log(projectId);
|
||||
this.projectService.SearchProjectRoles(projectId, 100, 0).then(resp => {
|
||||
this.loadedProjectId = projectId;
|
||||
this.roleOptions = resp.toObject().resultList;
|
||||
this.projectRoleOptions = resp.toObject().resultList;
|
||||
});
|
||||
}
|
||||
|
||||
updateRoles(grant: UserGrant.AsObject, selectionChange: MatSelectChange): void {
|
||||
this.userService.UpdateUserGrant(grant.id, grant.userId, selectionChange.value)
|
||||
.then(() => {
|
||||
this.toast.showInfo('GRANTS.TOAST.UPDATED', true);
|
||||
}).catch(error => {
|
||||
this.toast.showError(error);
|
||||
});
|
||||
switch (this.context) {
|
||||
case UserGrantContext.OWNED_PROJECT:
|
||||
if (grant.id && grant.projectId) {
|
||||
this.userService.UpdateProjectUserGrant(grant.id, grant.projectId, grant.userId, selectionChange.value)
|
||||
.then(() => {
|
||||
this.toast.showInfo('GRANTS.TOAST.UPDATED', true);
|
||||
}).catch(error => {
|
||||
this.toast.showError(error);
|
||||
});
|
||||
}
|
||||
break;
|
||||
case UserGrantContext.GRANTED_PROJECT:
|
||||
if (this.grantId && this.projectId) {
|
||||
this.userService.updateProjectGrantUserGrant(grant.id,
|
||||
this.grantId, grant.userId, selectionChange.value)
|
||||
.then(() => {
|
||||
this.toast.showInfo('GRANTS.TOAST.UPDATED', true);
|
||||
}).catch(error => {
|
||||
this.toast.showError(error);
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
deleteGrantSelection(): void {
|
||||
|
||||
Reference in New Issue
Block a user