feat(console): rename org (#4542)

* rename org

* add data-e2e

* e2e test

* restore state after

* use ngIf instead of hasrole directive and initialized regex

* rm h2 check

* Update e2e/cypress/e2e/organization/organizations.cy.ts

Co-authored-by: Elio Bischof <[email protected]>

* Update console/src/assets/i18n/de.json

Co-authored-by: Elio Bischof <[email protected]>

* Update console/src/assets/i18n/de.json

Co-authored-by: Elio Bischof <[email protected]>

* Update console/src/assets/i18n/en.json

Co-authored-by: Elio Bischof <[email protected]>

* change e2e test

* org param

* reintroduct org param

* use org query param

* org rename test

* no initial focus on button

* contain name

Co-authored-by: Elio Bischof <[email protected]>
This commit is contained in:
Max Peintner
2022-10-20 14:08:13 +02:00
committed by GitHub
co-authored by Elio Bischof
parent 2bfa51da1c
commit 6e89b7d0a1
16 changed files with 186 additions and 15 deletions
+6 -1
View File
@@ -8,7 +8,7 @@ import { DomSanitizer } from '@angular/platform-browser';
import { ActivatedRoute, Router, RouterOutlet } from '@angular/router';
import { LangChangeEvent, TranslateService } from '@ngx-translate/core';
import { Observable, of, Subject } from 'rxjs';
import { map, takeUntil } from 'rxjs/operators';
import { filter, map, takeUntil } from 'rxjs/operators';
import { accountCard, adminLineAnimation, navAnimations, routeAnimations, toolbarAnimation } from './animations';
import { Org } from './proto/generated/zitadel/org_pb';
@@ -191,6 +191,11 @@ export class AppComponent implements OnDestroy {
}
});
this.activatedRoute.queryParams.pipe(filter((params) => !!params.org)).subscribe((params) => {
const { org } = params;
this.authService.getActiveOrg(org);
});
this.authenticationService.authenticationChanged.pipe(takeUntil(this.destroy$)).subscribe((authenticated) => {
if (authenticated) {
this.authService
@@ -5,7 +5,7 @@
<div mat-dialog-content>
<cnsl-form-field class="formfield">
<cnsl-label>{{ data.labelKey | translate }}</cnsl-label>
<input cnslInput [(ngModel)]="name" />
<input data-e2e="name" cnslInput [(ngModel)]="name" />
</cnsl-form-field>
</div>
<div mat-dialog-actions class="action">
@@ -13,7 +13,7 @@
{{ 'ACTIONS.CLOSE' | translate }}
</button>
<button [disabled]="!name" cdkFocusInitial color="primary" mat-raised-button (click)="closeDialog(name)">
<button data-e2e="dialog-submit" [disabled]="!name" color="primary" mat-raised-button (click)="closeDialog(name)">
{{ 'ACTIONS.RENAME' | translate }}
</button>
</div>
@@ -7,7 +7,7 @@
</a>
<div class="cnsl-title-row-wrapper">
<div class="cnsl-title-row">
<h2 class="cnsl-title">{{ title }}</h2>
<h2 data-e2e="top-view-title" class="cnsl-title">{{ title }}</h2>
<div
class="cnsl-state-dot"
*ngIf="isActive || isInactive"
@@ -28,6 +28,7 @@
<ng-container *ngIf="hasActions">
<button
data-e2e="actions"
class="cnsl-actions-trigger-desk cnsl-action-button"
mat-raised-button
color="primary"
@@ -1,13 +1,14 @@
<cnsl-top-view
*ngIf="['org.write:' + org?.id, 'org.write$'] | hasRole as hasWrite$"
[hasBackButton]="false"
title="{{ org?.name }}"
[isActive]="org?.state === OrgState.ORG_STATE_ACTIVE"
[isInactive]="org?.state === OrgState.ORG_STATE_INACTIVE"
[hasContributors]="true"
stateTooltip="{{ 'ORG.STATE.' + org?.state | translate }}"
[hasActions]="['org.write:' + org?.id, 'org.write$'] | hasRole | async"
[hasActions]="hasWrite$ | async"
>
<ng-template topActions cnslHasRole [hasRole]="['org.write:' + org?.id, 'org.write$']">
<ng-container topActions *ngIf="hasWrite$ | async">
<button
mat-menu-item
*ngIf="org?.state === OrgState.ORG_STATE_ACTIVE"
@@ -23,7 +24,11 @@
>
{{ 'ORG.PAGES.REACTIVATE' | translate }}
</button>
</ng-template>
<button data-e2e="rename" mat-menu-item (click)="renameOrg()">
{{ 'ORG.PAGES.RENAME.ACTION' | translate }}
</button>
</ng-container>
<cnsl-contributors
topContributors
[totalResult]="totalMemberResult"
@@ -18,6 +18,7 @@ import { GrpcAuthService } from 'src/app/services/grpc-auth.service';
import { ManagementService } from 'src/app/services/mgmt.service';
import { ToastService } from 'src/app/services/toast.service';
import { Buffer } from 'buffer';
import { NameDialogComponent } from 'src/app/modules/name-dialog/name-dialog.component';
@Component({
selector: 'cnsl-org-detail',
@@ -44,7 +45,7 @@ export class OrgDetailComponent implements OnInit, OnDestroy {
public InfoSectionType: any = InfoSectionType;
constructor(
auth: GrpcAuthService,
private auth: GrpcAuthService,
private dialog: MatDialog,
public mgmtService: ManagementService,
private toast: ToastService,
@@ -235,4 +236,49 @@ export class OrgDetailComponent implements OnInit, OnDestroy {
this.loadMetadata();
});
}
public renameOrg(): void {
const dialogRef = this.dialog.open(NameDialogComponent, {
data: {
name: this.org?.name,
titleKey: 'ORG.PAGES.RENAME.TITLE',
descKey: 'ORG.PAGES.RENAME.DESCRIPTION',
labelKey: 'ORG.PAGES.NAME',
},
width: '400px',
});
dialogRef.afterClosed().subscribe((name) => {
if (name) {
this.updateOrg(name);
}
});
}
public updateOrg(name: string): void {
if (this.org) {
this.mgmtService
.updateOrg(name)
.then(() => {
this.toast.showInfo('ORG.TOAST.UPDATED', true);
if (this.org) {
this.org.name = name;
}
this.mgmtService
.getMyOrg()
.then((resp) => {
if (resp.org) {
this.org = resp.org;
this.auth.setActiveOrg(resp.org);
}
})
.catch((error) => {
this.toast.showError(error);
});
})
.catch((error) => {
this.toast.showError(error);
});
}
}
}
+2
View File
@@ -19,6 +19,7 @@ import { InfoSectionModule } from 'src/app/modules/info-section/info-section.mod
import { InputModule } from 'src/app/modules/input/input.module';
import { MetaLayoutModule } from 'src/app/modules/meta-layout/meta-layout.module';
import { MetadataModule } from 'src/app/modules/metadata/metadata.module';
import { NameDialogModule } from 'src/app/modules/name-dialog/name-dialog.module';
import { SettingsGridModule } from 'src/app/modules/settings-grid/settings-grid.module';
import { SharedModule } from 'src/app/modules/shared/shared.module';
import { TopViewModule } from 'src/app/modules/top-view/top-view.module';
@@ -52,6 +53,7 @@ import { OrgRoutingModule } from './org-routing.module';
WarnDialogModule,
MemberCreateDialogModule,
MatMenuModule,
NameDialogModule,
ChangesModule,
MatProgressSpinnerModule,
MetadataModule,
+8
View File
@@ -425,6 +425,8 @@ import {
UpdateOrgIDPResponse,
UpdateOrgMemberRequest,
UpdateOrgMemberResponse,
UpdateOrgRequest,
UpdateOrgResponse,
UpdateProjectGrantMemberRequest,
UpdateProjectGrantMemberResponse,
UpdateProjectGrantRequest,
@@ -2353,6 +2355,12 @@ export class ManagementService {
return this.grpcService.mgmt.updateApp(req, null).then((resp) => resp.toObject());
}
public updateOrg(name: string): Promise<UpdateOrgResponse.AsObject> {
const req = new UpdateOrgRequest();
req.setName(name);
return this.grpcService.mgmt.updateOrg(req, null).then((resp) => resp.toObject());
}
public updateOIDCAppConfig(req: UpdateOIDCAppConfigRequest): Promise<UpdateOIDCAppConfigResponse.AsObject> {
return this.grpcService.mgmt.updateOIDCAppConfig(req, null).then((resp) => resp.toObject());
}