From 207b20ff0feb86533cb76d03e29d88e34e8503b8 Mon Sep 17 00:00:00 2001 From: Miguel Cabrerizo <30386061+doncicuto@users.noreply.github.com> Date: Thu, 25 Apr 2024 07:02:20 +0200 Subject: [PATCH] fix(console): orgs list is shown empty when org is removed (#7781) fix:active orgs not shown when org is removed Co-authored-by: Livio Spring --- .../orgs/org-detail/org-detail.component.ts | 35 +++++++++++++++---- console/src/app/services/admin.service.ts | 7 ++++ console/src/app/services/mgmt.service.ts | 3 +- console/src/assets/i18n/bg.json | 1 + console/src/assets/i18n/cs.json | 1 + console/src/assets/i18n/de.json | 1 + console/src/assets/i18n/en.json | 5 +-- console/src/assets/i18n/es.json | 1 + console/src/assets/i18n/fr.json | 1 + console/src/assets/i18n/it.json | 1 + console/src/assets/i18n/ja.json | 1 + console/src/assets/i18n/mk.json | 1 + console/src/assets/i18n/nl.json | 1 + console/src/assets/i18n/pl.json | 1 + console/src/assets/i18n/pt.json | 1 + console/src/assets/i18n/ru.json | 1 + console/src/assets/i18n/zh.json | 1 + 17 files changed, 53 insertions(+), 10 deletions(-) diff --git a/console/src/app/pages/orgs/org-detail/org-detail.component.ts b/console/src/app/pages/orgs/org-detail/org-detail.component.ts index 81413bafef..0de6696ac3 100644 --- a/console/src/app/pages/orgs/org-detail/org-detail.component.ts +++ b/console/src/app/pages/orgs/org-detail/org-detail.component.ts @@ -15,6 +15,7 @@ import { Member } from 'src/app/proto/generated/zitadel/member_pb'; import { Metadata } from 'src/app/proto/generated/zitadel/metadata_pb'; import { Org, OrgState } from 'src/app/proto/generated/zitadel/org_pb'; import { User } from 'src/app/proto/generated/zitadel/user_pb'; +import { AdminService } from 'src/app/services/admin.service'; import { Breadcrumb, BreadcrumbService, BreadcrumbType } from 'src/app/services/breadcrumb.service'; import { GrpcAuthService } from 'src/app/services/grpc-auth.service'; import { ManagementService } from 'src/app/services/mgmt.service'; @@ -48,6 +49,7 @@ export class OrgDetailComponent implements OnInit, OnDestroy { private auth: GrpcAuthService, private dialog: MatDialog, public mgmtService: ManagementService, + private adminService: AdminService, private toast: ToastService, private router: Router, breadcrumbService: BreadcrumbService, @@ -146,15 +148,34 @@ export class OrgDetailComponent implements OnInit, OnDestroy { width: '400px', }); + // Before we remove the org we get the current default org + // we have to query before the current org is removed dialogRef.afterClosed().subscribe((resp) => { if (resp) { - this.mgmtService - .removeOrg() - .then(() => { - setTimeout(() => { - this.router.navigate(['/orgs']); - }, 1000); - this.toast.showInfo('ORG.TOAST.DELETED', true); + this.adminService + .getDefaultOrg() + .then((response) => { + const org = response?.org; + if (org) { + // We now remove the org + this.mgmtService + .removeOrg() + .then(() => { + setTimeout(() => { + // We change active org to default org as + // current org was deleted to avoid Organization doesn't exist + this.auth.setActiveOrg(org); + // Now we visit orgs + this.router.navigate(['/orgs']); + }, 1000); + this.toast.showInfo('ORG.TOAST.DELETED', true); + }) + .catch((error) => { + this.toast.showError(error); + }); + } else { + this.toast.showError('ORG.TOAST.DEFAULTORGNOTFOUND', false, true); + } }) .catch((error) => { this.toast.showError(error); diff --git a/console/src/app/services/admin.service.ts b/console/src/app/services/admin.service.ts index d1460b06f2..ca4c12b890 100644 --- a/console/src/app/services/admin.service.ts +++ b/console/src/app/services/admin.service.ts @@ -90,6 +90,8 @@ import { GetDefaultLanguageResponse, GetDefaultLoginTextsRequest, GetDefaultLoginTextsResponse, + GetDefaultOrgRequest, + GetDefaultOrgResponse, GetDefaultPasswordChangeMessageTextRequest, GetDefaultPasswordChangeMessageTextResponse, GetDefaultPasswordlessRegistrationMessageTextRequest, @@ -429,6 +431,11 @@ export class AdminService { this.storageService.getItem('onboarding-dismissed', StorageLocation.local) === 'true' ? true : false; } + public getDefaultOrg(): Promise { + const req = new GetDefaultOrgRequest(); + return this.grpcService.admin.getDefaultOrg(req, null).then((resp) => resp.toObject()); + } + public setDefaultOrg(orgId: string): Promise { const req = new SetDefaultOrgRequest(); req.setOrgId(orgId); diff --git a/console/src/app/services/mgmt.service.ts b/console/src/app/services/mgmt.service.ts index 0e3c0b3062..b167799b23 100644 --- a/console/src/app/services/mgmt.service.ts +++ b/console/src/app/services/mgmt.service.ts @@ -353,6 +353,7 @@ import { RemoveOrgMetadataRequest, RemoveOrgMetadataResponse, RemoveOrgRequest, + RemoveOrgResponse, RemovePersonalAccessTokenRequest, RemovePersonalAccessTokenResponse, RemoveProjectGrantMemberRequest, @@ -1749,7 +1750,7 @@ export class ManagementService { return this.grpcService.mgmt.removeUser(req, null).then((resp) => resp.toObject()); } - public removeOrg(): Promise { + public removeOrg(): Promise { const req = new RemoveOrgRequest(); return this.grpcService.mgmt.removeOrg(req, null).then((resp) => resp.toObject()); } diff --git a/console/src/assets/i18n/bg.json b/console/src/assets/i18n/bg.json index d606ceb64a..9ea937ec22 100644 --- a/console/src/assets/i18n/bg.json +++ b/console/src/assets/i18n/bg.json @@ -1285,6 +1285,7 @@ "MEMBERCHANGED": "Сменен управител.", "SETPRIMARY": "Основен набор от домейни.", "DELETED": "Организацията е изтрита успешно", + "DEFAULTORGNOTFOUND": "Организацията по подразбиране не беше намерена", "ORG_WAS_DELETED": "Организацията е изтрита." }, "DIALOG": { diff --git a/console/src/assets/i18n/cs.json b/console/src/assets/i18n/cs.json index c9a01468ac..b1c2e1c2f0 100644 --- a/console/src/assets/i18n/cs.json +++ b/console/src/assets/i18n/cs.json @@ -1292,6 +1292,7 @@ "MEMBERCHANGED": "Manažer změněn.", "SETPRIMARY": "Nastavena primární doména.", "DELETED": "Organizace úspěšně smazána", + "DEFAULTORGNOTFOUND": "Výchozí organizace nebyla nalezena", "ORG_WAS_DELETED": "Organizace byla smazána." }, "DIALOG": { diff --git a/console/src/assets/i18n/de.json b/console/src/assets/i18n/de.json index 7ea9423b05..4936d66aa2 100644 --- a/console/src/assets/i18n/de.json +++ b/console/src/assets/i18n/de.json @@ -1291,6 +1291,7 @@ "MEMBERCHANGED": "Manager geändert.", "SETPRIMARY": "Primäre Domain gesetzt.", "DELETED": "Organisation erfolgreich gelöscht", + "DEFAULTORGNOTFOUND": "Die Standardorganisation wurde nicht gefunden", "ORG_WAS_DELETED": "Organisation wurde gelöscht." }, "DIALOG": { diff --git a/console/src/assets/i18n/en.json b/console/src/assets/i18n/en.json index 658f59ba9e..0a541cf418 100644 --- a/console/src/assets/i18n/en.json +++ b/console/src/assets/i18n/en.json @@ -1291,8 +1291,9 @@ "MEMBERREMOVED": "Manager removed.", "MEMBERCHANGED": "Manager changed.", "SETPRIMARY": "Primary domain set.", - "DELETED": "Organisation deleted successfully", - "ORG_WAS_DELETED": "Organisation has been deleted." + "DELETED": "Organization deleted successfully", + "DEFAULTORGNOTFOUND": "The default organization was not found", + "ORG_WAS_DELETED": "Organization has been deleted." }, "DIALOG": { "DEACTIVATE": { diff --git a/console/src/assets/i18n/es.json b/console/src/assets/i18n/es.json index ce50afa77d..9e9f2766e1 100644 --- a/console/src/assets/i18n/es.json +++ b/console/src/assets/i18n/es.json @@ -1293,6 +1293,7 @@ "MEMBERCHANGED": "Mánager modificado.", "SETPRIMARY": "Dominio primario establecido.", "DELETED": "Organización borrada con éxito", + "DEFAULTORGNOTFOUND": "No se encontró la organización por defecto", "ORG_WAS_DELETED": "La organización ha sido borrada." }, "DIALOG": { diff --git a/console/src/assets/i18n/fr.json b/console/src/assets/i18n/fr.json index 33a9bc11bb..ae81a43e06 100644 --- a/console/src/assets/i18n/fr.json +++ b/console/src/assets/i18n/fr.json @@ -1291,6 +1291,7 @@ "MEMBERCHANGED": "Gestionnaire modifié.", "SETPRIMARY": "Domaine primaire défini.", "DELETED": "Organisation supprimée avec succès", + "DEFAULTORGNOTFOUND": "L'organisation par défaut est introuvable", "ORG_WAS_DELETED": "L'organisation a été supprimée" }, "DIALOG": { diff --git a/console/src/assets/i18n/it.json b/console/src/assets/i18n/it.json index 3a1e32a0d0..55eddea64d 100644 --- a/console/src/assets/i18n/it.json +++ b/console/src/assets/i18n/it.json @@ -1291,6 +1291,7 @@ "MEMBERCHANGED": "Manager cambiato con successo", "SETPRIMARY": "Dominio primario cambiato con successo", "DELETED": "Organizzazione eliminata con successo", + "DEFAULTORGNOTFOUND": "Impossibile trovare l'organizzazione predefinita", "ORG_WAS_DELETED": "Organizzazione è stata eliminata" }, "DIALOG": { diff --git a/console/src/assets/i18n/ja.json b/console/src/assets/i18n/ja.json index 35b93bbb6b..3e30cffb11 100644 --- a/console/src/assets/i18n/ja.json +++ b/console/src/assets/i18n/ja.json @@ -1292,6 +1292,7 @@ "MEMBERCHANGED": "マネージャーが変更されました。", "SETPRIMARY": "プライマリドメインが設定されました。", "DELETED": "組織が正常に削除されました。", + "DEFAULTORGNOTFOUND": "デフォルトの組織が見つかりませんでした", "ORG_WAS_DELETED": "組織が削除されました。" }, "DIALOG": { diff --git a/console/src/assets/i18n/mk.json b/console/src/assets/i18n/mk.json index 03447afd33..c5bcd375da 100644 --- a/console/src/assets/i18n/mk.json +++ b/console/src/assets/i18n/mk.json @@ -1293,6 +1293,7 @@ "MEMBERCHANGED": "Променет менаџер.", "SETPRIMARY": "Поставен основен домен.", "DELETED": "Организацијата успешно избришана", + "DEFAULTORGNOTFOUND": "Стандардната организација не беше пронајдена", "ORG_WAS_DELETED": "Организацијата е избришана." }, "DIALOG": { diff --git a/console/src/assets/i18n/nl.json b/console/src/assets/i18n/nl.json index 767db991fd..c8ea11d950 100644 --- a/console/src/assets/i18n/nl.json +++ b/console/src/assets/i18n/nl.json @@ -1292,6 +1292,7 @@ "MEMBERCHANGED": "Beheerder gewijzigd.", "SETPRIMARY": "Primaire domein ingesteld.", "DELETED": "Organisatie succesvol verwijderd", + "DEFAULTORGNOTFOUND": "De standaardorganisatie is niet gevonden", "ORG_WAS_DELETED": "Organisatie is verwijderd." }, "DIALOG": { diff --git a/console/src/assets/i18n/pl.json b/console/src/assets/i18n/pl.json index c4f9591f3d..8e15255e5c 100644 --- a/console/src/assets/i18n/pl.json +++ b/console/src/assets/i18n/pl.json @@ -1291,6 +1291,7 @@ "MEMBERCHANGED": "Zmieniono managera.", "SETPRIMARY": "Ustawiono domenę podstawową.", "DELETED": "Organizacja została usunięta pomyślnie", + "DEFAULTORGNOTFOUND": "Nie znaleziono organizacji domyślnej", "ORG_WAS_DELETED": "Organizacja została usunięta." }, "DIALOG": { diff --git a/console/src/assets/i18n/pt.json b/console/src/assets/i18n/pt.json index 930fa9795d..4809efb02f 100644 --- a/console/src/assets/i18n/pt.json +++ b/console/src/assets/i18n/pt.json @@ -1293,6 +1293,7 @@ "MEMBERCHANGED": "Gerente alterado.", "SETPRIMARY": "Domínio principal definido.", "DELETED": "Organização excluída com sucesso", + "DEFAULTORGNOTFOUND": "A organização padrão não foi encontrada", "ORG_WAS_DELETED": "Organização foi excluída." }, "DIALOG": { diff --git a/console/src/assets/i18n/ru.json b/console/src/assets/i18n/ru.json index 491cbf120c..943de8dd1b 100644 --- a/console/src/assets/i18n/ru.json +++ b/console/src/assets/i18n/ru.json @@ -1335,6 +1335,7 @@ "MEMBERCHANGED": "Менеджер изменён.", "SETPRIMARY": "Установлен основной домен.", "DELETED": "Организация успешно удалена", + "DEFAULTORGNOTFOUND": "Организация по умолчанию не найдена", "ORG_WAS_DELETED": "Организация удалена." }, "DIALOG": { diff --git a/console/src/assets/i18n/zh.json b/console/src/assets/i18n/zh.json index 659a25907e..31d9dcb09a 100644 --- a/console/src/assets/i18n/zh.json +++ b/console/src/assets/i18n/zh.json @@ -1291,6 +1291,7 @@ "MEMBERCHANGED": "管理者以改变。", "SETPRIMARY": "已设为主域名。", "DELETED": "成功删除的组织", + "DEFAULTORGNOTFOUND": "未找到默认组织", "ORG_WAS_DELETED": "组织被删除" }, "DIALOG": {