Merge pull request #2 from steven-zou/fix/issue_1766

fix self deletion issue of #1766
This commit is contained in:
Steven Zou 2017-03-27 16:36:09 +08:00 committed by GitHub
commit 3a3b1c5ad5
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",