SecurityObjectSelectorAdaptor.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: Cognos Analytics
  5. * Copyright IBM Corp. 2015, 2018
  6. * US Government Users Restricted Rights - Use, duplication or disclosure
  7. * restricted by GSA ADP Schedule Contract with IBM Corp.
  8. */
  9. define(['underscore', 'bi/admin/nls/StringResource', 'bi/admin/common/ui/listview/ListDataAdaptor'], function (_, StringResource, ListDataAdaptor) {
  10. var SecurityObjectSelectorAdaptor = ListDataAdaptor.extend({
  11. supportPaging: true,
  12. pageSize: 50,
  13. sortChanged: false,
  14. pagingWhileSearching: false,
  15. getColumnSpecs: function getColumnSpecs() {
  16. return [{
  17. 'type': 'Icon'
  18. }, {
  19. 'type': 'MultipleProperties',
  20. 'label': StringResource.get('name'),
  21. 'sortable': true,
  22. 'scope': 'row',
  23. 'items': [{
  24. 'type': 'Text',
  25. 'module': 'bi/admin/common/ui/listview/columns/SecurityObject',
  26. 'label': StringResource.get('name'),
  27. 'propertyName': 'defaultName',
  28. 'sortable': true,
  29. 'scope': 'row',
  30. 'enableAccountItemLink': this.enableAccountItemLink
  31. }, {
  32. 'type': 'Location',
  33. 'module': 'bi/admin/common/ui/listview/columns/SecurityObjectLocation',
  34. 'showAsActiveLink': false,
  35. 'clickCallback': this.locationChanged.bind(this)
  36. }]
  37. }, {
  38. 'type': 'Time',
  39. 'module': 'bi/admin/common/ui/listview/columns/SecurityObjectTime',
  40. 'label': StringResource.get('lastModified'),
  41. 'propertyName': 'modificationTime',
  42. 'sortable': true
  43. }];
  44. },
  45. locationChanged: function locationChanged(oData) {
  46. this._accountExplorer.setPathStack(oData.ancestors);
  47. var currentObj = oData.ancestors[oData.ancestors.length - 1];
  48. this.trigger('locationChanged', {
  49. 'data': currentObj,
  50. 'isFolderNav': false
  51. });
  52. },
  53. init: function init(options) {
  54. SecurityObjectSelectorAdaptor.inherited('init', this, arguments);
  55. $.extend(this, options);
  56. this.columnSpecs = this.getColumnSpecs();
  57. this.isGetMoreData = false;
  58. this.isGetLessData = false;
  59. },
  60. shouldShowFilter: function shouldShowFilter() {
  61. var showFilterUI = _.isUndefined(this.hideFilter) || !this.hideFilter;
  62. var canFilter = !_.isUndefined(this.allowedSelectionTypes) && this.allowedSelectionTypes.length > 1;
  63. return showFilterUI && canFilter;
  64. },
  65. isBrowse: function isBrowse() {
  66. return _.isUndefined(this.searchText) || this.searchText === "";
  67. },
  68. getItems: function getItems(searchPerformed) {
  69. if (this.isBrowse()) {
  70. this._getItemsForBrowsing();
  71. return Promise.resolve();
  72. } else if (this.isSearching && !searchPerformed) {
  73. if (this.isGetMoreData) {
  74. return this.getNextSearchPage(true);
  75. } else if (this.isGetLessData) {
  76. return this.getNextSearchPage(false);
  77. } else {
  78. return this._getSearchResult();
  79. }
  80. } else {
  81. this._doCommonFiltering(this._getGroupedContent());
  82. return Promise.resolve(this._accountExplorer._content);
  83. }
  84. },
  85. getNextSearchPage: function getNextSearchPage(isPageDown) {
  86. return this._accountExplorer.getNextSearchPage(isPageDown).then(function () {
  87. this._doCommonFiltering(this._getGroupedContent());
  88. }.bind(this));
  89. },
  90. _getSearchResult: function _getSearchResult() {
  91. return this._accountExplorer.search(this.searchText, this.searchType).then(function () {
  92. this._doCommonFiltering(this._getGroupedContent());
  93. }.bind(this));
  94. },
  95. _getAvailableNamespaces: function _getAvailableNamespaces() {
  96. var items = this._accountExplorer.getNamespaces(); //remove all namespaces that we are not logged into
  97. items = _.filter(items, function (item) {
  98. return item.auth;
  99. });
  100. return items;
  101. },
  102. _getGroupedContent: function _getGroupedContent() {
  103. var gc = this._accountExplorer.getGroupedContent();
  104. var items;
  105. if (this._filterType) {
  106. items = [].concat(gc.namespaceFolder, this._filterType.account ? gc['account'] : '', this._filterType.group ? gc['group'] : '', this._filterType.role ? gc['role'] : '');
  107. } else {
  108. items = [].concat(gc.namespaceFolder, gc['account'], gc['group'], gc['role']);
  109. }
  110. return items;
  111. },
  112. _getItemsForBrowsing: function _getItemsForBrowsing() {
  113. var path = this._accountExplorer.getCurrentPath();
  114. $(this).trigger("ldapBrowsingEvent", path.type);
  115. var items;
  116. if (path.type === 'directory') {
  117. items = this._getAvailableNamespaces();
  118. if (this.cognosNamespaceOnly) {
  119. items = _.filter(items, function (item) {
  120. return item.defaultName === "Cognos";
  121. });
  122. }
  123. } else {
  124. if (this.isGetMoreData) {
  125. this._accountExplorer.getNextBrowsePage(true);
  126. } else if (this.isGetLessData) {
  127. this._accountExplorer.getNextBrowsePage(false);
  128. }
  129. items = this._getGroupedContent();
  130. }
  131. this._doCommonFiltering(items);
  132. this.trigger('pathChanged', this._accountExplorer.getPathStack());
  133. },
  134. _doCommonFiltering: function _doCommonFiltering(items) {
  135. //NOSONAR
  136. var itemObjs = [];
  137. _.each(items, function (item) {
  138. //NOSONAR
  139. var shouldPush = true;
  140. if (item.type === 'account' && item.userName) {
  141. if (item.givenName && item.surname) {
  142. item.defaultName = item.givenName + ' ' + item.surname + ' (' + item.userName + ')';
  143. } else if (item.defaultName) {
  144. item.defaultName = item.defaultName + ' (' + item.userName + ')';
  145. }
  146. }
  147. if (this.objectInfo) {
  148. var objIdMatch = item.id !== object.id;
  149. var isAddMemberToCheck = this.isAddMemberTo && objIdMatch && !this._isEveryoneGroup(item) && //NOSONAR
  150. !this._isAllAuthUserGroup(item) && item.permissions.indexOf('write') > -1;
  151. shouldPush = isAddMemberToCheck || !this.isAddMemberTo && objIdMatch;
  152. }
  153. if (!_.isUndefined(this.allowedSelectionTypes)) {
  154. if (item.type === 'namespace' || item.type === 'namespaceFolder') {
  155. shouldPush = true;
  156. } else {
  157. if (_.contains(this.allowedSelectionTypes, item.type)) {
  158. shouldPush = true;
  159. } else {
  160. shouldPush = false;
  161. }
  162. }
  163. }
  164. if (shouldPush) {
  165. itemObjs.push(item);
  166. }
  167. }.bind(this));
  168. this.items = itemObjs;
  169. if (this._accountExplorer.pagingEnabled && this._accountExplorer.pagerControl) {
  170. this._accountExplorer.pagerControl.store.updatePager(this._accountExplorer, {}, this);
  171. }
  172. },
  173. _getRowsObj: function _getRowsObj(searchPerformed) {
  174. return this.getItems(searchPerformed).then(function () {
  175. return {
  176. rows: this.items,
  177. hasMore: false
  178. };
  179. }.bind(this));
  180. },
  181. getRows: function getRows() {
  182. if (this.pagingWhileSearching) {
  183. return this._getRowsObj(true);
  184. } else if (this.sortChanged) {
  185. return this._accountExplorer.selectPath(_.last(this._accountExplorer.getPathStack())).then(function () {
  186. this.sortChanged = false;
  187. return this._getRowsObj();
  188. }.bind(this));
  189. } else {
  190. return this._getRowsObj();
  191. }
  192. },
  193. setOrder: function setOrder(index, nextOrder) {
  194. this.sortChanged = true;
  195. var aCol = this.getColumnSpecs()[index];
  196. var sortProperty;
  197. if (aCol.type === 'MultipleProperties') {
  198. var colItems = aCol.items;
  199. sortProperty = colItems[0].propertyName;
  200. } else {
  201. sortProperty = this.getColumnSpecs()[index].propertyName;
  202. }
  203. this._accountExplorer.sortColumnName = sortProperty;
  204. this._accountExplorer.sortOrder = nextOrder;
  205. },
  206. hasMore: function hasMore() {
  207. return false;
  208. },
  209. _isEveryoneGroup: function _isEveryoneGroup(obj) {
  210. return obj.searchPath.indexOf("CAMID(\"::Everyone") >= 0;
  211. },
  212. _isAllAuthUserGroup: function _isAllAuthUserGroup(obj) {
  213. return obj.searchPath.indexOf("CAMID(\"::All Authenticated Users") >= 0;
  214. },
  215. rowClickHandler: function rowClickHandler(aSecExplorer, oData) {
  216. //NOSONAR
  217. if (oData.type === "namespace" && !oData.auth && !_.contains(this.allowedSelectionTypes, 'namespace')) {
  218. aSecExplorer.glassContext.appController.showToast(StringResource.get('noSigninToViewErrorMsg'), {
  219. type: 'error'
  220. });
  221. return;
  222. }
  223. if ((oData.type === "namespaceFolder" || oData.type === "namespace") && oData.permissions.indexOf("traverse") === -1 && !_.contains(this.allowedSelectionTypes, 'namespace')) {
  224. aSecExplorer.glassContext.appController.showToast(StringResource.get('noTraversePermissionErrorMsg'), {
  225. type: 'error'
  226. });
  227. return;
  228. }
  229. if ((oData.type === 'role' || oData.type === 'group') && !oData.hasChildren) {
  230. //for roles and groups if they do not have children then do nothing
  231. return;
  232. }
  233. switch (oData.type) {
  234. case 'namespace':
  235. this._accountExplorer.selectNamespace(oData).then(aSecExplorer.updateForNavigate.bind(aSecExplorer));
  236. break;
  237. case 'namespaceFolder':
  238. this._accountExplorer.selectFolder(oData).then(aSecExplorer.updateForNavigate.bind(aSecExplorer, oData));
  239. break;
  240. case 'group':
  241. this._accountExplorer.selectGroup(oData).then(aSecExplorer.updateForNavigate.bind(aSecExplorer));
  242. break;
  243. case 'role':
  244. this._accountExplorer.selectRole(oData).then(aSecExplorer.updateForNavigate.bind(aSecExplorer));
  245. break;
  246. case 'account':
  247. break;
  248. default:
  249. }
  250. }
  251. });
  252. return SecurityObjectSelectorAdaptor;
  253. });