feat(console): delete user (#819)

* add action col to user table, i18n

* delete user from detail component

* lint
This commit is contained in:
Max Peintner
2020-10-07 17:15:02 +02:00
committed by GitHub
parent 56d5704749
commit 5f0cddac37
12 changed files with 141 additions and 25 deletions
@@ -8,10 +8,17 @@
<span class="fill-space"></span>
<ng-template appHasRole [appHasRole]="['user.write', 'user.write:'+user?.id]">
<button mat-stroked-button color="warn" *ngIf="user?.state === UserState.USERSTATE_ACTIVE"
<ng-template appHasRole [appHasRole]="['user.delete$', 'user.delete:'+user?.id]">
<button mat-raised-button color="warn" (click)="deleteUser()"><i
class="las la-trash"></i>{{'USER.PAGES.DELETE' | translate}}</button>
</ng-template>
<ng-template appHasRole [appHasRole]="['user.write$', 'user.write:'+user?.id]">
<button class="state-button" mat-stroked-button color="warn"
*ngIf="user?.state === UserState.USERSTATE_ACTIVE"
(click)="changeState(UserState.USERSTATE_INACTIVE)">{{'USER.PAGES.DEACTIVATE' | translate}}</button>
<button mat-stroked-button color="warn" *ngIf="user?.state === UserState.USERSTATE_INACTIVE"
<button class="state-button" mat-stroked-button color="warn"
*ngIf="user?.state === UserState.USERSTATE_INACTIVE"
(click)="changeState(UserState.USERSTATE_ACTIVE)">{{'USER.PAGES.REACTIVATE' | translate}}</button>
</ng-template>
</div>
@@ -17,6 +17,10 @@
.fill-space {
flex: 1;
}
.state-button {
margin-left: .5rem;
}
}
.method-col {
@@ -1,9 +1,11 @@
import { Location } from '@angular/common';
import { Component, OnDestroy, OnInit } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { ActivatedRoute } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { Subscription } from 'rxjs';
import { ChangeType } from 'src/app/modules/changes/changes.component';
import { WarnDialogComponent } from 'src/app/modules/warn-dialog/warn-dialog.component';
import {
Gender,
MachineResponse,
@@ -44,6 +46,7 @@ export class UserDetailComponent implements OnInit, OnDestroy {
private toast: ToastService,
public mgmtUserService: ManagementService,
private _location: Location,
private dialog: MatDialog,
) { }
public ngOnInit(): void {
@@ -195,4 +198,29 @@ export class UserDetailComponent implements OnInit, OnDestroy {
this.toast.showError(error);
});
}
public deleteUser(): void {
const dialogRef = this.dialog.open(WarnDialogComponent, {
data: {
confirmKey: 'ACTIONS.DELETE',
cancelKey: 'ACTIONS.CANCEL',
titleKey: 'USER.DIALOG.DELETE_TITLE',
descriptionParam: this.user.human ??
this.user.machine ? { displayName: this.user.machine?.name } : { displayName: '' },
descriptionKey: 'USER.DIALOG.DELETE_DESCRIPTION',
},
width: '400px',
});
dialogRef.afterClosed().subscribe(resp => {
if (resp) {
this.mgmtUserService.DeleteUser(this.user.id).then(() => {
this.navigateBack();
this.toast.showInfo('USER.TOAST.DELETED', true);
}).catch(error => {
this.toast.showError(error);
});
}
});
}
}