123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389 |
- "use strict";
- /**
- * Licensed Materials - Property of IBM IBM Cognos Products: admin
- * Copyright IBM Corp. 2015, 2019
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['jquery', 'underscore', 'bi/admin/nls/StringResource', 'bi/admin/account/services/SecurityObjectSelectorAdaptor', 'bacontentnav/ui/dialogs/CopyMoveDialog', 'bi/admin/account/ui/SecurityObjectExplorerCopyMoveView'], function ($, _, StringResource, SecurityObjectSelectorAdaptor, CopyMoveDialog, SecurityObjectExplorerCopyMoveView) {
- var SecurityObjectExplorerAdaptor = SecurityObjectSelectorAdaptor.extend({
- supportPaging: true,
- pageSize: 50,
- sortChanged: false,
- _filterString: '',
- _filterType: '',
- rowClickHandler: function rowClickHandler(aSecExplorer, oData) {
- //NOSONAR:
- var rowClickHandlerResult;
- if (oData.type === "namespace" && !oData.auth) {
- aSecExplorer.glassContext.appController.showToast(StringResource.get('noSigninToViewErrorMsg'), {
- 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;
- }
- if ((oData.type === "namespaceFolder" || oData.type === "namespace") && oData.permissions.indexOf("traverse") === -1) {
- aSecExplorer.glassContext.appController.showToast(StringResource.get('noTraversePermissionErrorMsg'), {
- type: 'error'
- });
- return;
- }
- switch (oData.type) {
- case 'namespace':
- aSecExplorer.listView.clearShowWorking();
- rowClickHandlerResult = this._accountExplorer.selectNamespace(oData).then(aSecExplorer.updateForNavigate.bind(aSecExplorer)).catch(function (err) {
- this._handleNSObjectError(err, aSecExplorer);
- }.bind(this));
- break;
- case 'namespaceFolder':
- if (this.isBrowse()) {
- aSecExplorer.listView.clearShowWorking();
- rowClickHandlerResult = this._accountExplorer.selectFolder(oData).then(aSecExplorer.updateForNavigate.bind(aSecExplorer, oData)).catch(function (err) {
- this._handleNSObjectError(err, aSecExplorer);
- }.bind(this));
- } else {
- this.trigger('locationChanged', {
- 'data': oData,
- 'isFolderNav': true
- });
- }
- break;
- case 'group':
- if (this.isBrowse()) {
- aSecExplorer.listView.clearShowWorking();
- rowClickHandlerResult = this._accountExplorer.selectGroup(oData).then(aSecExplorer.updateForNavigate.bind(aSecExplorer)).catch(function (err) {
- this._handleNSObjectError(err, aSecExplorer);
- }.bind(this));
- } else {
- this.trigger('locationChanged', {
- 'data': oData,
- 'isFolderNav': true
- });
- }
- break;
- case 'role':
- if (this.isBrowse()) {
- aSecExplorer.listView.clearShowWorking();
- rowClickHandlerResult = this._accountExplorer.selectRole(oData).then(aSecExplorer.updateForNavigate.bind(aSecExplorer)).catch(function (err) {
- this._handleNSObjectError(err, aSecExplorer);
- }.bind(this));
- } else {
- this.trigger('locationChanged', {
- 'data': oData,
- 'isFolderNav': true
- });
- }
- break;
- case 'account':
- aSecExplorer.showProperties(oData);
- break;
- default:
- this._accountExplorer.logger.debug("Clicked on object type that is not understood " + oData.type);
- }
- return new Promise(function (resolve) {
- resolve(rowClickHandlerResult);
- });
- },
- _handleNSObjectError: function _handleNSObjectError(error, aSecExplorer) {
- aSecExplorer.listView.reload(false);
- var errorMessage = StringResource.get('nsObjectsRetrievalError');
- if (error.jqXHR.responseJSON) {
- errorMessage += '\n' + error.jqXHR.responseJSON.exceptionMessage;
- }
- aSecExplorer.glassContext.appController.showErrorMessage(errorMessage, StringResource.get('error'));
- },
- contextMenuHandler: function contextMenuHandler(securityObj, data) {
- data.selectedObject.securityObject = securityObj;
- var args = {
- "position": data.position,
- "menuId": 'com.ibm.bi.admin.accountListMenu',
- "activeObject": {
- handler: this,
- data: data.selectedObject,
- securityObject: securityObj
- }
- };
- securityObj.glassContext.appController.showContextMenu(args);
- },
- _getItemsContextMenus: function _getItemsContextMenus(data) {
- //NOSONAR
- var isBuiltinNs = this._accountExplorer.isBuiltinNamespace();
- var isOIDCNs = this._accountExplorer.isOidcNamespace();
- var isCognoUsersNs = this._accountExplorer.isCognosUsersNamespace();
- var dataWritePermission = data.permissions.indexOf('write') > -1 ? true : false;
- var availableContextMenuItems = ['property'];
- var parentObjectWritePermission = this._isWriteable(this._accountExplorer.parentObjectPermissions);
- switch (data.type) {
- case 'namespace':
- break;
- case 'namespaceFolder':
- if (isBuiltinNs && dataWritePermission && parentObjectWritePermission && this._canDeleteObject(data)) {
- availableContextMenuItems.push('delete');
- }
- if (this._canCopyOrMove(data)) {
- availableContextMenuItems.push('copyOrMove');
- }
- break;
- case 'account':
- case 'group':
- availableContextMenuItems.push('addMemberToRole');
- if (data.type === 'group' && !isOIDCNs) {
- availableContextMenuItems.push('members');
- }
- ;
- if (parentObjectWritePermission && dataWritePermission && this._checkCapabilities('canUseUsersGroupsAndRolesTool') && this._canDeleteObject(data)) {
- if (data.type === 'group' && (isBuiltinNs || isOIDCNs)) {
- availableContextMenuItems.push('delete');
- }
- ;
- if (data.type === 'account') {
- if (isCognoUsersNs) {
- availableContextMenuItems.push('delete');
- }
- if (data.modificationTime) {
- availableContextMenuItems.push('deleteUserProfile');
- availableContextMenuItems.push('copyUserProfile');
- } else {
- availableContextMenuItems.push('createUserProfile');
- }
- }
- ;
- }
- if (this._canCopyOrMove(data)) {
- availableContextMenuItems.push('copyOrMove');
- }
- ;
- break;
- case 'role':
- availableContextMenuItems.push('members');
- availableContextMenuItems.push('addMemberToRole');
- if (this._canCopyOrMove(data)) {
- availableContextMenuItems.push('copyOrMove');
- }
- if (isBuiltinNs && dataWritePermission && parentObjectWritePermission && this._canDeleteObject(data)) {
- availableContextMenuItems.push('delete');
- }
- break;
- default:
- this._accountExplorer.logger.debug("can not get context menu for " + data.type);
- }
- return availableContextMenuItems;
- },
- _isWriteable: function _isWriteable(permissions) {
- var retVal = false;
- _.find(permissions, function (permission) {
- retVal = permission === 'write';
- });
- return retVal;
- },
- _checkCapabilities: function _checkCapabilities(capabilityName) {
- return _.find(this.glassContext.services.userProfile.capabilities, function (capability) {
- return capability === capabilityName;
- });
- },
- _canCopyOrMove: function _canCopyOrMove(data) {
- //check if selection is in cognos namespace
- var isInCognosNamespace = this._isMovableInCognosNamespace(data);
- if (isInCognosNamespace === true) {
- return true;
- }
- return false;
- },
- _isMovableInCognosNamespace: function _isMovableInCognosNamespace(data) {
- if (data.searchPath.indexOf('CAMID("::') > -1) {
- return false;
- } else if (data.searchPath.indexOf('CAMID(":') > -1) {
- return true;
- }
- },
- _canDeleteObject: function _canDeleteObject(data) {
- if (/^CAMID\(\"\w*::/.test(data.searchPath) === true) {
- return false;
- } else if (data.id !== this.glassContext.profile.account.id) {
- return true;
- }
- return false;
- },
- isContextMenuItemVisible: function isContextMenuItemVisible(itemId, data) {
- var visible = false;
- var intersectionContextMenus = [];
- _.each(data, function (item) {
- var itemsContextMenus = this._getItemsContextMenus(item);
- if (intersectionContextMenus.length > 0) {
- intersectionContextMenus = _.intersection(intersectionContextMenus, itemsContextMenus);
- } else {
- intersectionContextMenus = itemsContextMenus;
- }
- }.bind(this));
- if (_.indexOf(intersectionContextMenus, itemId) !== -1) {
- visible = true;
- }
- if (data.length > 1 && (itemId === 'property' || itemId === 'members')) {
- visible = false;
- }
- return visible;
- },
- onContextMenu: function onContextMenu(id, data) {
- //NOSONAR
- var securityExplorer = data.securityObject;
- if (securityExplorer.parent.slideout.child) {
- securityExplorer.parent.slideout.child.hide();
- }
- var selectionType;
- if (data.length > 1) {
- for (var i = 0; i < data.length; ++i) {
- if (data[i].objectClass === "role") {
- selectionType = "role";
- break;
- }
- }
- } else {
- selectionType = data[0].objectClass;
- }
- switch (id) {
- case 'delete':
- securityExplorer._deleteAccountObj(data);
- break;
- case 'deleteUserProfile':
- securityExplorer._deleteUserProfileObj(data);
- break;
- case 'createUserProfile':
- securityExplorer.createUserProfile(data);
- break;
- case 'copyUserProfile':
- securityExplorer._copyUserProfileObj(data);
- break;
- case 'members':
- securityExplorer.showProperties(data[0], 'bi/admin/account/ui/MembersTab');
- break;
- case 'addMemberToRole':
- if (selectionType === "role") {
- securityExplorer._openSecurityObjectSelectorPane(data, 'role');
- } else {
- securityExplorer._openSecurityObjectSelectorPane(data, 'group,role');
- }
- break;
- case 'property':
- securityExplorer.showProperties(data[0]);
- break;
- case 'copyOrMove':
- var dialog = new CopyMoveDialog({
- 'title': StringResource.get('copyOrMove'),
- 'viewClass': SecurityObjectExplorerCopyMoveView,
- 'cssClass': 'contentListDialog',
- 'titleAriaLabel': CopyMoveDialog.getAriaLabelForDialogTitle('copyMoveDialog', data),
- 'viewOptions': {
- glassContext: this.glassContext,
- showBreadcrumbs: true,
- parent: data.securityObject,
- includeToolbar: true,
- inputObjects: data,
- type: 'copyMoveDialog',
- hideSearch: true,
- cognosNamespaceOnly: true,
- allowedSelectionTypes: 'Folders',
- onHide: function onHide() {
- this.parent.refresh();
- }
- }
- });
- dialog.open();
- break;
- default:
- }
- },
- getColumnSpecs: function getColumnSpecs() {
- var cols = SecurityObjectExplorerAdaptor.inherited('getColumnSpecs', this, arguments);
- cols.push({
- 'type': 'ContextMenu',
- 'width': '10%',
- 'module': 'bacontentnav/common/ui/list_columns/ContextMenu'
- });
- return cols;
- },
- init: function init(options) {
- if (_.isUndefined(options)) {
- options = {};
- }
- options.allowedSelectionTypes = ['namespaceFolder', 'group', 'role', 'account'];
- options.cognosNamespaceOnly = false;
- SecurityObjectExplorerAdaptor.inherited('init', this, arguments);
- $.extend(this, options);
- },
- _getAvailableNamespaces: function _getAvailableNamespaces() {
- return this._accountExplorer.getNamespaces();
- }
- });
- return SecurityObjectExplorerAdaptor;
- });
|