电子档案
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.

260 lines
8.1 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. 'use strict';
  14. angular.module('flowableApp').service('IdmService', ['$http', '$q', '$rootScope',
  15. function ($http, $q, $rootScope) {
  16. var httpAsPromise = function (options) {
  17. var deferred = $q.defer();
  18. $http(options).
  19. success(function (response, status, headers, config) {
  20. deferred.resolve(response);
  21. })
  22. .error(function (response, status, headers, config) {
  23. deferred.reject(response);
  24. });
  25. return deferred.promise;
  26. };
  27. /*
  28. PROFILE
  29. */
  30. this.getProfile = function () {
  31. return httpAsPromise(
  32. {
  33. method: 'GET',
  34. url: FLOWABLE.CONFIG.contextIdmRestRoot + '/rest/admin/profile'
  35. }
  36. )
  37. };
  38. this.updateProfileDetails = function(userData, successCallback, errorCallback) {
  39. var deferred = $q.defer();
  40. $http({
  41. method: 'POST',
  42. url: FLOWABLE.CONFIG.contextIdmRestRoot + '/rest/admin/profile',
  43. data: userData
  44. }).success(function (response, status, headers, config) {
  45. if (successCallback) {
  46. successCallback(response);
  47. }
  48. deferred.resolve(response);
  49. }).error(function (response, status, headers, config) {
  50. if (errorCallback) {
  51. errorCallback(response, status);
  52. }
  53. deferred.reject(response);
  54. });
  55. var promise = deferred.promise;
  56. return promise;
  57. };
  58. this.changePassword = function(oldPassword, newPassword) {
  59. return httpAsPromise(
  60. {
  61. method: 'POST',
  62. url: FLOWABLE.CONFIG.contextIdmRestRoot + '/rest/admin/profile-password',
  63. data: {originalPassword: oldPassword, newPassword: newPassword}
  64. }
  65. )
  66. };
  67. /*
  68. GROUPS
  69. */
  70. this.getGroups = function() {
  71. var params = {};
  72. return httpAsPromise(
  73. {
  74. method: 'GET',
  75. url: FLOWABLE.CONFIG.contextIdmRestRoot + '/rest/admin/groups',
  76. params: params
  77. }
  78. )
  79. };
  80. this.getFunctionalGroups = function() {
  81. var params = {};
  82. params.functional = 'true';
  83. return httpAsPromise(
  84. {
  85. method: 'GET',
  86. url: FLOWABLE.CONFIG.contextIdmRestRoot + '/rest/admin/groups',
  87. params: params
  88. }
  89. )
  90. };
  91. this.getGroup = function (groupId, includeAllUsers) {
  92. var params = {};
  93. if (includeAllUsers !== null && includeAllUsers !== undefined) {
  94. params.includeAllUsers = includeAllUsers;
  95. }
  96. return httpAsPromise(
  97. {
  98. method: 'GET',
  99. url: FLOWABLE.CONFIG.contextIdmRestRoot + '/rest/admin/groups/' + groupId,
  100. params: params
  101. }
  102. )
  103. };
  104. this.getUsersForGroup = function(groupId, filter, page, pageSize) {
  105. var params = {};
  106. if (filter !== null && filter !== undefined) {
  107. params.filter = filter;
  108. }
  109. if (page !== null && page !== undefined) {
  110. params.page = page;
  111. }
  112. if (pageSize !== null && pageSize !== undefined) {
  113. params.pageSize = pageSize
  114. }
  115. return httpAsPromise(
  116. {
  117. method: 'GET',
  118. url: FLOWABLE.CONFIG.contextIdmRestRoot + '/rest/admin/groups/' + groupId + '/users',
  119. params: params
  120. }
  121. )
  122. };
  123. this.createGroup = function (createGroupData) {
  124. return httpAsPromise(
  125. {
  126. method: 'POST',
  127. url: FLOWABLE.CONFIG.contextIdmRestRoot + '/rest/admin/groups',
  128. data: createGroupData
  129. }
  130. )
  131. };
  132. this.updateGroup = function (groupId, updatedGroupData) {
  133. var data = {name: updatedGroupData.name};
  134. return httpAsPromise(
  135. {
  136. method: 'PUT',
  137. url: FLOWABLE.CONFIG.contextIdmRestRoot + '/rest/admin/groups/' + groupId ,
  138. data: data
  139. }
  140. )
  141. };
  142. this.deleteGroup = function(groupId) {
  143. return httpAsPromise(
  144. {
  145. method: 'DELETE',
  146. url: FLOWABLE.CONFIG.contextIdmRestRoot + '/rest/admin/groups/' + groupId
  147. }
  148. )
  149. };
  150. this.activateGroup = function(groupId) {
  151. return httpAsPromise(
  152. {
  153. method: 'POST',
  154. url: FLOWABLE.CONFIG.contextIdmRestRoot + '/rest/admin/groups/' + groupId + '/action/activate'
  155. }
  156. )
  157. };
  158. this.deleteGroupMember = function(groupId, userId) {
  159. return httpAsPromise(
  160. {
  161. method: 'DELETE',
  162. url: FLOWABLE.CONFIG.contextIdmRestRoot + '/rest/admin/groups/' + groupId + '/members/' + userId
  163. }
  164. )
  165. };
  166. this.addGroupMember = function(groupId, userId) {
  167. return httpAsPromise(
  168. {
  169. method: 'POST',
  170. url: FLOWABLE.CONFIG.contextIdmRestRoot + '/rest/admin/groups/' + groupId + '/members/' + userId
  171. }
  172. )
  173. };
  174. this.getPrivileges = function() {
  175. return httpAsPromise({
  176. method: 'GET',
  177. url: FLOWABLE.CONFIG.contextIdmRestRoot + '/rest/admin/privileges'
  178. })
  179. };
  180. this.getPrivilege = function(privilegeId) {
  181. return httpAsPromise({
  182. method: 'GET',
  183. url: FLOWABLE.CONFIG.contextIdmRestRoot + '/rest/admin/privileges/' + privilegeId
  184. });
  185. };
  186. this.addUserPrivilege = function(privilegeId, userId) {
  187. return httpAsPromise(
  188. {
  189. method: 'POST',
  190. url: FLOWABLE.CONFIG.contextIdmRestRoot + '/rest/admin/privileges/' + privilegeId + '/users',
  191. data: { userId : userId}
  192. }
  193. )
  194. };
  195. this.deleteUserPrivilege = function(privilegeId, userId) {
  196. return httpAsPromise(
  197. {
  198. method: 'DELETE',
  199. url: FLOWABLE.CONFIG.contextIdmRestRoot + '/rest/admin/privileges/' + privilegeId + '/users/' + userId
  200. }
  201. )
  202. };
  203. this.addGroupPrivilege = function(privilegeId, groupId) {
  204. return httpAsPromise(
  205. {
  206. method: 'POST',
  207. url: FLOWABLE.CONFIG.contextIdmRestRoot + '/rest/admin/privileges/' + privilegeId + '/groups',
  208. data: { groupId : groupId}
  209. }
  210. )
  211. };
  212. this.deleteGroupPrivilege = function(privilegeId, groupId) {
  213. return httpAsPromise(
  214. {
  215. method: 'DELETE',
  216. url: FLOWABLE.CONFIG.contextIdmRestRoot + '/rest/admin/privileges/' + privilegeId + '/groups/' + groupId
  217. }
  218. )
  219. };
  220. }]);