"use strict"; /** * Licensed Materials - Property of IBM * IBM Cognos Products: Cognos Analytics * Copyright IBM Corp. 2015, 2018 * US Government Users Restricted Rights - Use, duplication or disclosure * restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['underscore', 'bi/admin/nls/StringResource', 'bi/admin/common/ui/listview/ListDataAdaptor'], function (_, StringResource, ListDataAdaptor) { var SecurityObjectSelectorAdaptor = ListDataAdaptor.extend({ supportPaging: true, pageSize: 50, sortChanged: false, pagingWhileSearching: false, getColumnSpecs: function getColumnSpecs() { return [{ 'type': 'Icon' }, { 'type': 'MultipleProperties', 'label': StringResource.get('name'), 'sortable': true, 'scope': 'row', 'items': [{ 'type': 'Text', 'module': 'bi/admin/common/ui/listview/columns/SecurityObject', 'label': StringResource.get('name'), 'propertyName': 'defaultName', 'sortable': true, 'scope': 'row', 'enableAccountItemLink': this.enableAccountItemLink }, { 'type': 'Location', 'module': 'bi/admin/common/ui/listview/columns/SecurityObjectLocation', 'showAsActiveLink': false, 'clickCallback': this.locationChanged.bind(this) }] }, { 'type': 'Time', 'module': 'bi/admin/common/ui/listview/columns/SecurityObjectTime', 'label': StringResource.get('lastModified'), 'propertyName': 'modificationTime', 'sortable': true }]; }, locationChanged: function locationChanged(oData) { this._accountExplorer.setPathStack(oData.ancestors); var currentObj = oData.ancestors[oData.ancestors.length - 1]; this.trigger('locationChanged', { 'data': currentObj, 'isFolderNav': false }); }, init: function init(options) { SecurityObjectSelectorAdaptor.inherited('init', this, arguments); $.extend(this, options); this.columnSpecs = this.getColumnSpecs(); this.isGetMoreData = false; this.isGetLessData = false; }, shouldShowFilter: function shouldShowFilter() { var showFilterUI = _.isUndefined(this.hideFilter) || !this.hideFilter; var canFilter = !_.isUndefined(this.allowedSelectionTypes) && this.allowedSelectionTypes.length > 1; return showFilterUI && canFilter; }, isBrowse: function isBrowse() { return _.isUndefined(this.searchText) || this.searchText === ""; }, getItems: function getItems(searchPerformed) { if (this.isBrowse()) { this._getItemsForBrowsing(); return Promise.resolve(); } else if (this.isSearching && !searchPerformed) { if (this.isGetMoreData) { return this.getNextSearchPage(true); } else if (this.isGetLessData) { return this.getNextSearchPage(false); } else { return this._getSearchResult(); } } else { this._doCommonFiltering(this._getGroupedContent()); return Promise.resolve(this._accountExplorer._content); } }, getNextSearchPage: function getNextSearchPage(isPageDown) { return this._accountExplorer.getNextSearchPage(isPageDown).then(function () { this._doCommonFiltering(this._getGroupedContent()); }.bind(this)); }, _getSearchResult: function _getSearchResult() { return this._accountExplorer.search(this.searchText, this.searchType).then(function () { this._doCommonFiltering(this._getGroupedContent()); }.bind(this)); }, _getAvailableNamespaces: function _getAvailableNamespaces() { var items = this._accountExplorer.getNamespaces(); //remove all namespaces that we are not logged into items = _.filter(items, function (item) { return item.auth; }); return items; }, _getGroupedContent: function _getGroupedContent() { var gc = this._accountExplorer.getGroupedContent(); var items; if (this._filterType) { items = [].concat(gc.namespaceFolder, this._filterType.account ? gc['account'] : '', this._filterType.group ? gc['group'] : '', this._filterType.role ? gc['role'] : ''); } else { items = [].concat(gc.namespaceFolder, gc['account'], gc['group'], gc['role']); } return items; }, _getItemsForBrowsing: function _getItemsForBrowsing() { var path = this._accountExplorer.getCurrentPath(); $(this).trigger("ldapBrowsingEvent", path.type); var items; if (path.type === 'directory') { items = this._getAvailableNamespaces(); if (this.cognosNamespaceOnly) { items = _.filter(items, function (item) { return item.defaultName === "Cognos"; }); } } else { if (this.isGetMoreData) { this._accountExplorer.getNextBrowsePage(true); } else if (this.isGetLessData) { this._accountExplorer.getNextBrowsePage(false); } items = this._getGroupedContent(); } this._doCommonFiltering(items); this.trigger('pathChanged', this._accountExplorer.getPathStack()); }, _doCommonFiltering: function _doCommonFiltering(items) { //NOSONAR var itemObjs = []; _.each(items, function (item) { //NOSONAR var shouldPush = true; if (item.type === 'account' && item.userName) { if (item.givenName && item.surname) { item.defaultName = item.givenName + ' ' + item.surname + ' (' + item.userName + ')'; } else if (item.defaultName) { item.defaultName = item.defaultName + ' (' + item.userName + ')'; } } if (this.objectInfo) { var objIdMatch = item.id !== object.id; var isAddMemberToCheck = this.isAddMemberTo && objIdMatch && !this._isEveryoneGroup(item) && //NOSONAR !this._isAllAuthUserGroup(item) && item.permissions.indexOf('write') > -1; shouldPush = isAddMemberToCheck || !this.isAddMemberTo && objIdMatch; } if (!_.isUndefined(this.allowedSelectionTypes)) { if (item.type === 'namespace' || item.type === 'namespaceFolder') { shouldPush = true; } else { if (_.contains(this.allowedSelectionTypes, item.type)) { shouldPush = true; } else { shouldPush = false; } } } if (shouldPush) { itemObjs.push(item); } }.bind(this)); this.items = itemObjs; if (this._accountExplorer.pagingEnabled && this._accountExplorer.pagerControl) { this._accountExplorer.pagerControl.store.updatePager(this._accountExplorer, {}, this); } }, _getRowsObj: function _getRowsObj(searchPerformed) { return this.getItems(searchPerformed).then(function () { return { rows: this.items, hasMore: false }; }.bind(this)); }, getRows: function getRows() { if (this.pagingWhileSearching) { return this._getRowsObj(true); } else if (this.sortChanged) { return this._accountExplorer.selectPath(_.last(this._accountExplorer.getPathStack())).then(function () { this.sortChanged = false; return this._getRowsObj(); }.bind(this)); } else { return this._getRowsObj(); } }, setOrder: function setOrder(index, nextOrder) { this.sortChanged = true; var aCol = this.getColumnSpecs()[index]; var sortProperty; if (aCol.type === 'MultipleProperties') { var colItems = aCol.items; sortProperty = colItems[0].propertyName; } else { sortProperty = this.getColumnSpecs()[index].propertyName; } this._accountExplorer.sortColumnName = sortProperty; this._accountExplorer.sortOrder = nextOrder; }, hasMore: function hasMore() { return false; }, _isEveryoneGroup: function _isEveryoneGroup(obj) { return obj.searchPath.indexOf("CAMID(\"::Everyone") >= 0; }, _isAllAuthUserGroup: function _isAllAuthUserGroup(obj) { return obj.searchPath.indexOf("CAMID(\"::All Authenticated Users") >= 0; }, rowClickHandler: function rowClickHandler(aSecExplorer, oData) { //NOSONAR if (oData.type === "namespace" && !oData.auth && !_.contains(this.allowedSelectionTypes, 'namespace')) { aSecExplorer.glassContext.appController.showToast(StringResource.get('noSigninToViewErrorMsg'), { type: 'error' }); return; } if ((oData.type === "namespaceFolder" || oData.type === "namespace") && oData.permissions.indexOf("traverse") === -1 && !_.contains(this.allowedSelectionTypes, 'namespace')) { aSecExplorer.glassContext.appController.showToast(StringResource.get('noTraversePermissionErrorMsg'), { type: 'error' }); return; } if ((oData.type === 'role' || oData.type === 'group') && !oData.hasChildren) { //for roles and groups if they do not have children then do nothing return; } switch (oData.type) { case 'namespace': this._accountExplorer.selectNamespace(oData).then(aSecExplorer.updateForNavigate.bind(aSecExplorer)); break; case 'namespaceFolder': this._accountExplorer.selectFolder(oData).then(aSecExplorer.updateForNavigate.bind(aSecExplorer, oData)); break; case 'group': this._accountExplorer.selectGroup(oData).then(aSecExplorer.updateForNavigate.bind(aSecExplorer)); break; case 'role': this._accountExplorer.selectRole(oData).then(aSecExplorer.updateForNavigate.bind(aSecExplorer)); break; case 'account': break; default: } } }); return SecurityObjectSelectorAdaptor; });