电子档案
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

389 lines
13 KiB

  1. /* Licensed under the Apache License, Version 2.0 (the "License");
  2. * you may not use this file except in compliance with the License.
  3. * You may obtain a copy of the License at
  4. *
  5. * http://www.apache.org/licenses/LICENSE-2.0
  6. *
  7. * Unless required by applicable law or agreed to in writing, software
  8. * distributed under the License is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. * See the License for the specific language governing permissions and
  11. * limitations under the License.
  12. */
  13. /**
  14. * Controller for user mgmt
  15. */
  16. flowableApp.controller('IdmUserMgmtController', ['$rootScope', '$scope', '$translate', '$http', '$timeout','$location', '$modal',
  17. function ($rootScope, $scope, $translate, $http, $timeout, $location, $modal) {
  18. $rootScope.setMainPageById('userMgmt');
  19. $scope.model = {
  20. loading: false,
  21. sorts: [
  22. {id: 'idAsc', name: $translate.instant('IDM.USER-MGMT.FILTERS.SORT-ID-A')},
  23. {id: 'idDesc', name: $translate.instant('IDM.USER-MGMT.FILTERS.SORT-ID-Z')},
  24. {id: 'emailAsc', name: $translate.instant('IDM.USER-MGMT.FILTERS.SORT-EMAIL-A')},
  25. {id: 'emailDesc', name: $translate.instant('IDM.USER-MGMT.FILTERS.SORT-EMAIL-Z')}
  26. ],
  27. waiting: false,
  28. delayed: false,
  29. selectedUsers: {},
  30. selectedUserCount: 0,
  31. start: 0
  32. };
  33. $scope.model.activeSort = $scope.model.sorts[0];
  34. $scope.clearSelectedUsers = function() {
  35. $scope.model.selectedUsers = {};
  36. $scope.model.selectedUserCount = 0;
  37. };
  38. $scope.loadUsers = function() {
  39. $scope.clearSelectedUsers();
  40. $scope.model.loading = true;
  41. var params = {
  42. filter: $scope.model.pendingFilterText,
  43. company: $scope.model.pendingCompanyText,
  44. sort: $scope.model.activeSort.id,
  45. start: $scope.model.start
  46. };
  47. $http({method: 'GET', url: FLOWABLE.CONFIG.contextIdmRestRoot + '/rest/admin/users', params: params}).
  48. success(function(data, status, headers, config) {
  49. data.moreUsers = data.start + data.size < data.total;
  50. $scope.model.users = data;
  51. $scope.model.loading = false;
  52. }).
  53. error(function(data, status, headers, config) {
  54. $scope.model.loading = false;
  55. });
  56. };
  57. $scope.refreshDelayed = function() {
  58. // If already waiting, another wait-cycle will be done
  59. // after the current wait is over
  60. if($scope.model.waiting) {
  61. $scope.model.delayed = true;
  62. } else {
  63. $scope.scheduleDelayedRefresh();
  64. }
  65. };
  66. $scope.scheduleDelayedRefresh = function() {
  67. $scope.model.waiting = true;
  68. $timeout(function() {
  69. $scope.model.waiting = false;
  70. if( $scope.model.delayed) {
  71. $scope.model.delayed = false;
  72. // Delay again
  73. $scope.scheduleDelayedRefresh();
  74. } else {
  75. // Actually do the refresh-call, after resetting start
  76. $scope.model.start = 0;
  77. $scope.loadUsers();
  78. }
  79. }, 100);
  80. };
  81. $scope.showNextUsers = function() {
  82. if($scope.model.users) {
  83. $scope.model.start = $scope.model.users.start + $scope.model.users.size;
  84. $scope.loadUsers();
  85. }
  86. };
  87. $scope.showPreviousUsers = function() {
  88. if($scope.model.users) {
  89. $scope.model.start = Math.max(0, $scope.model.users.start - $scope.model.users.size);
  90. $scope.loadUsers();
  91. }
  92. };
  93. $scope.activateSort = function(sort) {
  94. $scope.model.activeSort = sort;
  95. $scope.model.start = 0;
  96. $scope.loadUsers();
  97. };
  98. $scope.toggleUserSelection = function(user) {
  99. if($scope.model.selectedUsers[user.id]) {
  100. delete $scope.model.selectedUsers[user.id];
  101. $scope.model.selectedUserCount -= 1;
  102. } else {
  103. $scope.model.selectedUsers[user.id] = true;
  104. $scope.model.selectedUserCount +=1;
  105. }
  106. };
  107. $scope.addUser = function() {
  108. $scope.model.errorMessage = undefined;
  109. $scope.model.user = undefined;
  110. $scope.model.mode = 'create';
  111. _internalCreateModal({
  112. scope: $scope,
  113. template: 'views/popup/idm-user-create.html?version=' + new Date().getTime(),
  114. show: true
  115. }, $modal, $scope);
  116. };
  117. $scope.editUserAccountType = function() {
  118. $scope.model.mode = 'type';
  119. _internalCreateModal({
  120. scope: $scope,
  121. template: 'views/popup/idm-user-type-edit.html',
  122. show: true
  123. }, $modal, $scope);
  124. };
  125. $scope.editUserDetails = function() {
  126. $scope.model.user = undefined;
  127. $scope.model.mode = 'edit';
  128. var selectedUsers = $scope.getSelectedUsers();
  129. if (selectedUsers && selectedUsers.length == 1) {
  130. $scope.model.user = selectedUsers[0];
  131. }
  132. $scope.model.errorMessage = undefined;
  133. _internalCreateModal({
  134. scope: $scope,
  135. template: 'views/popup/idm-user-create.html?version=' + new Date().getTime(),
  136. show: true
  137. }, $modal, $scope);
  138. };
  139. $scope.editUserPassword = function() {
  140. $scope.model.mode = 'password';
  141. _internalCreateModal({
  142. scope: $scope,
  143. template: 'views/popup/idm-user-password-change.html',
  144. show: true
  145. }, $modal, $scope);
  146. };
  147. $scope.deleteUsers = function() {
  148. $scope.model.loading = true;
  149. $scope.getSelectedUsers().forEach(function(selectedUser) {
  150. $http({method: 'DELETE', url: FLOWABLE.CONFIG.contextIdmRestRoot + '/rest/admin/users/' + selectedUser.id}).
  151. success(function (data, status, headers, config) {
  152. $rootScope.addAlert('User deleted', 'info');
  153. $scope.loadUsers();
  154. $scope.model.loading = false;
  155. }).
  156. error(function (data, status, headers, config) {
  157. $scope.model.loading = false;
  158. if (data && data.message) {
  159. $rootScope.addAlert(data.message, 'error');
  160. } else {
  161. $rootScope.addAlert('Error while deleting user', 'error');
  162. }
  163. });
  164. });
  165. };
  166. $scope.getSelectedUsers = function() {
  167. var selected = [];
  168. for(var i = 0; i<$scope.model.users.size; i++) {
  169. var user = $scope.model.users.data[i];
  170. if(user) {
  171. for(var prop in $scope.model.selectedUsers) {
  172. if(user.id == prop) {
  173. selected.push(user);
  174. break;
  175. }
  176. }
  177. }
  178. }
  179. return selected;
  180. };
  181. $scope.loadUsers();
  182. }]);
  183. /**
  184. * Controller for the create user dialog
  185. */
  186. flowableApp.controller('IdmCreateUserPopupController', ['$rootScope', '$scope', '$http',
  187. function ($rootScope, $scope, $http) {
  188. if ($scope.model.user === null || $scope.model.user === undefined) {
  189. $scope.model.user = {};
  190. }
  191. $scope.createNewUser = function () {
  192. if (!$scope.model.user.id) {
  193. return;
  194. }
  195. var model = $scope.model;
  196. model.loading = true;
  197. var data = {
  198. id: model.user.id,
  199. email: model.user.email,
  200. firstName: model.user.firstName,
  201. lastName: model.user.lastName,
  202. password: model.user.password,
  203. tenantId: model.user.tenantId,
  204. };
  205. $http({method: 'POST', url: FLOWABLE.CONFIG.contextIdmRestRoot + '/rest/admin/users', data: data}).
  206. success(function (data, status, headers, config) {
  207. $rootScope.addAlert('New user created', 'info');
  208. $scope.loadUsers();
  209. $scope.model.loading = false;
  210. $scope.$hide();
  211. }).
  212. error(function (data, status, headers, config) {
  213. $scope.model.loading = false;
  214. if (data && data.message) {
  215. $rootScope.addAlert(data.message, 'error');
  216. } else {
  217. $rootScope.addAlert('Error while updating user status', 'error');
  218. }
  219. if (status == 403) {
  220. $scope.model.errorMessage = "Forbidden";
  221. } else if (status == 409) {
  222. $scope.model.errorMessage = "A user with that ID or email address already exists";
  223. } else {
  224. $scope.$hide();
  225. }
  226. });
  227. };
  228. $scope.editUserDetails = function() {
  229. if (!$scope.model.user.id) {
  230. return;
  231. }
  232. var model = $scope.model;
  233. model.loading = true;
  234. var data = {
  235. id: model.user.id,
  236. email: model.user.email,
  237. firstName: model.user.firstName,
  238. lastName: model.user.lastName,
  239. tenantId: model.user.tenantId,
  240. };
  241. $http({method: 'PUT', url: FLOWABLE.CONFIG.contextIdmRestRoot + '/rest/admin/users/' + $scope.model.user.id, data: data}).
  242. success(function (data, status, headers, config) {
  243. $scope.loadUsers();
  244. $scope.model.loading = false;
  245. $scope.$hide();
  246. }).
  247. error(function (data, status, headers, config) {
  248. $scope.model.loading = false;
  249. if (data && data.message) {
  250. $rootScope.addAlert(data.message, 'error');
  251. } else {
  252. $rootScope.addAlert('Error while updating user status', 'error');
  253. }
  254. if (status == 403) {
  255. $scope.model.errorMessage = "Forbidden";
  256. } else if (status == 409) {
  257. $scope.model.errorMessage = "A user with that email address already exists";
  258. } else {
  259. $scope.$hide();
  260. }
  261. });
  262. };
  263. $scope.cancel = function () {
  264. if (!$scope.model.loading) {
  265. $scope.$hide();
  266. }
  267. };
  268. }]);
  269. /**
  270. * Controller for the bulk update dialog
  271. */
  272. flowableApp.controller('IdmUserBulkUpdatePopupController', ['$rootScope', '$scope', '$http',
  273. function ($rootScope, $scope, $http) {
  274. if ($scope.model.mode == 'password') {
  275. $scope.model.updateUsers = {
  276. password: ''
  277. };
  278. }
  279. $scope.updateUsers = function () {
  280. $scope.model.loading = true;
  281. var users = $scope.getSelectedUsers();
  282. var userIds = [];
  283. for(var i=0; i<users.length; i++) {
  284. var user = users[i];
  285. if(user && user.id) {
  286. userIds.push(user.id);
  287. }
  288. }
  289. var data = {
  290. users: userIds
  291. };
  292. if ($scope.model.mode == 'password') {
  293. data.password = $scope.model.updateUsers.password;
  294. }
  295. $http({method: 'PUT', url: FLOWABLE.CONFIG.contextIdmRestRoot + '/rest/admin/users', data: data})
  296. .success(function(data, status, headers, config) {
  297. $scope.$hide();
  298. $scope.model.loading = false;
  299. $rootScope.addAlert($scope.model.selectedUserCount + ' user(s) updated', 'info');
  300. $scope.loadUsers();
  301. }).
  302. error(function(data, status, headers, config) {
  303. $scope.model.loading = false;
  304. if(data && data.message) {
  305. $rootScope.addAlert(data.message, 'error');
  306. } else {
  307. $rootScope.addAlert('Error while updating user status', 'error');
  308. }
  309. $scope.$hide();
  310. });
  311. };
  312. $scope.setStatus = function(newStatus) {
  313. $scope.model.updateUsers.status = newStatus;
  314. };
  315. $scope.setType = function(newType) {
  316. $scope.model.updateUsers.type = newType;
  317. };
  318. $scope.cancel = function () {
  319. if(!$scope.model.loading) {
  320. $scope.$hide();
  321. }
  322. };
  323. }]);