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';
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';
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;
private notificationService: NotificationService,
private authStorageService: AuthStorageService,
private urlBuilder: URLBuilderService,
- private cdDatePipe: CdDatePipe,
+ private settingsService: SettingsService,
public actionLabels: ActionLabelsI18n
) {
this.permission = this.authStorageService.getPermissions().user;
{
name: $localize`Username`,
prop: 'username',
- flexGrow: 1
+ flexGrow: 1,
+ cellTemplate: this.warningTpl
},
{
name: $localize`Name`,
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;
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();
+ }
}