SecurityObjectExplorerAdaptor.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM IBM Cognos Products: admin
  4. * Copyright IBM Corp. 2015, 2019
  5. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. */
  7. define(['jquery', 'underscore', 'bi/admin/nls/StringResource', 'bi/admin/account/services/SecurityObjectSelectorAdaptor', 'bacontentnav/ui/dialogs/CopyMoveDialog', 'bi/admin/account/ui/SecurityObjectExplorerCopyMoveView'], function ($, _, StringResource, SecurityObjectSelectorAdaptor, CopyMoveDialog, SecurityObjectExplorerCopyMoveView) {
  8. var SecurityObjectExplorerAdaptor = SecurityObjectSelectorAdaptor.extend({
  9. supportPaging: true,
  10. pageSize: 50,
  11. sortChanged: false,
  12. _filterString: '',
  13. _filterType: '',
  14. rowClickHandler: function rowClickHandler(aSecExplorer, oData) {
  15. //NOSONAR:
  16. var rowClickHandlerResult;
  17. if (oData.type === "namespace" && !oData.auth) {
  18. aSecExplorer.glassContext.appController.showToast(StringResource.get('noSigninToViewErrorMsg'), {
  19. type: 'error'
  20. });
  21. return;
  22. }
  23. if ((oData.type === 'role' || oData.type === 'group') && !oData.hasChildren) {
  24. //for roles and groups if they do not have children then do nothing
  25. return;
  26. }
  27. if ((oData.type === "namespaceFolder" || oData.type === "namespace") && oData.permissions.indexOf("traverse") === -1) {
  28. aSecExplorer.glassContext.appController.showToast(StringResource.get('noTraversePermissionErrorMsg'), {
  29. type: 'error'
  30. });
  31. return;
  32. }
  33. switch (oData.type) {
  34. case 'namespace':
  35. aSecExplorer.listView.clearShowWorking();
  36. rowClickHandlerResult = this._accountExplorer.selectNamespace(oData).then(aSecExplorer.updateForNavigate.bind(aSecExplorer)).catch(function (err) {
  37. this._handleNSObjectError(err, aSecExplorer);
  38. }.bind(this));
  39. break;
  40. case 'namespaceFolder':
  41. if (this.isBrowse()) {
  42. aSecExplorer.listView.clearShowWorking();
  43. rowClickHandlerResult = this._accountExplorer.selectFolder(oData).then(aSecExplorer.updateForNavigate.bind(aSecExplorer, oData)).catch(function (err) {
  44. this._handleNSObjectError(err, aSecExplorer);
  45. }.bind(this));
  46. } else {
  47. this.trigger('locationChanged', {
  48. 'data': oData,
  49. 'isFolderNav': true
  50. });
  51. }
  52. break;
  53. case 'group':
  54. if (this.isBrowse()) {
  55. aSecExplorer.listView.clearShowWorking();
  56. rowClickHandlerResult = this._accountExplorer.selectGroup(oData).then(aSecExplorer.updateForNavigate.bind(aSecExplorer)).catch(function (err) {
  57. this._handleNSObjectError(err, aSecExplorer);
  58. }.bind(this));
  59. } else {
  60. this.trigger('locationChanged', {
  61. 'data': oData,
  62. 'isFolderNav': true
  63. });
  64. }
  65. break;
  66. case 'role':
  67. if (this.isBrowse()) {
  68. aSecExplorer.listView.clearShowWorking();
  69. rowClickHandlerResult = this._accountExplorer.selectRole(oData).then(aSecExplorer.updateForNavigate.bind(aSecExplorer)).catch(function (err) {
  70. this._handleNSObjectError(err, aSecExplorer);
  71. }.bind(this));
  72. } else {
  73. this.trigger('locationChanged', {
  74. 'data': oData,
  75. 'isFolderNav': true
  76. });
  77. }
  78. break;
  79. case 'account':
  80. aSecExplorer.showProperties(oData);
  81. break;
  82. default:
  83. this._accountExplorer.logger.debug("Clicked on object type that is not understood " + oData.type);
  84. }
  85. return new Promise(function (resolve) {
  86. resolve(rowClickHandlerResult);
  87. });
  88. },
  89. _handleNSObjectError: function _handleNSObjectError(error, aSecExplorer) {
  90. aSecExplorer.listView.reload(false);
  91. var errorMessage = StringResource.get('nsObjectsRetrievalError');
  92. if (error.jqXHR.responseJSON) {
  93. errorMessage += '\n' + error.jqXHR.responseJSON.exceptionMessage;
  94. }
  95. aSecExplorer.glassContext.appController.showErrorMessage(errorMessage, StringResource.get('error'));
  96. },
  97. contextMenuHandler: function contextMenuHandler(securityObj, data) {
  98. data.selectedObject.securityObject = securityObj;
  99. var args = {
  100. "position": data.position,
  101. "menuId": 'com.ibm.bi.admin.accountListMenu',
  102. "activeObject": {
  103. handler: this,
  104. data: data.selectedObject,
  105. securityObject: securityObj
  106. }
  107. };
  108. securityObj.glassContext.appController.showContextMenu(args);
  109. },
  110. _getItemsContextMenus: function _getItemsContextMenus(data) {
  111. //NOSONAR
  112. var isBuiltinNs = this._accountExplorer.isBuiltinNamespace();
  113. var isOIDCNs = this._accountExplorer.isOidcNamespace();
  114. var isCognoUsersNs = this._accountExplorer.isCognosUsersNamespace();
  115. var dataWritePermission = data.permissions.indexOf('write') > -1 ? true : false;
  116. var availableContextMenuItems = ['property'];
  117. var parentObjectWritePermission = this._isWriteable(this._accountExplorer.parentObjectPermissions);
  118. switch (data.type) {
  119. case 'namespace':
  120. break;
  121. case 'namespaceFolder':
  122. if (isBuiltinNs && dataWritePermission && parentObjectWritePermission && this._canDeleteObject(data)) {
  123. availableContextMenuItems.push('delete');
  124. }
  125. if (this._canCopyOrMove(data)) {
  126. availableContextMenuItems.push('copyOrMove');
  127. }
  128. break;
  129. case 'account':
  130. case 'group':
  131. availableContextMenuItems.push('addMemberToRole');
  132. if (data.type === 'group' && !isOIDCNs) {
  133. availableContextMenuItems.push('members');
  134. }
  135. ;
  136. if (parentObjectWritePermission && dataWritePermission && this._checkCapabilities('canUseUsersGroupsAndRolesTool') && this._canDeleteObject(data)) {
  137. if (data.type === 'group' && (isBuiltinNs || isOIDCNs)) {
  138. availableContextMenuItems.push('delete');
  139. }
  140. ;
  141. if (data.type === 'account') {
  142. if (isCognoUsersNs) {
  143. availableContextMenuItems.push('delete');
  144. }
  145. if (data.modificationTime) {
  146. availableContextMenuItems.push('deleteUserProfile');
  147. availableContextMenuItems.push('copyUserProfile');
  148. } else {
  149. availableContextMenuItems.push('createUserProfile');
  150. }
  151. }
  152. ;
  153. }
  154. if (this._canCopyOrMove(data)) {
  155. availableContextMenuItems.push('copyOrMove');
  156. }
  157. ;
  158. break;
  159. case 'role':
  160. availableContextMenuItems.push('members');
  161. availableContextMenuItems.push('addMemberToRole');
  162. if (this._canCopyOrMove(data)) {
  163. availableContextMenuItems.push('copyOrMove');
  164. }
  165. if (isBuiltinNs && dataWritePermission && parentObjectWritePermission && this._canDeleteObject(data)) {
  166. availableContextMenuItems.push('delete');
  167. }
  168. break;
  169. default:
  170. this._accountExplorer.logger.debug("can not get context menu for " + data.type);
  171. }
  172. return availableContextMenuItems;
  173. },
  174. _isWriteable: function _isWriteable(permissions) {
  175. var retVal = false;
  176. _.find(permissions, function (permission) {
  177. retVal = permission === 'write';
  178. });
  179. return retVal;
  180. },
  181. _checkCapabilities: function _checkCapabilities(capabilityName) {
  182. return _.find(this.glassContext.services.userProfile.capabilities, function (capability) {
  183. return capability === capabilityName;
  184. });
  185. },
  186. _canCopyOrMove: function _canCopyOrMove(data) {
  187. //check if selection is in cognos namespace
  188. var isInCognosNamespace = this._isMovableInCognosNamespace(data);
  189. if (isInCognosNamespace === true) {
  190. return true;
  191. }
  192. return false;
  193. },
  194. _isMovableInCognosNamespace: function _isMovableInCognosNamespace(data) {
  195. if (data.searchPath.indexOf('CAMID("::') > -1) {
  196. return false;
  197. } else if (data.searchPath.indexOf('CAMID(":') > -1) {
  198. return true;
  199. }
  200. },
  201. _canDeleteObject: function _canDeleteObject(data) {
  202. if (/^CAMID\(\"\w*::/.test(data.searchPath) === true) {
  203. return false;
  204. } else if (data.id !== this.glassContext.profile.account.id) {
  205. return true;
  206. }
  207. return false;
  208. },
  209. isContextMenuItemVisible: function isContextMenuItemVisible(itemId, data) {
  210. var visible = false;
  211. var intersectionContextMenus = [];
  212. _.each(data, function (item) {
  213. var itemsContextMenus = this._getItemsContextMenus(item);
  214. if (intersectionContextMenus.length > 0) {
  215. intersectionContextMenus = _.intersection(intersectionContextMenus, itemsContextMenus);
  216. } else {
  217. intersectionContextMenus = itemsContextMenus;
  218. }
  219. }.bind(this));
  220. if (_.indexOf(intersectionContextMenus, itemId) !== -1) {
  221. visible = true;
  222. }
  223. if (data.length > 1 && (itemId === 'property' || itemId === 'members')) {
  224. visible = false;
  225. }
  226. return visible;
  227. },
  228. onContextMenu: function onContextMenu(id, data) {
  229. //NOSONAR
  230. var securityExplorer = data.securityObject;
  231. if (securityExplorer.parent.slideout.child) {
  232. securityExplorer.parent.slideout.child.hide();
  233. }
  234. var selectionType;
  235. if (data.length > 1) {
  236. for (var i = 0; i < data.length; ++i) {
  237. if (data[i].objectClass === "role") {
  238. selectionType = "role";
  239. break;
  240. }
  241. }
  242. } else {
  243. selectionType = data[0].objectClass;
  244. }
  245. switch (id) {
  246. case 'delete':
  247. securityExplorer._deleteAccountObj(data);
  248. break;
  249. case 'deleteUserProfile':
  250. securityExplorer._deleteUserProfileObj(data);
  251. break;
  252. case 'createUserProfile':
  253. securityExplorer.createUserProfile(data);
  254. break;
  255. case 'copyUserProfile':
  256. securityExplorer._copyUserProfileObj(data);
  257. break;
  258. case 'members':
  259. securityExplorer.showProperties(data[0], 'bi/admin/account/ui/MembersTab');
  260. break;
  261. case 'addMemberToRole':
  262. if (selectionType === "role") {
  263. securityExplorer._openSecurityObjectSelectorPane(data, 'role');
  264. } else {
  265. securityExplorer._openSecurityObjectSelectorPane(data, 'group,role');
  266. }
  267. break;
  268. case 'property':
  269. securityExplorer.showProperties(data[0]);
  270. break;
  271. case 'copyOrMove':
  272. var dialog = new CopyMoveDialog({
  273. 'title': StringResource.get('copyOrMove'),
  274. 'viewClass': SecurityObjectExplorerCopyMoveView,
  275. 'cssClass': 'contentListDialog',
  276. 'titleAriaLabel': CopyMoveDialog.getAriaLabelForDialogTitle('copyMoveDialog', data),
  277. 'viewOptions': {
  278. glassContext: this.glassContext,
  279. showBreadcrumbs: true,
  280. parent: data.securityObject,
  281. includeToolbar: true,
  282. inputObjects: data,
  283. type: 'copyMoveDialog',
  284. hideSearch: true,
  285. cognosNamespaceOnly: true,
  286. allowedSelectionTypes: 'Folders',
  287. onHide: function onHide() {
  288. this.parent.refresh();
  289. }
  290. }
  291. });
  292. dialog.open();
  293. break;
  294. default:
  295. }
  296. },
  297. getColumnSpecs: function getColumnSpecs() {
  298. var cols = SecurityObjectExplorerAdaptor.inherited('getColumnSpecs', this, arguments);
  299. cols.push({
  300. 'type': 'ContextMenu',
  301. 'width': '10%',
  302. 'module': 'bacontentnav/common/ui/list_columns/ContextMenu'
  303. });
  304. return cols;
  305. },
  306. init: function init(options) {
  307. if (_.isUndefined(options)) {
  308. options = {};
  309. }
  310. options.allowedSelectionTypes = ['namespaceFolder', 'group', 'role', 'account'];
  311. options.cognosNamespaceOnly = false;
  312. SecurityObjectExplorerAdaptor.inherited('init', this, arguments);
  313. $.extend(this, options);
  314. },
  315. _getAvailableNamespaces: function _getAvailableNamespaces() {
  316. return this._accountExplorer.getNamespaces();
  317. }
  318. });
  319. return SecurityObjectExplorerAdaptor;
  320. });