123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435 |
- /*
- * Password Management Servlets (PWM)
- * http://www.pwm-project.org
- *
- * Copyright (c) 2006-2009 Novell, Inc.
- * Copyright (c) 2009-2021 The PWM Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- import {Component} from '../../component';
- import {IHelpDeskService, ISuccessResponse} from '../../services/helpdesk.service';
- import {IScope, ui} from 'angular';
- import {noop} from 'angular';
- import {IActionButton, IHelpDeskConfigService, PASSWORD_UI_MODES} from '../../services/helpdesk-config.service';
- import {IPerson} from '../../models/person.model';
- import {IChangePasswordSuccess} from '../../components/changepassword/success-change-password.controller';
- import LocalStorageService from '../../services/local-storage.service';
- let autogenChangePasswordTemplateUrl =
- require('../../components/changepassword/autogen-change-password.component.html');
- let helpdeskDetailDialogTemplateUrl = require('./helpdesk-detail-dialog.template.html');
- let randomChangePasswordTemplateUrl = require('../../components/changepassword/random-change-password.component.html');
- let successChangePasswordTemplateUrl =
- require('../../components/changepassword/success-change-password.component.html');
- let typeChangePasswordTemplateUrl = require('../../components/changepassword/type-change-password.component.html');
- let verificationsDialogTemplateUrl = require('./verifications-dialog.template.html');
- const STATUS_WAIT = 'wait';
- const STATUS_CONFIRM = 'confirm';
- const STATUS_SUCCESS = 'success';
- const PROFILE_TAB_NAME = 'profileTab';
- @Component({
- stylesheetUrl: require('./helpdesk-detail.component.scss'),
- templateUrl: require('./helpdesk-detail.component.html')
- })
- export default class HelpDeskDetailComponent {
- customButtons: {[key: string]: IActionButton};
- person: any;
- personCard: IPerson;
- photosEnabled: boolean;
- searchViewLocalStorageKey: string;
- static $inject = [
- '$state',
- '$stateParams',
- 'ConfigService',
- 'HelpDeskService',
- 'IasDialogService',
- 'IasToggleService',
- 'LocalStorageService'
- ];
- constructor(private $state: ui.IStateService,
- private $stateParams: ui.IStateParamsService,
- private configService: IHelpDeskConfigService,
- private helpDeskService: IHelpDeskService,
- private IasDialogService: any,
- private toggleService: { showComponent: (componentName: string) => null },
- private localStorageService: LocalStorageService) {
- this.searchViewLocalStorageKey = this.localStorageService.keys.HELPDESK_SEARCH_VIEW;
- }
- $onInit(): void {
- this.configService.getCustomButtons().then((customButtons: {[key: string]: IActionButton}) => {
- this.customButtons = customButtons;
- });
- this.configService.photosEnabled().then((photosEnabled: boolean) => {
- this.photosEnabled = photosEnabled;
- });
- this.initialize();
- }
- buttonDisabled(buttonName: string): boolean {
- if (!this.person || !this.person.enabledButtons) {
- return false;
- }
- return (this.person.enabledButtons.indexOf(buttonName) === -1);
- }
- buttonVisible(buttonName: string): boolean {
- if (!this.person || !this.person.visibleButtons) {
- return false;
- }
- return (this.person.visibleButtons.indexOf(buttonName) !== -1);
- }
- changePassword(): void {
- this.configService.getPasswordUiMode()
- .then((passwordUiMode) => {
- if (passwordUiMode) {
- if (passwordUiMode === PASSWORD_UI_MODES.TYPE) {
- this.changePasswordType();
- }
- else if (passwordUiMode === PASSWORD_UI_MODES.AUTOGEN) {
- this.changePasswordAutogen();
- }
- else if (passwordUiMode === PASSWORD_UI_MODES.BOTH) {
- this.changePasswordType();
- }
- else if (passwordUiMode === PASSWORD_UI_MODES.RANDOM) {
- this.changePasswordRandom();
- }
- }
- else {
- throw new Error('Unable to retrieve a valid password UI mode.');
- }
- });
- }
- changePasswordAutogen() {
- this.IasDialogService
- .open({
- controller: 'AutogenChangePasswordController as $ctrl',
- templateUrl: autogenChangePasswordTemplateUrl,
- locals: {
- personUserKey: this.getUserKey()
- }
- })
- // If the password was changed, the promise resolves. IasDialogService passes the data intact.
- .then(this.changePasswordSuccess.bind(this), noop);
- }
- changePasswordClearResponses() {
- let userKey = this.getUserKey();
- this.IasDialogService
- .open({
- controller: [
- '$scope',
- 'HelpDeskService',
- 'translateFilter',
- ($scope: IScope | any,
- helpDeskService: IHelpDeskService,
- translateFilter: (id: string) => string) => {
- $scope.status = STATUS_WAIT;
- $scope.title = translateFilter('Button_ClearResponses');
- helpDeskService.clearResponses(userKey).then((data: ISuccessResponse) => {
- // TODO - error dialog?
- $scope.status = STATUS_SUCCESS;
- $scope.text = data.successMessage;
- this.refresh();
- });
- }
- ],
- templateUrl: helpdeskDetailDialogTemplateUrl
- });
- }
- changePasswordRandom() {
- this.IasDialogService
- .open({
- controller: 'RandomChangePasswordController as $ctrl',
- templateUrl: randomChangePasswordTemplateUrl,
- locals: {
- personUserKey: this.getUserKey()
- }
- })
- // If the password was changed, the promise resolves. IasDialogService passes the data intact.
- .then(this.changePasswordSuccess.bind(this), noop);
- }
- changePasswordSuccess(data: IChangePasswordSuccess) {
- this.IasDialogService
- .open({
- controller: 'SuccessChangePasswordController as $ctrl',
- templateUrl: successChangePasswordTemplateUrl,
- locals: {
- changePasswordSuccessData: data,
- personUserKey: this.getUserKey()
- }
- })
- .then(this.changePasswordClearResponses.bind(this), this.refresh.bind(this));
- }
- changePasswordType() {
- this.IasDialogService
- .open({
- controller: 'TypeChangePasswordController as $ctrl',
- templateUrl: typeChangePasswordTemplateUrl,
- locals: {
- personUserKey: this.getUserKey()
- }
- })
- // If the operator clicked "Random Passwords" or the password was changed, the promise resolves.
- .then((data: IChangePasswordSuccess & { autogenPasswords: boolean }) => {
- // If the operator clicked "Random Passwords", data.autogenPasswords will be true
- if (data.autogenPasswords) {
- this.changePasswordAutogen();
- }
- else {
- this.changePasswordSuccess(data); // IasDialogService passes the data intact.
- }
- }, noop);
- }
- clearOtpSecret(): void {
- if (this.buttonDisabled('clearOtpSecret')) {
- return;
- }
- let userKey = this.getUserKey();
- this.IasDialogService
- .open({
- controller: [
- '$scope',
- 'HelpDeskService',
- 'translateFilter',
- ($scope: IScope | any,
- helpDeskService: IHelpDeskService,
- translateFilter: (id: string) => string) => {
- $scope.status = STATUS_CONFIRM;
- $scope.title = translateFilter('Button_HelpdeskClearOtpSecret');
- $scope.text = translateFilter('Confirm');
- $scope.confirm = () => {
- $scope.status = STATUS_WAIT;
- helpDeskService.clearOtpSecret(userKey).then((data: ISuccessResponse) => {
- // TODO - error dialog?
- $scope.status = STATUS_SUCCESS;
- $scope.text = data.successMessage;
- this.refresh();
- });
- };
- }
- ],
- templateUrl: helpdeskDetailDialogTemplateUrl
- });
- }
- clearResponses(): void {
- if (this.buttonDisabled('clearResponses')) {
- return;
- }
- let userKey = this.getUserKey();
- this.IasDialogService
- .open({
- controller: [
- '$scope',
- 'HelpDeskService',
- 'translateFilter',
- ($scope: IScope | any,
- helpDeskService: IHelpDeskService,
- translateFilter: (id: string) => string) => {
- $scope.status = STATUS_CONFIRM;
- $scope.title = translateFilter('Button_ClearResponses');
- $scope.text = translateFilter('Confirm');
- $scope.confirm = () => {
- $scope.status = STATUS_WAIT;
- helpDeskService.clearResponses(userKey).then((data: ISuccessResponse) => {
- // TODO - error dialog?
- $scope.status = STATUS_SUCCESS;
- $scope.text = data.successMessage;
- this.refresh();
- });
- };
- }
- ],
- templateUrl: helpdeskDetailDialogTemplateUrl
- });
- }
- clickCustomButton(button: IActionButton): void {
- // Custom buttons are never disabled
- let userKey = this.getUserKey();
- this.IasDialogService
- .open({
- controller: [
- '$scope',
- 'HelpDeskService',
- 'translateFilter',
- ($scope: IScope | any,
- helpDeskService: IHelpDeskService,
- translateFilter: (id: string) => string) => {
- $scope.status = STATUS_CONFIRM;
- $scope.title = translateFilter('Button_Confirm') + ' ' + button.name;
- $scope.text = button.description;
- $scope.secondaryText = translateFilter('Confirm');
- $scope.confirm = () => {
- $scope.status = STATUS_WAIT;
- helpDeskService.customAction(button.name, userKey).then((data: ISuccessResponse) => {
- // TODO - error dialog? (note that this error dialog is slightly different)
- $scope.status = STATUS_SUCCESS;
- $scope.title = translateFilter('Title_Success');
- $scope.secondaryText = null;
- $scope.text = data.successMessage;
- this.refresh();
- });
- };
- }
- ],
- templateUrl: helpdeskDetailDialogTemplateUrl
- });
- }
- deleteUser(): void {
- if (this.buttonDisabled('deleteUser')) {
- return;
- }
- let userKey = this.getUserKey();
- this.IasDialogService
- .open({
- controller: [
- '$scope',
- 'HelpDeskService',
- 'IasDialogService',
- 'translateFilter',
- ($scope: IScope | any,
- helpDeskService: IHelpDeskService,
- IasDialogService: any,
- translateFilter: (id: string) => string) => {
- $scope.status = STATUS_CONFIRM;
- $scope.title = translateFilter('Button_Confirm');
- $scope.text = translateFilter('Confirm_DeleteUser');
- $scope.confirm = () => {
- $scope.status = STATUS_WAIT;
- helpDeskService.deleteUser(userKey).then((data: ISuccessResponse) => {
- // TODO - error dialog?
- $scope.status = STATUS_SUCCESS;
- $scope.title = translateFilter('Title_Success');
- $scope.text = data.successMessage;
- $scope.close = () => {
- IasDialogService.close();
- this.gotoSearch();
- };
- });
- };
- }
- ],
- templateUrl: helpdeskDetailDialogTemplateUrl
- });
- }
- getUserKey(): string {
- return this.$stateParams['personId'];
- }
- gotoSearch(): void {
- let view = this.localStorageService.getItem(this.searchViewLocalStorageKey);
- if (view) {
- this.$state.go(view);
- }
- else {
- this.$state.go('search.cards');
- }
- }
- initialize(): void {
- const personId = this.getUserKey();
- this.helpDeskService.getPersonCard(personId).then((personCard: IPerson) => {
- this.personCard = personCard;
- });
- this.toggleService.showComponent(PROFILE_TAB_NAME);
- this.helpDeskService
- .getPerson(personId)
- .then((person: any) => {
- this.person = person;
- }, this.gotoSearch.bind(this));
- }
- refresh(): void {
- this.person = null;
- this.initialize();
- }
- unlockUser(): void {
- if (this.buttonDisabled('unlock')) {
- return;
- }
- let userKey = this.getUserKey();
- this.IasDialogService
- .open({
- controller: [
- '$scope',
- 'HelpDeskService',
- 'translateFilter',
- ($scope: IScope | any,
- helpDeskService: IHelpDeskService,
- translateFilter: (id: string) => string) => {
- $scope.status = STATUS_CONFIRM;
- $scope.title = translateFilter('Button_Unlock');
- $scope.text = translateFilter('Confirm');
- $scope.confirm = () => {
- $scope.status = STATUS_WAIT;
- helpDeskService.unlockIntruder(userKey).then((data: ISuccessResponse) => {
- // TODO - error dialog?
- $scope.status = STATUS_SUCCESS;
- $scope.text = data.successMessage;
- this.refresh();
- });
- };
- }
- ],
- templateUrl: helpdeskDetailDialogTemplateUrl
- });
- }
- verifyUser(): void {
- this.IasDialogService
- .open({
- controller: 'VerificationsDialogController as $ctrl',
- templateUrl: verificationsDialogTemplateUrl,
- locals: {
- personUserKey: this.getUserKey(),
- showRequiredOnly: false
- }
- });
- }
- }
|