Skip to content

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

chore: hide unaccessible database (#6654)

boojack48c2857b2ba9
diff --git a/frontend/src/components/DatabaseListSidePanel.vue b/frontend/src/components/DatabaseListSidePanel.vue
index 3f2ae47e3e..d6aac1d243 100644
--- a/frontend/src/components/DatabaseListSidePanel.vue
+++ b/frontend/src/components/DatabaseListSidePanel.vue
@@ -8,30 +8,52 @@
</template>
<script lang="ts" setup>
-import { computed, watchEffect } from "vue";
+import { computed, ref, watchEffect } from "vue";
import { cloneDeep, uniqBy } from "lodash-es";
import { useRouter } from "vue-router";
import { useI18n } from "vue-i18n";
import { Action, defineAction, useRegisterActions } from "@bytebase/vue-kbar";
import type { BBOutlineItem } from "@/bbkit/types";
import { UNKNOWN_USER_NAME } from "@/types";
-import { databaseV1Slug, environmentV1Name, projectV1Slug } from "@/utils";
+import {
+ databaseV1Slug,
+ environmentV1Name,
+ projectV1Slug,
+ isDatabaseV1Accessible,
+} from "@/utils";
import {
useEnvironmentV1List,
useDatabaseV1Store,
useCurrentUserV1,
+ usePolicyV1Store,
} from "@/store";
import { State } from "@/types/proto/v1/common";
import { TenantMode } from "@/types/proto/v1/project_service";
+import {
+ Policy,
+ PolicyResourceType,
+ PolicyType,
+} from "@/types/proto/v1/org_policy_service";
const { t } = useI18n();
const databaseV1Store = useDatabaseV1Store();
const router = useRouter();
-
const currentUserV1 = useCurrentUserV1();
-
const rawEnvironmentList = useEnvironmentV1List();
+const policyList = ref<Policy[]>([]);
+
+const preparePolicyList = () => {
+ usePolicyV1Store()
+ .fetchPolicies({
+ resourceType: PolicyResourceType.DATABASE,
+ policyType: PolicyType.ACCESS_CONTROL,
+ })
+ .then((list) => (policyList.value = list));
+};
+
+watchEffect(preparePolicyList);
+
// Reserve the environment list, put "Prod" to the top.
const environmentList = computed(() =>
cloneDeep(rawEnvironmentList.value).reverse()
@@ -52,7 +74,10 @@ watchEffect(prepareList);
const databaseList = computed(() => {
return databaseV1Store
.databaseListByUser(currentUserV1.value)
- .filter((db) => db.syncState === State.ACTIVE);
+ .filter((db) => db.syncState === State.ACTIVE)
+ .filter((database) =>
+ isDatabaseV1Accessible(database, policyList.value, currentUserV1.value)
+ );
});
const databaseListByEnvironment = computed(() => {
diff --git a/frontend/src/components/ProjectDatabasesPanel.vue b/frontend/src/components/ProjectDatabasesPanel.vue
index 5842f80511..a47a21de44 100644
--- a/frontend/src/components/ProjectDatabasesPanel.vue
+++ b/frontend/src/components/ProjectDatabasesPanel.vue
@@ -49,14 +49,20 @@
</template>
<script lang="ts" setup>
-import { reactive, PropType, computed } from "vue";
+import { reactive, PropType, computed, ref, watchEffect } from "vue";
import { NInputGroup } from "naive-ui";
import { uniqBy } from "lodash-es";
import { ComposedDatabase, ComposedInstance, UNKNOWN_ID } from "../types";
-import { filterDatabaseV1ByKeyword } from "@/utils";
+import { filterDatabaseV1ByKeyword, isDatabaseV1Accessible } from "@/utils";
import { DatabaseV1Table } from "./v2";
import { EnvironmentTabFilter, InstanceSelect, SearchBox } from "./v2";
+import {
+ Policy,
+ PolicyResourceType,
+ PolicyType,
+} from "@/types/proto/v1/org_policy_service";
+import { useCurrentUserV1, usePolicyV1Store } from "@/store";
interface LocalState {
environment: string;
@@ -71,14 +77,29 @@ const props = defineProps({
},
});
+const currentUserV1 = useCurrentUserV1();
const state = reactive<LocalState>({
environment: String(UNKNOWN_ID),
instance: String(UNKNOWN_ID),
keyword: "",
});
+const policyList = ref<Policy[]>([]);
+
+const preparePolicyList = () => {
+ usePolicyV1Store()
+ .fetchPolicies({
+ resourceType: PolicyResourceType.DATABASE,
+ policyType: PolicyType.ACCESS_CONTROL,
+ })
+ .then((list) => (policyList.value = list));
+};
+
+watchEffect(preparePolicyList);
const filteredDatabaseList = computed(() => {
- let list = [...props.databaseList];
+ let list = [...props.databaseList].filter((database) =>
+ isDatabaseV1Accessible(database, policyList.value, currentUserV1.value)
+ );
if (state.environment !== String(UNKNOWN_ID)) {
list = list.filter(
(db) => db.instanceEntity.environmentEntity.uid === state.environment
diff --git a/frontend/src/views/DatabaseDashboard.vue b/frontend/src/views/DatabaseDashboard.vue
index 79371e204a..a430d0aeef 100644
--- a/frontend/src/views/DatabaseDashboard.vue
+++ b/frontend/src/views/DatabaseDashboard.vue
@@ -65,7 +65,7 @@
</template>
<script lang="ts" setup>
-import { computed, watchEffect, onMounted, reactive } from "vue";
+import { computed, watchEffect, onMounted, reactive, ref } from "vue";
import { useRoute, useRouter } from "vue-router";
import { NInputGroup, NTooltip } from "naive-ui";
@@ -86,14 +86,21 @@ import {
filterDatabaseV1ByKeyword,
hasWorkspacePermissionV1,
sortDatabaseV1List,
-} from "../utils";
+ isDatabaseV1Accessible,
+} from "@/utils";
import {
useCurrentUserV1,
useDBGroupStore,
useDatabaseV1Store,
useEnvironmentV1Store,
+ usePolicyV1Store,
useUIStateStore,
} from "@/store";
+import {
+ Policy,
+ PolicyResourceType,
+ PolicyType,
+} from "@/types/proto/v1/org_policy_service";
interface LocalState {
instanceFilter: string;
@@ -119,6 +126,18 @@ const state = reactive<LocalState>({
const currentUserV1 = useCurrentUserV1();
const databaseV1Store = useDatabaseV1Store();
const dbGroupStore = useDBGroupStore();
+const policyList = ref<Policy[]>([]);
+
+const preparePolicyList = () => {
+ usePolicyV1Store()
+ .fetchPolicies({
+ resourceType: PolicyResourceType.DATABASE,
+ policyType: PolicyType.ACCESS_CONTROL,
+ })
+ .then((list) => (policyList.value = list));
+};
+
+watchEffect(preparePolicyList);
const selectedEnvironment = computed(() => {
const { environment } = route.query;
@@ -184,7 +203,9 @@ const changeSearchText = (searchText: string) => {
};
const filteredDatabaseList = computed(() => {
- let list = [...state.databaseV1List];
+ let list = [...state.databaseV1List].filter((database) =>
+ isDatabaseV1Accessible(database, policyList.value, currentUserV1.value)
+ );
const environment = selectedEnvironment.value;
if (environment && environment.name !== `environments/${UNKNOWN_ID}`) {
list = list.filter(