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

@@ -13,9 +13,6 @@ import {
WORKFLOW_SETTINGS_MODAL_KEY,
WORKFLOW_SHARE_MODAL_KEY,
} from '@/constants';
import type { PermissionsMap } from '@/permissions';
import type { WorkflowScope } from '@n8n/permissions';
import ShortenName from '@/components/ShortenName.vue';
import TagsContainer from '@/components/TagsContainer.vue';
import PushConnectionTracker from '@/components/PushConnectionTracker.vue';
@@ -38,8 +35,7 @@ import { saveAs } from 'file-saver';
import { useTitleChange } from '@/composables/useTitleChange';
import { useMessage } from '@/composables/useMessage';
import { useToast } from '@/composables/useToast';
import { getWorkflowPermissions } from '@/permissions';
import { getResourcePermissions } from '@/permissions';
import { createEventBus } from 'n8n-design-system/utils';
import { nodeViewEventBus } from '@/event-bus';
import { hasPermission } from '@/utils/rbac/permissions';
@@ -55,7 +51,7 @@ import type {
} from '@/Interface';
import { useI18n } from '@/composables/useI18n';
import { useTelemetry } from '@/composables/useTelemetry';
import type { BaseTextKey } from '../../plugins/i18n';
import type { BaseTextKey } from '@/plugins/i18n';
import { useNpsSurveyStore } from '@/stores/npsSurvey.store';
import { useLocalStorage } from '@vueuse/core';
@@ -140,9 +136,9 @@ const onExecutionsTab = computed(() => {
].includes((route.name as string) || '');
});
const workflowPermissions = computed<PermissionsMap<WorkflowScope>>(() => {
return getWorkflowPermissions(workflowsStore.getWorkflowById(props.workflow.id));
});
const workflowPermissions = computed(
() => getResourcePermissions(workflowsStore.getWorkflowById(props.workflow.id)?.scopes).workflow,
);
const workflowMenuItems = computed<ActionDropdownItem[]>(() => {
const actions: ActionDropdownItem[] = [
@@ -153,7 +149,7 @@ const workflowMenuItems = computed<ActionDropdownItem[]>(() => {
},
];
if (!props.readOnly) {
if ((workflowPermissions.value.delete && !props.readOnly) || isNewWorkflow.value) {
actions.unshift({
id: WORKFLOW_MENU_ACTIONS.DUPLICATE,
label: locale.baseText('menuActions.duplicate'),
@@ -631,7 +627,7 @@ function showCreateWorkflowSuccessToast(id?: string) {
:preview-value="shortenedName"
:is-edit-enabled="isNameEditEnabled"
:max-length="MAX_WORKFLOW_NAME_LENGTH"
:disabled="readOnly"
:disabled="readOnly || (!isNewWorkflow && !workflowPermissions.update)"
placeholder="Enter workflow name"
class="name"
@toggle="onNameToggle"
@@ -644,7 +640,7 @@ function showCreateWorkflowSuccessToast(id?: string) {
<span v-if="settingsStore.areTagsEnabled" class="tags" data-test-id="workflow-tags-container">
<TagsDropdown
v-if="isTagsEditEnabled && !readOnly"
v-if="isTagsEditEnabled && !readOnly && (isNewWorkflow || workflowPermissions.update)"
ref="dropdown"
v-model="appliedTagIds"
:event-bus="tagsEventBus"
@@ -654,7 +650,13 @@ function showCreateWorkflowSuccessToast(id?: string) {
@blur="onTagsBlur"
@esc="onTagsEditEsc"
/>
<div v-else-if="(workflow.tags ?? []).length === 0 && !readOnly">
<div
v-else-if="
(workflow.tags ?? []).length === 0 &&
!readOnly &&
(isNewWorkflow || workflowPermissions.update)
"
>
<span class="add-tag clickable" data-test-id="new-tag-link" @click="onTagsEditEnable">
+ {{ $locale.baseText('workflowDetails.addTag') }}
</span>
@@ -673,7 +675,11 @@ function showCreateWorkflowSuccessToast(id?: string) {
<PushConnectionTracker class="actions">
<span :class="`activator ${$style.group}`">
<WorkflowActivator :workflow-active="workflow.active" :workflow-id="workflow.id" />
<WorkflowActivator
:workflow-active="workflow.active"
:workflow-id="workflow.id"
:workflow-permissions="workflowPermissions"
/>
</span>
<EnterpriseEdition :features="[EnterpriseEditionFeature.Sharing]">
<div :class="$style.group">
@@ -717,9 +723,11 @@ function showCreateWorkflowSuccessToast(id?: string) {
<SaveButton
type="primary"
:saved="!uiStore.stateIsDirty && !isNewWorkflow"
:disabled="isWorkflowSaving || readOnly"
:disabled="
isWorkflowSaving || readOnly || (!isNewWorkflow && !workflowPermissions.update)
"
:is-saving="isWorkflowSaving"
with-shortcut
:with-shortcut="!readOnly && workflowPermissions.update"
:shortcut-tooltip="$locale.baseText('saveWorkflowButton.hint')"
data-test-id="workflow-save-button"
@click="onSaveButtonClick"