feat(core-app): CB-1435 option to disable operations with metadata

This commit is contained in:
Naumov Alexey
2021-11-18 01:31:50 +03:00
parent 3a7aa1f9b5
commit 0fc8945492
5 changed files with 34 additions and 5 deletions
@@ -16,6 +16,8 @@ const defaultSettings = {
'app.logViewer.maxFailedRequests': 3,
// temporary limit for all nodes children in app
'app.navigationTree.childrenLimit': 500,
'app.metadata.editing': false,
'app.metadata.deleting': false,
};
export type CoreSettings = typeof defaultSettings;
@@ -11,6 +11,7 @@ import { CommonDialogService, ConfirmationDialogDelete, DialogueStateResult, Ren
import { NotificationService } from '@cloudbeaver/core-events';
import { ActionService, ACTION_DELETE, ACTION_OPEN, ACTION_REFRESH, ACTION_RENAME, DATA_CONTEXT_MENU_NESTED, MenuSeparatorItem, MenuService } from '@cloudbeaver/core-view';
import { CoreSettingsService } from '../../../src/CoreSettingsService';
import { DATA_CONTEXT_NAV_NODE_ACTIONS } from '../../NavigationTree/NavigationTreeNode/TreeNodeMenu/DATA_CONTEXT_NAV_NODE_ACTIONS';
import { DATA_CONTEXT_NAV_NODE } from './DATA_CONTEXT_NAV_NODE';
import { ENodeFeature } from './ENodeFeature';
@@ -34,6 +35,7 @@ export class NavNodeContextMenuService extends Bootstrap {
private readonly navTreeResource: NavTreeResource,
private readonly actionService: ActionService,
private readonly menuService: MenuService,
private readonly coreSettingsService: CoreSettingsService
) {
super();
}
@@ -41,7 +43,7 @@ export class NavNodeContextMenuService extends Bootstrap {
register(): void {
this.actionService.addHandler({
id: 'nav-node-base-handler',
isActionApplicable(context, action) {
isActionApplicable: (context, action) => {
const node = context.tryGet(DATA_CONTEXT_NAV_NODE);
if (!node) {
@@ -49,11 +51,23 @@ export class NavNodeContextMenuService extends Bootstrap {
}
if (action === ACTION_RENAME) {
return node.features?.includes(ENodeFeature.canRename) || false;
const globalPermission = this.coreSettingsService.settings.getValue('app.metadata.editing');
if (!globalPermission) {
return false;
}
return !!node.features?.includes(ENodeFeature.canRename);
}
if (action === ACTION_DELETE) {
return node.features?.includes(ENodeFeature.canDelete) || false;
const globalPermission = this.coreSettingsService.settings.getValue('app.metadata.deleting');
if (!globalPermission) {
return false;
}
return !!node.features?.includes(ENodeFeature.canDelete);
}
return [
@@ -23,9 +23,16 @@ interface Props {
export const ObjectPropertyTableFooter = observer<Props>(function ObjectPropertyTableFooter({ nodeIds, tableState, className }) {
const service = useService(ObjectPropertyTableFooterService);
const items = service.constructMenuWithContext(nodeIds, tableState);
const hidden = items.every(item => item.isHidden);
if (hidden) {
return null;
}
return (
<ToolsPanel className={className}>
{service.constructMenuWithContext(nodeIds, tableState).map((topItem, i) => (
{items.map((topItem, i) => (
<ObjectPropertyTableFooterItem key={i} menuItem={topItem} />
))}
</ToolsPanel>
@@ -6,7 +6,7 @@
* you may not use this file except in compliance with the License.
*/
import { ENodeFeature, getNodeName, NavNode, NavNodeInfoResource, NavTreeResource } from '@cloudbeaver/core-app';
import { CoreSettingsService, ENodeFeature, getNodeName, NavNode, NavNodeInfoResource, NavTreeResource } from '@cloudbeaver/core-app';
import type { TableState } from '@cloudbeaver/core-blocks';
import { injectable } from '@cloudbeaver/core-di';
import {
@@ -32,6 +32,7 @@ export class ObjectPropertyTableFooterService {
private readonly navNodeInfoResource: NavNodeInfoResource,
private readonly notificationService: NotificationService,
private readonly commonDialogService: CommonDialogService,
private readonly coreSettingsService: CoreSettingsService
) {
this.contextMenuService.addPanel(this.objectPropertyTableFooterToken);
@@ -44,6 +45,7 @@ export class ObjectPropertyTableFooterService {
isPresent(context) {
return context.contextType === ObjectPropertyTableFooterService.objectPropertyContextType;
},
isHidden: () => !this.coreSettingsService.settings.getValue('app.metadata.deleting'),
isDisabled: context => {
if (context.data.tableState.selectedList.length === 0) {
return true;
@@ -9,6 +9,10 @@
defaultLanguage: "en"
},
app: {
metadata: {
editing: false,
deleting: false,
},
// Log viewer config
logViewer: {
refreshTimeout: 3000,