Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: permission checks for task action (#16708)

boojack36c3771f34d1
diff --git a/frontend/src/components/Plan/components/RolloutView/RolloutView.vue b/frontend/src/components/Plan/components/RolloutView/RolloutView.vue
index 9fcf8b9fb0..8264508bfa 100644
--- a/frontend/src/components/Plan/components/RolloutView/RolloutView.vue
+++ b/frontend/src/components/Plan/components/RolloutView/RolloutView.vue
@@ -34,11 +34,7 @@
:merged-stages="mergedStages"
:task-status-filter="taskStatusFilter"
/>
- <TaskTable
- v-else
- :rollout="rollout"
- :task-status-filter="taskStatusFilter"
- />
+ <TaskTableView v-else :task-status-filter="taskStatusFilter" />
</div>
</div>
</template>
@@ -50,10 +46,9 @@ import { ref } from "vue";
import { Task_Status } from "@/types/proto/v1/rollout_service";
import StagesView from "./StagesView.vue";
import TaskFilter from "./TaskFilter.vue";
-import TaskTable from "./TaskTable.vue";
+import TaskTableView from "./TaskTableView.vue";
import { provideRolloutViewContext } from "./context";
-// Provide the context and get its values directly
const { rollout, mergedStages } = provideRolloutViewContext();
const isTableView = ref(false);
diff --git a/frontend/src/components/Plan/components/RolloutView/RunTasksButton.vue b/frontend/src/components/Plan/components/RolloutView/RunTasksButton.vue
index af95377341..dd4ae7b80a 100644
--- a/frontend/src/components/Plan/components/RolloutView/RunTasksButton.vue
+++ b/frontend/src/components/Plan/components/RolloutView/RunTasksButton.vue
@@ -1,5 +1,9 @@
<template>
- <NButton v-if="hasRunnableTasks" size="tiny" @click="handleRunTasks">
+ <NButton
+ v-if="hasRunnableTasks && canRunTasks"
+ size="tiny"
+ @click="handleRunTasks"
+ >
<template #icon>
<PlayIcon class="w-4 h-4" />
</template>
@@ -11,8 +15,11 @@
import { PlayIcon } from "lucide-vue-next";
import { NButton } from "naive-ui";
import { computed } from "vue";
+import { useCurrentProjectV1 } from "@/store";
import type { Stage } from "@/types/proto/v1/rollout_service";
import { Task_Status } from "@/types/proto/v1/rollout_service";
+import { useRolloutViewContext } from "./context";
+import { useTaskActionPermissions } from "./taskPermissions";
const props = defineProps<{
stage: Stage;
@@ -22,6 +29,10 @@ const emit = defineEmits<{
(event: "run-tasks"): void;
}>();
+const { project } = useCurrentProjectV1();
+const { rollout } = useRolloutViewContext();
+const { canPerformTaskAction } = useTaskActionPermissions();
+
const hasRunnableTasks = computed(() => {
return props.stage.tasks.some(
(task) =>
@@ -31,6 +42,13 @@ const hasRunnableTasks = computed(() => {
);
});
+const canRunTasks = computed(() => {
+ if (!rollout.value) {
+ return false;
+ }
+ return canPerformTaskAction(props.stage.tasks, rollout.value, project.value);
+});
+
const handleRunTasks = () => {
emit("run-tasks");
};
diff --git a/frontend/src/components/Plan/components/RolloutView/StageCard.vue b/frontend/src/components/Plan/components/RolloutView/StageCard.vue
index e82439fa66..55a1c1a345 100644
--- a/frontend/src/components/Plan/components/RolloutView/StageCard.vue
+++ b/frontend/src/components/Plan/components/RolloutView/StageCard.vue
@@ -10,28 +10,38 @@
<div
class="w-full flex flex-row justify-between items-center gap-2 px-2 pt-2 pb-1"
>
- <p>
+ <div class="flex items-center space-x-1">
<span class="text-base font-medium">
{{ environmentStore.getEnvironmentByName(stage.environment).title }}
</span>
- <NTag class="ml-2" v-if="!isCreated" round size="tiny">Preview</NTag>
- </p>
- <div v-if="isCreated">
- <RunTasksButton :stage="stage" @run-tasks="handleRunAllTasks" />
+ <NTag v-if="!isCreated" round size="tiny">{{
+ $t("common.preview")
+ }}</NTag>
</div>
- <div v-else>
+ <div class="flex justify-end items-center">
+ <RunTasksButton
+ v-if="isCreated && canRunTasks"
+ :stage="stage"
+ @run-tasks="handleRunAllTasks"
+ />
<NPopconfirm
+ v-else-if="!isCreated && canCreateRollout"
:negative-text="null"
:positive-text="$t('common.confirm')"
:positive-button-props="{ size: 'tiny' }"
@positive-click="createRolloutToStage"
>
<template #trigger>
- <NButton text size="small">
- <template #icon>
- <CirclePlayIcon class="w-4 h-4" />
+ <NTooltip>
+ <template #trigger>
+ <NButton text size="small">
+ <template #icon>
+ <CircleFadingPlusIcon class="w-4 h-4" />
+ </template>
+ </NButton>
</template>
- </NButton>
+ {{ $t("common.create") }}
+ </NTooltip>
</template>
{{ $t("common.confirm-and-add") }}
</NPopconfirm>
@@ -79,7 +89,7 @@
<script setup lang="ts">
import { create } from "@bufbuild/protobuf";
-import { CirclePlayIcon } from "lucide-vue-next";
+import { CircleFadingPlusIcon } from "lucide-vue-next";
import { NTag, NTooltip, NVirtualList, NButton, NPopconfirm } from "naive-ui";
import { twMerge } from "tailwind-merge";
import { computed, ref } from "vue";
@@ -107,6 +117,7 @@ import RunTasksButton from "./RunTasksButton.vue";
import TaskDatabaseName from "./TaskDatabaseName.vue";
import TaskRolloutActionPanel from "./TaskRolloutActionPanel.vue";
import { useRolloutViewContext } from "./context";
+import { useTaskActionPermissions } from "./taskPermissions";
const props = defineProps<{
stage: Stage;
@@ -119,13 +130,11 @@ const { project } = useCurrentProjectV1();
const environmentStore = useEnvironmentV1Store();
const { events } = usePlanContextWithRollout();
const { rollout } = useRolloutViewContext();
+const { canPerformTaskAction } = useTaskActionPermissions();
const showRunTasksPanel = ref(false);
const isCreated = computed(() => {
- if (!rollout.value) {
- return false;
- }
return rollout.value.stages.some(
(stage) => stage.environment === props.stage.environment
);
@@ -140,9 +149,17 @@ const filteredTasks = computed(() => {
);
});
+const canRunTasks = computed(() => {
+ return canPerformTaskAction(props.stage.tasks, rollout.value, project.value);
+});
+
+const canCreateRollout = computed(() => {
+ return canRunTasks.value;
+});
+
// Helper function to extract IDs from task and stage names
const getTaskRouteParams = (task: Task) => {
- const rolloutId = rollout.value?.name.split("/").pop();
+ const rolloutId = rollout.value.name.split("/").pop();
const stageId = props.stage.name.split("/").pop();
const taskId = task.name.split("/").pop();
diff --git a/frontend/src/components/Plan/components/RolloutView/TaskOperations.vue b/frontend/src/components/Plan/components/RolloutView/TaskOperations.vue
new file mode 100644
index 0000000000..78ea5b3ee7
--- /dev/null
+++ b/frontend/src/components/Plan/components/RolloutView/TaskOperations.vue
@@ -0,0 +1,301 @@
+<template>
+ <NScrollbar x-scrollable>
+ <div
+ v-bind="$attrs"
+ class="text-sm flex flex-col lg:flex-row items-start lg:items-center bg-blue-100 py-3 px-4 text-main gap-y-2 gap-x-4"
+ >
+ <span class="whitespace-nowrap">{{
+ tasks.length > 0
+ ? $t("task.selected-n-tasks", { n: tasks.length })
+ : $t("task.no-tasks-selected")
+ }}</span>
+ <div class="flex items-center">
+ <template v-for="action in actions" :key="action.text">
+ <NTooltip
+ :disabled="!action.disabled || !action.tooltip(action.text)"
+ >
+ <template #trigger>
+ <NButton
+ quaternary
+ size="small"
+ type="primary"
+ :disabled="action.disabled"
+ @click="action.click"
+ >
+ <template #icon>
+ <component :is="action.icon" class="h-4 w-4" />
+ </template>
+ <span class="text-sm">{{ action.text }}</span>
+ </NButton>
+ </template>
+ <span class="w-56 text-sm">
+ {{ action.tooltip(action.text.toLowerCase()) }}
+ </span>
+ </NTooltip>
+ </template>
+ </div>
+ </div>
+ </NScrollbar>
+
+ <!-- Task Rollout Action Panel -->
+ <TaskRolloutActionPanel
+ v-if="state.showActionPanel && state.selectedAction && actionTarget"
+ :action="state.selectedAction"
+ :target="actionTarget"
+ @close="handleActionPanelClose"
+ />
+</template>
+
+<script lang="ts" setup>
+import { PlayIcon, XIcon, SkipForwardIcon } from "lucide-vue-next";
+import { NButton, NScrollbar, NTooltip } from "naive-ui";
+import type { VNode } from "vue";
+import { computed, h, reactive } from "vue";
+import { useI18n } from "vue-i18n";
+import { useCurrentProjectV1 } from "@/store";
+import { Task_Status } from "@/types/proto/v1/rollout_service";
+import type { Task, Rollout, Stage } from "@/types/proto/v1/rollout_service";
+import { usePlanContext } from "../../logic";
+import TaskRolloutActionPanel from "./TaskRolloutActionPanel.vue";
+import { useTaskActionPermissions } from "./taskPermissions";
+
+interface TaskAction {
+ icon: VNode;
+ text: string;
+ disabled: boolean;
+ click: () => void;
+ tooltip: (action: string) => string;
+}
+
+interface LocalState {
+ showActionPanel: boolean;
+ selectedAction?: "RUN" | "SKIP" | "CANCEL";
+}
+
+const props = defineProps<{
+ tasks: Task[];
+ rollout: Rollout;
+}>();
+
+const emit = defineEmits<{
+ (event: "refresh"): void;
+ (event: "task-action-completed"): void;
+}>();
+
+const state = reactive<LocalState>({
+ showActionPanel: false,
+ selectedAction: undefined,
+});
+
+const { t } = useI18n();
+const { project } = useCurrentProjectV1();
+const planContext = usePlanContext();
+const { canPerformTaskAction } = useTaskActionPermissions();
+
+// Get stages for selected tasks
+const selectedTaskStages = computed(() => {
+ const stageMap = new Map<string, Stage>();
+ props.rollout.stages.forEach((stage) => {
+ stage.tasks.forEach((task) => {
+ if (props.tasks.some((selectedTask) => selectedTask.name === task.name)) {
+ stageMap.set(stage.name, stage);
+ }
+ });
+ });
+ return Array.from(stageMap.values());
+});
+
+// Check if selected tasks are from multiple stages (cross-stage)
+const isCrossStage = computed(() => {
+ return selectedTaskStages.value.length > 1;
+});
+
+// Permission checks for each action
+const canRunTasks = computed(() => {
+ if (props.tasks.length === 0) return false;
+ return canPerformTaskAction(
+ props.tasks,
+ props.rollout,
+ project.value,
+ planContext.issue?.value
+ );
+});
+
+const canSkipTasks = computed(() => {
+ if (props.tasks.length === 0) return false;
+ return canPerformTaskAction(
+ props.tasks,
+ props.rollout,
+ project.value,
+ planContext.issue?.value
+ );
+});
+
+const canCancelTasks = computed(() => {
+ if (props.tasks.length === 0) return false;
+ return canPerformTaskAction(
+ props.tasks,
+ props.rollout,
+ project.value,
+ planContext.issue?.value
+ );
+});
+
+// Action target for the panel
+const actionTarget = computed(() => {
+ if (!state.selectedAction || selectedTaskStages.value.length === 0) {
+ return undefined;
+ }
+
+ if (state.selectedAction === "CANCEL") {
+ // For cancel actions, we would need task runs, but for now we'll use tasks
+ return {
+ type: "tasks" as const,
+ tasks: props.tasks,
+ stage: selectedTaskStages.value[0], // Use first stage for simplicity
+ };
+ } else {
+ return {
+ type: "tasks" as const,
+ tasks: props.tasks,
+ stage: selectedTaskStages.value[0], // Use first stage for simplicity
+ };
+ }
+});
+
+// Check if tasks have the right status for each action
+const hasRunnableTasks = computed(() => {
+ return props.tasks.some((task) =>
+ [Task_Status.NOT_STARTED, Task_Status.FAILED].includes(task.status)
+ );
+});
+
+const hasCancellableTasks = computed(() => {
+ return props.tasks.some((task) =>
+ [Task_Status.PENDING, Task_Status.RUNNING].includes(task.status)
+ );
+});
+
+const hasSkippableTasks = computed(() => {
+ return props.tasks.some((task) =>
+ [
+ Task_Status.NOT_STARTED,
+ Task_Status.FAILED,
+ Task_Status.CANCELED,
+ ].includes(task.status)
+ );
+});
+
+const getDisabledTooltip = (_action: string) => {
+ if (props.tasks.length === 0) {
+ return t("task.no-tasks-selected");
+ }
+ if (isCrossStage.value) {
+ return t("task.cross-stage-not-supported");
+ }
+ return "";
+};
+
+const actions = computed((): TaskAction[] => {
+ const resp: TaskAction[] = [];
+
+ // Run action - always show
+ resp.push({
+ icon: h(PlayIcon),
+ text: t("common.run"),
+ disabled:
+ props.tasks.length === 0 ||
+ isCrossStage.value ||
+ !canRunTasks.value ||
+ !hasRunnableTasks.value,
+ click: () => {
+ state.selectedAction = "RUN";
+ state.showActionPanel = true;
+ },
+ tooltip: (action) => {
+ if (props.tasks.length === 0) {
+ return getDisabledTooltip(action);
+ }
+ if (isCrossStage.value) {
+ return getDisabledTooltip(action);
+ }
+ if (!canRunTasks.value) {
+ return t("task.no-permission");
+ }
+ if (!hasRunnableTasks.value) {
+ return t("task.no-runnable-tasks");
+ }
+ return "";
+ },
+ });
+
+ // Skip action - always show
+ resp.push({
+ icon: h(SkipForwardIcon),
+ text: t("common.skip"),
+ disabled:
+ props.tasks.length === 0 ||
+ isCrossStage.value ||
+ !canSkipTasks.value ||
+ !hasSkippableTasks.value,
+ click: () => {
+ state.selectedAction = "SKIP";
+ state.showActionPanel = true;
+ },
+ tooltip: (action) => {
+ if (props.tasks.length === 0) {
+ return getDisabledTooltip(action);
+ }
+ if (isCrossStage.value) {
+ return getDisabledTooltip(action);
+ }
+ if (!canSkipTasks.value) {
+ return t("task.no-permission");
+ }
+ if (!hasSkippableTasks.value) {
+ return t("task.no-skippable-tasks");
+ }
+ return "";
+ },
+ });
+
+ // Cancel action - always show
+ resp.push({
+ icon: h(XIcon),
+ text: t("common.cancel"),
+ disabled:
+ props.tasks.length === 0 ||
+ isCrossStage.value ||
+ !canCancelTasks.value ||
+ !hasCancellableTasks.value,
+ click: () => {
+ state.selectedAction = "CANCEL";
+ state.showActionPanel = true;
+ },
+ tooltip: (action) => {
+ if (props.tasks.length === 0) {
+ return getDisabledTooltip(action);
+ }
+ if (isCrossStage.value) {
+ return getDisabledTooltip(action);
+ }
+ if (!canCancelTasks.value) {
+ return t("task.no-permission");
+ }
+ if (!hasCancellableTasks.value) {
+ return t("task.no-cancellable-tasks");
+ }
+ return "";
+ },
+ });
+
+ return resp;
+});
+
+const handleActionPanelClose = () => {
+ state.showActionPanel = false;
+ state.selectedAction = undefined;
+ emit("task-action-completed");
+ emit("refresh");
+};
+</script>
diff --git a/frontend/src/components/Plan/components/RolloutView/TaskRolloutActionPanel.vue b/frontend/src/components/Plan/components/RolloutView/TaskRolloutActionPanel.vue
index d9c0a15126..5a5814e785 100644
--- a/frontend/src/components/Plan/components/RolloutView/TaskRolloutActionPanel.vue
+++ b/frontend/src/components/Plan/components/RolloutView/TaskRolloutActionPanel.vue
@@ -32,28 +32,9 @@
</template>
<template v-else>{{ $t("common.tasks") }}</template>
<span class="opacity-80" v-if="eligibleTasks.length > 1">
- <template v-if="showTaskSelection">
- ({{ selectedTaskNames.size }} / {{ eligibleTasks.length }})
- </template>
- <template v-else> ({{ eligibleTasks.length }}) </template>
+ ({{ eligibleTasks.length }})
</span>
</label>
- <div v-if="showTaskSelection" class="flex gap-x-2">
- <NButton
- size="tiny"
- :disabled="selectedTaskNames.size === eligibleTasks.length"
- @click="selectAllTasks"
- >
- {{ $t("sql-review.select-all") }}
- </NButton>
- <NButton
- size="tiny"
- :disabled="selectedTaskNames.size === 0"
- @click="selectNoTasks"
- >
- {{ "Clear" }}
- </NButton>
- </div>
</div>
<div class="flex-1 overflow-y-auto">
<template v-if="useVirtualScroll">
@@ -69,14 +50,6 @@
class="flex items-center text-sm"
:style="{ height: `${itemHeight}px` }"
>
- <NCheckbox
- v-if="showTaskSelection"
- :checked="selectedTaskNames.has(task.name)"
- @update:checked="
- (checked) => handleTaskSelectionChange(task, checked)
- "
- class="mr-2"
- />
<NTag
v-if="semanticTaskType(task.type)"
class="mr-2"
@@ -99,14 +72,6 @@
:key="task.name"
class="flex items-center"
>
- <NCheckbox
- v-if="showTaskSelection"
- :checked="selectedTaskNames.has(task.name)"
- @update:checked="
- (checked) => handleTaskSelectionChange(task, checked)
- "
- class="mr-2"
- />
<NTag
v-if="semanticTaskType(task.type)"
class="mr-2"
@@ -215,13 +180,13 @@ import dayjs from "dayjs";
import Long from "long";
import {
NButton,
- NCheckbox,
NDatePicker,
NInput,
NScrollbar,
NTag,
NTooltip,
NVirtualList,
+ NCheckbox,
} from "naive-ui";
import { computed, reactive, ref } from "vue";
import { useI18n } from "vue-i18n";
@@ -266,7 +231,6 @@ const state = reactive<LocalState>({
const environmentStore = useEnvironmentV1Store();
const comment = ref("");
const runTimeInMS = ref<number | undefined>(undefined);
-const selectedTaskNames = ref<Set<string>>(new Set());
// Extract stage from target
const targetStage = computed(() => {
@@ -341,28 +305,14 @@ const eligibleTasks = computed(() => {
return [];
});
-// Show task selection UI when there are multiple eligible tasks and no specific tasks provided
-const showTaskSelection = computed(() => {
- return (
- eligibleTasks.value.length > 1 &&
- props.target.type === "tasks" &&
- !targetTasks.value
- );
-});
-
-// Get the tasks that will actually be run (selected or all)
+// Get the tasks that will actually be run
const runnableTasks = computed(() => {
- if (showTaskSelection.value && selectedTaskNames.value.size > 0) {
- return eligibleTasks.value.filter((task) =>
- selectedTaskNames.value.has(task.name)
- );
- }
return eligibleTasks.value;
});
// Virtual scroll configuration
const useVirtualScroll = computed(() => eligibleTasks.value.length > 50);
-const itemHeight = computed(() => (showTaskSelection.value ? 40 : 32)); // Height of each task item in pixels
+const itemHeight = computed(() => 32); // Height of each task item in pixels
const showScheduledTimePicker = computed(() => {
return props.action === "RUN";
@@ -372,11 +322,7 @@ const confirmErrors = computed(() => {
const errors: string[] = [];
if (runnableTasks.value.length === 0) {
- if (showTaskSelection.value && eligibleTasks.value.length > 0) {
- errors.push("Please select at least one task");
- } else {
- errors.push(t("common.no-data"));
- }
+ errors.push(t("common.no-data"));
}
// Validate scheduled time if not running immediately (only for RUN)
@@ -454,33 +400,8 @@ const handleConfirm = async () => {
}
};
-const handleTaskSelectionChange = (task: Task, checked: boolean) => {
- if (checked) {
- selectedTaskNames.value.add(task.name);
- } else {
- selectedTaskNames.value.delete(task.name);
- }
- // Trigger reactivity
- selectedTaskNames.value = new Set(selectedTaskNames.value);
-};
-
-const selectAllTasks = () => {
- selectedTaskNames.value = new Set(eligibleTasks.value.map((t) => t.name));
-};
-
-const selectNoTasks = () => {
- selectedTaskNames.value.clear();
- selectedTaskNames.value = new Set();
-};
-
const resetState = () => {
comment.value = "";
runTimeInMS.value = undefined;
- selectedTaskNames.value.clear();
-
- // Pre-select all tasks by default when showing selection
- if (showTaskSelection.value) {
- selectAllTasks();
- }
};
</script>
diff --git a/frontend/src/components/Plan/components/RolloutView/TaskTable.vue b/frontend/src/components/Plan/components/RolloutView/TaskTable.vue
index eb58e6a980..cff0567d4e 100644
--- a/frontend/src/components/Plan/components/RolloutView/TaskTable.vue
+++ b/frontend/src/components/Plan/components/RolloutView/TaskTable.vue
@@ -1,18 +1,18 @@
<template>
- <div class="w-full h-full flex flex-col p-4">
- <NDataTable
- size="small"
- :columns="columnList"
- :data="taskList"
- :striped="true"
- :bordered="true"
- :row-key="(task: Task) => task.name"
- :virtual-scroll="virtualScrollEnabled"
- :max-height="'80vh'"
- :row-height="virtualScrollEnabled ? 40 : undefined"
- :row-props="rowProps"
- />
- </div>
+ <NDataTable
+ size="small"
+ :columns="columnList"
+ :data="taskList"
+ :striped="true"
+ :bordered="false"
+ :row-key="(task: Task) => task.name"
+ :virtual-scroll="virtualScrollEnabled"
+ :max-height="'80vh'"
+ :row-height="virtualScrollEnabled ? 40 : undefined"
+ :row-props="rowProps"
+ :checked-row-keys="selectedTaskNames"
+ @update:checked-row-keys="handleSelectionChange"
+ />
</template>
<script lang="tsx" setup>
@@ -29,30 +29,36 @@ import { databaseForTask } from "@/components/Rollout/RolloutDetail/utils";
import { InstanceV1EngineIcon } from "@/components/v2";
import { PROJECT_V1_ROUTE_ROLLOUT_DETAIL_TASK_DETAIL } from "@/router/dashboard/projectV1";
import { useCurrentProjectV1, useEnvironmentV1Store } from "@/store";
-import type {
- Task,
- Rollout,
- Task_Status,
-} from "@/types/proto/v1/rollout_service";
+import type { Task, Task_Status } from "@/types/proto/v1/rollout_service";
import {
extractProjectResourceName,
extractSchemaVersionFromTask,
} from "@/utils";
import { useRolloutViewContext } from "./context";
-const props = defineProps<{
- rollout: Rollout;
- taskStatusFilter: Task_Status[];
+const props = withDefaults(
+ defineProps<{
+ taskStatusFilter: Task_Status[];
+ selectedTasks?: Task[];
+ }>(),
+ {
+ selectedTasks: () => [],
+ }
+);
+
+const emit = defineEmits<{
+ (event: "update:selected-tasks", tasks: Task[]): void;
+ (event: "refresh"): void;
}>();
const { t } = useI18n();
const router = useRouter();
const { project } = useCurrentProjectV1();
const environmentStore = useEnvironmentV1Store();
-const { mergedStages } = useRolloutViewContext();
+const { rollout, mergedStages } = useRolloutViewContext();
const taskList = computed(() => {
- const allTasks = flatten(mergedStages.value.map((stage) => stage.tasks));
+ const allTasks = flatten(rollout.value.stages.map((stage) => stage.tasks));
if (props.taskStatusFilter.length === 0) {
return allTasks;
}
@@ -61,6 +67,18 @@ const taskList = computed(() => {
);
});
+// Selection handling
+const selectedTaskNames = computed(() => {
+ return props.selectedTasks.map((task) => task.name);
+});
+
+const handleSelectionChange = (selectedKeys: Array<string | number>) => {
+ const selectedTasks = taskList.value.filter((task) =>
+ selectedKeys.includes(task.name)
+ );
+ emit("update:selected-tasks", selectedTasks);
+};
+
const stages = computed(() => mergedStages.value);
// Virtual scroll configuration
@@ -82,7 +100,7 @@ const getTaskRouteParams = (task: Task) => {
const stage = stageMap.value.get(task.name);
if (!stage) return null;
- const rolloutId = props.rollout.name.split("/").pop();
+ const rolloutId = rollout.value.name.split("/").pop();
const stageId = stage.name.split("/").pop();
const taskId = task.name.split("/").pop();
@@ -115,6 +133,17 @@ const rowProps = (task: Task) => {
const columnList = computed((): DataTableColumn<Task>[] => {
return [
+ {
+ type: "selection",
+ width: 50,
+ cellProps: () => {
+ return {
+ onClick: (e: MouseEvent) => {
+ e.stopPropagation();
+ },
+ };
+ },
+ },
{
key: "status",
width: 80,
diff --git a/frontend/src/components/Plan/components/RolloutView/TaskTableView.vue b/frontend/src/components/Plan/components/RolloutView/TaskTableView.vue
new file mode 100644
index 0000000000..78b1a6c451
--- /dev/null
+++ b/frontend/src/components/Plan/components/RolloutView/TaskTableView.vue
@@ -0,0 +1,50 @@
+<template>
+ <div class="w-full flex flex-col mt-4">
+ <!-- Task Operations Bar -->
+ <TaskOperations
+ :tasks="selectedTasks"
+ :rollout="rollout"
+ @refresh="handleRefresh"
+ @task-action-completed="handleTaskActionCompleted"
+ />
+
+ <!-- Task Table -->
+ <div class="flex-1 overflow-hidden">
+ <TaskTable
+ :task-status-filter="taskStatusFilter"
+ :selected-tasks="selectedTasks"
+ @update:selected-tasks="handleSelectedTasksUpdate"
+ @refresh="handleRefresh"
+ />
+ </div>
+ </div>
+</template>
+
+<script setup lang="ts">
+import { ref } from "vue";
+import type { Task, Task_Status } from "@/types/proto/v1/rollout_service";
+import { usePlanContextWithRollout } from "../../logic";
+import TaskOperations from "./TaskOperations.vue";
+import TaskTable from "./TaskTable.vue";
+
+defineProps<{
+ taskStatusFilter: Task_Status[];
+}>();
+
+const { rollout, events } = usePlanContextWithRollout();
+const selectedTasks = ref<Task[]>([]);
+
+const handleSelectedTasksUpdate = (tasks: Task[]) => {
+ selectedTasks.value = tasks;
+};
+
+const handleRefresh = () => {
+ events.emit("status-changed", { eager: true });
+};
+
+const handleTaskActionCompleted = () => {
+ // Clear selection after action is completed
+ selectedTasks.value = [];
+ handleRefresh();
+};
+</script>
diff --git a/frontend/src/components/Plan/components/RolloutView/taskPermissions.ts b/frontend/src/components/Plan/components/RolloutView/taskPermissions.ts
new file mode 100644
index 0000000000..aae60794cf
--- /dev/null
+++ b/frontend/src/components/Plan/components/RolloutView/taskPermissions.ts
@@ -0,0 +1,130 @@
+import { uniq } from "lodash-es";
+import { useCurrentUserV1, useCurrentProjectV1 } from "@/store";
+import { userNamePrefix, roleNamePrefix } from "@/store/modules/v1/common";
+import type { ComposedProject } from "@/types";
+import { Issue_Type, type Issue } from "@/types/proto/v1/issue_service";
+import type { Task } from "@/types/proto/v1/rollout_service";
+import type { Rollout } from "@/types/proto/v1/rollout_service";
+import {
+ hasWorkspacePermissionV2,
+ hasProjectPermissionV2,
+ memberMapToRolesInProjectIAM,
+} from "@/utils";
+
+/**
+ * Check if the current user can perform task actions for the given tasks
+ */
+export const useTaskActionPermissions = () => {
+ const currentUser = useCurrentUserV1();
+ const { project } = useCurrentProjectV1();
+ const formatedCurrentUser = `${userNamePrefix}${currentUser.value.email}`;
+
+ /**
+ * Get releaser candidates for an issue (similar to releaserCandidatesForIssue)
+ */
+ const getReleaserCandidatesForIssue = (issue: Issue): string[] => {
+ const projectMembersMap = memberMapToRolesInProjectIAM(
+ project.value.iamPolicy
+ );
+ const users: string[] = [];
+
+ for (let i = 0; i < issue.releasers.length; i++) {
+ const releaserRole = issue.releasers[i];
+ if (releaserRole.startsWith(roleNamePrefix)) {
+ for (const [user, roleSet] of projectMembersMap.entries()) {
+ if (roleSet.has(releaserRole)) {
+ users.push(user);
+ }
+ }
+ } else if (releaserRole.startsWith(userNamePrefix)) {
+ users.push(releaserRole);
+ }
+ }
+
+ return uniq(users);
+ };
+
+ /**
+ * Check if user can perform task actions based on issue releaser roles
+ */
+ const canPerformTaskActionForIssue = (issue: Issue): boolean => {
+ // For data export issues, only the creator can run tasks
+ if (issue.type === Issue_Type.DATABASE_EXPORT) {
+ return issue.creator === formatedCurrentUser;
+ }
+
+ const releaserCandidates = getReleaserCandidatesForIssue(issue);
+ // Check if current user is in releaser candidates
+ return releaserCandidates.includes(formatedCurrentUser);
+ };
+
+ /**
+ * Check if user can perform task actions based on environment rollout policy
+ * This follows the logic from canUserRunEnvironmentTasks in backend
+ */
+ const canPerformTaskActionForEnvironment = (
+ project: ComposedProject,
+ _environment: string
+ ): boolean => {
+ // Users with bb.taskRuns.create can always create task runs
+ if (hasWorkspacePermissionV2("bb.taskRuns.create")) {
+ return true;
+ }
+
+ // Check project-level permissions for task runs
+ if (hasProjectPermissionV2(project, "bb.taskRuns.create")) {
+ return true;
+ }
+
+ // TODO: Check rollout policy for environment-specific permissions
+ // This would require fetching the rollout policy for the environment
+ // For now, we'll use basic project permissions
+
+ return false;
+ };
+
+ /**
+ * Main function to check if user can perform task actions
+ */
+ const canPerformTaskAction = (
+ tasks: Task[],
+ rollout: Rollout,
+ project: ComposedProject,
+ issue?: Issue
+ ): boolean => {
+ if (tasks.length === 0) {
+ return false;
+ }
+
+ // If there's an issue, check issue-based permissions.
+ if (issue) {
+ return canPerformTaskActionForIssue(issue);
+ }
+
+ // Otherwise, check environment-based permissions
+ // Get unique environments from tasks
+ const environments = new Set<string>();
+ rollout.stages.forEach((stage) => {
+ stage.tasks.forEach((task) => {
+ if (tasks.some((selectedTask) => selectedTask.name === task.name)) {
+ environments.add(stage.environment);
+ }
+ });
+ });
+
+ // Check permissions for each environment
+ for (const environment of environments) {
+ if (!canPerformTaskActionForEnvironment(project, environment)) {
+ return false;
+ }
+ }
+
+ return true;
+ };
+
+ return {
+ canPerformTaskAction,
+ canPerformTaskActionForIssue,
+ canPerformTaskActionForEnvironment,
+ };
+};
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index ba0cb2b117..ead4f0badd 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -278,6 +278,13 @@
"cancel-task": "Cancel task | Cancel tasks",
"created": "Created",
"run-immediately": "Run task immediately | Run tasks immediately",
+ "selected-n-tasks": "{n} task selected | {n} tasks selected",
+ "no-tasks-selected": "No tasks selected",
+ "no-runnable-tasks": "No runnable tasks",
+ "no-skippable-tasks": "No skippable tasks",
+ "no-cancellable-tasks": "No cancellable tasks",
+ "cross-stage-not-supported": "Cross-stage operations not supported",
+ "no-permission": "No permission to perform this action",
"scheduled-time": "Scheduled time",
"select-scheduled-time": "Select scheduled time",
"error": {
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 9b8d386ca7..e38587f584 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -278,6 +278,13 @@
"cancel-task": "Cancelar tarea | Cancelar tareas",
"created": "Creado",
"run-immediately": "Ejecutar tarea inmediatamente",
+ "selected-n-tasks": "{n} tarea seleccionada | {n} tareas seleccionadas",
+ "no-tasks-selected": "No hay tareas seleccionadas",
+ "no-runnable-tasks": "No hay tareas ejecutables",
+ "no-skippable-tasks": "No hay tareas que se puedan omitir",
+ "no-cancellable-tasks": "No hay tareas cancelables",
+ "cross-stage-not-supported": "No se admiten operaciones entre etapas",
+ "no-permission": "No hay permiso para realizar esta acción",
"scheduled-time": "Hora programada",
"select-scheduled-time": "Seleccionar hora programada",
"error": {
@@ -2798,4 +2805,4 @@
"last-visit": "Última visita",
"changelog-for-version": "Registro de cambios para {version}"
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 0dc5ef2dbc..79c60d018b 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -278,6 +278,13 @@
"cancel-task": "タスクをキャンセルする",
"created": "内蔵",
"run-immediately": "すぐに実行",
+ "selected-n-tasks": "{n} 個のタスクが選択されました | {n} 個のタスクが選択されました",
+ "no-tasks-selected": "タスクが選択されていません",
+ "no-runnable-tasks": "実行可能なタスクはありません",
+ "no-skippable-tasks": "スキップ可能なタスクはありません",
+ "no-cancellable-tasks": "キャンセル可能なタスクはありません",
+ "cross-stage-not-supported": "ステージ間の操作はサポートされていません",
+ "no-permission": "この操作を実行する権限がありません",
"scheduled-time": "予定時刻",
"select-scheduled-time": "予定時刻を選択してください",
"error": {
@@ -2798,4 +2805,4 @@
"last-visit": "最終訪問",
"changelog-for-version": "{version} の変更履歴"
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index 42b2636069..a4c4ff33a9 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -278,6 +278,13 @@
"cancel-task": "Hủy tác vụ | Hủy các tác vụ",
"created": "Đã tạo",
"run-immediately": "Chạy nhiệm vụ ngay lập tức",
+ "selected-n-tasks": "{n} nhiệm vụ đã chọn | {n} nhiệm vụ đã chọn",
+ "no-tasks-selected": "Không có nhiệm vụ nào được chọn",
+ "no-runnable-tasks": "Không có tác vụ nào có thể chạy được",
+ "no-skippable-tasks": "Không có nhiệm vụ nào có thể bỏ qua",
+ "no-cancellable-tasks": "Không có nhiệm vụ nào có thể hủy bỏ",
+ "cross-stage-not-supported": "Hoạt động liên giai đoạn không được hỗ trợ",
+ "no-permission": "Không có quyền thực hiện hành động này",
"scheduled-time": "Thời gian đã lên lịch",
"select-scheduled-time": "Chọn thời gian đã lên lịch",
"error": {
@@ -2798,4 +2805,4 @@
"last-visit": "Lần truy cập cuối",
"changelog-for-version": "Nhật ký thay đổi cho phiên bản {version}"
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index d6add8bf32..8421bcae0c 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -278,6 +278,13 @@
"cancel-task": "取消任务",
"created": "创建于",
"run-immediately": "立即运行任务",
+ "selected-n-tasks": "已选择 {n} 个任务",
+ "no-tasks-selected": "未选择任何任务",
+ "no-runnable-tasks": "没有可运行的任务",
+ "no-skippable-tasks": "没有可跳过的任务",
+ "no-cancellable-tasks": "没有可取消的任务",
+ "cross-stage-not-supported": "不支持跨阶段操作",
+ "no-permission": "无权限执行该操作",
"scheduled-time": "计划时间",
"select-scheduled-time": "选择计划时间",
"error": {