Skip to content

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

fix: unify rollout button permission checks (#17221)

boojacke8b3ca0a1e9f
diff --git a/frontend/src/components/Plan/components/RolloutView/RolloutView.vue b/frontend/src/components/Plan/components/RolloutView/RolloutView.vue
index 1ccaed4df3..1d8e4b4429 100644
--- a/frontend/src/components/Plan/components/RolloutView/RolloutView.vue
+++ b/frontend/src/components/Plan/components/RolloutView/RolloutView.vue
@@ -26,7 +26,6 @@
<StagesView
:rollout="rollout"
:merged-stages="mergedStages"
- :readonly="readonly"
@run-tasks="handleRunTasks"
@create-rollout-to-stage="handleCreateRolloutToStage"
/>
@@ -65,7 +64,7 @@ import { useRolloutViewContext } from "./context";
const { t } = useI18n();
const { project } = useCurrentProjectV1();
-const { events, readonly } = usePlanContextWithRollout();
+const { events } = usePlanContextWithRollout();
const { rollout, mergedStages } = useRolloutViewContext();
const runTasksPanel = ref<{
diff --git a/frontend/src/components/Plan/components/RolloutView/RunTasksButton.vue b/frontend/src/components/Plan/components/RolloutView/RunTasksButton.vue
deleted file mode 100644
index b97ad1e42c..0000000000
--- a/frontend/src/components/Plan/components/RolloutView/RunTasksButton.vue
+++ /dev/null
@@ -1,55 +0,0 @@
-<template>
- <NButton
- v-if="hasRunnableTasks && canRunTasks"
- v-bind="$attrs"
- @click.stop="handleRunTasks"
- >
- <template #icon>
- <PlayIcon />
- </template>
- {{ $t("common.run") }}
- </NButton>
-</template>
-
-<script setup lang="ts">
-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-es/v1/rollout_service_pb";
-import { Task_Status } from "@/types/proto-es/v1/rollout_service_pb";
-import { useRolloutViewContext } from "./context";
-import { useTaskActionPermissions } from "./taskPermissions";
-
-const props = defineProps<{
- stage: Stage;
-}>();
-
-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) =>
- task.status === Task_Status.NOT_STARTED ||
- task.status === Task_Status.PENDING ||
- task.status === Task_Status.FAILED
- );
-});
-
-const canRunTasks = computed(() => {
- if (!rollout.value) {
- return false;
- }
- return canPerformTaskAction(props.stage.tasks, rollout.value, project.value);
-});
-
-const handleRunTasks = () => {
- emit("run-tasks");
-};
-</script>
diff --git a/frontend/src/components/Plan/components/RolloutView/StageCard.vue b/frontend/src/components/Plan/components/RolloutView/StageCard.vue
index c35189d5af..69e27846b6 100644
--- a/frontend/src/components/Plan/components/RolloutView/StageCard.vue
+++ b/frontend/src/components/Plan/components/RolloutView/StageCard.vue
@@ -147,14 +147,18 @@
</div>
<!-- Right side: Actions -->
- <div v-if="!readonly" class="flex justify-end items-center">
- <RunTasksButton
- v-if="isCreated"
- :stage="stage"
- :size="'small'"
- :disabled="!canRunTasks || runableTasks.length === 0"
- @run-tasks="handleRunAllTasks"
- />
+ <div class="flex justify-end items-center">
+ <NButton
+ v-if="isCreated && runableTasks.length > 0"
+ size="small"
+ :disabled="!canRunTasks"
+ @click.stop="handleRunAllTasks"
+ >
+ <template #icon>
+ <PlayIcon />
+ </template>
+ {{ $t("common.run") }}
+ </NButton>
<NPopconfirm
v-else-if="!isCreated && canCreateRollout"
:negative-text="null"
@@ -190,6 +194,7 @@ import {
ChevronDownIcon,
ChevronUpIcon,
CalendarClockIcon,
+ PlayIcon,
} from "lucide-vue-next";
import { NTooltip, NButton, NPopconfirm, NTag } from "naive-ui";
import { twMerge } from "tailwind-merge";
@@ -222,25 +227,26 @@ import {
getStageStatus,
humanizeTs,
} from "@/utils";
-import RunTasksButton from "./RunTasksButton.vue";
+import { usePlanContextWithRollout } from "../../logic";
import { useTaskActionPermissions } from "./taskPermissions";
const props = defineProps<{
rollout: Rollout;
stage: Stage;
taskStatusFilter?: Task_Status[];
- readonly?: boolean;
defaultShowTasks?: boolean;
}>();
-const router = useRouter();
-const { project } = useCurrentProjectV1();
-const environmentStore = useEnvironmentV1Store();
const emit = defineEmits<{
(event: "run-tasks", stage: Stage, tasks: Task[]): void;
(event: "create-rollout-to-stage", stage: Stage): void;
}>();
+const router = useRouter();
+const { project } = useCurrentProjectV1();
+const environmentStore = useEnvironmentV1Store();
+const { readonly, issue } = usePlanContextWithRollout();
+
const { canPerformTaskAction } = useTaskActionPermissions();
const isCreated = computed(() => {
@@ -297,10 +303,14 @@ const runableTasks = computed(() => {
});
const canRunTasks = computed(() => {
+ if (readonly.value) {
+ return false;
+ }
return canPerformTaskAction(
filteredTasks.value,
props.rollout,
- project.value
+ project.value,
+ issue.value
);
});
diff --git a/frontend/src/components/Plan/components/RolloutView/StageView.vue b/frontend/src/components/Plan/components/RolloutView/StageView.vue
index 4c7b414af5..36dd6551c8 100644
--- a/frontend/src/components/Plan/components/RolloutView/StageView.vue
+++ b/frontend/src/components/Plan/components/RolloutView/StageView.vue
@@ -22,11 +22,7 @@
<!-- Tasks Table View -->
<div class="flex-1 min-h-0">
- <TaskTableView
- :task-status-filter="taskStatusFilter"
- :stage="stage"
- :readonly="readonly"
- />
+ <TaskTableView :task-status-filter="taskStatusFilter" :stage="stage" />
</div>
</div>
</template>
@@ -50,7 +46,7 @@ const props = defineProps<{
const route = useRoute();
const environmentStore = useEnvironmentV1Store();
-const { rollout, readonly } = usePlanContextWithRollout();
+const { rollout } = usePlanContextWithRollout();
const stage = computed(() => {
return rollout.value.stages.find((s) => s.id === props.stageId) as Stage;
diff --git a/frontend/src/components/Plan/components/RolloutView/StagesView.vue b/frontend/src/components/Plan/components/RolloutView/StagesView.vue
index 54241bccfe..43c59960ad 100644
--- a/frontend/src/components/Plan/components/RolloutView/StagesView.vue
+++ b/frontend/src/components/Plan/components/RolloutView/StagesView.vue
@@ -12,7 +12,6 @@
:rollout="rollout"
:stage="stage"
:task-status-filter="taskStatusFilter"
- :readonly="readonly"
:default-show-tasks="defaultShowTasksStage === stage.name"
@run-tasks="(stage, tasks) => $emit('run-tasks', stage, tasks)"
@create-rollout-to-stage="
@@ -37,7 +36,6 @@ const props = defineProps<{
rollout: Rollout;
mergedStages: Stage[];
taskStatusFilter?: Task_Status[];
- readonly?: boolean;
}>();
defineEmits<{
diff --git a/frontend/src/components/Plan/components/RolloutView/TaskOperations.vue b/frontend/src/components/Plan/components/RolloutView/TaskOperations.vue
index 5b62d2364d..53dbf69565 100644
--- a/frontend/src/components/Plan/components/RolloutView/TaskOperations.vue
+++ b/frontend/src/components/Plan/components/RolloutView/TaskOperations.vue
@@ -55,13 +55,16 @@ 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-es/v1/rollout_service_pb";
import type {
Task,
Rollout,
Stage,
} from "@/types/proto-es/v1/rollout_service_pb";
+import { usePlanContextWithRollout } from "../../logic";
import TaskRolloutActionPanel from "./TaskRolloutActionPanel.vue";
+import { useTaskActionPermissions } from "./taskPermissions";
interface TaskAction {
icon: VNode;
@@ -80,7 +83,6 @@ const props = defineProps<{
tasks: Task[];
rollout: Rollout;
stage: Stage;
- readonly?: boolean;
}>();
const emit = defineEmits<{
@@ -94,6 +96,9 @@ const state = reactive<LocalState>({
});
const { t } = useI18n();
+const { project } = useCurrentProjectV1();
+const { readonly, issue } = usePlanContextWithRollout();
+const { canPerformTaskAction } = useTaskActionPermissions();
// Action target for the panel
const actionTarget = computed(() => {
@@ -144,10 +149,26 @@ const hasSkippableTasks = computed(() => {
);
});
+// Check if user has permission to perform task actions
+const canPerformTaskActions = computed(() => {
+ if (readonly.value) {
+ return false;
+ }
+ return canPerformTaskAction(
+ props.tasks,
+ props.rollout,
+ project.value,
+ issue.value
+ );
+});
+
const getDisabledTooltip = (_action: string) => {
if (props.tasks.length === 0) {
return t("task.no-tasks-selected");
}
+ if (!canPerformTaskActions.value) {
+ return t("task.no-permission");
+ }
return "";
};
@@ -158,7 +179,10 @@ const actions = computed((): TaskAction[] => {
resp.push({
icon: h(PlayIcon),
text: t("common.run"),
- disabled: props.tasks.length === 0 || !hasRunnableTasks.value,
+ disabled:
+ props.tasks.length === 0 ||
+ !hasRunnableTasks.value ||
+ !canPerformTaskActions.value,
click: () => {
state.selectedAction = "RUN";
state.showActionPanel = true;
@@ -167,6 +191,9 @@ const actions = computed((): TaskAction[] => {
if (props.tasks.length === 0) {
return getDisabledTooltip(action);
}
+ if (!canPerformTaskActions.value) {
+ return getDisabledTooltip(action);
+ }
if (!hasRunnableTasks.value) {
return t("task.no-runnable-tasks");
}
@@ -178,7 +205,10 @@ const actions = computed((): TaskAction[] => {
resp.push({
icon: h(SkipForwardIcon),
text: t("common.skip"),
- disabled: props.tasks.length === 0 || !hasSkippableTasks.value,
+ disabled:
+ props.tasks.length === 0 ||
+ !hasSkippableTasks.value ||
+ !canPerformTaskActions.value,
click: () => {
state.selectedAction = "SKIP";
state.showActionPanel = true;
@@ -187,6 +217,9 @@ const actions = computed((): TaskAction[] => {
if (props.tasks.length === 0) {
return getDisabledTooltip(action);
}
+ if (!canPerformTaskActions.value) {
+ return getDisabledTooltip(action);
+ }
if (!hasSkippableTasks.value) {
return t("task.no-skippable-tasks");
}
@@ -198,7 +231,10 @@ const actions = computed((): TaskAction[] => {
resp.push({
icon: h(XIcon),
text: t("common.cancel"),
- disabled: props.tasks.length === 0 || !hasCancellableTasks.value,
+ disabled:
+ props.tasks.length === 0 ||
+ !hasCancellableTasks.value ||
+ !canPerformTaskActions.value,
click: () => {
state.selectedAction = "CANCEL";
state.showActionPanel = true;
@@ -207,6 +243,9 @@ const actions = computed((): TaskAction[] => {
if (props.tasks.length === 0) {
return getDisabledTooltip(action);
}
+ if (!canPerformTaskActions.value) {
+ return getDisabledTooltip(action);
+ }
if (!hasCancellableTasks.value) {
return t("task.no-cancellable-tasks");
}
diff --git a/frontend/src/components/Plan/components/RolloutView/TaskStatusActions.vue b/frontend/src/components/Plan/components/RolloutView/TaskStatusActions.vue
index 396a011496..dc39d26c26 100644
--- a/frontend/src/components/Plan/components/RolloutView/TaskStatusActions.vue
+++ b/frontend/src/components/Plan/components/RolloutView/TaskStatusActions.vue
@@ -1,7 +1,7 @@
<template>
<div>
<div
- v-if="!props.readonly && (primaryAction || dropdownOptions.length > 0)"
+ v-if="!readonly && (primaryAction || dropdownOptions.length > 0)"
class="flex flex-row justify-end items-center gap-x-2"
>
<NButton v-if="primaryAction" size="small" @click="handlePrimaryAction">
@@ -38,6 +38,7 @@ import { EllipsisVerticalIcon } from "lucide-vue-next";
import { NButton, NDropdown } from "naive-ui";
import { computed, ref } from "vue";
import { useI18n } from "vue-i18n";
+import { useCurrentProjectV1 } from "@/store";
import { Task_Status } from "@/types/proto-es/v1/rollout_service_pb";
import type {
Task,
@@ -45,7 +46,9 @@ import type {
Rollout,
Stage,
} from "@/types/proto-es/v1/rollout_service_pb";
+import { usePlanContextWithRollout } from "../../logic";
import TaskRolloutActionPanel from "./TaskRolloutActionPanel.vue";
+import { useTaskActionPermissions } from "./taskPermissions";
type TaskStatusAction =
// NOT_STARTED -> PENDING
@@ -61,7 +64,6 @@ const props = defineProps<{
task: Task;
taskRuns: TaskRun[];
rollout?: Rollout;
- readonly?: boolean;
}>();
const emit = defineEmits<{
@@ -69,6 +71,9 @@ const emit = defineEmits<{
}>();
const { t } = useI18n();
+const { project } = useCurrentProjectV1();
+const { readonly, issue } = usePlanContextWithRollout();
+const { canPerformTaskAction } = useTaskActionPermissions();
const showActionPanel = ref(false);
const selectedAction = ref<TaskStatusAction>();
@@ -122,7 +127,24 @@ const stage = computed((): Stage => {
} as unknown as Stage;
});
+// Check if user has permission to perform task actions
+const canPerformTaskActions = computed(() => {
+ if (!props.rollout || readonly.value) {
+ return false;
+ }
+ return canPerformTaskAction(
+ [props.task],
+ props.rollout,
+ project.value,
+ issue.value
+ );
+});
+
const primaryAction = computed((): TaskStatusAction | null => {
+ if (!canPerformTaskActions.value) {
+ return null;
+ }
+
if (
[Task_Status.NOT_STARTED, Task_Status.CANCELED].includes(props.task.status)
) {
@@ -135,6 +157,10 @@ const primaryAction = computed((): TaskStatusAction | null => {
});
const dropdownActions = computed((): TaskStatusAction[] => {
+ if (!canPerformTaskActions.value) {
+ return [];
+ }
+
if (
[
Task_Status.NOT_STARTED,
diff --git a/frontend/src/components/Plan/components/RolloutView/TaskTableView.vue b/frontend/src/components/Plan/components/RolloutView/TaskTableView.vue
index f7e81beb51..162698ca62 100644
--- a/frontend/src/components/Plan/components/RolloutView/TaskTableView.vue
+++ b/frontend/src/components/Plan/components/RolloutView/TaskTableView.vue
@@ -5,7 +5,6 @@
:tasks="selectedTasks"
:rollout="rollout"
:stage="props.stage"
- :readonly="props.readonly"
@refresh="handleRefresh"
@action-confirmed="handleTaskActionConfirmed"
/>
@@ -37,7 +36,6 @@ import TaskTable from "./TaskTable.vue";
const props = defineProps<{
taskStatusFilter: Task_Status[];
stage: Stage;
- readonly?: boolean;
}>();
const { rollout, events } = usePlanContextWithRollout();