Skip to content

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

Fetch projectRoleMapping in database api so that the fetched project has the membership info

天舟6f4eddae3bd8
diff --git a/frontend/src/store/modules/database.ts b/frontend/src/store/modules/database.ts
index 0c9a65c49f..be72ea1686 100644
--- a/frontend/src/store/modules/database.ts
+++ b/frontend/src/store/modules/database.ts
@@ -50,7 +50,7 @@ function convert(
instance = rootGetters["instance/convert"](item);
}
if (item.type == "project" && item.id == projectId) {
- project = rootGetters["project/convert"](item);
+ project = rootGetters["project/convert"](item, includedList);
}
}
@@ -165,7 +165,11 @@ const actions = {
// 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?include=project`)).data;
+ const data = (
+ await axios.get(
+ `/api/database?include=project,project.projectRoleMapping`
+ )
+ ).data;
const databaseList = data.data.map((database: ResourceObject) => {
return convert(database, [], rootGetters);
});
@@ -181,7 +185,7 @@ const actions = {
) {
const data = (
await axios.get(
- `/api/database?instance=${instanceId}&include=instance,project,dataSource`
+ `/api/database?instance=${instanceId}&include=instance,project,project.projectRoleMapping,dataSource`
)
).data;
const databaseList = data.data.map((database: ResourceObject) => {
@@ -196,7 +200,7 @@ const actions = {
async fetchDatabaseListByUser({ commit, rootGetters }: any, userId: UserId) {
const data = (
await axios.get(
- `/api/database?user=${userId}&include=instance,project,dataSource`
+ `/api/database?user=${userId}&include=instance,project,project.projectRoleMapping,dataSource`
)
).data;
const databaseList = data.data.map((database: ResourceObject) => {
@@ -238,8 +242,8 @@ const actions = {
}: { databaseId: DatabaseId; instanceId?: InstanceId }
) {
const url = instanceId
- ? `/api/instance/${instanceId}/database/${databaseId}?include=instance,project,dataSource`
- : `/api/database/${databaseId}?include=instance,project,dataSource`;
+ ? `/api/instance/${instanceId}/database/${databaseId}?include=instance,project,project.projectRoleMapping,dataSource`
+ : `/api/database/${databaseId}?include=instance,project,project.projectRoleMapping,dataSource`;
const data = (await axios.get(url)).data;
const database = convert(data.data, data.included, rootGetters);
@@ -253,12 +257,15 @@ const actions = {
async createDatabase({ commit, rootGetters }: any, newDatabase: DatabaseNew) {
const data = (
- await axios.post(`/api/database?include=instance,project,dataSource`, {
- data: {
- type: "database",
- attributes: newDatabase,
- },
- })
+ await axios.post(
+ `/api/database?include=instance,project,project.projectRoleMapping,dataSource`,
+ {
+ data: {
+ type: "database",
+ attributes: newDatabase,
+ },
+ }
+ )
).data;
const createdDatabase: Database = convert(
data.data,
@@ -288,7 +295,7 @@ const actions = {
) {
const data = (
await axios.patch(
- `/api/database/${databaseId}?include=instance,project,dataSource`,
+ `/api/database/${databaseId}?include=instance,project,project.projectRoleMapping,dataSource`,
{
data: {
type: "databasepatch",
diff --git a/frontend/src/store/modules/project.ts b/frontend/src/store/modules/project.ts
index 26be24f0ea..61bcbb3343 100644
--- a/frontend/src/store/modules/project.ts
+++ b/frontend/src/store/modules/project.ts
@@ -113,8 +113,8 @@ const getters = {
getters: any,
rootState: any,
rootGetters: any
- ) => (instance: ResourceObject): Project => {
- return convert(instance, [], rootGetters);
+ ) => (instance: ResourceObject, includedList: ResourceObject[]): Project => {
+ return convert(instance, includedList, rootGetters);
},
projectList: (state: ProjectState) => (): Project[] => {
diff --git a/frontend/src/views/DatabaseDetail.vue b/frontend/src/views/DatabaseDetail.vue
index e9a9aaafd2..bd32338920 100644
--- a/frontend/src/views/DatabaseDetail.vue
+++ b/frontend/src/views/DatabaseDetail.vue
@@ -104,100 +104,102 @@
/>
</div>
- <template
- v-for="(item, index) of [
- { type: 'RW', list: readWriteDataSourceList },
- { type: 'RO', list: readOnlyDataSourceList },
- ]"
- :key="index"
- >
- <div v-if="item.list.length" class="pt-6">
- <div class="text-lg leading-6 font-medium text-main mb-4">
- <span v-data-source-type>{{ item.type }}</span>
- </div>
- <div class="space-y-4">
- <div v-for="(ds, index) of item.list" :key="index">
- <!-- Hide the data source detail link for now -->
- <div v-if="false" class="relative mb-2">
- <div
- class="absolute inset-0 flex items-center"
- aria-hidden="true"
- >
- <div class="w-full border-t border-gray-300"></div>
- </div>
- <div class="relative flex justify-start">
- <router-link
- :to="`/db/${databaseSlug}/datasource/${dataSourceSlug(
- ds
- )}`"
- class="pr-3 bg-white font-medium normal-link"
+ <template v-if="allowViewDataSource">
+ <template
+ v-for="(item, index) of [
+ { type: 'RW', list: readWriteDataSourceList },
+ { type: 'RO', list: readOnlyDataSourceList },
+ ]"
+ :key="index"
+ >
+ <div v-if="item.list.length" class="pt-6">
+ <div class="text-lg leading-6 font-medium text-main mb-4">
+ <span v-data-source-type>{{ item.type }}</span>
+ </div>
+ <div class="space-y-4">
+ <div v-for="(ds, index) of item.list" :key="index">
+ <!-- Hide the data source detail link for now -->
+ <div v-if="false" class="relative mb-2">
+ <div
+ class="absolute inset-0 flex items-center"
+ aria-hidden="true"
>
- {{ ds.name }}
- </router-link>
+ <div class="w-full border-t border-gray-300"></div>
+ </div>
+ <div class="relative flex justify-start">
+ <router-link
+ :to="`/db/${databaseSlug}/datasource/${dataSourceSlug(
+ ds
+ )}`"
+ class="pr-3 bg-white font-medium normal-link"
+ >
+ {{ ds.name }}
+ </router-link>
+ </div>
</div>
- </div>
- <div
- v-if="allowChangeDataSource"
- class="flex justify-end space-x-3"
- >
- <template v-if="isEditingDataSource(ds)">
- <button
- type="button"
- class="btn-normal"
- @click.prevent="cancelEditDataSource"
- >
- Cancel
- </button>
- <button
- type="button"
- class="btn-normal"
- :disabled="!allowSaveDataSource"
- @click.prevent="saveEditDataSource"
- >
- <!-- Heroicon name: solid/save -->
- <svg
- class="-ml-1 mr-2 h-5 w-5 text-control-light"
- fill="currentColor"
- viewBox="0 0 20 20"
- xmlns="http://www.w3.org/2000/svg"
+ <div
+ v-if="allowChangeDataSource"
+ class="flex justify-end space-x-3"
+ >
+ <template v-if="isEditingDataSource(ds)">
+ <button
+ type="button"
+ class="btn-normal"
+ @click.prevent="cancelEditDataSource"
>
- <path
- d="M7.707 10.293a1 1 0 10-1.414 1.414l3 3a1 1 0 001.414 0l3-3a1 1 0 00-1.414-1.414L11 11.586V6h5a2 2 0 012 2v7a2 2 0 01-2 2H4a2 2 0 01-2-2V8a2 2 0 012-2h5v5.586l-1.293-1.293zM9 4a1 1 0 012 0v2H9V4z"
- ></path>
- </svg>
- <span>Save</span>
- </button>
- </template>
- <template v-else>
- <button
- type="button"
- class="btn-normal"
- @click.prevent="editDataSource(ds)"
- >
- <!-- Heroicon name: solid/pencil -->
- <svg
- class="-ml-1 mr-2 h-5 w-5 text-control-light"
- fill="currentColor"
- viewBox="0 0 20 20"
- xmlns="http://www.w3.org/2000/svg"
+ Cancel
+ </button>
+ <button
+ type="button"
+ class="btn-normal"
+ :disabled="!allowSaveDataSource"
+ @click.prevent="saveEditDataSource"
>
- <path
- d="M13.586 3.586a2 2 0 112.828 2.828l-.793.793-2.828-2.828.793-.793zM11.379 5.793L3 14.172V17h2.828l8.38-8.379-2.83-2.828z"
- ></path>
- </svg>
- <span>Edit</span>
- </button>
- </template>
+ <!-- Heroicon name: solid/save -->
+ <svg
+ class="-ml-1 mr-2 h-5 w-5 text-control-light"
+ fill="currentColor"
+ viewBox="0 0 20 20"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ d="M7.707 10.293a1 1 0 10-1.414 1.414l3 3a1 1 0 001.414 0l3-3a1 1 0 00-1.414-1.414L11 11.586V6h5a2 2 0 012 2v7a2 2 0 01-2 2H4a2 2 0 01-2-2V8a2 2 0 012-2h5v5.586l-1.293-1.293zM9 4a1 1 0 012 0v2H9V4z"
+ ></path>
+ </svg>
+ <span>Save</span>
+ </button>
+ </template>
+ <template v-else>
+ <button
+ type="button"
+ class="btn-normal"
+ @click.prevent="editDataSource(ds)"
+ >
+ <!-- Heroicon name: solid/pencil -->
+ <svg
+ class="-ml-1 mr-2 h-5 w-5 text-control-light"
+ fill="currentColor"
+ viewBox="0 0 20 20"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ d="M13.586 3.586a2 2 0 112.828 2.828l-.793.793-2.828-2.828.793-.793zM11.379 5.793L3 14.172V17h2.828l8.38-8.379-2.83-2.828z"
+ ></path>
+ </svg>
+ <span>Edit</span>
+ </button>
+ </template>
+ </div>
+ <DataSourceConnectionPanel
+ :editing="isEditingDataSource(ds)"
+ :dataSource="
+ isEditingDataSource(ds) ? state.editingDataSource : ds
+ "
+ />
</div>
- <DataSourceConnectionPanel
- :editing="isEditingDataSource(ds)"
- :dataSource="
- isEditingDataSource(ds) ? state.editingDataSource : ds
- "
- />
</div>
</div>
- </div>
+ </template>
</template>
</div>
</div>
@@ -214,7 +216,7 @@ import DataSourceConnectionPanel from "../components/DataSourceConnectionPanel.v
import PrincipalSelect from "../components/PrincipalSelect.vue";
import ProjectSelect from "../components/ProjectSelect.vue";
import { idFromSlug, isDBAOrOwner } from "../utils";
-import { PrincipalId, DataSource, ProjectId, DataSourcePatch } from "../types";
+import { DataSource, ProjectId, DataSourcePatch } from "../types";
import { cloneDeep, isEqual } from "lodash";
interface LocalState {
@@ -257,20 +259,26 @@ export default {
return isCurrentUserDBAOrOwner.value;
});
+ const allowViewDataSource = computed(() => {
+ if (isCurrentUserDBAOrOwner.value) {
+ return true;
+ }
+
+ for (const member of database.value.project.memberList) {
+ if (member.principal.id == currentUser.value.id) {
+ return true;
+ }
+ }
+
+ return false;
+ });
+
const allowChangeDataSource = computed(() => {
return isCurrentUserDBAOrOwner.value;
});
const dataSourceList = computed(() => {
- return database.value.dataSourceList.filter((dataSource: DataSource) => {
- return (
- isCurrentUserDBAOrOwner.value ||
- // If the current user is not DBA, we will only show the granted data source.
- dataSource.memberList.find((item) => {
- return item.principal.id == currentUser.value.id;
- })
- );
- });
+ return database.value.dataSourceList;
});
const readWriteDataSourceList = computed(() => {
@@ -351,6 +359,7 @@ export default {
database,
isCurrentUserDBAOrOwner,
allowChangeProject,
+ allowViewDataSource,
allowChangeDataSource,
readWriteDataSourceList,
readOnlyDataSourceList,