mirror of
https://github.com/andwati/zitadel.git
synced 2026-12-06 10:58:48 +00:00
fix(console): fix self-management without explicit roles (#11583)
# Which Problems Are Solved The self-management of user without any permissions in Console was no longer possible and the UI was completely stuck. This was due to the method `getActiveOrg`, which returned an error in case no organization could be retrieved. # How the Problems Are Solved - Return `undefined` in case no organization is found and handle cases where an organization is required. - Redirect the user to `/users/me` if no organization is retrieved on the start - Prevent users without roles to access the home page # Additional Changes None # Additional Context closes #11567
This commit is contained in:
@@ -10,7 +10,7 @@ const routes: Routes = [
|
|||||||
{
|
{
|
||||||
path: '',
|
path: '',
|
||||||
loadChildren: () => import('./pages/home/home.module'),
|
loadChildren: () => import('./pages/home/home.module'),
|
||||||
canActivate: [authGuard],
|
canActivate: [authGuard, roleGuard],
|
||||||
data: {
|
data: {
|
||||||
roles: ['.'],
|
roles: ['.'],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -223,6 +223,12 @@ export class AppComponent {
|
|||||||
takeUntilDestroyed(),
|
takeUntilDestroyed(),
|
||||||
)
|
)
|
||||||
.subscribe({
|
.subscribe({
|
||||||
|
next: async (org) => {
|
||||||
|
if (!org) {
|
||||||
|
return this.router.navigate(['/users/me']);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
error: async (err) => {
|
error: async (err) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return this.router.navigate(['/users/me']);
|
return this.router.navigate(['/users/me']);
|
||||||
|
|||||||
@@ -117,40 +117,42 @@ export class MembershipsTableComponent implements OnInit, OnDestroy {
|
|||||||
public async goto(membership: Membership.AsObject) {
|
public async goto(membership: Membership.AsObject) {
|
||||||
const org = await this.authService.getActiveOrg();
|
const org = await this.authService.getActiveOrg();
|
||||||
|
|
||||||
if (membership.orgId && !membership.projectId && !membership.projectGrantId) {
|
if (org) {
|
||||||
// only shown on auth user, or if currentOrg === resourceOwner
|
if (membership.orgId && !membership.projectId && !membership.projectGrantId) {
|
||||||
try {
|
// only shown on auth user, or if currentOrg === resourceOwner
|
||||||
const membershipOrg = await this.authService.getActiveOrg(membership.orgId);
|
try {
|
||||||
await this.router.navigate(['/org/members']);
|
const membershipOrg = await this.authService.getActiveOrg(membership.orgId);
|
||||||
this.startOrgContextWorkflow(membershipOrg.id, org.id);
|
await this.router.navigate(['/org/members']);
|
||||||
} catch (error) {
|
this.startOrgContextWorkflow(membershipOrg?.id, org.id);
|
||||||
this.toast.showInfo('USER.MEMBERSHIPS.NOPERMISSIONTOEDIT', true);
|
} catch (error) {
|
||||||
|
this.toast.showInfo('USER.MEMBERSHIPS.NOPERMISSIONTOEDIT', true);
|
||||||
|
}
|
||||||
|
} else if (membership.projectGrantId && membership.details?.resourceOwner) {
|
||||||
|
// only shown on auth user
|
||||||
|
try {
|
||||||
|
const membershipOrg = await this.authService.getActiveOrg(membership.details?.resourceOwner);
|
||||||
|
await this.router.navigate(['/granted-projects', membership.projectId, 'grants', membership.projectGrantId]);
|
||||||
|
this.startOrgContextWorkflow(membershipOrg?.id, org.id);
|
||||||
|
} catch (error) {
|
||||||
|
this.toast.showInfo('USER.MEMBERSHIPS.NOPERMISSIONTOEDIT', true);
|
||||||
|
}
|
||||||
|
} else if (membership.projectId && membership.details?.resourceOwner) {
|
||||||
|
// only shown on auth user, or if currentOrg === resourceOwner
|
||||||
|
try {
|
||||||
|
const membershipOrg = await this.authService.getActiveOrg(membership.details?.resourceOwner);
|
||||||
|
await this.router.navigate(['/projects', membership.projectId, 'members']);
|
||||||
|
this.startOrgContextWorkflow(membershipOrg?.id, org.id);
|
||||||
|
} catch (error) {
|
||||||
|
this.toast.showInfo('USER.MEMBERSHIPS.NOPERMISSIONTOEDIT', true);
|
||||||
|
}
|
||||||
|
} else if (membership.iam) {
|
||||||
|
// only shown on auth user
|
||||||
|
await this.router.navigate(['/instance/members']);
|
||||||
}
|
}
|
||||||
} else if (membership.projectGrantId && membership.details?.resourceOwner) {
|
|
||||||
// only shown on auth user
|
|
||||||
try {
|
|
||||||
const membershipOrg = await this.authService.getActiveOrg(membership.details?.resourceOwner);
|
|
||||||
await this.router.navigate(['/granted-projects', membership.projectId, 'grants', membership.projectGrantId]);
|
|
||||||
this.startOrgContextWorkflow(membershipOrg.id, org.id);
|
|
||||||
} catch (error) {
|
|
||||||
this.toast.showInfo('USER.MEMBERSHIPS.NOPERMISSIONTOEDIT', true);
|
|
||||||
}
|
|
||||||
} else if (membership.projectId && membership.details?.resourceOwner) {
|
|
||||||
// only shown on auth user, or if currentOrg === resourceOwner
|
|
||||||
try {
|
|
||||||
const membershipOrg = await this.authService.getActiveOrg(membership.details?.resourceOwner);
|
|
||||||
await this.router.navigate(['/projects', membership.projectId, 'members']);
|
|
||||||
this.startOrgContextWorkflow(membershipOrg.id, org.id);
|
|
||||||
} catch (error) {
|
|
||||||
this.toast.showInfo('USER.MEMBERSHIPS.NOPERMISSIONTOEDIT', true);
|
|
||||||
}
|
|
||||||
} else if (membership.iam) {
|
|
||||||
// only shown on auth user
|
|
||||||
await this.router.navigate(['/instance/members']);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private startOrgContextWorkflow(membershipOrgId: string, currentOrgId?: string | null): void {
|
private startOrgContextWorkflow(membershipOrgId?: string, currentOrgId?: string | null): void {
|
||||||
if (!currentOrgId || (membershipOrgId && currentOrgId && currentOrgId !== membershipOrgId)) {
|
if (!currentOrgId || (membershipOrgId && currentOrgId && currentOrgId !== membershipOrgId)) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.workflowService.startWorkflow(OrgContextChangedWorkflowOverlays, null);
|
this.workflowService.startWorkflow(OrgContextChangedWorkflowOverlays, null);
|
||||||
|
|||||||
@@ -75,6 +75,10 @@ export class DomainPolicyComponent implements OnInit {
|
|||||||
|
|
||||||
public async savePolicy(): Promise<void> {
|
public async savePolicy(): Promise<void> {
|
||||||
const org = await this.authService.getActiveOrg();
|
const org = await this.authService.getActiveOrg();
|
||||||
|
if (!org) {
|
||||||
|
console.log('No active organization found. Cannot save domain policy.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
switch (this.serviceType) {
|
switch (this.serviceType) {
|
||||||
case PolicyComponentServiceType.MGMT:
|
case PolicyComponentServiceType.MGMT:
|
||||||
if ((this.domainData as OrgIAMPolicy.AsObject).isDefault) {
|
if ((this.domainData as OrgIAMPolicy.AsObject).isDefault) {
|
||||||
@@ -150,6 +154,10 @@ export class DomainPolicyComponent implements OnInit {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const org = await this.authService.getActiveOrg();
|
const org = await this.authService.getActiveOrg();
|
||||||
|
if (!org) {
|
||||||
|
console.log('No active organization found. Cannot reset domain policy.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
await this.adminService.resetCustomDomainPolicyToDefault(org.id);
|
await this.adminService.resetCustomDomainPolicyToDefault(org.id);
|
||||||
this.toast.showInfo('POLICY.TOAST.RESETSUCCESS', true);
|
this.toast.showInfo('POLICY.TOAST.RESETSUCCESS', true);
|
||||||
await new Promise((res) => setTimeout(res, 1000));
|
await new Promise((res) => setTimeout(res, 1000));
|
||||||
|
|||||||
@@ -184,6 +184,10 @@ export class UserCreateV2Component implements OnInit {
|
|||||||
this.loading.set(true);
|
this.loading.set(true);
|
||||||
|
|
||||||
const activeOrg = await this.authService.getActiveOrg();
|
const activeOrg = await this.authService.getActiveOrg();
|
||||||
|
if (!activeOrg) {
|
||||||
|
console.log('No active organization found. Cannot create user.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
const userValues = this.userForm.getRawValue();
|
const userValues = this.userForm.getRawValue();
|
||||||
|
|
||||||
const humanReq: MessageInitShape<typeof AddHumanUserRequestSchema> = {
|
const humanReq: MessageInitShape<typeof AddHumanUserRequestSchema> = {
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ export class GrpcAuthService {
|
|||||||
return this.grpcService.auth.listMyMetadata(req, null).then((resp) => resp.toObject());
|
return this.grpcService.auth.listMyMetadata(req, null).then((resp) => resp.toObject());
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getActiveOrg(id?: string): Promise<Org.AsObject> {
|
public async getActiveOrg(id?: string): Promise<Org.AsObject | undefined> {
|
||||||
if (id) {
|
if (id) {
|
||||||
const find = this.cachedOrgs.getValue().find((tmp) => tmp.id === id);
|
const find = this.cachedOrgs.getValue().find((tmp) => tmp.id === id);
|
||||||
if (find) {
|
if (find) {
|
||||||
@@ -249,7 +249,7 @@ export class GrpcAuthService {
|
|||||||
|
|
||||||
if (orgs.length === 0) {
|
if (orgs.length === 0) {
|
||||||
this._activeOrgChanged.next(undefined);
|
this._activeOrgChanged.next(undefined);
|
||||||
return Promise.reject(new Error('No organizations found!'));
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const orgToSet = orgs.find((element) => element.id !== '0' && element.name !== '');
|
const orgToSet = orgs.find((element) => element.id !== '0' && element.name !== '');
|
||||||
|
|||||||
Reference in New Issue
Block a user