From fd57ffc34552ddaf7cdd231cb3fb100852d22666 Mon Sep 17 00:00:00 2001 From: Max Peintner Date: Tue, 30 Jul 2024 13:38:20 +0200 Subject: [PATCH] fix(console): fill cachedorgs when read from local storage (#8363) This fixes a problem where the org settings were hidden. The console reads the context from either a query param or the local storage. When one context was found, it executed a single request with orgId filter. This let to a single org and then to a hidden org setting, as we hide org settings for instances with a single result. (cherry picked from commit 51210c8e34580709b94c0d12d365b0512c4b10f1) --- console/src/app/services/grpc-auth.service.ts | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/console/src/app/services/grpc-auth.service.ts b/console/src/app/services/grpc-auth.service.ts index c7e379c84f..24feee0ad1 100644 --- a/console/src/app/services/grpc-auth.service.ts +++ b/console/src/app/services/grpc-auth.service.ts @@ -261,27 +261,33 @@ export class GrpcAuthService { this.setActiveOrg(orgs[0]); return Promise.resolve(orgs[0]); } else { + // throw error if the org was specifically requested but not found return Promise.reject(new Error('requested organization not found')); } } } else { let orgs = this.cachedOrgs.getValue(); - const org = this.storage.getItem(StorageKey.organization, StorageLocation.local); if (org) { - const orgQuery = new OrgQuery(); - const orgIdQuery = new OrgIDQuery(); - orgIdQuery.setId(org.id); - orgQuery.setIdQuery(orgIdQuery); + orgs = (await this.listMyProjectOrgs(ORG_LIMIT, 0)).resultList; + this.cachedOrgs.next(orgs); - const specificOrg = (await this.listMyProjectOrgs(ORG_LIMIT, 0, [orgQuery])).resultList; - if (specificOrg.length === 1) { - this.setActiveOrg(specificOrg[0]); - return Promise.resolve(specificOrg[0]); + const find = this.cachedOrgs.getValue().find((tmp) => tmp.id === id); + if (find) { + this.setActiveOrg(find); + return Promise.resolve(find); } else { - orgs = (await this.listMyProjectOrgs(ORG_LIMIT, 0)).resultList; - this.cachedOrgs.next(orgs); + const orgQuery = new OrgQuery(); + const orgIdQuery = new OrgIDQuery(); + orgIdQuery.setId(org.id); + orgQuery.setIdQuery(orgIdQuery); + + const specificOrg = (await this.listMyProjectOrgs(ORG_LIMIT, 0, [orgQuery])).resultList; + if (specificOrg.length === 1) { + this.setActiveOrg(specificOrg[0]); + return Promise.resolve(specificOrg[0]); + } } } else { orgs = (await this.listMyProjectOrgs(ORG_LIMIT, 0)).resultList;