SecurityObjectExplorerView.js 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: Cognos Analytics
  5. * Copyright IBM Corp. 2015, 2020
  6. * US Government Users Restricted Rights - Use, duplication or disclosure
  7. * restricted by GSA ADP Schedule Contract with IBM Corp.
  8. */
  9. define(['q', 'underscore', 'doT', 'bi/commons/utils/Utils', 'bi/admin/account/AccountExplorer', 'bi/admin/common/ui/MagicWand', 'bacontentnav/common/ui/Breadcrumbs', 'bi/commons/ui/AccessibleView', 'bi/admin/common/ui/listview/ListView', 'bi/admin/nls/StringResource', 'bacontentnav/common/ui/ContentGenericDialog', 'text!bi/admin/account/templates/SecurityObjectExplorerTemplate.html', 'text!bi/admin/account/templates/CreateNewGroupTemplate.html', 'text!bi/admin/account/templates/CreateNewUserTemplate.html', 'bi/admin/common/utils/AJAXUtils', 'bi/commons/utils/BidiUtil', 'bi/commons/utils/ContentFormatter', 'bi/commons/ui/properties/PropertyUIControl', 'bacontentnav/common/ui/contentbar_components/Button', 'react-dom', 'react', 'ba-react-admin/ba-react-admin.min', 'bi/admin/common/Uploader'], function (Q, _, dot, Utils, AccountExplorer, MagicWand, Breadcrumbs, View, ListView, StringResource, ContentGenericDialog, SecurityObjectExplorerTemplate, CreateNewGroupTemplate, CreateNewUserTemplate, AJAXUtils, BidiUtil, ContentFormatter, PropertyUIControl, Button, ReactDOM, React, AdminReact, Uploader) {
  10. 'use strict'; //NOSONAR: meant to be strict
  11. var SecurityObjectExplorerView = View.extend({
  12. showBreadcrumbs: true,
  13. defaultTypes: ['namespaceFolder', 'group', 'role', 'account'],
  14. _breadCrumbs: null,
  15. _accountExplorer: null,
  16. listAdaptor: null,
  17. init: function init(options) {
  18. SecurityObjectExplorerView.inherited('init', this, arguments);
  19. this.glassContext = options.glassContext;
  20. if (!this._accountExplorer && options.accountExplorer) {
  21. this._accountExplorer = options.accountExplorer;
  22. } else {
  23. this._accountExplorer = this._getNewAccountExplorer({
  24. glassContext: options.glassContext
  25. });
  26. }
  27. this.listAdaptor = options.listAdaptor;
  28. this.parent = options.parent;
  29. this.includeToolbar = options.includeToolbar ? options.includeToolbar : false;
  30. this.hideSearch = options.hideSearch;
  31. this.filterPushed = false;
  32. this.hidePaging = options.hidePaging;
  33. this.pagingEnabled = false;
  34. this.filterStringValue = {
  35. 'group': true,
  36. 'account': true,
  37. 'role': true
  38. };
  39. },
  40. _getNewAccountExplorer: function _getNewAccountExplorer(options) {
  41. return new AccountExplorer(options);
  42. },
  43. _getLdapStatus: function _getLdapStatus() {
  44. var options = {
  45. dataType: 'json',
  46. type: 'GET',
  47. data: {},
  48. url: AJAXUtils.getAJAXURL("ldapStatus"),
  49. cache: false
  50. };
  51. return this.glassContext.services.ajax.ajax(options);
  52. },
  53. _showPaging: function _showPaging() {
  54. // this checks if we want to show paging in a component. For example we want to hide it in accounts copy/move view.
  55. return _.isUndefined(this.hidePaging) || !this.hidePaging;
  56. },
  57. _populatePagingStatusAndValue: function _populatePagingStatusAndValue() {
  58. var pagingEnabled = this._checkIfPagingIsEnabled();
  59. var pagingValue = this._getPagingValue();
  60. return Promise.all([pagingEnabled, pagingValue]).then(function (responses) {
  61. this.pagingEnabled = responses[1] === 'true';
  62. this.pagingValueSet = parseInt(responses[0]);
  63. }.bind(this));
  64. },
  65. _renderPagingWidget: function _renderPagingWidget() {
  66. if (this.pagingEnabled && this._showPaging()) {
  67. this._accountExplorer.pagingEnabled = this.pagingEnabled;
  68. this._accountExplorer.pagingValueSet = this.pagingValueSet;
  69. this._accountExplorer.searchPageSize = this.pagingValueSet;
  70. var pagingBar = React.createElement(AdminReact.Pagination, {
  71. 'glassContext': this.glassContext,
  72. 'StringResource': StringResource,
  73. 'accountExplorer': this._accountExplorer,
  74. 'listView': this.listView,
  75. 'defaultPagingValue': this.pagingValueSet,
  76. 'listAdaptor': this.listAdaptor
  77. });
  78. this.pagerControl = ReactDOM.render(pagingBar, this.$el.find('.bi-admin-account-pagingBar')[0]);
  79. this._accountExplorer.pagerControl = this.pagerControl;
  80. this.$el.find('.bi-admin-account-pagingBar').hide();
  81. $(this.listAdaptor).on("ldapBrowsingEvent", function (event, type) {
  82. this._updatePagingBar(type);
  83. }.bind(this));
  84. }
  85. },
  86. _checkIfPagingIsEnabled: function _checkIfPagingIsEnabled() {
  87. var endpoint = "v1/configuration/keys/Admin.namespaceChildrenPerPage";
  88. var pagingSettingsPromise = this.glassContext.services.fetch.get(endpoint);
  89. return pagingSettingsPromise.then(function (response) {
  90. return response.data['Admin.namespaceChildrenPerPage'];
  91. });
  92. },
  93. _getPagingValue: function _getPagingValue() {
  94. var endpoint = "v1/configuration/keys/Admin.enableNamespaceChildrenPaging";
  95. var pagingValuePromise = this.glassContext.services.fetch.get(endpoint);
  96. return pagingValuePromise.then(function (response) {
  97. return response.data['Admin.enableNamespaceChildrenPaging'];
  98. });
  99. },
  100. _renderTemplate: function _renderTemplate() {
  101. var paneInfo = {
  102. 'strings': {
  103. 'type': StringResource.get('type'),
  104. 'addNewUser': StringResource.get('addNewUser'),
  105. 'addNewGroup': StringResource.get('addNewGroup'),
  106. 'addNewRole': StringResource.get('addNewRole'),
  107. 'addNewFolder': StringResource.get('addNewFolder'),
  108. 'import': StringResource.get('import')
  109. },
  110. showFilter: this.listAdaptor.shouldShowFilter()
  111. };
  112. var sHtml = dot.template(SecurityObjectExplorerTemplate)(paneInfo);
  113. this.$el.html(sHtml);
  114. BidiUtil.initElementForBidi(this.$el.find(".bi-admin-input.bi-admin-input-search")[0]);
  115. this.myAccount = React.createElement(AdminReact.UserWidget, {
  116. 'parent': this,
  117. 'glassContext': this.glassContent,
  118. 'StringResource': StringResource,
  119. 'clickFunc': this._createObj.bind(this),
  120. 'importOpenIdFunc': this.importOpenId.bind(this),
  121. 'importFunc': this.importFunc.bind(this),
  122. 'label': 'First Label'
  123. });
  124. ReactDOM.render(this.myAccount, this.$el.find('.bi-admin-account-createNewBar')[0]); //init to hide create bar before get ldap status and checking permissions
  125. this.$el.find('.bi-admin-account-createNewBar').hide();
  126. this.$el.find('.multiUploadText').text(StringResource.get('importText'));
  127. },
  128. importFunc: function importFunc(selectedOption) {
  129. if (selectedOption === 'importUsers') {
  130. //import users
  131. this.importOpenId('users');
  132. } else if (selectedOption === 'importGroups') {
  133. //import groups
  134. this.importOpenId('groups');
  135. }
  136. },
  137. _updateOrUploadUsers: function _updateOrUploadUsers(options) {
  138. var pid = this._accountExplorer.getCurrentPath().id;
  139. var requestOptions = {
  140. 'headers': {
  141. 'Content-Type': 'text/csv'
  142. },
  143. 'url': 'v1/users?pid=' + pid,
  144. 'type': 'POST',
  145. 'data': options.data,
  146. 'Content-Length': options.byteLength,
  147. 'processData': false
  148. };
  149. return this.glassContext.services.ajax.ajax(requestOptions);
  150. },
  151. _updateOrUploadGroups: function _updateOrUploadGroups(options) {
  152. var pid = this._accountExplorer.getCurrentPath().id;
  153. var requestOptions = {
  154. 'headers': {
  155. 'Content-Type': 'text/csv'
  156. },
  157. 'url': 'v1/groups?pid=' + pid,
  158. 'type': 'POST',
  159. 'data': options.data,
  160. 'Content-Length': options.byteLength,
  161. 'processData': false
  162. };
  163. return this.glassContext.services.ajax.ajax(requestOptions);
  164. },
  165. _createUploader: function _createUploader(type) {
  166. if (type === 'users') {
  167. return new Uploader({
  168. 'glassContext': this.glassContext,
  169. '$el': this.$el,
  170. 'fileType': 'csv',
  171. 'ajax': this._updateOrUploadUsers.bind(this),
  172. 'ajaxOptions': {}
  173. });
  174. } else if (type === 'groups') {
  175. return new Uploader({
  176. 'glassContext': this.glassContext,
  177. '$el': this.$el,
  178. 'fileType': 'csv',
  179. 'ajax': this._updateOrUploadGroups.bind(this),
  180. 'ajaxOptions': {}
  181. });
  182. }
  183. },
  184. _refreshAccountListPane: function _refreshAccountListPane(isCreatingObject) {
  185. if (this.pagingEnabled) {
  186. this.listAdaptor.sortChanged = false;
  187. AdminReact.PaginationHelper.reloadListViewinPagingContext(this.glassContext, this._accountExplorer, this.listView, this.listAdaptor, isCreatingObject);
  188. } else {
  189. this.listAdaptor.sortChanged = true;
  190. this.listView.reload(false);
  191. }
  192. },
  193. importOpenId: function importOpenId(type) {
  194. var fileUploader = this._createUploader(type);
  195. return fileUploader.doUpload().then(function () {
  196. this._refreshAccountListPane(true);
  197. }.bind(this), function (err) {
  198. this.glassContext.appController.showErrorMessage(StringResource.get('OIDCErrorSuggestion', {
  199. serverError: err.responseJSON.messages
  200. }), StringResource.get('error'));
  201. }.bind(this));
  202. },
  203. changeBrowseSearch: function changeBrowseSearch(isBrowsing) {
  204. var elList = this.$el.find('.bi-admin-account-list');
  205. if (isBrowsing) {
  206. this._accountExplorer.newSearch();
  207. this.listView.setPaging(true);
  208. elList.addClass("security-browsing");
  209. } else {
  210. this.listView.setPaging(true);
  211. elList.removeClass("security-browsing");
  212. }
  213. },
  214. _renderSearch: function _renderSearch() {
  215. var rSearch = this.$el.find(".bi-admin-filterbar-leading");
  216. var searchComp = React.createElement(AdminReact.AdminSearchInput, {
  217. 'parent': this,
  218. StringResource: StringResource,
  219. placeholder: StringResource.get('filterTips'),
  220. onSearch: function (evt, newValue, searchType) {
  221. var isBrowsing = newValue === "";
  222. this.listView.setPaging(false);
  223. this.listAdaptor.searchText = encodeURIComponent(newValue.trim());
  224. this.listAdaptor.searchType = searchType;
  225. this.listAdaptor.isSearching = true;
  226. this._accountExplorer.clearGroupedContent();
  227. this.listView._clearTable();
  228. this.listView.showWorking();
  229. if (!isBrowsing) {
  230. this.listView.reload(false).then(function () {
  231. this.changeBrowseSearch(isBrowsing);
  232. if (this.pagingEnabled && this.pagerControl) {
  233. this.pagerControl.store.updatePager(this._accountExplorer, this.listView, this.listAdaptor);
  234. }
  235. }.bind(this));
  236. } else {
  237. this._accountExplorer.selectCurrentPath().then(function () {
  238. this.listView.reload(false).then(function () {
  239. this.changeBrowseSearch(isBrowsing);
  240. this._clearSearch();
  241. }.bind(this));
  242. }.bind(this));
  243. }
  244. }.bind(this),
  245. ref: function (searchInput) {
  246. this._searchInput = searchInput;
  247. }.bind(this),
  248. onClear: function (e) {
  249. var isBrowsing = true;
  250. this.listView.setPaging(false);
  251. this.listAdaptor.searchText = "";
  252. this._accountExplorer.clearGroupedContent();
  253. this._accountExplorer.selectCurrentPath().then(function () {
  254. this.listView.reload(false).then(function () {
  255. this.changeBrowseSearch(isBrowsing);
  256. }.bind(this));
  257. if (this.pagingEnabled && this.pagerControl) {
  258. this._clearSearch();
  259. }
  260. }.bind(this));
  261. }.bind(this)
  262. });
  263. ReactDOM.render(searchComp, rSearch[0]);
  264. $(this.listAdaptor).on("ldapBrowsingEvent", function (event, type) {
  265. this._updateFilterBar(type);
  266. }.bind(this));
  267. },
  268. _clearSearch: function _clearSearch() {
  269. this.pagerControl.store.updatePager(this._accountExplorer, this.listView, this.listAdaptor);
  270. this.listAdaptor.isSearching = undefined;
  271. },
  272. _initializeAccountExplorer: function _initializeAccountExplorer() {
  273. var deferred = Q.defer();
  274. this._accountExplorer._defaultTypes = this.defaultTypes;
  275. this._accountExplorer.startUp().done(function () {
  276. if (this.listAdaptor.cognosNamespaceOnly) {
  277. this._accountExplorer.selectNamespace("Cognos").done(function () {
  278. this._updateAccountExplorerInit().done(function () {
  279. this.filterStringValue.account = false;
  280. this.filterStringValue.role = true;
  281. if (this.listAdaptor.allowedSelectionTypes === "role") {
  282. this.filterStringValue.group = false;
  283. } else {
  284. this.filterStringValue.group = true;
  285. }
  286. deferred.resolve();
  287. }.bind(this));
  288. }.bind(this));
  289. } else {
  290. this._updateAccountExplorerInit().done(function () {
  291. this.filterStringValue.account = true;
  292. this.filterStringValue.role = true;
  293. this.filterStringValue.group = true;
  294. deferred.resolve();
  295. }.bind(this));
  296. }
  297. }.bind(this));
  298. return deferred.promise;
  299. },
  300. _updateAccountExplorerInit: function _updateAccountExplorerInit() {
  301. var deferred = Q.defer();
  302. this._getLdapStatus().done(function (result) {
  303. this._ldapStatus = !!result['ads-state'];
  304. this._configToolBar();
  305. deferred.resolve();
  306. }.bind(this));
  307. this.listAdaptor._accountExplorer = this._accountExplorer;
  308. this.listAdaptor.on('pathChanged', function (path) {
  309. this._updateBreadcrumb(path);
  310. this.listAdaptor.off('locationChanged');
  311. this.listAdaptor.on("locationChanged", function (obj) {
  312. this._navigate(obj.data);
  313. }.bind(this));
  314. }.bind(this));
  315. return deferred.promise;
  316. },
  317. _renderListView: function _renderListView() {
  318. var deferred = Q.defer();
  319. var elList = this.$el.find('.bi-admin-account-list');
  320. elList.addClass("security-browsing");
  321. elList.empty();
  322. this.listView = this._getNewListView({
  323. el: elList,
  324. dataAdaptor: this.listAdaptor,
  325. glassContext: this.glassContext,
  326. accessibleLabel: this.title,
  327. activeInputForm: null,
  328. multiSelect: true,
  329. onSelectionChange: this.onSelectionChange
  330. });
  331. this.listView.singleSelectCallback = this._rowClickHandler.bind(this);
  332. if (this.listAdaptor.contextMenuHandler) {
  333. this.listView.contextMenuCallback = this.listAdaptor.contextMenuHandler.bind(this.listAdaptor, this);
  334. }
  335. this.listView.render().then(function () {
  336. if (!this.pagingEnabled) {
  337. this._bindListViewEvents();
  338. }
  339. }.bind(this)).then(deferred.resolve, deferred.reject);
  340. return deferred.promise;
  341. },
  342. refresh: function refresh() {
  343. this._refreshAccountListPane();
  344. },
  345. _getNewListView: function _getNewListView(options) {
  346. return new ListView(options);
  347. },
  348. _bindListViewEvents: function _bindListViewEvents() {
  349. $(this.listView).on("previousPage", function () {
  350. if (!this._accountExplorer.isTopOfPage()) {
  351. this.listView.setPaging(false);
  352. this._accountExplorer.cacheOldContent();
  353. this._accountExplorer.clearGroupedContent();
  354. this._accountExplorer.selectCurrentPath().then(function () {
  355. this.listAdaptor.isGetLessData = true;
  356. this.listView.reload(false).then(function () {
  357. this.changeBrowseSearch(false);
  358. this.listAdaptor.isGetLessData = false;
  359. this.listView.setPaging(true);
  360. }.bind(this));
  361. }.bind(this));
  362. }
  363. }.bind(this));
  364. $(this.listView).on("nextPage", function () {
  365. if (!this.scrollCausedByRowClick && !this._accountExplorer.noMoreData) {
  366. this.listView.setPaging(false);
  367. this._accountExplorer.cacheOldContent();
  368. this._accountExplorer.clearGroupedContent();
  369. this._accountExplorer.selectCurrentPath().then(function () {
  370. this.listAdaptor.isGetMoreData = true;
  371. this.listView.reload(false).then(function () {
  372. this.changeBrowseSearch(false);
  373. this.listAdaptor.isGetMoreData = false;
  374. this.listView.adjustScrollForPageDown();
  375. this.listView.setPaging(true);
  376. }.bind(this));
  377. }.bind(this));
  378. } else {
  379. delete this.scrollCausedByRowClick;
  380. }
  381. }.bind(this));
  382. },
  383. clearShowWorking: function clearShowWorking() {
  384. this.$el.find(".adminAccountsShowWorking").remove();
  385. },
  386. showWorking: function showWorking() {
  387. var loadingAnimation = Utils.getLoadingAnimation(1);
  388. var $container = $('<div class="adminAccountsShowWorking emptyTableContent bi-admin-working"></div>');
  389. $container.append(loadingAnimation);
  390. this.$el.append($container);
  391. },
  392. render: function render() {
  393. var deferred = Q.defer();
  394. this._renderTemplate();
  395. this.showWorking();
  396. var accountsPagingStatus = this._populatePagingStatusAndValue().catch(function (err) {
  397. this.pagingEnabled = false;
  398. this.logger.error(err);
  399. }.bind(this));
  400. this._renderSearch();
  401. this._initializeAccountExplorer().then(function () {
  402. return accountsPagingStatus;
  403. }).then(this._renderListView.bind(this)).then(function () {
  404. this._bindEvents();
  405. this._renderPagingWidget();
  406. this.clearShowWorking();
  407. }.bind(this)).then(deferred.resolve, deferred.reject);
  408. return deferred.promise;
  409. },
  410. _bindFilter: function _bindFilter() {
  411. if (!this.filterPushed) {
  412. this.filterPushed = true;
  413. this.glassContext.appController.showSlideOut({
  414. 'parent': this.parent.slideout,
  415. 'position': 'left',
  416. 'width': '200px',
  417. 'content': {
  418. 'parentView': this,
  419. 'glassContext': this.glassCtxt,
  420. 'showSwitchButton': true,
  421. 'module': 'bi/admin/account/slideout/UserGroupSelectorPane',
  422. 'view': this,
  423. 'callback': this
  424. }
  425. }).on('hide', function () {
  426. this.filterPushed = false;
  427. }.bind(this));
  428. }
  429. },
  430. getSelectedObjects: function getSelectedObjects() {
  431. return this.listView.getSelectedObjects();
  432. },
  433. _getFilterBar: function _getFilterBar() {
  434. return this.$el.find(".bi-admin-filterbar.folderpane-filterbar");
  435. },
  436. _getPaginBar: function _getPaginBar() {
  437. return this.$el.find(".bi-admin-account-pagingBar");
  438. },
  439. _updateFilterBar: function _updateFilterBar(type) {
  440. var filterBar = this._getFilterBar();
  441. this._hideBar(filterBar, type);
  442. },
  443. _updatePagingBar: function _updatePagingBar(type) {
  444. var pagingBar = this._getPaginBar();
  445. this._hideBar(pagingBar, type);
  446. },
  447. _hideBar: function _hideBar(bar, type) {
  448. if (type === "directory") {
  449. bar.css("display", "none");
  450. } else {
  451. bar.css("display", "block");
  452. }
  453. },
  454. _bindEvents: function _bindEvents() {
  455. this.$el.find('.multiUploadBtn').on('primaryaction', function () {}.bind(this));
  456. var $filterButton = this.$el.find('#filterDef').on('primaryaction', function () {
  457. this._bindFilter();
  458. }.bind(this));
  459. var $label = $('<span class="bi-admin-filter-icon">');
  460. $label.text(this._filterString(this.filterStringValue));
  461. ContentFormatter.middleShortenString($label);
  462. $label.appendTo($filterButton);
  463. },
  464. setFocus: function setFocus() {
  465. this.$el.find('.bi-admin-filterbar-leading input').focus();
  466. },
  467. setFocusOnAccountList: function setFocusOnAccountList() {
  468. if (!this.listView.setFocus()) {
  469. this.setFocus();
  470. }
  471. },
  472. _filterString: function _filterString(filterString) {
  473. var types = ['account', 'role', 'group'];
  474. var filters = 0;
  475. var labelString;
  476. for (var i = 0; i < types.length; i++) {
  477. if (filterString[types[i]]) {
  478. if (filters === 0) {
  479. labelString = StringResource.get(types[i]);
  480. } else {
  481. labelString = labelString.concat(',').concat(' ').concat(StringResource.get(types[i]));
  482. }
  483. filters++;
  484. }
  485. }
  486. if (filters === 0) {
  487. labelString = StringResource.get('none');
  488. } else if (filters === types.length) {
  489. labelString = StringResource.get('allMember');
  490. }
  491. return labelString;
  492. },
  493. _filter: function _filter(filterStr) {
  494. var $label = this.$el.find('.bi-admin-filter-icon');
  495. if ($label) {
  496. $label[0].title = '';
  497. }
  498. var labelString = this._filterString(filterStr);
  499. $label.text(labelString);
  500. ContentFormatter.middleShortenString($label[0]);
  501. this.listAdaptor._filterType = filterStr || '';
  502. this._accountExplorer._filterType = this.listAdaptor._filterType;
  503. this.listAdaptor._filterString = '';
  504. if (!this.pagingEnabled) {
  505. this.listView.reload(false);
  506. } else {
  507. AdminReact.PaginationHelper.reloadListViewinFilteredContext(this.glassContext, this._accountExplorer, this.listView, this.listAdaptor);
  508. }
  509. ;
  510. },
  511. updateForNavigate: function updateForNavigate(data) {
  512. if (!this.hideSearch) {
  513. this._searchInput.clearSearch();
  514. }
  515. this.changeBrowseSearch(true);
  516. this.listView.setPaging(false);
  517. this._accountExplorer.updateHasMoreData();
  518. this.listView.reload(false).done(function () {
  519. this.setFocusOnAccountList();
  520. this.listView.setPaging(true);
  521. if (this.pagingEnabled && this.pagerControl) {
  522. this.pagerControl.store.updatePager(this._accountExplorer, this.listView, this.listAdaptor);
  523. }
  524. }.bind(this));
  525. this._configToolBar(data);
  526. },
  527. _navigate: function _navigate(item) {
  528. this.listAdaptor.searchText = undefined;
  529. this._accountExplorer.selectPath(item).done(function () {
  530. this.updateForNavigate(item);
  531. }.bind(this, item));
  532. },
  533. _onNavigate: function _onNavigate(index) {
  534. var bc = this._breadCrumbs.ancestors;
  535. if (index >= bc.length - 1) {
  536. return;
  537. }
  538. var item = bc[index];
  539. this.scrollCausedByRowClick = true;
  540. this._navigate(item);
  541. },
  542. _checkCapabilities: function _checkCapabilities(capabilityName) {
  543. return _.find(this.glassContext.services.userProfile.capabilities, function (capability) {
  544. return capability === capabilityName;
  545. });
  546. },
  547. _canShowToolbar: function _canShowToolbar(ns) {
  548. return this._checkCapabilities('canUseUsersGroupsAndRolesTool') && (ns.defaultName === 'Cognos' || ns.defaultName === 'Cognos Users' || this._isNonBrowsableNamespace());
  549. },
  550. _isWriteable: function _isWriteable(permissions) {
  551. var retVal = false;
  552. _.find(permissions, function (permission) {
  553. retVal = permission === 'write';
  554. });
  555. return retVal;
  556. },
  557. _configToolBar: function _configToolBar(data) {
  558. //NOSONAR
  559. var createNewBar = this.$el.find('.bi-admin-account-createNewBar');
  560. createNewBar.css("padding", "initial");
  561. createNewBar.css("paddingTop", "5px");
  562. var filter = this.$el.find('.dropdown-toggle');
  563. var ns = this._accountExplorer.getCurrentNamespace();
  564. if (this._accountExplorer.tenantNsFolderId && this._accountExplorer.tenantNsFolderId !== 'xOg__' && this._accountExplorer.currentRequest === 'v1/namespaces/xOg__/items?') {
  565. this._accountExplorer.getFolderPermission(this._accountExplorer.tenantNsFolderId).then(function (tenantNsFolderPermissions) {
  566. this._renderConfigToolBar(data, createNewBar, filter, ns, tenantNsFolderPermissions);
  567. }.bind(this)).catch(function (e) {
  568. this.tenantNsFolderPermissions = null;
  569. this._renderConfigToolBar(data, createNewBar, filter, ns);
  570. }.bind(this));
  571. } else {
  572. this._renderConfigToolBar(data, createNewBar, filter, ns);
  573. }
  574. return Promise.resolve();
  575. },
  576. _renderConfigToolBar: function _renderConfigToolBar(data, createNewBar, filter, ns, tenantNsFolderPermissions) {
  577. createNewBar.find('.admin-import-dropdown').hide();
  578. if (!ns) {
  579. createNewBar.hide();
  580. filter.hide();
  581. } else if (this.type === 'copyMoveDialog') {
  582. if (ns.defaultName === 'Cognos') {
  583. createNewBar.find('#newGroup').hide();
  584. createNewBar.find('#newUser').hide();
  585. createNewBar.find('#newRole').hide();
  586. createNewBar.find('#newFolder').show();
  587. createNewBar.find('.admin-import-dropdown').hide();
  588. } else {
  589. createNewBar.find('#newGroup').hide();
  590. createNewBar.find('#newUser').hide();
  591. createNewBar.find('#newFolder').hide();
  592. createNewBar.find('#newRole').hide();
  593. createNewBar.find('.admin-import-dropdown').hide();
  594. }
  595. if (this._canShowToolbar(ns)) {
  596. createNewBar.show();
  597. } else {
  598. createNewBar.hide();
  599. }
  600. if (!this.includeToolbar) {
  601. createNewBar.hide();
  602. }
  603. filter.show();
  604. } else {
  605. //Check if non browsable namespace and is not a cloud evironment (doesn't have a tenented cognos ns folder)
  606. if (_.contains(ns.capabilities, 'notBrowsable') && this._isNotCloudEnviroment()) {
  607. createNewBar.find('#newUser').show();
  608. createNewBar.find('#newGroup').show();
  609. createNewBar.find('#newFolder').hide();
  610. createNewBar.find('#newRole').hide();
  611. createNewBar.find('.admin-import-dropdown').show();
  612. } else if (data && data.type === 'namespaceFolder' && this._isWriteable(data.permissions) || ns.defaultName === 'Cognos' && this._accountExplorer.tenantNsFolderId === 'xOg__' && this._isWriteable(ns.permissions) || ns.defaultName === 'Cognos' && this._accountExplorer.tenantNsFolderId !== 'xOg__' && this._isWriteable(tenantNsFolderPermissions)) {
  613. this._hideButtonBasedOnTargetType('group', createNewBar.find('#newGroup'));
  614. this._hideButtonBasedOnTargetType('folder', createNewBar.find('#newFolder'));
  615. this._hideButtonBasedOnTargetType('role', createNewBar.find('#newRole'));
  616. createNewBar.find('#newUser').hide();
  617. } else if (ns.defaultName === 'Cognos Users') {
  618. createNewBar.find('#newUser').show();
  619. createNewBar.find('#newGroup').hide();
  620. createNewBar.find('#newFolder').hide();
  621. createNewBar.find('#newRole').hide();
  622. } else {
  623. createNewBar.find('#newGroup').hide();
  624. createNewBar.find('#newUser').hide();
  625. createNewBar.find('#newFolder').hide();
  626. createNewBar.find('#newRole').hide();
  627. }
  628. if (this._canShowToolbar(ns)) {
  629. createNewBar.show();
  630. } else {
  631. createNewBar.hide();
  632. }
  633. filter.show();
  634. }
  635. },
  636. _isNotCloudEnviroment: function _isNotCloudEnviroment() {
  637. return this._accountExplorer.tenantNsFolderId === 'xOg__';
  638. },
  639. _hideButtonBasedOnTargetType: function _hideButtonBasedOnTargetType(buttonType, button) {
  640. if (!this.targetType || this.targetType.indexOf(buttonType) !== -1) {
  641. button.show();
  642. } else {
  643. button.hide();
  644. }
  645. },
  646. reloadList: function reloadList() {
  647. return this.listView.reload(false);
  648. },
  649. _rowClickHandler: function _rowClickHandler(oData) {
  650. this.scrollCausedByRowClick = true;
  651. if (this.listAdaptor.rowClickHandler) {
  652. this.listAdaptor.rowClickHandler(this, oData);
  653. }
  654. },
  655. _updateBreadcrumb: function _updateBreadcrumb(path) {
  656. var $breadcrumbs = this.$el.find('#breadcrumbs');
  657. if (this.showBreadcrumbs) {
  658. if (this._breadCrumbs) {
  659. this._breadCrumbs.updateBreadcrumb(path);
  660. } else {
  661. //render Breadcrumbs
  662. this._breadCrumbs = new Breadcrumbs({
  663. 'el': $breadcrumbs,
  664. 'label': StringResource.get('breadCrumbsAccessibleLabel'),
  665. 'breadcrumbs': [{
  666. defaultName: '',
  667. url: ''
  668. }],
  669. 'navigateCallback': this._onNavigate.bind(this)
  670. });
  671. this._breadCrumbs.ancestors = this._breadCrumbs.breadcrumbs;
  672. this._breadCrumbs.render();
  673. this._breadCrumbs.updateBreadcrumb(path);
  674. }
  675. }
  676. },
  677. _allowCreateUser: function _allowCreateUser() {
  678. var retVal = false;
  679. if (this._ldapStatus) {
  680. var path = this._accountExplorer.getCurrentPath();
  681. var isSignInCognos = false;
  682. _.each(this._accountExplorer.authNamespaces, function (authNamespace) {
  683. if (authNamespace.searchPath.split('"')[1] === 'CognosEx') {
  684. isSignInCognos = true;
  685. }
  686. });
  687. retVal = !!path && path.type === 'namespace' && path.defaultName === 'Cognos' && isSignInCognos;
  688. }
  689. return retVal;
  690. },
  691. _isNonBrowsableNamespace: function _isNonBrowsableNamespace() {
  692. var ns = this._accountExplorer.getCurrentNamespace();
  693. return _.contains(ns.capabilities, 'notBrowsable');
  694. },
  695. _createObj: function _createObj(type) {
  696. var ns = this._accountExplorer.getCurrentNamespace();
  697. type = type || this._filterType;
  698. var pid = this._accountExplorer.getCurrentPath().id;
  699. if (_.contains(ns.capabilities, 'notBrowsable') && type === 'account') {
  700. this.glassContext.appController.showSlideOut({
  701. 'parent': this.parent.slideout,
  702. 'width': "400px",
  703. 'content': {
  704. 'showGobackButton': false,
  705. 'module': 'bi/admin/account/slideout/AddOpenIdPane',
  706. 'parentView': this,
  707. 'objectInfo': ns,
  708. 'pid': pid,
  709. 'glassContext': this.glassContext
  710. }
  711. });
  712. } else if (type === "account") {
  713. var userPrototype = {
  714. businessPhone: "",
  715. contentLocale: "",
  716. faxPhone: "",
  717. homePhone: "",
  718. mobilePhone: "",
  719. pagerPhone: "",
  720. postalAddress: "",
  721. productLocale: "",
  722. userName: "",
  723. hidden: false,
  724. shown: false,
  725. password: "",
  726. description: "",
  727. type: "account"
  728. };
  729. this.newGroupSlideout = this.glassContext.appController.showSlideOut({
  730. 'parent': this.parent.slideout,
  731. 'width': "400px",
  732. 'content': {
  733. 'module': 'bi/admin/account/slideout/CreateNewPane',
  734. 'parentView': this,
  735. 'template': type === 'account' ? CreateNewUserTemplate : CreateNewGroupTemplate,
  736. 'objectInfo': type === 'account' ? userPrototype : {},
  737. 'pid': pid,
  738. 'type': type,
  739. 'glassContext': this.glassContext
  740. }
  741. });
  742. } else if (this._isNonBrowsableNamespace() && type === 'group') {
  743. this.listView.addInput('nonBrowsableGroup', pid, this._accountExplorer, this.listAdaptor);
  744. } else {
  745. this.listView.addInput(type, pid, this._accountExplorer, this.listAdaptor);
  746. }
  747. },
  748. showProperties: function showProperties(item, tabModule) {
  749. this.propertySlideout = this.glassContext.appController.showSlideOut({
  750. 'parent': this.parent.slideout,
  751. 'launchPoint': this.parent.slideout.$el.find('span.goback-icon'),
  752. 'width': "400px",
  753. 'onHide': function () {
  754. if (this.propertySlideout && this.propertySlideout.contentView && this.propertySlideout.contentView.onHide) {
  755. this.propertySlideout.contentView.onHide().then(function () {
  756. //remove propertiesPageView
  757. this.propertySlideout.hide();
  758. }.bind(this));
  759. }
  760. }.bind(this),
  761. 'content': {
  762. 'module': 'bi/admin/common/PropertiesPageView',
  763. 'parentView': this,
  764. 'objectInfo': item,
  765. 'type': item.type,
  766. 'selectedTabModule': tabModule || "",
  767. 'accountExplorer': this._accountExplorer,
  768. 'glassContext': this.glassContext
  769. }
  770. });
  771. },
  772. _deleteAccountObj: function _deleteAccountObj(data) {
  773. require(['bi/admin/account/ui/ConfirmDeleteContentView'], function (ConfirmDeleteContentView) {
  774. var dialog = new ContentGenericDialog({
  775. 'title': StringResource.get('confirmDelete'),
  776. 'viewClass': ConfirmDeleteContentView,
  777. 'viewOptions': {
  778. 'accountObj': data,
  779. 'accountAdaptor': this.listAdaptor,
  780. 'listView': this.listView,
  781. 'showCheckbox': false,
  782. 'accountExplorer': this._accountExplorer,
  783. 'glassContext': this.glassContext
  784. }
  785. });
  786. dialog.setLaunchPoint(this.$el.find('.bi-admin-filterbar-leading input'));
  787. dialog.open();
  788. }.bind(this));
  789. },
  790. _deleteUserProfileObj: function _deleteUserProfileObj(data) {
  791. require(['bi/admin/account/ui/ConfirmDeleteContentView'], function (ConfirmDeleteContentView) {
  792. var dialog = new ContentGenericDialog({
  793. 'title': StringResource.get('confirmDelete'),
  794. 'viewClass': ConfirmDeleteContentView,
  795. 'viewOptions': {
  796. 'accountObj': data,
  797. 'accountAdaptor': this.listAdaptor,
  798. 'listView': this.listView,
  799. 'showCheckbox': false,
  800. 'accountExplorer': this._accountExplorer,
  801. 'glassContext': this.glassContext,
  802. 'deleteUserProfile': true
  803. }
  804. });
  805. dialog.setLaunchPoint(this.$el.find('.bi-admin-filterbar-leading input'));
  806. dialog.open();
  807. }.bind(this));
  808. },
  809. createUserProfile: function createUserProfile(data) {
  810. var storeId = data[0].id;
  811. var url = AJAXUtils.getPath("createUserProfile", storeId);
  812. var ajaxOptions = {
  813. 'dataType': 'json',
  814. 'type': 'GET',
  815. 'url': url
  816. };
  817. return this.glassContext.getCoreSvc('.Ajax').ajax(ajaxOptions).then(function (data) {
  818. this.glassContext.appController.showToast(StringResource.get("userProfileCreationSuccessful"));
  819. this._refreshAccountListPane();
  820. }.bind(this), function (ajaxOptions, error) {
  821. this.glassContext.appController.showErrorMessage(StringResource.get("userProfileCreationFailed") + ", " + AJAXUtils.buildErrorMessage(error.responseJSON.errors));
  822. }.bind(this));
  823. },
  824. _copyUserProfileObj: function _copyUserProfileObj(data) {
  825. this.copyProfileSlideout = this.glassContext.appController.showSlideOut({
  826. 'parent': this.parent.slideout,
  827. 'width': "400px",
  828. 'onHide': function () {
  829. if (this.copyProfileSlideout && this.copyProfileSlideout.contentView && this.copyProfileSlideout.contentView.onHide) {
  830. this.copyProfileSlideout.contentView.onHide().then(function () {
  831. this.copyProfileSlideout.hide();
  832. }.bind(this));
  833. }
  834. }.bind(this),
  835. 'content': {
  836. 'module': 'bi/admin/account/slideout/CopyUserProfilePane',
  837. 'parentView': this,
  838. 'data': data,
  839. 'accountExplorer': this._accountExplorer,
  840. 'glassContext': this.glassContext,
  841. listRefresh: this._refreshAccountListPane.bind(this),
  842. deleteUserProfile: this._deleteUserProfileObj.bind(this)
  843. }
  844. });
  845. },
  846. _openSecurityObjectSelectorPane: function _openSecurityObjectSelectorPane(data, targetType) {
  847. var res;
  848. if (targetType.indexOf(',') > -1) {
  849. res = targetType.split(",");
  850. } else {
  851. res = [];
  852. res.push(targetType);
  853. }
  854. this.memberInfo = data;
  855. var self = this;
  856. var sTitle = StringResource.get('addMemberTo');
  857. this.addMemberSlideout = this.glassContext.appController.showSlideOut({
  858. 'parent': this.parent.slideout,
  859. 'width': "400px",
  860. 'content': {
  861. 'title': sTitle,
  862. 'module': 'bi/admin/account/slideout/SecurityObjectSelectorPane',
  863. 'parentView': self,
  864. 'objectInfo': self.memberInfo,
  865. 'allowedSelectionTypes': res,
  866. 'filterType': res,
  867. 'multiSelect': self.memberInfo.length > 1 ? false : true,
  868. 'defaultTypes': ['namespaceFolder', 'group', 'role', 'account'],
  869. 'isAddMemberTo': true,
  870. 'cognosNamespaceOnly': true,
  871. 'targetType': targetType,
  872. 'accountExplorer': this._accountExplorer
  873. }
  874. });
  875. }
  876. });
  877. return SecurityObjectExplorerView;
  878. });