From df6e3c5d0ac7c06fad4ae3361936142777548d20 Mon Sep 17 00:00:00 2001 From: Steven Zou Date: Mon, 27 Mar 2017 16:35:26 +0800 Subject: [PATCH] fix self deletion issue of #1766 --- src/ui_ng/src/app/user/user.component.html | 2 +- src/ui_ng/src/app/user/user.component.ts | 24 +++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/ui_ng/src/app/user/user.component.html b/src/ui_ng/src/app/user/user.component.html index 45cb9f4ee..48c1987d1 100644 --- a/src/ui_ng/src/app/user/user.component.html +++ b/src/ui_ng/src/app/user/user.component.html @@ -17,7 +17,7 @@ {{'USER.COLUMN_EMAIL' | translate}} {{'USER.COLUMN_REG_NAME' | translate}} - + diff --git a/src/ui_ng/src/app/user/user.component.ts b/src/ui_ng/src/app/user/user.component.ts index 53b3357a8..f0f0dad8c 100644 --- a/src/ui_ng/src/app/user/user.component.ts +++ b/src/ui_ng/src/app/user/user.component.ts @@ -12,6 +12,8 @@ import { ConfirmationState, ConfirmationTargets, AlertType, httpStatusCode } fro import { errorHandler, accessErrorHandler } from '../shared/shared.utils'; import { MessageService } from '../global-message/message.service'; +import { SessionService } from '../shared/session.service'; + @Component({ selector: 'harbor-user', templateUrl: 'user.component.html', @@ -35,7 +37,8 @@ export class UserComponent implements OnInit, OnDestroy { private userService: UserService, private translate: TranslateService, private deletionDialogService: ConfirmationDialogService, - private msgService: MessageService) { + private msgService: MessageService, + private session: SessionService) { this.deletionSubscription = deletionDialogService.confirmationConfirm$.subscribe(confirmed => { if (confirmed && confirmed.source === ConfirmationTargets.USER && @@ -45,6 +48,17 @@ export class UserComponent implements OnInit, OnDestroy { }); } + private isMySelf(uid: number): boolean { + let currentUser = this.session.getCurrentUser(); + if(currentUser){ + if(currentUser.user_id === uid ){ + return true; + } + } + + return false; + } + private isMatchFilterTerm(terms: string, testedItem: string): boolean { return testedItem.indexOf(terms) != -1; } @@ -101,6 +115,10 @@ export class UserComponent implements OnInit, OnDestroy { return; } + if(this.isMySelf(user.user_id)){ + return; + } + //Value copy let updatedUser: User = { user_id: user.user_id @@ -130,6 +148,10 @@ export class UserComponent implements OnInit, OnDestroy { return; } + if(this.isMySelf(user.user_id)){ + return; //Double confirm + } + //Confirm deletion let msg: ConfirmationMessage = new ConfirmationMessage( "USER.DELETION_TITLE",