Skip to content

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

chore: update project layout items for each user role (#6074)

boojack6bb7ff394658
diff --git a/frontend/src/components/Issue/IssueHighlightPanel.vue b/frontend/src/components/Issue/IssueHighlightPanel.vue
index a40512b6c7..51a61964da 100644
--- a/frontend/src/components/Issue/IssueHighlightPanel.vue
+++ b/frontend/src/components/Issue/IssueHighlightPanel.vue
@@ -150,13 +150,16 @@ const showExportButton = computed(() => {
// Don't show export button when issue is closed or done.
if (issue.value.status !== "OPEN") return false;
- const payload = (issue.value.payload as any)
+ const issuePayload = (issue.value.payload as any)
.grantRequest as GrantRequestPayload;
+ if (
+ issuePayload.role !== "roles/EXPORTER" ||
+ currentUser.value.id !== issue.value.creator.id
+ ) {
+ return false;
+ }
- return (
- currentUser.value.id === issue.value.creator.id &&
- payload.role === "roles/EXPORTER"
- );
+ return true;
});
const issueTaskStatus = () => {
diff --git a/frontend/src/components/Issue/action/ExportDataButton.vue b/frontend/src/components/Issue/action/ExportDataButton.vue
index 1eead1a6a2..c91da28663 100644
--- a/frontend/src/components/Issue/action/ExportDataButton.vue
+++ b/frontend/src/components/Issue/action/ExportDataButton.vue
@@ -1,5 +1,9 @@
<template>
- <button class="btn-primary" @click="state.showConfirmModal = true">
+ <button
+ class="btn-primary flex flex-row justify-center items-center"
+ @click="state.showConfirmModal = true"
+ >
+ <heroicons-outline:document-download class="w-4 h-auto mr-0.5" />
{{ $t("common.export") }}
</button>
@@ -35,7 +39,7 @@
<script lang="ts" setup>
import { computed, onMounted, reactive } from "vue";
-import { useIssueLogic } from "../logic";
+import { useExtraIssueLogic, useIssueLogic } from "../logic";
import { DatabaseId, GrantRequestPayload, Issue, UNKNOWN_ID } from "@/types";
import { useInstanceV1Store } from "@/store/modules/v1/instance";
import { pushNotification, useDatabaseStore, useSQLStore } from "@/store";
@@ -54,6 +58,7 @@ interface LocalState {
isRequesting: boolean;
}
+const { changeIssueStatus } = useExtraIssueLogic();
const { issue } = useIssueLogic();
const databaseStore = useDatabaseStore();
const instanceV1Store = useInstanceV1Store();
@@ -185,5 +190,8 @@ const handleExport = async () => {
link.click();
state.isRequesting = false;
state.showConfirmModal = false;
+
+ // After data exported successfully, we change the issue status to DONE automatically.
+ changeIssueStatus("DONE", "");
};
</script>
diff --git a/frontend/src/layouts/ProjectLayout.vue b/frontend/src/layouts/ProjectLayout.vue
index 686cc7e61d..d08bce5ec5 100644
--- a/frontend/src/layouts/ProjectLayout.vue
+++ b/frontend/src/layouts/ProjectLayout.vue
@@ -105,12 +105,23 @@ export default defineComponent({
const projectTabItemList = computed((): ProjectTabItem[] => {
if (
- !currentUserIamPolicy.allowToChangeDatabaseOfProject(
+ !currentUserIamPolicy.isMemberOfProject(
`projects/${project.value.resourceId}`
)
) {
return [{ name: t("common.databases"), hash: "databases" }];
}
+ if (
+ !currentUserIamPolicy.allowToChangeDatabaseOfProject(
+ `projects/${project.value.resourceId}`
+ )
+ ) {
+ const list = [{ name: t("common.databases"), hash: "databases" }];
+ if (!isDefaultProject.value) {
+ list.push({ name: t("common.settings"), hash: "setting" });
+ }
+ return list;
+ }
const list: (ProjectTabItem | null)[] = [
{ name: t("common.overview"), hash: "overview" },
diff --git a/frontend/src/store/modules/v1/projectIamPolicy.ts b/frontend/src/store/modules/v1/projectIamPolicy.ts
index d958d40992..1474069e1b 100644
--- a/frontend/src/store/modules/v1/projectIamPolicy.ts
+++ b/frontend/src/store/modules/v1/projectIamPolicy.ts
@@ -7,7 +7,7 @@ import { Database, MaybeRef } from "@/types";
import { useProjectStore } from "../project";
import { useProjectV1Store } from "./project";
import { useCurrentUserV1 } from "../auth";
-import { UserRole } from "@/types/proto/v1/auth_service";
+import { hasWorkspacePermissionV1 } from "@/utils";
export const useProjectIamPolicyStore = defineStore(
"project-iam-policy",
@@ -95,18 +95,44 @@ export const useCurrentUserIamPolicy = () => {
const projectStore = useProjectV1Store();
const currentUser = useCurrentUserV1();
- watchEffect(async () => {
- for (const project of projectStore.projectList) {
- await iamPolicyStore.getOrFetchProjectIamPolicy(project.name);
- }
+ watchEffect(() => {
+ // Fetch all project iam policies.
+ Promise.all(
+ projectStore.projectList.map((project) =>
+ iamPolicyStore.getOrFetchProjectIamPolicy(project.name)
+ )
+ );
});
- const isWorkspaceOwner = computed(
- () => currentUser.value.userRole === UserRole.OWNER
+ // hasWorkspaceSuperPrivilege checks whether the current user has the super privilege to access all databases. AKA. Owners and DBAs
+ const hasWorkspaceSuperPrivilege = hasWorkspacePermissionV1(
+ "bb.permission.workspace.manage-access-control",
+ currentUser.value.userRole
);
+ const isMemberOfProject = (projectName: string) => {
+ if (hasWorkspaceSuperPrivilege) {
+ return true;
+ }
+
+ const policy = iamPolicyStore.policyMap.get(projectName);
+ if (!policy) {
+ return false;
+ }
+ for (const binding of policy.bindings) {
+ if (
+ binding.members.find(
+ (member) => member === `user:${currentUser.value.email}`
+ )
+ ) {
+ return true;
+ }
+ }
+ return false;
+ };
+
const allowToChangeDatabaseOfProject = (projectName: string) => {
- if (isWorkspaceOwner.value) {
+ if (hasWorkspaceSuperPrivilege) {
return true;
}
@@ -129,14 +155,13 @@ export const useCurrentUserIamPolicy = () => {
};
const allowToQueryDatabase = async (database: Database) => {
- if (isWorkspaceOwner.value) {
+ if (hasWorkspaceSuperPrivilege) {
return true;
}
const policy = await iamPolicyStore.getOrFetchProjectIamPolicy(
`projects/${database.project.resourceId}`
);
- console.log("!", policy, database.project.resourceId);
if (!policy) {
return false;
}
@@ -182,6 +207,7 @@ export const useCurrentUserIamPolicy = () => {
};
return {
+ isMemberOfProject,
allowToChangeDatabaseOfProject,
allowToQueryDatabase,
};
diff --git a/frontend/src/utils/policy.ts b/frontend/src/utils/policy.ts
index 621211223f..eee86c7280 100644
--- a/frontend/src/utils/policy.ts
+++ b/frontend/src/utils/policy.ts
@@ -3,7 +3,7 @@ import type { Database, Instance, Principal } from "@/types";
import { hasWorkspacePermission } from "./role";
import { Policy, PolicyType } from "@/types/proto/v1/org_policy_service";
import { State } from "@/types/proto/v1/common";
-import { isMemberOfProject } from ".";
+import { EnvironmentTier } from "@/types/proto/v1/environment_service";
export const isInstanceAccessible = (instance: Instance, user: Principal) => {
if (!hasFeature("bb.feature.access-control")) {
@@ -25,7 +25,7 @@ export const isInstanceAccessible = (instance: Instance, user: Principal) => {
// See if the instance is in a production environment
const { environment } = instance;
- if (environment.tier === "UNPROTECTED") {
+ if (environment.tier === EnvironmentTier.UNPROTECTED) {
return true;
}
@@ -37,10 +37,6 @@ export const isDatabaseAccessible = (
policyList: Policy[],
user: Principal
) => {
- if (!isMemberOfProject(database.project, user)) {
- return false;
- }
-
if (!hasFeature("bb.feature.access-control")) {
// The current plan doesn't have access control feature.
// Fallback to true.
@@ -59,7 +55,7 @@ export const isDatabaseAccessible = (
}
const { environment } = database.instance;
- if (environment.tier === "UNPROTECTED") {
+ if (environment.tier === EnvironmentTier.UNPROTECTED) {
return true;
}
diff --git a/frontend/src/utils/role.ts b/frontend/src/utils/role.ts
index 9c6a25eb27..94194d6fbd 100644
--- a/frontend/src/utils/role.ts
+++ b/frontend/src/utils/role.ts
@@ -2,6 +2,7 @@ import { computed, unref } from "vue";
import { MaybeRef, ProjectRoleType, RoleType } from "../types";
import { hasFeature, useCurrentUser, useRoleStore } from "@/store";
import { t } from "@/plugins/i18n";
+import { UserRole } from "@/types/proto/v1/auth_service";
export type WorkspacePermissionType =
| "bb.permission.workspace.debug"
@@ -82,6 +83,24 @@ export function hasWorkspacePermission(
}
}
+export function hasWorkspacePermissionV1(
+ permission: WorkspacePermissionType,
+ role: UserRole
+): boolean {
+ if (!hasFeature("bb.feature.rbac")) {
+ return true;
+ }
+ switch (role) {
+ case UserRole.DEVELOPER:
+ return WORKSPACE_PERMISSION_MATRIX.get(permission)![0];
+ case UserRole.DBA:
+ return WORKSPACE_PERMISSION_MATRIX.get(permission)![1];
+ case UserRole.OWNER:
+ return WORKSPACE_PERMISSION_MATRIX.get(permission)![2];
+ }
+ return true;
+}
+
export const useWorkspacePermission = (
permission: MaybeRef<WorkspacePermissionType>
) => {
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultView.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultView.vue
index 6bddb7ad90..dc1d1480b6 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultView.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultView.vue
@@ -48,7 +48,7 @@
</NButton>
<!-- In enterprise plan, we don't allow export data in SQL editor. -->
<NDropdown
- v-if="!hasCustomRoleFeature"
+ v-if="showExportButton"
trigger="hover"
:options="exportDropdownOptions"
@select="handleExportBtnClick"
@@ -166,7 +166,11 @@ const showSearchFeature = computed(() => {
return instanceHasStructuredQueryResult(instance);
});
-const hasCustomRoleFeature = featureToRef("bb.feature.custom-role");
+// show export button only when the subscription is not enterprise.
+// In enterprise plan, all users need to fill in the export data request issue.
+const showExportButton = computed(() => {
+ return !featureToRef("bb.feature.custom-role").value;
+});
// use a debounced value to improve performance when typing rapidly
const keyword = debouncedRef(