Feature 10941: User Management Enhancements
- Added NG-UI support for user management enhancements
- It includes login history along with password expiry & account
expiry warnings, unlock & renew user for admin users
- Change password field for admin: visible at user actions field
Change password field for users: visible at header of UI
Change-Id: If952069b62efd6226b633b35b3634cf3f7848096
Signed-off-by: SANDHYA.JS <sandhya.j@tataelxsi.co.in>
diff --git a/src/app/utilities/users-action/UsersActionComponent.html b/src/app/utilities/users-action/UsersActionComponent.html
index 90559f9..c108655 100644
--- a/src/app/utilities/users-action/UsersActionComponent.html
+++ b/src/app/utilities/users-action/UsersActionComponent.html
@@ -21,20 +21,32 @@
{{'ACTION' | translate}}
</button>
<div class="dropdown-menu list-action-dropdown" ngbDropdownMenu>
- <button type="button" class="btn btn-primary dropdown-item" (click)="editUserModal('editPassword')" placement="left" container="body"
- ngbTooltip="{{'PAGE.USERS.EDITCREDENTIALS' | translate}}">
+ <button *ngIf="isAdminShow" type="button" class="btn btn-primary dropdown-item" (click)="editUserModal('editPassword')"
+ placement="left" container="body" ngbTooltip="{{'PAGE.USERS.EDITCREDENTIALS' | translate}}">
<i class="fa fa-edit icons"></i> {{'PAGE.USERS.EDITCREDENTIALS' | translate}}
</button>
- <button type="button" class="btn btn-primary dropdown-item" (click)="editUserModal('editUserName')" placement="left" container="body"
- ngbTooltip="{{'PAGE.USERS.EDITUSERNAME' | translate}}">
+ <button *ngIf="!isAdminShow && !isUserShow" type="button" class="btn btn-primary dropdown-item" (click)="editUserModal('editPassword')"
+ placement="left" container="body" ngbTooltip="{{'PAGE.USERS.EDITCREDENTIALS' | translate}}">
+ <i class="fa fa-edit icons"></i> {{'PAGE.USERS.EDITCREDENTIALS' | translate}}
+ </button>
+ <button type="button" class="btn btn-primary dropdown-item" (click)="editUserModal('editUserName')"
+ placement="left" container="body" ngbTooltip="{{'PAGE.USERS.EDITUSERNAME' | translate}}">
<i class="fas fa-user-edit"></i> {{'PAGE.USERS.EDITUSERNAME' | translate}}
</button>
- <button type="button" class="btn btn-primary dropdown-item" (click)="projectRolesModal()" placement="left" container="body"
- ngbTooltip="{{'PAGE.USERS.PROJECTSROLES' | translate}}">
+ <button type="button" class="btn btn-primary dropdown-item" (click)="projectRolesModal()" placement="left"
+ container="body" ngbTooltip="{{'PAGE.USERS.PROJECTSROLES' | translate}}">
<i class="fas fa-user-check"></i> {{'PAGE.USERS.PROJECTSROLES' | translate}}
</button>
- <button type="button" class="btn btn-primary dropdown-item" (click)="deleteUser()" placement="left" container="body"
- ngbTooltip="{{'DELETE' | translate}}">
+ <button [hidden] ="!isAdminShow || isUserStatus !== 'expired'" type="button" class="btn btn-primary dropdown-item" (click)="unlockRenewUser('renew')" placement="left"
+ container="body" ngbTooltip="{{'PAGE.USERS.RENEW' | translate}}">
+ <i class="fas fa-user-clock"></i> {{'PAGE.USERS.RENEW' | translate}}
+ </button>
+ <button [hidden] ="!isAdminShow || isUserStatus !== 'locked'" type="button" class="btn btn-primary dropdown-item" (click)="unlockRenewUser('unlock')" placement="left"
+ container="body" ngbTooltip="{{'PAGE.USERS.UNLOCK' | translate}}">
+ <i class="fas fa-unlock"></i> {{'PAGE.USERS.UNLOCK' | translate}}
+ </button>
+ <button type="button" class="btn btn-primary dropdown-item" (click)="deleteUser()" placement="left"
+ container="body" ngbTooltip="{{'DELETE' | translate}}">
<i class="far fa-trash-alt icons" title="delete"></i> {{'DELETE' | translate}}
</button>
</div>
diff --git a/src/app/utilities/users-action/UsersActionComponent.ts b/src/app/utilities/users-action/UsersActionComponent.ts
index cb0b462..04fd58a 100644
--- a/src/app/utilities/users-action/UsersActionComponent.ts
+++ b/src/app/utilities/users-action/UsersActionComponent.ts
@@ -18,6 +18,7 @@
/**
* @file Users Action Component
*/
+import { isNullOrUndefined } from 'util';
import { Component, Injector } from '@angular/core';
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { TranslateService } from '@ngx-translate/core';
@@ -27,6 +28,7 @@
import { ProjectRoleComponent } from 'ProjectRoleComponent';
import { SharedService } from 'SharedService';
import { UserData } from 'UserModel';
+import { WarningComponent } from 'WarningComponent';
/**
* Creating component
* @Component takes UsersActionComponent.html as template url
@@ -46,6 +48,15 @@
/** handle translate @public */
public translateService: TranslateService;
+ /** Admin Visibility Check @public */
+ public isAdminShow: boolean;
+
+ /** User Visibility Check @public */
+ public isUserShow: boolean;
+
+ /** User Status Check @public */
+ public isUserStatus: string;
+
/** Instance of the modal service @private */
private modalService: NgbModal;
@@ -59,6 +70,17 @@
this.translateService = this.injector.get(TranslateService);
}
+ /**
+ * Lifecyle Hooks the trigger before component is instantiate
+ */
+ public ngOnInit(): void {
+ this.isAdminShow = localStorage.getItem('admin_show') === 'true' ? true : false;
+ this.isUserShow = localStorage.getItem('user_show') === 'true' ? true : false;
+ if (!isNullOrUndefined(this.value.user_status)) {
+ this.isUserStatus = this.value.user_status;
+ }
+ }
+
/** Delete User Account @public */
public deleteUser(): void {
// eslint-disable-next-line security/detect-non-literal-fs-filename
@@ -107,4 +129,34 @@
// Catch Navigation Error
});
}
+
+ /** To Unlock or Renew User @public */
+ public unlockRenewUser(editType: string): void {
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
+ const modalRef: NgbModalRef = this.modalService.open(WarningComponent, { backdrop: 'static' });
+ localStorage.setItem('renew', 'true');
+ const id: string = localStorage.getItem('user_id');
+ if (editType === 'unlock') {
+ modalRef.componentInstance.heading = this.translateService.instant('Unlock User');
+ modalRef.componentInstance.confirmationMessage = this.translateService.instant('Are you sure want to unlock this user');
+ modalRef.componentInstance.submitMessage = this.translateService.instant('Unlock');
+ modalRef.componentInstance.action = Boolean(true);
+ modalRef.componentInstance.editType = editType;
+ modalRef.componentInstance.id = this.value.identifier;
+ } else {
+ modalRef.componentInstance.heading = this.translateService.instant('Renew User');
+ modalRef.componentInstance.confirmationMessage = this.translateService.instant('Are you sure want to renew this user');
+ modalRef.componentInstance.submitMessage = this.translateService.instant('Renew');
+ modalRef.componentInstance.action = Boolean(true);
+ modalRef.componentInstance.editType = editType;
+ modalRef.componentInstance.id = this.value.identifier;
+ }
+ modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
+ if (result) {
+ this.sharedService.callData();
+ }
+ }).catch((): void => {
+ // Catch Navigation Error
+ });
+ }
}
diff --git a/src/app/utilities/warning/WarningComponent.html b/src/app/utilities/warning/WarningComponent.html
index 9be2656..92adccb 100644
--- a/src/app/utilities/warning/WarningComponent.html
+++ b/src/app/utilities/warning/WarningComponent.html
@@ -28,6 +28,7 @@
</div>
<div class="modal-footer">
<button (click)="closeModal('close')" class="btn btn-danger">{{'CANCEL' | translate }}</button>
- <button (click)="closeModal('done')" class="btn btn-success">{{submitMessage}}</button>
+ <button *ngIf="!action" (click)="closeModal('done')" class="btn btn-success">{{submitMessage}}</button>
+ <button *ngIf="action" (click)="onSubmit()" class="btn btn-success">{{submitMessage}}</button>
</div>
<app-loader [waitingMessage]="message" *ngIf="isLoad"></app-loader>
\ No newline at end of file
diff --git a/src/app/utilities/warning/WarningComponent.ts b/src/app/utilities/warning/WarningComponent.ts
index 0ccb888..c687fb0 100644
--- a/src/app/utilities/warning/WarningComponent.ts
+++ b/src/app/utilities/warning/WarningComponent.ts
@@ -18,8 +18,14 @@
/**
* @file WarningConfiguration Model
*/
+import { HttpHeaders } from '@angular/common/http';
import { Component, Injector, Input } from '@angular/core';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
+import { TranslateService } from '@ngx-translate/core';
+import { NotifierService } from 'angular-notifier';
+import { APIURLHEADER, ERRORDATA, MODALCLOSERESPONSEDATA, UNLOCKPARAMS } from 'CommonModel';
+import { environment } from 'environment';
+import { RestService } from 'RestService';
/**
* Creating component
* @Component takes WarningComponent.html as template url
@@ -55,9 +61,36 @@
/** Give the message for the loading @public */
public message: string = 'PLEASEWAIT';
+ /** Contains id of the admin user @public */
+ @Input()
+ public id: string;
+
+ /** Holds which action to perform @public */
+ @Input()
+ public action: boolean = false;
+
+ /** Contains editType data @public */
+ @Input()
+ public editType: string;
+
+ /** handle translate @public */
+ public translateService: TranslateService;
+
+ /** Controls the header form @private */
+ private headers: HttpHeaders;
+
+ /** Instance of the rest service @private */
+ private restService: RestService;
+
+ /** Notifier service to popup notification @private */
+ private notifierService: NotifierService;
+
constructor(injector: Injector) {
this.injector = injector;
this.activeModal = this.injector.get(NgbActiveModal);
+ this.restService = this.injector.get(RestService);
+ this.translateService = this.injector.get(TranslateService);
+ this.notifierService = this.injector.get(NotifierService);
}
/**
@@ -71,4 +104,41 @@
public closeModal(getMessage: string): void {
this.activeModal.close({ message: getMessage });
}
+
+ /**
+ * called on submit @private onSubmit
+ */
+ public onSubmit(): void {
+ this.isLoad = true;
+ const modalData: MODALCLOSERESPONSEDATA = {
+ message: 'Done'
+ };
+ const id: string = localStorage.getItem('user_id');
+ const payLoad: UNLOCKPARAMS = {};
+ if (this.editType === 'unlock') {
+ payLoad.system_admin_id = id;
+ payLoad.unlock = true;
+ } else {
+ payLoad.system_admin_id = id;
+ payLoad.renew = true;
+ }
+ const apiURLHeader: APIURLHEADER = {
+ url: environment.USERS_URL + '/' + this.id,
+ httpOptions: { headers: this.headers }
+ };
+ this.restService.patchResource(apiURLHeader, payLoad).subscribe((result: {}): void => {
+ this.activeModal.close(modalData);
+ this.isLoad = false;
+ if (this.editType === 'unlock') {
+ this.notifierService.notify('success', this.translateService.instant('PAGE.USERS.UNLOCKUSER'));
+ } else {
+ this.notifierService.notify('success', this.translateService.instant('PAGE.USERS.RENEWUSER'));
+ }
+ }, (error: ERRORDATA): void => {
+ this.restService.handleError(error, 'put');
+ this.isLoad = false;
+ }, (): void => {
+ this.isLoad = false;
+ });
+ }
}