From 0084a637266bb69dd8a7174d3eeaaf45209af77d Mon Sep 17 00:00:00 2001 From: Alireza Heidari Date: Wed, 9 Oct 2024 15:00:44 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B:=20fix=20import=20type=20error?= =?UTF-8?q?=20and=20check=20for=20registered=20and=20anonymous=20user=20in?= =?UTF-8?q?=20`WorkflowInvocationHeader`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WorkflowInvocationHeader.vue | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/client/src/components/WorkflowInvocationState/WorkflowInvocationHeader.vue b/client/src/components/WorkflowInvocationState/WorkflowInvocationHeader.vue index d6f0142d5040..93b47c32b4f5 100644 --- a/client/src/components/WorkflowInvocationState/WorkflowInvocationHeader.vue +++ b/client/src/components/WorkflowInvocationState/WorkflowInvocationHeader.vue @@ -3,13 +3,15 @@ import { faClock } from "@fortawesome/free-regular-svg-icons"; import { faArrowLeft, faEdit, faHdd, faSitemap, faUpload } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome"; import { BAlert, BButton, BButtonGroup } from "bootstrap-vue"; +import { storeToRefs } from "pinia"; import { computed, ref } from "vue"; import { RouterLink } from "vue-router"; +import { isRegisteredUser } from "@/api"; import type { WorkflowInvocationElementView } from "@/api/invocations"; import { useWorkflowInstance } from "@/composables/useWorkflowInstance"; import { useUserStore } from "@/stores/userStore"; -import { Workflow } from "@/stores/workflowStore"; +import type { Workflow } from "@/stores/workflowStore"; import localize from "@/utils/localization"; import { errorMessageAsString } from "@/utils/simple-error"; @@ -31,10 +33,10 @@ const props = defineProps(); const { workflow } = useWorkflowInstance(props.invocation.workflow_id); -const userStore = useUserStore(); +const { currentUser, isAnonymous } = storeToRefs(useUserStore()); const owned = computed(() => { - if (userStore.currentUser && workflow.value) { - return userStore.currentUser.username === workflow.value.owner; + if (isRegisteredUser(currentUser.value) && workflow.value) { + return currentUser.value.username === workflow.value.owner; } else { return false; } @@ -129,7 +131,7 @@ function getWorkflowName(): string { v-else v-b-tooltip.hover.noninteractive size="sm" - :disabled="userStore.isAnonymous" + :disabled="isAnonymous" :title="localize('Import this workflow')" :icon="faUpload" variant="outline-primary" From e70109fc073bdd5c7d2376f91ce262e5f27c986f Mon Sep 17 00:00:00 2001 From: Alireza Heidari Date: Wed, 9 Oct 2024 15:15:36 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=94=EF=B8=8F:=20refactor=20`WorkflowI?= =?UTF-8?q?nvocationHeader`=20unit=20=20test=20to=20use=20fake=20registere?= =?UTF-8?q?d=20user?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WorkflowInvocationHeader.test.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/client/src/components/WorkflowInvocationState/WorkflowInvocationHeader.test.ts b/client/src/components/WorkflowInvocationState/WorkflowInvocationHeader.test.ts index f6308952b587..6964145c03b6 100644 --- a/client/src/components/WorkflowInvocationState/WorkflowInvocationHeader.test.ts +++ b/client/src/components/WorkflowInvocationState/WorkflowInvocationHeader.test.ts @@ -1,4 +1,5 @@ import { createTestingPinia } from "@pinia/testing"; +import { getFakeRegisteredUser } from "@tests/test-data"; import { shallowMount } from "@vue/test-utils"; import flushPromises from "flush-promises"; import { getLocalVue } from "tests/jest/helpers"; @@ -81,14 +82,9 @@ async function mountWorkflowInvocationHeader(ownsWorkflow = true, hasReturnBtn = }); const userStore = useUserStore(); - userStore.currentUser = { - id: "1", - email: "test@mail.test", - tags_used: [], - isAnonymous: false, - total_disk_usage: 0, + userStore.currentUser = getFakeRegisteredUser({ username: ownsWorkflow ? WORKFLOW_OWNER : OTHER_USER, - }; + }); return { wrapper }; }