Skip to content

Commit

Permalink
Update work queue permission checks to use object level checks when a…
Browse files Browse the repository at this point in the history
…pproproate
  • Loading branch information
pleek91 committed Aug 27, 2024
1 parent 0a2d23d commit 7d521b1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
26 changes: 17 additions & 9 deletions src/components/WorkPoolQueueMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
<p-icon-button-menu v-bind="$attrs" class="work-pool-queue-menu">
<CopyOverflowMenuItem label="Copy ID" :item="workPoolQueue.id" />

<router-link :to="routes.workPoolQueueEdit(workPoolName, workPoolQueue.name)">
<p-overflow-menu-item v-if="can.update.work_queue" label="Edit" />
</router-link>
<template v-if="workPoolQueue.can.update">
<router-link :to="routes.workPoolQueueEdit(workPoolName, workPoolQueue.name)">
<p-overflow-menu-item label="Edit" />
</router-link>
</template>

<p-overflow-menu-item v-if="showDelete" label="Delete" @click="open" />
<template v-if="showDelete">
<p-overflow-menu-item label="Delete" @click="open" />
</template>

<slot v-bind="{ workPoolQueue }">
<router-link v-if="can.create.automation" :to="routes.automateWorkPoolQueue(workPoolQueue.id)">
Expand All @@ -32,10 +36,9 @@
</script>

<script lang="ts" setup>
import { useSubscription } from '@prefecthq/vue-compositions'
import { computed } from 'vue'
import { CopyOverflowMenuItem, ConfirmDeleteModal } from '@/components'
import { useCan, useShowModal, useWorkspaceApi, useWorkspaceRoutes } from '@/compositions'
import { useCan, useShowModal, useWorkPool, useWorkspaceApi, useWorkspaceRoutes } from '@/compositions'
import { WorkPoolQueue } from '@/models'
import { deleteItem } from '@/utilities'
Expand All @@ -52,11 +55,16 @@
const api = useWorkspaceApi()
const routes = useWorkspaceRoutes()
const { showModal, open, close } = useShowModal()
const workPoolSubscription = useSubscription(api.workPools.getWorkPoolByName, [props.workPoolName])
const workPool = computed(() => workPoolSubscription.response)
const { workPool } = useWorkPool(() => props.workPoolName)
const showDelete = computed(() => {
return !workPool.value || workPool.value.defaultQueueId !== props.workPoolQueue.id && can.delete.work_queue
if (!workPool.value) {
return false
}
const isDefaultWorkQueue = workPool.value.defaultQueueId === props.workPoolQueue.id
return !isDefaultWorkQueue && props.workPoolQueue.can.delete
})
async function deleteWorkPoolQueue(name: string): Promise<void> {
Expand Down
8 changes: 5 additions & 3 deletions src/components/WorkPoolQueueToggle.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<template>
<p-tooltip text="Pause or resume this work queue">
<p-toggle v-if="can.update.work_queue" v-model="internalValue" />
</p-tooltip>
<template v-if="workPoolQueue.can.update">
<p-tooltip text="Pause or resume this work queue">
<p-toggle v-model="internalValue" />
</p-tooltip>
</template>
</template>

<script lang="ts" setup>
Expand Down
17 changes: 9 additions & 8 deletions src/components/WorkPoolQueuesTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
<p-list-header sticky>
<ResultsCount v-if="selected.length == 0" label="Work Queue" :count="filteredWorkPoolQueues.length" />
<SelectedCount v-else :count="selected.length" />
<p-button v-if="can.create.work_queue && !selected.length" size="sm" icon="PlusIcon" :to="routes.workPoolQueueCreate(workPoolName)" />

<WorkPoolQueuesDeleteButton v-if="can.delete.work_queue" :work-pool-name="workPoolName" :work-pool-queues="selected" @delete="handleDelete" />
<template v-if="workPool?.can.update && !selected.length">
<p-button size="sm" icon="PlusIcon" :to="routes.workPoolQueueCreate(workPoolName)" />
</template>

<template v-if="workPool?.can.delete">
<WorkPoolQueuesDeleteButton :work-pool-name="workPoolName" :work-pool-queues="selected" @delete="handleDelete" />
</template>

<template #controls>
<SearchInput v-model="search" label="Search" placeholder="Search" />
Expand Down Expand Up @@ -47,7 +52,7 @@
import { useSubscription } from '@prefecthq/vue-compositions'
import { ref, computed } from 'vue'
import { SearchInput, ResultsCount, SelectedCount, WorkPoolQueuesDeleteButton, WorkPoolQueuePriorityLabel, WorkersLateIndicator, WorkPoolQueueToggle, WorkPoolQueueStatusBadge } from '@/components'
import { useCan, useWorkspaceRoutes, useWorkspaceApi, useComponent } from '@/compositions'
import { useCan, useWorkspaceRoutes, useWorkspaceApi, useComponent, useWorkPool } from '@/compositions'
import { WorkPoolQueue, WorkPoolQueueTableData } from '@/models'
import { hasString, isRecord } from '@/utilities'
Expand All @@ -62,14 +67,10 @@
const search = ref('')
const workPoolSubscription = useSubscription(api.workPools.getWorkPoolByName, [props.workPoolName])
const workPool = computed(() => {
return workPoolSubscription.response
})
const { workPool, subscription: workPoolSubscription } = useWorkPool(() => props.workPoolName)
const workPoolQueuesSubscription = useSubscription(api.workPoolQueues.getWorkPoolQueues, [props.workPoolName])
const workPoolQueues = computed(() => workPoolQueuesSubscription.response ?? [])
const workPoolQueuesData = computed(() => workPoolQueues.value.map(queue => new WorkPoolQueueTableData({
...queue,
disabled: !workPool.value || workPool.value.defaultQueueId == queue.id,
Expand Down

0 comments on commit 7d521b1

Please sign in to comment.