123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- "use strict";
- 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();
- 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) {
-
- var itemObjs = [];
- _.each(items, function (item) {
-
- 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) &&
- !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) {
-
- 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) {
-
- 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;
- });
|