fix(editor): Connect up new project viewer role to the FE (#9913)

This commit is contained in:
Csaba Tuncsik
2024-08-13 15:45:28 +02:00
committed by GitHub
parent 56c4692c94
commit 117e2d968f
56 changed files with 1482 additions and 1155 deletions

View File

@@ -38,6 +38,7 @@ describe('useContextMenu', () => {
workflowsStore = useWorkflowsStore();
workflowsStore.workflow.nodes = nodes;
workflowsStore.workflow.scopes = ['workflow:update'];
vi.spyOn(workflowsStore, 'getCurrentWorkflow').mockReturnValue({
nodes,
getNode: (_: string) => {
@@ -127,6 +128,7 @@ describe('useContextMenu', () => {
describe('Read-only mode', () => {
it('should return the correct actions when right clicking a sticky', () => {
vi.spyOn(uiStore, 'isReadOnlyView', 'get').mockReturnValue(true);
workflowsStore.workflow.scopes = ['workflow:read'];
const { open, isOpen, actions, targetNodeIds } = useContextMenu();
const sticky = nodeFactory({ type: STICKY_NODE_TYPE });
vi.spyOn(workflowsStore, 'getNodeById').mockReturnValue(sticky);

View File

@@ -10,6 +10,7 @@ import { getMousePosition } from '../utils/nodeViewUtils';
import { useI18n } from './useI18n';
import { usePinnedData } from './usePinnedData';
import { isPresent } from '../utils/typesUtils';
import { getResourcePermissions } from '@/permissions';
export type ContextMenuTarget =
| { source: 'canvas'; nodeIds: string[] }
@@ -46,8 +47,15 @@ export const useContextMenu = (onAction: ContextMenuActionCallback = () => {}) =
const i18n = useI18n();
const workflowPermissions = computed(
() => getResourcePermissions(workflowsStore.workflow.scopes).workflow,
);
const isReadOnly = computed(
() => sourceControlStore.preferences.branchReadOnly || uiStore.isReadOnlyView,
() =>
sourceControlStore.preferences.branchReadOnly ||
uiStore.isReadOnlyView ||
!workflowPermissions.value.update,
);
const targetNodeIds = computed(() => {