123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975 |
- "use strict";
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: Cognos Analytics
- * Copyright IBM Corp. 2015, 2020
- * US Government Users Restricted Rights - Use, duplication or disclosure
- * restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- 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) {
- 'use strict'; //NOSONAR: meant to be strict
- var SecurityObjectExplorerView = View.extend({
- showBreadcrumbs: true,
- defaultTypes: ['namespaceFolder', 'group', 'role', 'account'],
- _breadCrumbs: null,
- _accountExplorer: null,
- listAdaptor: null,
- init: function init(options) {
- SecurityObjectExplorerView.inherited('init', this, arguments);
- this.glassContext = options.glassContext;
- if (!this._accountExplorer && options.accountExplorer) {
- this._accountExplorer = options.accountExplorer;
- } else {
- this._accountExplorer = this._getNewAccountExplorer({
- glassContext: options.glassContext
- });
- }
- this.listAdaptor = options.listAdaptor;
- this.parent = options.parent;
- this.includeToolbar = options.includeToolbar ? options.includeToolbar : false;
- this.hideSearch = options.hideSearch;
- this.filterPushed = false;
- this.hidePaging = options.hidePaging;
- this.pagingEnabled = false;
- this.filterStringValue = {
- 'group': true,
- 'account': true,
- 'role': true
- };
- },
- _getNewAccountExplorer: function _getNewAccountExplorer(options) {
- return new AccountExplorer(options);
- },
- _getLdapStatus: function _getLdapStatus() {
- var options = {
- dataType: 'json',
- type: 'GET',
- data: {},
- url: AJAXUtils.getAJAXURL("ldapStatus"),
- cache: false
- };
- return this.glassContext.services.ajax.ajax(options);
- },
- _showPaging: function _showPaging() {
- // this checks if we want to show paging in a component. For example we want to hide it in accounts copy/move view.
- return _.isUndefined(this.hidePaging) || !this.hidePaging;
- },
- _populatePagingStatusAndValue: function _populatePagingStatusAndValue() {
- var pagingEnabled = this._checkIfPagingIsEnabled();
- var pagingValue = this._getPagingValue();
- return Promise.all([pagingEnabled, pagingValue]).then(function (responses) {
- this.pagingEnabled = responses[1] === 'true';
- this.pagingValueSet = parseInt(responses[0]);
- }.bind(this));
- },
- _renderPagingWidget: function _renderPagingWidget() {
- if (this.pagingEnabled && this._showPaging()) {
- this._accountExplorer.pagingEnabled = this.pagingEnabled;
- this._accountExplorer.pagingValueSet = this.pagingValueSet;
- this._accountExplorer.searchPageSize = this.pagingValueSet;
- var pagingBar = React.createElement(AdminReact.Pagination, {
- 'glassContext': this.glassContext,
- 'StringResource': StringResource,
- 'accountExplorer': this._accountExplorer,
- 'listView': this.listView,
- 'defaultPagingValue': this.pagingValueSet,
- 'listAdaptor': this.listAdaptor
- });
- this.pagerControl = ReactDOM.render(pagingBar, this.$el.find('.bi-admin-account-pagingBar')[0]);
- this._accountExplorer.pagerControl = this.pagerControl;
- this.$el.find('.bi-admin-account-pagingBar').hide();
- $(this.listAdaptor).on("ldapBrowsingEvent", function (event, type) {
- this._updatePagingBar(type);
- }.bind(this));
- }
- },
- _checkIfPagingIsEnabled: function _checkIfPagingIsEnabled() {
- var endpoint = "v1/configuration/keys/Admin.namespaceChildrenPerPage";
- var pagingSettingsPromise = this.glassContext.services.fetch.get(endpoint);
- return pagingSettingsPromise.then(function (response) {
- return response.data['Admin.namespaceChildrenPerPage'];
- });
- },
- _getPagingValue: function _getPagingValue() {
- var endpoint = "v1/configuration/keys/Admin.enableNamespaceChildrenPaging";
- var pagingValuePromise = this.glassContext.services.fetch.get(endpoint);
- return pagingValuePromise.then(function (response) {
- return response.data['Admin.enableNamespaceChildrenPaging'];
- });
- },
- _renderTemplate: function _renderTemplate() {
- var paneInfo = {
- 'strings': {
- 'type': StringResource.get('type'),
- 'addNewUser': StringResource.get('addNewUser'),
- 'addNewGroup': StringResource.get('addNewGroup'),
- 'addNewRole': StringResource.get('addNewRole'),
- 'addNewFolder': StringResource.get('addNewFolder'),
- 'import': StringResource.get('import')
- },
- showFilter: this.listAdaptor.shouldShowFilter()
- };
- var sHtml = dot.template(SecurityObjectExplorerTemplate)(paneInfo);
- this.$el.html(sHtml);
- BidiUtil.initElementForBidi(this.$el.find(".bi-admin-input.bi-admin-input-search")[0]);
- this.myAccount = React.createElement(AdminReact.UserWidget, {
- 'parent': this,
- 'glassContext': this.glassContent,
- 'StringResource': StringResource,
- 'clickFunc': this._createObj.bind(this),
- 'importOpenIdFunc': this.importOpenId.bind(this),
- 'importFunc': this.importFunc.bind(this),
- 'label': 'First Label'
- });
- ReactDOM.render(this.myAccount, this.$el.find('.bi-admin-account-createNewBar')[0]); //init to hide create bar before get ldap status and checking permissions
- this.$el.find('.bi-admin-account-createNewBar').hide();
- this.$el.find('.multiUploadText').text(StringResource.get('importText'));
- },
- importFunc: function importFunc(selectedOption) {
- if (selectedOption === 'importUsers') {
- //import users
- this.importOpenId('users');
- } else if (selectedOption === 'importGroups') {
- //import groups
- this.importOpenId('groups');
- }
- },
- _updateOrUploadUsers: function _updateOrUploadUsers(options) {
- var pid = this._accountExplorer.getCurrentPath().id;
- var requestOptions = {
- 'headers': {
- 'Content-Type': 'text/csv'
- },
- 'url': 'v1/users?pid=' + pid,
- 'type': 'POST',
- 'data': options.data,
- 'Content-Length': options.byteLength,
- 'processData': false
- };
- return this.glassContext.services.ajax.ajax(requestOptions);
- },
- _updateOrUploadGroups: function _updateOrUploadGroups(options) {
- var pid = this._accountExplorer.getCurrentPath().id;
- var requestOptions = {
- 'headers': {
- 'Content-Type': 'text/csv'
- },
- 'url': 'v1/groups?pid=' + pid,
- 'type': 'POST',
- 'data': options.data,
- 'Content-Length': options.byteLength,
- 'processData': false
- };
- return this.glassContext.services.ajax.ajax(requestOptions);
- },
- _createUploader: function _createUploader(type) {
- if (type === 'users') {
- return new Uploader({
- 'glassContext': this.glassContext,
- '$el': this.$el,
- 'fileType': 'csv',
- 'ajax': this._updateOrUploadUsers.bind(this),
- 'ajaxOptions': {}
- });
- } else if (type === 'groups') {
- return new Uploader({
- 'glassContext': this.glassContext,
- '$el': this.$el,
- 'fileType': 'csv',
- 'ajax': this._updateOrUploadGroups.bind(this),
- 'ajaxOptions': {}
- });
- }
- },
- _refreshAccountListPane: function _refreshAccountListPane(isCreatingObject) {
- if (this.pagingEnabled) {
- this.listAdaptor.sortChanged = false;
- AdminReact.PaginationHelper.reloadListViewinPagingContext(this.glassContext, this._accountExplorer, this.listView, this.listAdaptor, isCreatingObject);
- } else {
- this.listAdaptor.sortChanged = true;
- this.listView.reload(false);
- }
- },
- importOpenId: function importOpenId(type) {
- var fileUploader = this._createUploader(type);
- return fileUploader.doUpload().then(function () {
- this._refreshAccountListPane(true);
- }.bind(this), function (err) {
- this.glassContext.appController.showErrorMessage(StringResource.get('OIDCErrorSuggestion', {
- serverError: err.responseJSON.messages
- }), StringResource.get('error'));
- }.bind(this));
- },
- changeBrowseSearch: function changeBrowseSearch(isBrowsing) {
- var elList = this.$el.find('.bi-admin-account-list');
- if (isBrowsing) {
- this._accountExplorer.newSearch();
- this.listView.setPaging(true);
- elList.addClass("security-browsing");
- } else {
- this.listView.setPaging(true);
- elList.removeClass("security-browsing");
- }
- },
- _renderSearch: function _renderSearch() {
- var rSearch = this.$el.find(".bi-admin-filterbar-leading");
- var searchComp = React.createElement(AdminReact.AdminSearchInput, {
- 'parent': this,
- StringResource: StringResource,
- placeholder: StringResource.get('filterTips'),
- onSearch: function (evt, newValue, searchType) {
- var isBrowsing = newValue === "";
- this.listView.setPaging(false);
- this.listAdaptor.searchText = encodeURIComponent(newValue.trim());
- this.listAdaptor.searchType = searchType;
- this.listAdaptor.isSearching = true;
- this._accountExplorer.clearGroupedContent();
- this.listView._clearTable();
- this.listView.showWorking();
- if (!isBrowsing) {
- this.listView.reload(false).then(function () {
- this.changeBrowseSearch(isBrowsing);
- if (this.pagingEnabled && this.pagerControl) {
- this.pagerControl.store.updatePager(this._accountExplorer, this.listView, this.listAdaptor);
- }
- }.bind(this));
- } else {
- this._accountExplorer.selectCurrentPath().then(function () {
- this.listView.reload(false).then(function () {
- this.changeBrowseSearch(isBrowsing);
- this._clearSearch();
- }.bind(this));
- }.bind(this));
- }
- }.bind(this),
- ref: function (searchInput) {
- this._searchInput = searchInput;
- }.bind(this),
- onClear: function (e) {
- var isBrowsing = true;
- this.listView.setPaging(false);
- this.listAdaptor.searchText = "";
- this._accountExplorer.clearGroupedContent();
- this._accountExplorer.selectCurrentPath().then(function () {
- this.listView.reload(false).then(function () {
- this.changeBrowseSearch(isBrowsing);
- }.bind(this));
- if (this.pagingEnabled && this.pagerControl) {
- this._clearSearch();
- }
- }.bind(this));
- }.bind(this)
- });
- ReactDOM.render(searchComp, rSearch[0]);
- $(this.listAdaptor).on("ldapBrowsingEvent", function (event, type) {
- this._updateFilterBar(type);
- }.bind(this));
- },
- _clearSearch: function _clearSearch() {
- this.pagerControl.store.updatePager(this._accountExplorer, this.listView, this.listAdaptor);
- this.listAdaptor.isSearching = undefined;
- },
- _initializeAccountExplorer: function _initializeAccountExplorer() {
- var deferred = Q.defer();
- this._accountExplorer._defaultTypes = this.defaultTypes;
- this._accountExplorer.startUp().done(function () {
- if (this.listAdaptor.cognosNamespaceOnly) {
- this._accountExplorer.selectNamespace("Cognos").done(function () {
- this._updateAccountExplorerInit().done(function () {
- this.filterStringValue.account = false;
- this.filterStringValue.role = true;
- if (this.listAdaptor.allowedSelectionTypes === "role") {
- this.filterStringValue.group = false;
- } else {
- this.filterStringValue.group = true;
- }
- deferred.resolve();
- }.bind(this));
- }.bind(this));
- } else {
- this._updateAccountExplorerInit().done(function () {
- this.filterStringValue.account = true;
- this.filterStringValue.role = true;
- this.filterStringValue.group = true;
- deferred.resolve();
- }.bind(this));
- }
- }.bind(this));
- return deferred.promise;
- },
- _updateAccountExplorerInit: function _updateAccountExplorerInit() {
- var deferred = Q.defer();
- this._getLdapStatus().done(function (result) {
- this._ldapStatus = !!result['ads-state'];
- this._configToolBar();
- deferred.resolve();
- }.bind(this));
- this.listAdaptor._accountExplorer = this._accountExplorer;
- this.listAdaptor.on('pathChanged', function (path) {
- this._updateBreadcrumb(path);
- this.listAdaptor.off('locationChanged');
- this.listAdaptor.on("locationChanged", function (obj) {
- this._navigate(obj.data);
- }.bind(this));
- }.bind(this));
- return deferred.promise;
- },
- _renderListView: function _renderListView() {
- var deferred = Q.defer();
- var elList = this.$el.find('.bi-admin-account-list');
- elList.addClass("security-browsing");
- elList.empty();
- this.listView = this._getNewListView({
- el: elList,
- dataAdaptor: this.listAdaptor,
- glassContext: this.glassContext,
- accessibleLabel: this.title,
- activeInputForm: null,
- multiSelect: true,
- onSelectionChange: this.onSelectionChange
- });
- this.listView.singleSelectCallback = this._rowClickHandler.bind(this);
- if (this.listAdaptor.contextMenuHandler) {
- this.listView.contextMenuCallback = this.listAdaptor.contextMenuHandler.bind(this.listAdaptor, this);
- }
- this.listView.render().then(function () {
- if (!this.pagingEnabled) {
- this._bindListViewEvents();
- }
- }.bind(this)).then(deferred.resolve, deferred.reject);
- return deferred.promise;
- },
- refresh: function refresh() {
- this._refreshAccountListPane();
- },
- _getNewListView: function _getNewListView(options) {
- return new ListView(options);
- },
- _bindListViewEvents: function _bindListViewEvents() {
- $(this.listView).on("previousPage", function () {
- if (!this._accountExplorer.isTopOfPage()) {
- this.listView.setPaging(false);
- this._accountExplorer.cacheOldContent();
- this._accountExplorer.clearGroupedContent();
- this._accountExplorer.selectCurrentPath().then(function () {
- this.listAdaptor.isGetLessData = true;
- this.listView.reload(false).then(function () {
- this.changeBrowseSearch(false);
- this.listAdaptor.isGetLessData = false;
- this.listView.setPaging(true);
- }.bind(this));
- }.bind(this));
- }
- }.bind(this));
- $(this.listView).on("nextPage", function () {
- if (!this.scrollCausedByRowClick && !this._accountExplorer.noMoreData) {
- this.listView.setPaging(false);
- this._accountExplorer.cacheOldContent();
- this._accountExplorer.clearGroupedContent();
- this._accountExplorer.selectCurrentPath().then(function () {
- this.listAdaptor.isGetMoreData = true;
- this.listView.reload(false).then(function () {
- this.changeBrowseSearch(false);
- this.listAdaptor.isGetMoreData = false;
- this.listView.adjustScrollForPageDown();
- this.listView.setPaging(true);
- }.bind(this));
- }.bind(this));
- } else {
- delete this.scrollCausedByRowClick;
- }
- }.bind(this));
- },
- clearShowWorking: function clearShowWorking() {
- this.$el.find(".adminAccountsShowWorking").remove();
- },
- showWorking: function showWorking() {
- var loadingAnimation = Utils.getLoadingAnimation(1);
- var $container = $('<div class="adminAccountsShowWorking emptyTableContent bi-admin-working"></div>');
- $container.append(loadingAnimation);
- this.$el.append($container);
- },
- render: function render() {
- var deferred = Q.defer();
- this._renderTemplate();
- this.showWorking();
- var accountsPagingStatus = this._populatePagingStatusAndValue().catch(function (err) {
- this.pagingEnabled = false;
- this.logger.error(err);
- }.bind(this));
- this._renderSearch();
- this._initializeAccountExplorer().then(function () {
- return accountsPagingStatus;
- }).then(this._renderListView.bind(this)).then(function () {
- this._bindEvents();
- this._renderPagingWidget();
- this.clearShowWorking();
- }.bind(this)).then(deferred.resolve, deferred.reject);
- return deferred.promise;
- },
- _bindFilter: function _bindFilter() {
- if (!this.filterPushed) {
- this.filterPushed = true;
- this.glassContext.appController.showSlideOut({
- 'parent': this.parent.slideout,
- 'position': 'left',
- 'width': '200px',
- 'content': {
- 'parentView': this,
- 'glassContext': this.glassCtxt,
- 'showSwitchButton': true,
- 'module': 'bi/admin/account/slideout/UserGroupSelectorPane',
- 'view': this,
- 'callback': this
- }
- }).on('hide', function () {
- this.filterPushed = false;
- }.bind(this));
- }
- },
- getSelectedObjects: function getSelectedObjects() {
- return this.listView.getSelectedObjects();
- },
- _getFilterBar: function _getFilterBar() {
- return this.$el.find(".bi-admin-filterbar.folderpane-filterbar");
- },
- _getPaginBar: function _getPaginBar() {
- return this.$el.find(".bi-admin-account-pagingBar");
- },
- _updateFilterBar: function _updateFilterBar(type) {
- var filterBar = this._getFilterBar();
- this._hideBar(filterBar, type);
- },
- _updatePagingBar: function _updatePagingBar(type) {
- var pagingBar = this._getPaginBar();
- this._hideBar(pagingBar, type);
- },
- _hideBar: function _hideBar(bar, type) {
- if (type === "directory") {
- bar.css("display", "none");
- } else {
- bar.css("display", "block");
- }
- },
- _bindEvents: function _bindEvents() {
- this.$el.find('.multiUploadBtn').on('primaryaction', function () {}.bind(this));
- var $filterButton = this.$el.find('#filterDef').on('primaryaction', function () {
- this._bindFilter();
- }.bind(this));
- var $label = $('<span class="bi-admin-filter-icon">');
- $label.text(this._filterString(this.filterStringValue));
- ContentFormatter.middleShortenString($label);
- $label.appendTo($filterButton);
- },
- setFocus: function setFocus() {
- this.$el.find('.bi-admin-filterbar-leading input').focus();
- },
- setFocusOnAccountList: function setFocusOnAccountList() {
- if (!this.listView.setFocus()) {
- this.setFocus();
- }
- },
- _filterString: function _filterString(filterString) {
- var types = ['account', 'role', 'group'];
- var filters = 0;
- var labelString;
- for (var i = 0; i < types.length; i++) {
- if (filterString[types[i]]) {
- if (filters === 0) {
- labelString = StringResource.get(types[i]);
- } else {
- labelString = labelString.concat(',').concat(' ').concat(StringResource.get(types[i]));
- }
- filters++;
- }
- }
- if (filters === 0) {
- labelString = StringResource.get('none');
- } else if (filters === types.length) {
- labelString = StringResource.get('allMember');
- }
- return labelString;
- },
- _filter: function _filter(filterStr) {
- var $label = this.$el.find('.bi-admin-filter-icon');
- if ($label) {
- $label[0].title = '';
- }
- var labelString = this._filterString(filterStr);
- $label.text(labelString);
- ContentFormatter.middleShortenString($label[0]);
- this.listAdaptor._filterType = filterStr || '';
- this._accountExplorer._filterType = this.listAdaptor._filterType;
- this.listAdaptor._filterString = '';
- if (!this.pagingEnabled) {
- this.listView.reload(false);
- } else {
- AdminReact.PaginationHelper.reloadListViewinFilteredContext(this.glassContext, this._accountExplorer, this.listView, this.listAdaptor);
- }
- ;
- },
- updateForNavigate: function updateForNavigate(data) {
- if (!this.hideSearch) {
- this._searchInput.clearSearch();
- }
- this.changeBrowseSearch(true);
- this.listView.setPaging(false);
- this._accountExplorer.updateHasMoreData();
- this.listView.reload(false).done(function () {
- this.setFocusOnAccountList();
- this.listView.setPaging(true);
- if (this.pagingEnabled && this.pagerControl) {
- this.pagerControl.store.updatePager(this._accountExplorer, this.listView, this.listAdaptor);
- }
- }.bind(this));
- this._configToolBar(data);
- },
- _navigate: function _navigate(item) {
- this.listAdaptor.searchText = undefined;
- this._accountExplorer.selectPath(item).done(function () {
- this.updateForNavigate(item);
- }.bind(this, item));
- },
- _onNavigate: function _onNavigate(index) {
- var bc = this._breadCrumbs.ancestors;
- if (index >= bc.length - 1) {
- return;
- }
- var item = bc[index];
- this.scrollCausedByRowClick = true;
- this._navigate(item);
- },
- _checkCapabilities: function _checkCapabilities(capabilityName) {
- return _.find(this.glassContext.services.userProfile.capabilities, function (capability) {
- return capability === capabilityName;
- });
- },
- _canShowToolbar: function _canShowToolbar(ns) {
- return this._checkCapabilities('canUseUsersGroupsAndRolesTool') && (ns.defaultName === 'Cognos' || ns.defaultName === 'Cognos Users' || this._isNonBrowsableNamespace());
- },
- _isWriteable: function _isWriteable(permissions) {
- var retVal = false;
- _.find(permissions, function (permission) {
- retVal = permission === 'write';
- });
- return retVal;
- },
- _configToolBar: function _configToolBar(data) {
- //NOSONAR
- var createNewBar = this.$el.find('.bi-admin-account-createNewBar');
- createNewBar.css("padding", "initial");
- createNewBar.css("paddingTop", "5px");
- var filter = this.$el.find('.dropdown-toggle');
- var ns = this._accountExplorer.getCurrentNamespace();
- if (this._accountExplorer.tenantNsFolderId && this._accountExplorer.tenantNsFolderId !== 'xOg__' && this._accountExplorer.currentRequest === 'v1/namespaces/xOg__/items?') {
- this._accountExplorer.getFolderPermission(this._accountExplorer.tenantNsFolderId).then(function (tenantNsFolderPermissions) {
- this._renderConfigToolBar(data, createNewBar, filter, ns, tenantNsFolderPermissions);
- }.bind(this)).catch(function (e) {
- this.tenantNsFolderPermissions = null;
- this._renderConfigToolBar(data, createNewBar, filter, ns);
- }.bind(this));
- } else {
- this._renderConfigToolBar(data, createNewBar, filter, ns);
- }
- return Promise.resolve();
- },
- _renderConfigToolBar: function _renderConfigToolBar(data, createNewBar, filter, ns, tenantNsFolderPermissions) {
- createNewBar.find('.admin-import-dropdown').hide();
- if (!ns) {
- createNewBar.hide();
- filter.hide();
- } else if (this.type === 'copyMoveDialog') {
- if (ns.defaultName === 'Cognos') {
- createNewBar.find('#newGroup').hide();
- createNewBar.find('#newUser').hide();
- createNewBar.find('#newRole').hide();
- createNewBar.find('#newFolder').show();
- createNewBar.find('.admin-import-dropdown').hide();
- } else {
- createNewBar.find('#newGroup').hide();
- createNewBar.find('#newUser').hide();
- createNewBar.find('#newFolder').hide();
- createNewBar.find('#newRole').hide();
- createNewBar.find('.admin-import-dropdown').hide();
- }
- if (this._canShowToolbar(ns)) {
- createNewBar.show();
- } else {
- createNewBar.hide();
- }
- if (!this.includeToolbar) {
- createNewBar.hide();
- }
- filter.show();
- } else {
- //Check if non browsable namespace and is not a cloud evironment (doesn't have a tenented cognos ns folder)
- if (_.contains(ns.capabilities, 'notBrowsable') && this._isNotCloudEnviroment()) {
- createNewBar.find('#newUser').show();
- createNewBar.find('#newGroup').show();
- createNewBar.find('#newFolder').hide();
- createNewBar.find('#newRole').hide();
- createNewBar.find('.admin-import-dropdown').show();
- } 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)) {
- this._hideButtonBasedOnTargetType('group', createNewBar.find('#newGroup'));
- this._hideButtonBasedOnTargetType('folder', createNewBar.find('#newFolder'));
- this._hideButtonBasedOnTargetType('role', createNewBar.find('#newRole'));
- createNewBar.find('#newUser').hide();
- } else if (ns.defaultName === 'Cognos Users') {
- createNewBar.find('#newUser').show();
- createNewBar.find('#newGroup').hide();
- createNewBar.find('#newFolder').hide();
- createNewBar.find('#newRole').hide();
- } else {
- createNewBar.find('#newGroup').hide();
- createNewBar.find('#newUser').hide();
- createNewBar.find('#newFolder').hide();
- createNewBar.find('#newRole').hide();
- }
- if (this._canShowToolbar(ns)) {
- createNewBar.show();
- } else {
- createNewBar.hide();
- }
- filter.show();
- }
- },
- _isNotCloudEnviroment: function _isNotCloudEnviroment() {
- return this._accountExplorer.tenantNsFolderId === 'xOg__';
- },
- _hideButtonBasedOnTargetType: function _hideButtonBasedOnTargetType(buttonType, button) {
- if (!this.targetType || this.targetType.indexOf(buttonType) !== -1) {
- button.show();
- } else {
- button.hide();
- }
- },
- reloadList: function reloadList() {
- return this.listView.reload(false);
- },
- _rowClickHandler: function _rowClickHandler(oData) {
- this.scrollCausedByRowClick = true;
- if (this.listAdaptor.rowClickHandler) {
- this.listAdaptor.rowClickHandler(this, oData);
- }
- },
- _updateBreadcrumb: function _updateBreadcrumb(path) {
- var $breadcrumbs = this.$el.find('#breadcrumbs');
- if (this.showBreadcrumbs) {
- if (this._breadCrumbs) {
- this._breadCrumbs.updateBreadcrumb(path);
- } else {
- //render Breadcrumbs
- this._breadCrumbs = new Breadcrumbs({
- 'el': $breadcrumbs,
- 'label': StringResource.get('breadCrumbsAccessibleLabel'),
- 'breadcrumbs': [{
- defaultName: '',
- url: ''
- }],
- 'navigateCallback': this._onNavigate.bind(this)
- });
- this._breadCrumbs.ancestors = this._breadCrumbs.breadcrumbs;
- this._breadCrumbs.render();
- this._breadCrumbs.updateBreadcrumb(path);
- }
- }
- },
- _allowCreateUser: function _allowCreateUser() {
- var retVal = false;
- if (this._ldapStatus) {
- var path = this._accountExplorer.getCurrentPath();
- var isSignInCognos = false;
- _.each(this._accountExplorer.authNamespaces, function (authNamespace) {
- if (authNamespace.searchPath.split('"')[1] === 'CognosEx') {
- isSignInCognos = true;
- }
- });
- retVal = !!path && path.type === 'namespace' && path.defaultName === 'Cognos' && isSignInCognos;
- }
- return retVal;
- },
- _isNonBrowsableNamespace: function _isNonBrowsableNamespace() {
- var ns = this._accountExplorer.getCurrentNamespace();
- return _.contains(ns.capabilities, 'notBrowsable');
- },
- _createObj: function _createObj(type) {
- var ns = this._accountExplorer.getCurrentNamespace();
- type = type || this._filterType;
- var pid = this._accountExplorer.getCurrentPath().id;
- if (_.contains(ns.capabilities, 'notBrowsable') && type === 'account') {
- this.glassContext.appController.showSlideOut({
- 'parent': this.parent.slideout,
- 'width': "400px",
- 'content': {
- 'showGobackButton': false,
- 'module': 'bi/admin/account/slideout/AddOpenIdPane',
- 'parentView': this,
- 'objectInfo': ns,
- 'pid': pid,
- 'glassContext': this.glassContext
- }
- });
- } else if (type === "account") {
- var userPrototype = {
- businessPhone: "",
- contentLocale: "",
- faxPhone: "",
- homePhone: "",
- mobilePhone: "",
- pagerPhone: "",
- postalAddress: "",
- productLocale: "",
- userName: "",
- hidden: false,
- shown: false,
- password: "",
- description: "",
- type: "account"
- };
- this.newGroupSlideout = this.glassContext.appController.showSlideOut({
- 'parent': this.parent.slideout,
- 'width': "400px",
- 'content': {
- 'module': 'bi/admin/account/slideout/CreateNewPane',
- 'parentView': this,
- 'template': type === 'account' ? CreateNewUserTemplate : CreateNewGroupTemplate,
- 'objectInfo': type === 'account' ? userPrototype : {},
- 'pid': pid,
- 'type': type,
- 'glassContext': this.glassContext
- }
- });
- } else if (this._isNonBrowsableNamespace() && type === 'group') {
- this.listView.addInput('nonBrowsableGroup', pid, this._accountExplorer, this.listAdaptor);
- } else {
- this.listView.addInput(type, pid, this._accountExplorer, this.listAdaptor);
- }
- },
- showProperties: function showProperties(item, tabModule) {
- this.propertySlideout = this.glassContext.appController.showSlideOut({
- 'parent': this.parent.slideout,
- 'launchPoint': this.parent.slideout.$el.find('span.goback-icon'),
- 'width': "400px",
- 'onHide': function () {
- if (this.propertySlideout && this.propertySlideout.contentView && this.propertySlideout.contentView.onHide) {
- this.propertySlideout.contentView.onHide().then(function () {
- //remove propertiesPageView
- this.propertySlideout.hide();
- }.bind(this));
- }
- }.bind(this),
- 'content': {
- 'module': 'bi/admin/common/PropertiesPageView',
- 'parentView': this,
- 'objectInfo': item,
- 'type': item.type,
- 'selectedTabModule': tabModule || "",
- 'accountExplorer': this._accountExplorer,
- 'glassContext': this.glassContext
- }
- });
- },
- _deleteAccountObj: function _deleteAccountObj(data) {
- require(['bi/admin/account/ui/ConfirmDeleteContentView'], function (ConfirmDeleteContentView) {
- var dialog = new ContentGenericDialog({
- 'title': StringResource.get('confirmDelete'),
- 'viewClass': ConfirmDeleteContentView,
- 'viewOptions': {
- 'accountObj': data,
- 'accountAdaptor': this.listAdaptor,
- 'listView': this.listView,
- 'showCheckbox': false,
- 'accountExplorer': this._accountExplorer,
- 'glassContext': this.glassContext
- }
- });
- dialog.setLaunchPoint(this.$el.find('.bi-admin-filterbar-leading input'));
- dialog.open();
- }.bind(this));
- },
- _deleteUserProfileObj: function _deleteUserProfileObj(data) {
- require(['bi/admin/account/ui/ConfirmDeleteContentView'], function (ConfirmDeleteContentView) {
- var dialog = new ContentGenericDialog({
- 'title': StringResource.get('confirmDelete'),
- 'viewClass': ConfirmDeleteContentView,
- 'viewOptions': {
- 'accountObj': data,
- 'accountAdaptor': this.listAdaptor,
- 'listView': this.listView,
- 'showCheckbox': false,
- 'accountExplorer': this._accountExplorer,
- 'glassContext': this.glassContext,
- 'deleteUserProfile': true
- }
- });
- dialog.setLaunchPoint(this.$el.find('.bi-admin-filterbar-leading input'));
- dialog.open();
- }.bind(this));
- },
- createUserProfile: function createUserProfile(data) {
- var storeId = data[0].id;
- var url = AJAXUtils.getPath("createUserProfile", storeId);
- var ajaxOptions = {
- 'dataType': 'json',
- 'type': 'GET',
- 'url': url
- };
- return this.glassContext.getCoreSvc('.Ajax').ajax(ajaxOptions).then(function (data) {
- this.glassContext.appController.showToast(StringResource.get("userProfileCreationSuccessful"));
- this._refreshAccountListPane();
- }.bind(this), function (ajaxOptions, error) {
- this.glassContext.appController.showErrorMessage(StringResource.get("userProfileCreationFailed") + ", " + AJAXUtils.buildErrorMessage(error.responseJSON.errors));
- }.bind(this));
- },
- _copyUserProfileObj: function _copyUserProfileObj(data) {
- this.copyProfileSlideout = this.glassContext.appController.showSlideOut({
- 'parent': this.parent.slideout,
- 'width': "400px",
- 'onHide': function () {
- if (this.copyProfileSlideout && this.copyProfileSlideout.contentView && this.copyProfileSlideout.contentView.onHide) {
- this.copyProfileSlideout.contentView.onHide().then(function () {
- this.copyProfileSlideout.hide();
- }.bind(this));
- }
- }.bind(this),
- 'content': {
- 'module': 'bi/admin/account/slideout/CopyUserProfilePane',
- 'parentView': this,
- 'data': data,
- 'accountExplorer': this._accountExplorer,
- 'glassContext': this.glassContext,
- listRefresh: this._refreshAccountListPane.bind(this),
- deleteUserProfile: this._deleteUserProfileObj.bind(this)
- }
- });
- },
- _openSecurityObjectSelectorPane: function _openSecurityObjectSelectorPane(data, targetType) {
- var res;
- if (targetType.indexOf(',') > -1) {
- res = targetType.split(",");
- } else {
- res = [];
- res.push(targetType);
- }
- this.memberInfo = data;
- var self = this;
- var sTitle = StringResource.get('addMemberTo');
- this.addMemberSlideout = this.glassContext.appController.showSlideOut({
- 'parent': this.parent.slideout,
- 'width': "400px",
- 'content': {
- 'title': sTitle,
- 'module': 'bi/admin/account/slideout/SecurityObjectSelectorPane',
- 'parentView': self,
- 'objectInfo': self.memberInfo,
- 'allowedSelectionTypes': res,
- 'filterType': res,
- 'multiSelect': self.memberInfo.length > 1 ? false : true,
- 'defaultTypes': ['namespaceFolder', 'group', 'role', 'account'],
- 'isAddMemberTo': true,
- 'cognosNamespaceOnly': true,
- 'targetType': targetType,
- 'accountExplorer': this._accountExplorer
- }
- });
- }
- });
- return SecurityObjectExplorerView;
- });
|