Skip to content

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

chore: hide change database entries for those users without privileges (#6168)

boojack426c7d39b401
diff --git a/frontend/src/components/QuickActionPanel.vue b/frontend/src/components/QuickActionPanel.vue
index 90a1c833c6..2b6289969a 100644
--- a/frontend/src/components/QuickActionPanel.vue
+++ b/frontend/src/components/QuickActionPanel.vue
@@ -32,66 +32,68 @@
</h3>
</div>
- <div
- v-if="quickAction === 'quickaction.bb.database.create'"
- class="flex flex-col items-center w-24"
- data-label="bb-quick-action-new-db"
- >
- <button class="btn-icon-primary p-3" @click.prevent="createDatabase">
- <heroicons-outline:database class="w-5 h-5" />
- </button>
- <h3
- class="flex-1 mt-1.5 text-center text-sm font-normal text-main tracking-tight"
+ <template v-if="shouldShowAlterDatabaseEntries">
+ <div
+ v-if="quickAction === 'quickaction.bb.database.create'"
+ class="flex flex-col items-center w-24"
+ data-label="bb-quick-action-new-db"
>
- {{ $t("quick-action.new-db") }}
- </h3>
- </div>
+ <button class="btn-icon-primary p-3" @click.prevent="createDatabase">
+ <heroicons-outline:database class="w-5 h-5" />
+ </button>
+ <h3
+ class="flex-1 mt-1.5 text-center text-sm font-normal text-main tracking-tight"
+ >
+ {{ $t("quick-action.new-db") }}
+ </h3>
+ </div>
- <div
- v-if="quickAction === 'quickaction.bb.database.request'"
- class="flex flex-col items-center w-24"
- >
- <button class="btn-icon-primary p-3" @click.prevent="requestDatabase">
- <heroicons-outline:database class="w-5 h-5" />
- </button>
- <h3
- class="flex-1 mt-1.5 text-center text-sm font-normal text-main tracking-tight"
+ <div
+ v-if="quickAction === 'quickaction.bb.database.request'"
+ class="flex flex-col items-center w-24"
>
- {{ $t("quick-action.request-db") }}
- </h3>
- </div>
+ <button class="btn-icon-primary p-3" @click.prevent="requestDatabase">
+ <heroicons-outline:database class="w-5 h-5" />
+ </button>
+ <h3
+ class="flex-1 mt-1.5 text-center text-sm font-normal text-main tracking-tight"
+ >
+ {{ $t("quick-action.request-db") }}
+ </h3>
+ </div>
- <div
- v-if="quickAction === 'quickaction.bb.database.schema.update'"
- class="flex flex-col items-center w-24"
- >
- <button
- class="btn-icon-primary p-3"
- data-label="bb-alter-schema-button"
- @click.prevent="alterSchema"
- >
- <heroicons-outline:pencil-alt class="w-5 h-5" />
- </button>
- <h3
- class="flex-1 mt-1.5 text-center text-sm font-normal text-main tracking-tight"
+ <div
+ v-if="quickAction === 'quickaction.bb.database.schema.update'"
+ class="flex flex-col items-center w-24"
>
- {{ $t("database.alter-schema") }}
- </h3>
- </div>
+ <button
+ class="btn-icon-primary p-3"
+ data-label="bb-alter-schema-button"
+ @click.prevent="alterSchema"
+ >
+ <heroicons-outline:pencil-alt class="w-5 h-5" />
+ </button>
+ <h3
+ class="flex-1 mt-1.5 text-center text-sm font-normal text-main tracking-tight"
+ >
+ {{ $t("database.alter-schema") }}
+ </h3>
+ </div>
- <div
- v-if="quickAction === 'quickaction.bb.database.data.update'"
- class="flex flex-col items-center w-24"
- >
- <button class="btn-icon-primary p-3" @click.prevent="changeData">
- <heroicons-outline:pencil class="w-5 h-5" />
- </button>
- <h3
- class="flex-1 mt-1.5 text-center text-sm font-normal text-main tracking-tight"
+ <div
+ v-if="quickAction === 'quickaction.bb.database.data.update'"
+ class="flex flex-col items-center w-24"
>
- {{ $t("database.change-data") }}
- </h3>
- </div>
+ <button class="btn-icon-primary p-3" @click.prevent="changeData">
+ <heroicons-outline:pencil class="w-5 h-5" />
+ </button>
+ <h3
+ class="flex-1 mt-1.5 text-center text-sm font-normal text-main tracking-tight"
+ >
+ {{ $t("database.change-data") }}
+ </h3>
+ </div>
+ </template>
<div
v-if="isDev() && quickAction === 'quickaction.bb.database.troubleshoot'"
@@ -310,7 +312,9 @@ import { QuickActionType } from "../types";
import { idFromSlug, isDev } from "../utils";
import {
useCommandStore,
+ useCurrentUserIamPolicy,
useInstanceStore,
+ useProjectV1ListByCurrentUser,
useRouterStore,
useSubscriptionStore,
} from "@/store";
@@ -344,6 +348,7 @@ const route = useRoute();
const routerStore = useRouterStore();
const commandStore = useCommandStore();
const subscriptionStore = useSubscriptionStore();
+
const hasCustomRoleFeature = computed(() => {
return subscriptionStore.hasFeature("bb.feature.custom-role");
});
@@ -365,6 +370,19 @@ const projectId = computed((): string | undefined => {
return undefined;
});
+// Only show alter schema and change data if the user has permission to alter schema of at least one project.
+const shouldShowAlterDatabaseEntries = computed(() => {
+ const { projectList } = useProjectV1ListByCurrentUser();
+ const currentUserIamPolicy = useCurrentUserIamPolicy();
+ return projectList.value
+ .map((project) => {
+ return currentUserIamPolicy.allowToChangeDatabaseOfProject(
+ `projects/${project.name}`
+ );
+ })
+ .includes(true);
+});
+
watch(route, () => {
state.showModal = false;
});
diff --git a/frontend/src/store/modules/v1/projectIamPolicy.ts b/frontend/src/store/modules/v1/projectIamPolicy.ts
index 4b9646cab7..389ef3965b 100644
--- a/frontend/src/store/modules/v1/projectIamPolicy.ts
+++ b/frontend/src/store/modules/v1/projectIamPolicy.ts
@@ -10,7 +10,9 @@ import { useCurrentUserV1 } from "../auth";
import {
getDatabaseNameById,
hasWorkspacePermissionV1,
+ isDeveloperOfProjectV1,
isMemberOfProjectV1,
+ isOwnerOfProjectV1,
parseConditionExpressionString,
} from "@/utils";
@@ -153,27 +155,23 @@ export const useCurrentUserIamPolicy = () => {
return isMemberOfProjectV1(policy, currentUser.value);
};
- const allowToChangeDatabaseOfProject = (projectName: string) => {
+ const isProjectOwnerOrDeveloper = (projectName: string) => {
if (hasWorkspaceSuperPrivilege) {
return true;
}
- const policy = iamPolicyStore.getProjectIamPolicy(projectName);
+ const policy = iamPolicyStore.policyMap.get(projectName);
if (!policy) {
return false;
}
- for (const binding of policy.bindings) {
- if (
- (binding.role === PresetRoleType.OWNER ||
- binding.role === PresetRoleType.DEVELOPER) &&
- binding.members.find(
- (member) => member === `user:${currentUser.value.email}`
- )
- ) {
- return true;
- }
- }
- return false;
+ return (
+ isOwnerOfProjectV1(policy, currentUser.value) ||
+ isDeveloperOfProjectV1(policy, currentUser.value)
+ );
+ };
+
+ const allowToChangeDatabaseOfProject = (projectName: string) => {
+ return isProjectOwnerOrDeveloper(projectName);
};
const allowToQueryDatabase = (database: Database) => {
@@ -275,6 +273,7 @@ export const useCurrentUserIamPolicy = () => {
return {
isMemberOfProject,
+ isProjectOwnerOrDeveloper,
allowToChangeDatabaseOfProject,
allowToQueryDatabase,
allowToExportDatabase,
diff --git a/frontend/src/utils/v1/project.ts b/frontend/src/utils/v1/project.ts
index a33dd42a20..bd06dad3d3 100644
--- a/frontend/src/utils/v1/project.ts
+++ b/frontend/src/utils/v1/project.ts
@@ -54,6 +54,12 @@ export const isOwnerOfProjectV1 = (iamPolicy: IamPolicy, user: User) => {
return roleListInProjectV1(iamPolicy, user).includes(PresetRoleType.OWNER);
};
+export const isDeveloperOfProjectV1 = (iamPolicy: IamPolicy, user: User) => {
+ return roleListInProjectV1(iamPolicy, user).includes(
+ PresetRoleType.DEVELOPER
+ );
+};
+
export const memberListInProjectV1 = (
project: Project,
iamPolicy: IamPolicy
diff --git a/frontend/src/views/DashboardSidebar.vue b/frontend/src/views/DashboardSidebar.vue
index 66f5f77731..ac28951bfc 100644
--- a/frontend/src/views/DashboardSidebar.vue
+++ b/frontend/src/views/DashboardSidebar.vue
@@ -40,6 +40,7 @@
{{ $t("sql-editor.self") }}
</a>
<router-link
+ v-if="shouldShowSyncSchemaEntry"
to="/sync-schema"
class="outline-item group flex items-center px-2 py-2 capitalize"
>
@@ -75,6 +76,11 @@
</template>
<script lang="ts" setup>
+import { computed } from "vue";
+import {
+ useCurrentUserIamPolicy,
+ useProjectV1ListByCurrentUser,
+} from "@/store";
import { useKBarHandler } from "@bytebase/vue-kbar";
import BytebaseLogo from "@/components/BytebaseLogo.vue";
import BookmarkListSidePanel from "@/components/BookmarkListSidePanel.vue";
@@ -85,6 +91,19 @@ const isMac = navigator.platform.match(/mac/i);
const handler = useKBarHandler();
+// Only show sync schema if the user has permission to alter schema of at least one project.
+const shouldShowSyncSchemaEntry = computed(() => {
+ const { projectList } = useProjectV1ListByCurrentUser();
+ const currentUserIamPolicy = useCurrentUserIamPolicy();
+ return projectList.value
+ .map((project) => {
+ return currentUserIamPolicy.allowToChangeDatabaseOfProject(
+ `projects/${project.name}`
+ );
+ })
+ .includes(true);
+});
+
const onClickSearchButton = () => {
handler.value.show();
};