Skip to content

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

chore: update changelist permissions (#10349)

ecmadaob1f792fab69c
diff --git a/frontend/src/components/Changelist/ChangelistDashboard/ChangelistDashboard.vue b/frontend/src/components/Changelist/ChangelistDashboard/ChangelistDashboard.vue
index 55fc9f107f..f2edb9b86c 100644
--- a/frontend/src/components/Changelist/ChangelistDashboard/ChangelistDashboard.vue
+++ b/frontend/src/components/Changelist/ChangelistDashboard/ChangelistDashboard.vue
@@ -1,6 +1,6 @@
<template>
<div class="flex flex-col gap-y-4">
- <NavBar :disable-project-select="!!project" />
+ <NavBar :disable-project-select="!!project" :allow-create="allowCreate" />
<ChangelistTable
:changelists="filteredChangelists"
@@ -19,20 +19,21 @@
<script lang="ts" setup>
import { computed, onMounted, ref } from "vue";
import { useEmitteryEventListener } from "@/composables/useEmitteryEventListener";
-import { useChangelistStore } from "@/store";
+import { useChangelistStore, useCurrentUserV1 } from "@/store";
import { ComposedProject } from "@/types";
import { Changelist } from "@/types/proto/v1/changelist_service";
+import { hasProjectPermissionV2 } from "@/utils";
import ChangelistTable from "./ChangelistTable.vue";
import CreateChangelistPanel from "./CreateChangelistPanel.vue";
import NavBar from "./NavBar.vue";
import { provideChangelistDashboardContext } from "./context";
const props = defineProps<{
- project?: ComposedProject;
+ project: ComposedProject;
}>();
const { filter, events } = provideChangelistDashboardContext(
- props.project?.name
+ props.project.name
);
const isFetching = ref(false);
@@ -66,4 +67,12 @@ const fetchChangelists = async () => {
useEmitteryEventListener(events, "refresh", fetchChangelists);
onMounted(fetchChangelists);
+
+const allowCreate = computed(() => {
+ return hasProjectPermissionV2(
+ props.project,
+ useCurrentUserV1().value,
+ "bb.changelists.create"
+ );
+});
</script>
diff --git a/frontend/src/components/Changelist/ChangelistDashboard/NavBar.vue b/frontend/src/components/Changelist/ChangelistDashboard/NavBar.vue
index b8ba56c483..4b5b89d79b 100644
--- a/frontend/src/components/Changelist/ChangelistDashboard/NavBar.vue
+++ b/frontend/src/components/Changelist/ChangelistDashboard/NavBar.vue
@@ -12,7 +12,11 @@
v-model:value="filter.keyword"
:placeholder="$t('common.filter-by-name')"
/>
- <NButton type="primary" @click="showCreatePanel = true">
+ <NButton
+ v-if="!allowCreate"
+ type="primary"
+ @click="showCreatePanel = true"
+ >
<heroicons-solid:plus class="w-4 h-auto mr-0.5" />
{{ $t("changelist.new") }}
</NButton>
@@ -30,6 +34,7 @@ import { useChangelistDashboardContext } from "./context";
defineProps<{
disableProjectSelect?: boolean;
+ allowCreate: boolean;
}>();
const { filter, showCreatePanel, events } = useChangelistDashboardContext();
diff --git a/frontend/src/components/Changelist/ChangelistDetail/ChangelistDetail.vue b/frontend/src/components/Changelist/ChangelistDetail/ChangelistDetail.vue
index a3b7f20ed0..af46398229 100644
--- a/frontend/src/components/Changelist/ChangelistDetail/ChangelistDetail.vue
+++ b/frontend/src/components/Changelist/ChangelistDetail/ChangelistDetail.vue
@@ -10,7 +10,7 @@
@reorder-move="(row, delta) => handleReorderMove(row, delta)"
/>
- <div class="flex flex-row">
+ <div v-if="allowDelete" class="flex flex-row">
<DeleteChangelistButton />
</div>
@@ -64,7 +64,7 @@ import { provideChangelistDetailContext } from "./context";
const { t } = useI18n();
const route = useRoute();
-const { changelist, reorderMode, isUpdating, events } =
+const { changelist, reorderMode, isUpdating, events, allowDelete } =
provideChangelistDetailContext();
const state = reactive({
diff --git a/frontend/src/components/Changelist/ChangelistDetail/NavBar/NavBar.vue b/frontend/src/components/Changelist/ChangelistDetail/NavBar/NavBar.vue
index df5ed610d9..27a97fa991 100644
--- a/frontend/src/components/Changelist/ChangelistDetail/NavBar/NavBar.vue
+++ b/frontend/src/components/Changelist/ChangelistDetail/NavBar/NavBar.vue
@@ -5,10 +5,10 @@
</div>
<div class="flex items-center justify-end gap-x-3">
<template v-if="!reorderMode">
- <ReorderButton @click="beginReorder" />
+ <ReorderButton v-if="allowEdit" @click="beginReorder" />
<ExportButton />
- <AddChangeButton />
- <ApplyToDatabaseButton />
+ <AddChangeButton v-if="allowEdit" />
+ <ApplyToDatabaseButton v-if="allowApply" />
</template>
<template v-if="reorderMode">
@@ -33,7 +33,7 @@ import ReorderButton from "./ReorderButton.vue";
import TitleEditor from "./TitleEditor.vue";
import { useReorderChangelist } from "./reorder";
-const { reorderMode } = useChangelistDetailContext();
+const { reorderMode, allowEdit, allowApply } = useChangelistDetailContext();
const {
begin: beginReorder,
diff --git a/frontend/src/components/Changelist/ChangelistDetail/context.ts b/frontend/src/components/Changelist/ChangelistDetail/context.ts
index 53caac460b..4b4eb0cb2f 100644
--- a/frontend/src/components/Changelist/ChangelistDetail/context.ts
+++ b/frontend/src/components/Changelist/ChangelistDetail/context.ts
@@ -15,7 +15,12 @@ import {
useProjectV1Store,
} from "@/store";
import { projectNamePrefix } from "@/store/modules/v1/common";
-import { ComposedProject, unknownChangelist, unknownProject } from "@/types";
+import {
+ ComposedProject,
+ unknownChangelist,
+ unknownProject,
+ ProjectPermission,
+} from "@/types";
import {
Changelist,
Changelist_Change as Change,
@@ -31,6 +36,8 @@ export type ChangelistDetailContext = {
changelist: Ref<Changelist>;
project: Ref<ComposedProject>;
allowEdit: Ref<boolean>;
+ allowDelete: Ref<boolean>;
+ allowApply: Ref<boolean>;
reorderMode: Ref<boolean>;
selectedChanges: Ref<Change[]>;
showAddChangePanel: Ref<boolean>;
@@ -77,24 +84,29 @@ export const provideChangelistDetailContext = () => {
);
});
+ const checkPermission = (permission: ProjectPermission): boolean => {
+ return (
+ hasProjectPermissionV2(project.value, me.value, permission) ||
+ extractUserResourceName(changelist.value.creator) === me.value.email
+ );
+ };
+
+ const allowDelete = computed(() => {
+ return checkPermission("bb.changelists.delete");
+ });
+ const allowApply = computed(() => {
+ return hasProjectPermissionV2(project.value, me.value, "bb.issues.create");
+ });
const allowEdit = computed(() => {
- if (
- hasProjectPermissionV2(project.value, me.value, "bb.changelists.update")
- ) {
- return true;
- }
- if (extractUserResourceName(changelist.value.creator) === me.value.email) {
- // Allow the initial creator of the changelist to edit it.
- return true;
- }
- // Disallowed to edit otherwise.
- return false;
+ return checkPermission("bb.changelists.update");
});
const context: ChangelistDetailContext = {
changelist,
project,
allowEdit,
+ allowDelete,
+ allowApply,
reorderMode: ref(false),
selectedChanges: ref([]),
showAddChangePanel: ref(false),
diff --git a/frontend/src/router/dashboard/projectV1.ts b/frontend/src/router/dashboard/projectV1.ts
index b3c3b277eb..768ec14277 100644
--- a/frontend/src/router/dashboard/projectV1.ts
+++ b/frontend/src/router/dashboard/projectV1.ts
@@ -289,7 +289,6 @@ const projectV1Routes: RouteRecordRaw[] = [
name: PROJECT_V1_ROUTE_ANOMALIES,
meta: {
overrideTitle: true,
- // TODO(ed): permission check
requiredProjectPermissionList: () => ["bb.projects.get"],
},
component: () =>
@@ -301,7 +300,6 @@ const projectV1Routes: RouteRecordRaw[] = [
name: PROJECT_V1_ROUTE_ACTIVITIES,
meta: {
overrideTitle: true,
- // TODO(ed): permission check
requiredProjectPermissionList: () => ["bb.projects.get"],
},
component: () => import("@/views/project/ProjectActivityDashboard.vue"),
@@ -312,7 +310,6 @@ const projectV1Routes: RouteRecordRaw[] = [
name: PROJECT_V1_ROUTE_GITOPS,
meta: {
overrideTitle: true,
- // TODO(ed): permission check
requiredProjectPermissionList: () => ["bb.projects.get"],
},
component: () =>
@@ -323,7 +320,6 @@ const projectV1Routes: RouteRecordRaw[] = [
path: "webhooks",
meta: {
overrideTitle: true,
- // TODO(ed): permission check
requiredProjectPermissionList: () => ["bb.projects.get"],
},
props: true,
@@ -364,7 +360,6 @@ const projectV1Routes: RouteRecordRaw[] = [
name: PROJECT_V1_ROUTE_MEMBERS,
meta: {
overrideTitle: true,
- // TODO(ed): permission check
requiredProjectPermissionList: () => [
"bb.projects.get",
"bb.projects.getIamPolicy",