Skip to content

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

Follow up from the last commit to only fetch the database info itself

天舟be68db5ab66b
diff --git a/frontend/src/components/DatabaseListSidePanel.vue b/frontend/src/components/DatabaseListSidePanel.vue
index 774219ac5e..2b17c4200a 100644
--- a/frontend/src/components/DatabaseListSidePanel.vue
+++ b/frontend/src/components/DatabaseListSidePanel.vue
@@ -8,20 +8,33 @@
</template>
<script lang="ts">
-import { computed, watchEffect } from "vue";
+import { computed, reactive, watchEffect } from "vue";
import { useStore } from "vuex";
import cloneDeep from "lodash-es/cloneDeep";
-import { ALL_DATABASE_NAME, Environment, EnvironmentId } from "../types";
+import {
+ ALL_DATABASE_NAME,
+ Database,
+ Environment,
+ EnvironmentId,
+} from "../types";
import { databaseSlug, allowDatabaseAccess } from "../utils";
import { BBOutlineItem } from "../bbkit/types";
+interface LocalState {
+ databaseList: Database[];
+}
+
export default {
name: "DatabaseListSidePanel",
props: {},
setup(props, ctx) {
const store = useStore();
+ const state = reactive<LocalState>({
+ databaseList: [],
+ });
+
const currentUser = computed(() => store.getters["auth/currentUser"]());
const environmentList = computed(() => {
@@ -33,6 +46,9 @@ export default {
const prepareDatabaseList = () => {
store
.dispatch("database/fetchDatabaseListByUser", currentUser.value.id)
+ .then((databaseList) => {
+ state.databaseList = databaseList;
+ })
.catch((error) => {
console.log(error);
});
@@ -41,14 +57,11 @@ export default {
watchEffect(prepareDatabaseList);
const databaseListByEnvironment = computed(() => {
- const databaseList = store.getters["database/databaseListByUserId"](
- currentUser.value.id
- );
const envToDbMap: Map<EnvironmentId, BBOutlineItem[]> = new Map();
for (const environment of environmentList.value) {
envToDbMap.set(environment.id, []);
}
- for (const database of databaseList) {
+ for (const database of state.databaseList) {
if (database.name != ALL_DATABASE_NAME) {
const dbList = envToDbMap.get(database.instance.environment.id)!;
let databaseName = database.name;
diff --git a/frontend/src/components/ProvideContext.vue b/frontend/src/components/ProvideContext.vue
index 1e3b04525d..ff9c8f632c 100644
--- a/frontend/src/components/ProvideContext.vue
+++ b/frontend/src/components/ProvideContext.vue
@@ -29,7 +29,9 @@ export default {
// database hasn't been fetched yet, that solution is more complex and might not bring better
// performance because it requires to do more round-trips because of the N+1 nature. Thus,
// we choose to do a full fetch when initializing the context here.
- // [TODO] The backend needs to redact the password info for database which the user is not granted.
+ // [NOTE] This only fetches the database info itself, won't fetch the instance and especially
+ // the data source info which contains connection credentials might not be granted to the current
+ // user.
store.dispatch("database/fetchDatabaseList"),
store.dispatch("uistate/restoreState"),
]);
diff --git a/frontend/src/store/modules/database.ts b/frontend/src/store/modules/database.ts
index b14f51b7ef..8744d671e6 100644
--- a/frontend/src/store/modules/database.ts
+++ b/frontend/src/store/modules/database.ts
@@ -138,10 +138,15 @@ const getters = {
const actions = {
async fetchDatabaseList({ commit, rootGetters }: any) {
- const data = (await axios.get(`/api/database?include=instance,dataSource`))
- .data;
+ // Unlike other list fetch, we don't fetch the instance and data source here.
+ // As the sole purpose for the fetch here is to prepare the database info
+ // itself (in particular the database name) to be displayed in the task list
+ // on the home page.
+ // The data source contains sensitive connection credentials so we shouldn't
+ // return it unconditionally.
+ const data = (await axios.get(`/api/database`)).data;
const databaseList = data.data.map((database: ResourceObject) => {
- return convert(database, data.included, rootGetters);
+ return convert(database, [], rootGetters);
});
commit("upsertDatabaseList", { databaseList });