diff --git a/console/src/app/app-routing.module.ts b/console/src/app/app-routing.module.ts index 4e11c2c03..c70e7531f 100644 --- a/console/src/app/app-routing.module.ts +++ b/console/src/app/app-routing.module.ts @@ -10,7 +10,7 @@ const routes: Routes = [ { path: '', loadChildren: () => import('./pages/home/home.module'), - canActivate: [authGuard], + canActivate: [authGuard, roleGuard], data: { roles: ['.'], }, diff --git a/console/src/app/app.component.ts b/console/src/app/app.component.ts index 94bd2c539..c6813ff93 100644 --- a/console/src/app/app.component.ts +++ b/console/src/app/app.component.ts @@ -223,6 +223,12 @@ export class AppComponent { takeUntilDestroyed(), ) .subscribe({ + next: async (org) => { + if (!org) { + return this.router.navigate(['/users/me']); + } + return true; + }, error: async (err) => { console.error(err); return this.router.navigate(['/users/me']); diff --git a/console/src/app/modules/memberships-table/memberships-table.component.ts b/console/src/app/modules/memberships-table/memberships-table.component.ts index 11b65ba23..909e95c41 100644 --- a/console/src/app/modules/memberships-table/memberships-table.component.ts +++ b/console/src/app/modules/memberships-table/memberships-table.component.ts @@ -117,40 +117,42 @@ export class MembershipsTableComponent implements OnInit, OnDestroy { public async goto(membership: Membership.AsObject) { const org = await this.authService.getActiveOrg(); - if (membership.orgId && !membership.projectId && !membership.projectGrantId) { - // only shown on auth user, or if currentOrg === resourceOwner - try { - const membershipOrg = await this.authService.getActiveOrg(membership.orgId); - await this.router.navigate(['/org/members']); - this.startOrgContextWorkflow(membershipOrg.id, org.id); - } catch (error) { - this.toast.showInfo('USER.MEMBERSHIPS.NOPERMISSIONTOEDIT', true); + if (org) { + if (membership.orgId && !membership.projectId && !membership.projectGrantId) { + // only shown on auth user, or if currentOrg === resourceOwner + try { + const membershipOrg = await this.authService.getActiveOrg(membership.orgId); + await this.router.navigate(['/org/members']); + this.startOrgContextWorkflow(membershipOrg?.id, org.id); + } 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)) { setTimeout(() => { this.workflowService.startWorkflow(OrgContextChangedWorkflowOverlays, null); diff --git a/console/src/app/modules/policies/domain-policy/domain-policy.component.ts b/console/src/app/modules/policies/domain-policy/domain-policy.component.ts index 406840134..0c819212b 100644 --- a/console/src/app/modules/policies/domain-policy/domain-policy.component.ts +++ b/console/src/app/modules/policies/domain-policy/domain-policy.component.ts @@ -75,6 +75,10 @@ export class DomainPolicyComponent implements OnInit { public async savePolicy(): Promise { const org = await this.authService.getActiveOrg(); + if (!org) { + console.log('No active organization found. Cannot save domain policy.'); + return; + } switch (this.serviceType) { case PolicyComponentServiceType.MGMT: if ((this.domainData as OrgIAMPolicy.AsObject).isDefault) { @@ -150,6 +154,10 @@ export class DomainPolicyComponent implements OnInit { try { 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); this.toast.showInfo('POLICY.TOAST.RESETSUCCESS', true); await new Promise((res) => setTimeout(res, 1000)); diff --git a/console/src/app/pages/users/user-create/user-create-v2/user-create-v2.component.ts b/console/src/app/pages/users/user-create/user-create-v2/user-create-v2.component.ts index 97eb88d8d..f9a1b8ba1 100644 --- a/console/src/app/pages/users/user-create/user-create-v2/user-create-v2.component.ts +++ b/console/src/app/pages/users/user-create/user-create-v2/user-create-v2.component.ts @@ -184,6 +184,10 @@ export class UserCreateV2Component implements OnInit { this.loading.set(true); const activeOrg = await this.authService.getActiveOrg(); + if (!activeOrg) { + console.log('No active organization found. Cannot create user.'); + return; + } const userValues = this.userForm.getRawValue(); const humanReq: MessageInitShape = { diff --git a/console/src/app/services/grpc-auth.service.ts b/console/src/app/services/grpc-auth.service.ts index 619257806..2f12e4ead 100644 --- a/console/src/app/services/grpc-auth.service.ts +++ b/console/src/app/services/grpc-auth.service.ts @@ -197,7 +197,7 @@ export class GrpcAuthService { return this.grpcService.auth.listMyMetadata(req, null).then((resp) => resp.toObject()); } - public async getActiveOrg(id?: string): Promise { + public async getActiveOrg(id?: string): Promise { if (id) { const find = this.cachedOrgs.getValue().find((tmp) => tmp.id === id); if (find) { @@ -249,7 +249,7 @@ export class GrpcAuthService { if (orgs.length === 0) { this._activeOrgChanged.next(undefined); - return Promise.reject(new Error('No organizations found!')); + return undefined; } const orgToSet = orgs.find((element) => element.id !== '0' && element.name !== '');