]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-list/user-list.component.ts
import quincy beta 17.1.0
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / core / auth / user-list / user-list.component.ts
old mode 100644 (file)
new mode 100755 (executable)
index 09c0d82..3a16fdc
@@ -2,6 +2,7 @@ import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core';
 
 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
 
+import { SettingsService } from '~/app/shared/api/settings.service';
 import { UserService } from '~/app/shared/api/user.service';
 import { CriticalConfirmationModalComponent } from '~/app/shared/components/critical-confirmation-modal/critical-confirmation-modal.component';
 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
@@ -12,7 +13,6 @@ import { CdTableAction } from '~/app/shared/models/cd-table-action';
 import { CdTableColumn } from '~/app/shared/models/cd-table-column';
 import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
 import { Permission } from '~/app/shared/models/permissions';
-import { CdDatePipe } from '~/app/shared/pipes/cd-date.pipe';
 import { EmptyPipe } from '~/app/shared/pipes/empty.pipe';
 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
 import { ModalService } from '~/app/shared/services/modal.service';
@@ -30,12 +30,19 @@ const BASE_URL = 'user-management/users';
 export class UserListComponent implements OnInit {
   @ViewChild('userRolesTpl', { static: true })
   userRolesTpl: TemplateRef<any>;
+  @ViewChild('warningTpl', { static: true })
+  warningTpl: TemplateRef<any>;
+  @ViewChild('durationTpl', { static: true })
+  durationTpl: TemplateRef<any>;
 
   permission: Permission;
   tableActions: CdTableAction[];
   columns: CdTableColumn[];
   users: Array<any>;
+  expirationWarningAlert: number;
+  expirationDangerAlert: number;
   selection = new CdTableSelection();
+  icons = Icons;
 
   modalRef: NgbModalRef;
 
@@ -46,7 +53,7 @@ export class UserListComponent implements OnInit {
     private notificationService: NotificationService,
     private authStorageService: AuthStorageService,
     private urlBuilder: URLBuilderService,
-    private cdDatePipe: CdDatePipe,
+    private settingsService: SettingsService,
     public actionLabels: ActionLabelsI18n
   ) {
     this.permission = this.authStorageService.getPermissions().user;
@@ -77,7 +84,8 @@ export class UserListComponent implements OnInit {
       {
         name: $localize`Username`,
         prop: 'username',
-        flexGrow: 1
+        flexGrow: 1,
+        cellTemplate: this.warningTpl
       },
       {
         name: $localize`Name`,
@@ -104,19 +112,29 @@ export class UserListComponent implements OnInit {
         cellTransformation: CellTemplate.checkIcon
       },
       {
-        name: $localize`Password expiration date`,
+        name: $localize`Password expires`,
         prop: 'pwdExpirationDate',
         flexGrow: 1,
-        pipe: this.cdDatePipe
+        cellTemplate: this.durationTpl
       }
     ];
+    const settings: string[] = ['USER_PWD_EXPIRATION_WARNING_1', 'USER_PWD_EXPIRATION_WARNING_2'];
+    this.settingsService.getValues(settings).subscribe((data) => {
+      this.expirationWarningAlert = data['USER_PWD_EXPIRATION_WARNING_1'];
+      this.expirationDangerAlert = data['USER_PWD_EXPIRATION_WARNING_2'];
+    });
   }
 
   getUsers() {
     this.userService.list().subscribe((users: Array<any>) => {
       users.forEach((user) => {
+        user['remainingTimeWithoutSeconds'] = 0;
         if (user['pwdExpirationDate'] && user['pwdExpirationDate'] > 0) {
           user['pwdExpirationDate'] = user['pwdExpirationDate'] * 1000;
+          user['remainingTimeWithoutSeconds'] = this.getRemainingTimeWithoutSeconds(
+            user.pwdExpirationDate
+          );
+          user['remainingDays'] = this.getRemainingDays(user.pwdExpirationDate);
         }
       });
       this.users = users;
@@ -161,4 +179,48 @@ export class UserListComponent implements OnInit {
       submitAction: () => this.deleteUser(username)
     });
   }
+
+  getWarningIconClass(expirationDays: number): any {
+    if (expirationDays === null || this.expirationWarningAlert > 10) {
+      return '';
+    }
+    const remainingDays = this.getRemainingDays(expirationDays);
+    if (remainingDays <= this.expirationDangerAlert) {
+      return 'icon-danger-color';
+    } else {
+      return 'icon-warning-color';
+    }
+  }
+
+  getWarningClass(expirationDays: number): any {
+    if (expirationDays === null || this.expirationWarningAlert > 10) {
+      return '';
+    }
+    const remainingDays = this.getRemainingDays(expirationDays);
+    if (remainingDays <= this.expirationDangerAlert) {
+      return 'border-danger';
+    } else {
+      return 'border-warning';
+    }
+  }
+
+  getRemainingDays(time: number): number {
+    if (time === undefined || time == null) {
+      return undefined;
+    }
+    if (time < 0) {
+      return 0;
+    }
+    const toDays = 1000 * 60 * 60 * 24;
+    return Math.max(0, Math.floor(this.getRemainingTime(time) / toDays));
+  }
+
+  getRemainingTimeWithoutSeconds(time: number): number {
+    const withSeconds = this.getRemainingTime(time);
+    return Math.floor(withSeconds / (1000 * 60)) * 60 * 1000;
+  }
+
+  getRemainingTime(time: number): number {
+    return time - Date.now();
+  }
 }