helpdesk-detail.component.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. /*
  2. * Password Management Servlets (PWM)
  3. * http://www.pwm-project.org
  4. *
  5. * Copyright (c) 2006-2009 Novell, Inc.
  6. * Copyright (c) 2009-2021 The PWM Project
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. */
  20. import {Component} from '../../component';
  21. import {IHelpDeskService, ISuccessResponse} from '../../services/helpdesk.service';
  22. import {IScope, ui} from 'angular';
  23. import {noop} from 'angular';
  24. import {IActionButton, IHelpDeskConfigService, PASSWORD_UI_MODES} from '../../services/helpdesk-config.service';
  25. import {IPerson} from '../../models/person.model';
  26. import {IChangePasswordSuccess} from '../../components/changepassword/success-change-password.controller';
  27. import LocalStorageService from '../../services/local-storage.service';
  28. let autogenChangePasswordTemplateUrl =
  29. require('../../components/changepassword/autogen-change-password.component.html');
  30. let helpdeskDetailDialogTemplateUrl = require('./helpdesk-detail-dialog.template.html');
  31. let randomChangePasswordTemplateUrl = require('../../components/changepassword/random-change-password.component.html');
  32. let successChangePasswordTemplateUrl =
  33. require('../../components/changepassword/success-change-password.component.html');
  34. let typeChangePasswordTemplateUrl = require('../../components/changepassword/type-change-password.component.html');
  35. let verificationsDialogTemplateUrl = require('./verifications-dialog.template.html');
  36. const STATUS_WAIT = 'wait';
  37. const STATUS_CONFIRM = 'confirm';
  38. const STATUS_SUCCESS = 'success';
  39. const PROFILE_TAB_NAME = 'profileTab';
  40. @Component({
  41. stylesheetUrl: require('./helpdesk-detail.component.scss'),
  42. templateUrl: require('./helpdesk-detail.component.html')
  43. })
  44. export default class HelpDeskDetailComponent {
  45. customButtons: {[key: string]: IActionButton};
  46. person: any;
  47. personCard: IPerson;
  48. photosEnabled: boolean;
  49. searchViewLocalStorageKey: string;
  50. static $inject = [
  51. '$state',
  52. '$stateParams',
  53. 'ConfigService',
  54. 'HelpDeskService',
  55. 'IasDialogService',
  56. 'IasToggleService',
  57. 'LocalStorageService'
  58. ];
  59. constructor(private $state: ui.IStateService,
  60. private $stateParams: ui.IStateParamsService,
  61. private configService: IHelpDeskConfigService,
  62. private helpDeskService: IHelpDeskService,
  63. private IasDialogService: any,
  64. private toggleService: { showComponent: (componentName: string) => null },
  65. private localStorageService: LocalStorageService) {
  66. this.searchViewLocalStorageKey = this.localStorageService.keys.HELPDESK_SEARCH_VIEW;
  67. }
  68. $onInit(): void {
  69. this.configService.getCustomButtons().then((customButtons: {[key: string]: IActionButton}) => {
  70. this.customButtons = customButtons;
  71. });
  72. this.configService.photosEnabled().then((photosEnabled: boolean) => {
  73. this.photosEnabled = photosEnabled;
  74. });
  75. this.initialize();
  76. }
  77. buttonDisabled(buttonName: string): boolean {
  78. if (!this.person || !this.person.enabledButtons) {
  79. return false;
  80. }
  81. return (this.person.enabledButtons.indexOf(buttonName) === -1);
  82. }
  83. buttonVisible(buttonName: string): boolean {
  84. if (!this.person || !this.person.visibleButtons) {
  85. return false;
  86. }
  87. return (this.person.visibleButtons.indexOf(buttonName) !== -1);
  88. }
  89. changePassword(): void {
  90. this.configService.getPasswordUiMode()
  91. .then((passwordUiMode) => {
  92. if (passwordUiMode) {
  93. if (passwordUiMode === PASSWORD_UI_MODES.TYPE) {
  94. this.changePasswordType();
  95. }
  96. else if (passwordUiMode === PASSWORD_UI_MODES.AUTOGEN) {
  97. this.changePasswordAutogen();
  98. }
  99. else if (passwordUiMode === PASSWORD_UI_MODES.BOTH) {
  100. this.changePasswordType();
  101. }
  102. else if (passwordUiMode === PASSWORD_UI_MODES.RANDOM) {
  103. this.changePasswordRandom();
  104. }
  105. }
  106. else {
  107. throw new Error('Unable to retrieve a valid password UI mode.');
  108. }
  109. });
  110. }
  111. changePasswordAutogen() {
  112. this.IasDialogService
  113. .open({
  114. controller: 'AutogenChangePasswordController as $ctrl',
  115. templateUrl: autogenChangePasswordTemplateUrl,
  116. locals: {
  117. personUserKey: this.getUserKey()
  118. }
  119. })
  120. // If the password was changed, the promise resolves. IasDialogService passes the data intact.
  121. .then(this.changePasswordSuccess.bind(this), noop);
  122. }
  123. changePasswordClearResponses() {
  124. let userKey = this.getUserKey();
  125. this.IasDialogService
  126. .open({
  127. controller: [
  128. '$scope',
  129. 'HelpDeskService',
  130. 'translateFilter',
  131. ($scope: IScope | any,
  132. helpDeskService: IHelpDeskService,
  133. translateFilter: (id: string) => string) => {
  134. $scope.status = STATUS_WAIT;
  135. $scope.title = translateFilter('Button_ClearResponses');
  136. helpDeskService.clearResponses(userKey).then((data: ISuccessResponse) => {
  137. // TODO - error dialog?
  138. $scope.status = STATUS_SUCCESS;
  139. $scope.text = data.successMessage;
  140. this.refresh();
  141. });
  142. }
  143. ],
  144. templateUrl: helpdeskDetailDialogTemplateUrl
  145. });
  146. }
  147. changePasswordRandom() {
  148. this.IasDialogService
  149. .open({
  150. controller: 'RandomChangePasswordController as $ctrl',
  151. templateUrl: randomChangePasswordTemplateUrl,
  152. locals: {
  153. personUserKey: this.getUserKey()
  154. }
  155. })
  156. // If the password was changed, the promise resolves. IasDialogService passes the data intact.
  157. .then(this.changePasswordSuccess.bind(this), noop);
  158. }
  159. changePasswordSuccess(data: IChangePasswordSuccess) {
  160. this.IasDialogService
  161. .open({
  162. controller: 'SuccessChangePasswordController as $ctrl',
  163. templateUrl: successChangePasswordTemplateUrl,
  164. locals: {
  165. changePasswordSuccessData: data,
  166. personUserKey: this.getUserKey()
  167. }
  168. })
  169. .then(this.changePasswordClearResponses.bind(this), this.refresh.bind(this));
  170. }
  171. changePasswordType() {
  172. this.IasDialogService
  173. .open({
  174. controller: 'TypeChangePasswordController as $ctrl',
  175. templateUrl: typeChangePasswordTemplateUrl,
  176. locals: {
  177. personUserKey: this.getUserKey()
  178. }
  179. })
  180. // If the operator clicked "Random Passwords" or the password was changed, the promise resolves.
  181. .then((data: IChangePasswordSuccess & { autogenPasswords: boolean }) => {
  182. // If the operator clicked "Random Passwords", data.autogenPasswords will be true
  183. if (data.autogenPasswords) {
  184. this.changePasswordAutogen();
  185. }
  186. else {
  187. this.changePasswordSuccess(data); // IasDialogService passes the data intact.
  188. }
  189. }, noop);
  190. }
  191. clearOtpSecret(): void {
  192. if (this.buttonDisabled('clearOtpSecret')) {
  193. return;
  194. }
  195. let userKey = this.getUserKey();
  196. this.IasDialogService
  197. .open({
  198. controller: [
  199. '$scope',
  200. 'HelpDeskService',
  201. 'translateFilter',
  202. ($scope: IScope | any,
  203. helpDeskService: IHelpDeskService,
  204. translateFilter: (id: string) => string) => {
  205. $scope.status = STATUS_CONFIRM;
  206. $scope.title = translateFilter('Button_HelpdeskClearOtpSecret');
  207. $scope.text = translateFilter('Confirm');
  208. $scope.confirm = () => {
  209. $scope.status = STATUS_WAIT;
  210. helpDeskService.clearOtpSecret(userKey).then((data: ISuccessResponse) => {
  211. // TODO - error dialog?
  212. $scope.status = STATUS_SUCCESS;
  213. $scope.text = data.successMessage;
  214. this.refresh();
  215. });
  216. };
  217. }
  218. ],
  219. templateUrl: helpdeskDetailDialogTemplateUrl
  220. });
  221. }
  222. clearResponses(): void {
  223. if (this.buttonDisabled('clearResponses')) {
  224. return;
  225. }
  226. let userKey = this.getUserKey();
  227. this.IasDialogService
  228. .open({
  229. controller: [
  230. '$scope',
  231. 'HelpDeskService',
  232. 'translateFilter',
  233. ($scope: IScope | any,
  234. helpDeskService: IHelpDeskService,
  235. translateFilter: (id: string) => string) => {
  236. $scope.status = STATUS_CONFIRM;
  237. $scope.title = translateFilter('Button_ClearResponses');
  238. $scope.text = translateFilter('Confirm');
  239. $scope.confirm = () => {
  240. $scope.status = STATUS_WAIT;
  241. helpDeskService.clearResponses(userKey).then((data: ISuccessResponse) => {
  242. // TODO - error dialog?
  243. $scope.status = STATUS_SUCCESS;
  244. $scope.text = data.successMessage;
  245. this.refresh();
  246. });
  247. };
  248. }
  249. ],
  250. templateUrl: helpdeskDetailDialogTemplateUrl
  251. });
  252. }
  253. clickCustomButton(button: IActionButton): void {
  254. // Custom buttons are never disabled
  255. let userKey = this.getUserKey();
  256. this.IasDialogService
  257. .open({
  258. controller: [
  259. '$scope',
  260. 'HelpDeskService',
  261. 'translateFilter',
  262. ($scope: IScope | any,
  263. helpDeskService: IHelpDeskService,
  264. translateFilter: (id: string) => string) => {
  265. $scope.status = STATUS_CONFIRM;
  266. $scope.title = translateFilter('Button_Confirm') + ' ' + button.name;
  267. $scope.text = button.description;
  268. $scope.secondaryText = translateFilter('Confirm');
  269. $scope.confirm = () => {
  270. $scope.status = STATUS_WAIT;
  271. helpDeskService.customAction(button.name, userKey).then((data: ISuccessResponse) => {
  272. // TODO - error dialog? (note that this error dialog is slightly different)
  273. $scope.status = STATUS_SUCCESS;
  274. $scope.title = translateFilter('Title_Success');
  275. $scope.secondaryText = null;
  276. $scope.text = data.successMessage;
  277. this.refresh();
  278. });
  279. };
  280. }
  281. ],
  282. templateUrl: helpdeskDetailDialogTemplateUrl
  283. });
  284. }
  285. deleteUser(): void {
  286. if (this.buttonDisabled('deleteUser')) {
  287. return;
  288. }
  289. let userKey = this.getUserKey();
  290. this.IasDialogService
  291. .open({
  292. controller: [
  293. '$scope',
  294. 'HelpDeskService',
  295. 'IasDialogService',
  296. 'translateFilter',
  297. ($scope: IScope | any,
  298. helpDeskService: IHelpDeskService,
  299. IasDialogService: any,
  300. translateFilter: (id: string) => string) => {
  301. $scope.status = STATUS_CONFIRM;
  302. $scope.title = translateFilter('Button_Confirm');
  303. $scope.text = translateFilter('Confirm_DeleteUser');
  304. $scope.confirm = () => {
  305. $scope.status = STATUS_WAIT;
  306. helpDeskService.deleteUser(userKey).then((data: ISuccessResponse) => {
  307. // TODO - error dialog?
  308. $scope.status = STATUS_SUCCESS;
  309. $scope.title = translateFilter('Title_Success');
  310. $scope.text = data.successMessage;
  311. $scope.close = () => {
  312. IasDialogService.close();
  313. this.gotoSearch();
  314. };
  315. });
  316. };
  317. }
  318. ],
  319. templateUrl: helpdeskDetailDialogTemplateUrl
  320. });
  321. }
  322. getUserKey(): string {
  323. return this.$stateParams['personId'];
  324. }
  325. gotoSearch(): void {
  326. let view = this.localStorageService.getItem(this.searchViewLocalStorageKey);
  327. if (view) {
  328. this.$state.go(view);
  329. }
  330. else {
  331. this.$state.go('search.cards');
  332. }
  333. }
  334. initialize(): void {
  335. const personId = this.getUserKey();
  336. this.helpDeskService.getPersonCard(personId).then((personCard: IPerson) => {
  337. this.personCard = personCard;
  338. });
  339. this.toggleService.showComponent(PROFILE_TAB_NAME);
  340. this.helpDeskService
  341. .getPerson(personId)
  342. .then((person: any) => {
  343. this.person = person;
  344. }, this.gotoSearch.bind(this));
  345. }
  346. refresh(): void {
  347. this.person = null;
  348. this.initialize();
  349. }
  350. unlockUser(): void {
  351. if (this.buttonDisabled('unlock')) {
  352. return;
  353. }
  354. let userKey = this.getUserKey();
  355. this.IasDialogService
  356. .open({
  357. controller: [
  358. '$scope',
  359. 'HelpDeskService',
  360. 'translateFilter',
  361. ($scope: IScope | any,
  362. helpDeskService: IHelpDeskService,
  363. translateFilter: (id: string) => string) => {
  364. $scope.status = STATUS_CONFIRM;
  365. $scope.title = translateFilter('Button_Unlock');
  366. $scope.text = translateFilter('Confirm');
  367. $scope.confirm = () => {
  368. $scope.status = STATUS_WAIT;
  369. helpDeskService.unlockIntruder(userKey).then((data: ISuccessResponse) => {
  370. // TODO - error dialog?
  371. $scope.status = STATUS_SUCCESS;
  372. $scope.text = data.successMessage;
  373. this.refresh();
  374. });
  375. };
  376. }
  377. ],
  378. templateUrl: helpdeskDetailDialogTemplateUrl
  379. });
  380. }
  381. verifyUser(): void {
  382. this.IasDialogService
  383. .open({
  384. controller: 'VerificationsDialogController as $ctrl',
  385. templateUrl: verificationsDialogTemplateUrl,
  386. locals: {
  387. personUserKey: this.getUserKey(),
  388. showRequiredOnly: false
  389. }
  390. });
  391. }
  392. }