fix self deletion issue of #1766

This commit is contained in:
Steven Zou 2017-03-27 16:35:26 +08:00
parent 58527c2226
commit df6e3c5d0a
2 changed files with 24 additions and 2 deletions

View File

@ -17,7 +17,7 @@
<clr-dg-column>{{'USER.COLUMN_EMAIL' | translate}}</clr-dg-column>
<clr-dg-column>{{'USER.COLUMN_REG_NAME' | translate}}</clr-dg-column>
<clr-dg-row *ngFor="let user of users" [clrDgItem]="user">
<clr-dg-action-overflow>
<clr-dg-action-overflow [hidden]="isMySelf(user.user_id)">
<button class="action-item" (click)="changeAdminRole(user)">{{adminActions(user)}}</button>
<button class="action-item" (click)="deleteUser(user)">{{'USER.DEL_ACTION' | translate}}</button>
</clr-dg-action-overflow>

View File

@ -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",