Skip to content

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

feat(frontend): access control settings improvements (#4180)

Liu Ji2c7b9513c6f9
diff --git a/frontend/src/components/AccessControl/AddRuleForm.vue b/frontend/src/components/AccessControl/AddRuleForm.vue
index 63687f2a69..f89f7122c1 100644
--- a/frontend/src/components/AccessControl/AddRuleForm.vue
+++ b/frontend/src/components/AccessControl/AddRuleForm.vue
@@ -47,10 +47,24 @@
v-if="!state.isLoading && databaseList.length === 0"
class="w-full flex flex-col py-6 justify-start items-center"
>
- <heroicons-outline:inbox class="w-12 h-auto text-gray-500" />
- <span class="text-sm leading-6 text-gray-500">{{
- $t("common.no-data")
- }}</span>
+ <i18n-t
+ keypath="settings.access-control.no-database-in-protected-environment"
+ tag="div"
+ class="text-sm leading-6 text-gray-500 max-w-[15rem] whitespace-pre-wrap text-center"
+ >
+ <template #protected_environment>
+ <a
+ href="https://www.bytebase.com/docs/administration/database-access-control"
+ class="normal-link lowercase"
+ target="__BLANK"
+ >
+ {{ $t("environment.protected-environment") }}
+ <heroicons-outline:external-link
+ class="inline-block w-4 h-4 -mt-0.5 mr-0.5"
+ />
+ </a>
+ </template>
+ </i18n-t>
</div>
<div class="flex items-center justify-between">
@@ -86,14 +100,11 @@
import { computed, PropType, reactive } from "vue";
import type { Database, DatabaseId, Policy } from "@/types";
-import { DEFAULT_PROJECT_ID } from "@/types";
-import { useDatabaseStore } from "@/store";
import { filterDatabaseByKeyword } from "@/utils";
type LocalState = {
isLoading: boolean;
searchText: string;
- databaseList: Database[];
selectedDatabaseIdList: Set<DatabaseId>;
};
@@ -102,6 +113,10 @@ const props = defineProps({
type: Array as PropType<Policy[]>,
default: () => [],
},
+ databaseList: {
+ type: Array as PropType<Database[]>,
+ default: () => [],
+ },
});
const emit = defineEmits<{
@@ -112,22 +127,9 @@ const emit = defineEmits<{
const state = reactive<LocalState>({
isLoading: false,
searchText: "",
- databaseList: [],
selectedDatabaseIdList: new Set(),
});
-const databaseStore = useDatabaseStore();
-
-const prepareList = async () => {
- state.isLoading = true;
-
- const allDatabaseList = await databaseStore.fetchDatabaseList();
- state.databaseList = allDatabaseList
- .filter((db) => db.instance.environment.tier === "PROTECTED")
- .filter((db) => db.project.id !== DEFAULT_PROJECT_ID);
- state.isLoading = false;
-};
-
const presetDatabaseIdList = computed(() => {
const databaseIdList = props.policyList.map(
(policy) => policy.resourceId as DatabaseId
@@ -137,7 +139,7 @@ const presetDatabaseIdList = computed(() => {
const databaseList = computed(() => {
// Don't show the databases already have access control policy.
- let list = state.databaseList.filter(
+ let list = props.databaseList.filter(
(db) => !presetDatabaseIdList.value.has(db.id)
);
@@ -204,6 +206,4 @@ const toggleAllDatabasesSelection = (
});
}
};
-
-prepareList();
</script>
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index d39ce4f31d..7fe368cf4e 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -423,9 +423,12 @@
"remove-sensitive-column-tips": "Expose this column?"
},
"access-control": {
- "description": "Allow developers to execute queries for the following databases in the protected environments from SQL Editor.",
+ "description": "Allow developers to execute queries for the following databases in the protected environments from SQL Editor. {link}",
"add-rule": "Add rule",
- "remove-policy-tips": "Remove this rule?"
+ "remove-policy-tips": "Remove this rule?",
+ "inactive-rules": "Inactive rules",
+ "inactive-rules-description": "These rules are inactive because environment is not protected.",
+ "no-database-in-protected-environment": "Make sure there are databases in the {protected_environment}."
},
"release": {
"new-version-available": "New version is available",
@@ -755,7 +758,8 @@
"disable-auto-backup": {
"self": "Disable database automatic backup",
"content": "Disabling automatic backup policy is not applied retroactively.\nAre you sure about applying to all databases in this environment?"
- }
+ },
+ "protected-environment": "Protected environment"
},
"quick-start": {
"bookmark-an-issue": "Bookmark an issue",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 8571f25054..64a3c6060e 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -423,9 +423,12 @@
"remove-sensitive-column-tips": "不再对此列数据脱敏?"
},
"access-control": {
- "description": "允许开发者通过 SQL 编辑器对下列受保护环境中的数据库执行查询。",
+ "description": "允许开发者通过 SQL 编辑器对下列受保护环境中的数据库执行查询。{link}",
"add-rule": "添加规则",
- "remove-policy-tips": "删除这条规则?"
+ "remove-policy-tips": "删除这条规则?",
+ "inactive-rules": "无效的规则",
+ "inactive-rules-description": "这些规则不再生效,因为所属环境不是受保护的。",
+ "no-database-in-protected-environment": "请确保{protected_environment}中有数据库。"
},
"release": {
"new-version-available": "有新版本可更新",
@@ -755,7 +758,8 @@
"disable-auto-backup": {
"self": "禁用数据库自动备份",
"content": "禁用自动备份策略仅对新添加的数据库生效。\n是否要将该设置应用到当前环境下的所有数据库?"
- }
+ },
+ "protected-environment": "受保护的环境"
},
"quick-start": {
"bookmark-an-issue": "收藏工单",
diff --git a/frontend/src/views/SettingWorkspaceAccessControl.vue b/frontend/src/views/SettingWorkspaceAccessControl.vue
index fe433a14cd..89fd2a5b7a 100644
--- a/frontend/src/views/SettingWorkspaceAccessControl.vue
+++ b/frontend/src/views/SettingWorkspaceAccessControl.vue
@@ -1,9 +1,17 @@
<template>
<div class="w-full mt-4 space-y-4">
<div class="flex justify-between">
- <div class="textinfolabel max-w-xl">
- {{ $t("settings.access-control.description") }}
- </div>
+ <i18n-t
+ tag="div"
+ keypath="settings.access-control.description"
+ class="textinfolabel"
+ >
+ <template #link>
+ <LearnMoreLink
+ url="https://www.bytebase.com/docs/administration/database-access-control"
+ />
+ </template>
+ </i18n-t>
<div>
<button
@@ -19,7 +27,7 @@
<div class="relative min-h-[12rem]">
<BBTable
:column-list="COLUMN_LIST"
- :data-source="state.policyList"
+ :data-source="activePolicyList"
:show-header="true"
:left-bordered="true"
:right-bordered="true"
@@ -80,7 +88,7 @@
</BBTable>
<div
- v-if="!state.isLoading && state.policyList.length === 0"
+ v-if="!state.isLoading && activePolicyList.length === 0"
class="w-full flex flex-col py-6 justify-start items-center"
>
<heroicons-outline:inbox class="w-12 h-auto text-gray-500" />
@@ -89,6 +97,76 @@
}}</span>
</div>
+ <template v-if="inactivePolicyList.length > 0">
+ <div class="text-lg mt-6 mb-1">
+ {{ $t("settings.access-control.inactive-rules") }}
+ </div>
+ <div class="textinfolabel max-w-xl mb-4">
+ {{ $t("settings.access-control.inactive-rules-description") }}
+ </div>
+ <BBTable
+ :column-list="COLUMN_LIST"
+ :data-source="inactivePolicyList"
+ :show-header="true"
+ :left-bordered="true"
+ :right-bordered="true"
+ :row-clickable="false"
+ >
+ <template #body="{ rowData: policy }: { rowData: Policy }">
+ <BBTableCell class="w-[25%]" :left-padding="4">
+ <div class="flex items-center space-x-2">
+ <span>{{ databaseOfPolicy(policy).name }}</span>
+ </div>
+ </BBTableCell>
+ <BBTableCell class="w-[15%]">
+ {{ projectName(databaseOfPolicy(policy).project) }}
+ </BBTableCell>
+ <BBTableCell class="w-[15%]">
+ <div class="flex items-center">
+ {{
+ environmentName(databaseOfPolicy(policy).instance.environment)
+ }}
+ <ProtectedEnvironmentIcon
+ class="ml-1"
+ :environment="databaseOfPolicy(policy).instance.environment"
+ />
+ </div>
+ </BBTableCell>
+ <BBTableCell class="w-[15%]">
+ <div class="flex flex-row items-center space-x-1">
+ <InstanceEngineIcon
+ :instance="databaseOfPolicy(policy).instance"
+ />
+ <span class="flex-1 whitespace-pre-wrap">
+ {{ instanceName(databaseOfPolicy(policy).instance) }}
+ </span>
+ </div>
+ </BBTableCell>
+ <BBTableCell>
+ {{ humanizeTs(policy.updatedTs) }}
+ </BBTableCell>
+ <BBTableCell>
+ <div class="flex items-center justify-center">
+ <NPopconfirm @positive-click="handleRemove(policy)">
+ <template #trigger>
+ <button
+ :disabled="!allowAdmin"
+ class="w-5 h-5 p-0.5 bg-white hover:bg-control-bg-hover rounded cursor-pointer disabled:cursor-not-allowed disabled:hover:bg-white disabled:text-gray-400"
+ >
+ <heroicons-outline:trash />
+ </button>
+ </template>
+
+ <div class="whitespace-nowrap">
+ {{ $t("settings.access-control.remove-policy-tips") }}
+ </div>
+ </NPopconfirm>
+ </div>
+ </BBTableCell>
+ </template>
+ </BBTable>
+ </template>
+
<div
v-if="state.isLoading || state.isUpdating"
class="absolute w-full h-full inset-0 bg-white/50 flex flex-col items-center justify-center"
@@ -111,6 +189,7 @@
>
<AddRuleForm
:policy-list="state.policyList"
+ :database-list="state.databaseList"
@cancel="state.showAddRuleModal = false"
@add="handleAddRule"
/>
@@ -121,6 +200,7 @@
import { computed, reactive, watchEffect } from "vue";
import { useI18n } from "vue-i18n";
import { NPopconfirm } from "naive-ui";
+import { uniq } from "lodash-es";
import {
featureToRef,
@@ -132,13 +212,13 @@ import {
AccessControlPolicyPayload,
Database,
DatabaseId,
+ DEFAULT_PROJECT_ID,
Policy,
PolicyUpsert,
} from "@/types";
import { BBTableColumn } from "@/bbkit/types";
import { hasWorkspacePermission } from "@/utils";
import AddRuleForm from "@/components/AccessControl/AddRuleForm.vue";
-import { uniq } from "lodash-es";
interface LocalState {
showFeatureModal: boolean;
@@ -146,6 +226,7 @@ interface LocalState {
isLoading: boolean;
isUpdating: boolean;
policyList: Policy[];
+ databaseList: Database[];
}
const { t } = useI18n();
@@ -155,6 +236,7 @@ const state = reactive<LocalState>({
isLoading: false,
isUpdating: false,
policyList: [],
+ databaseList: [],
});
const databaseStore = useDatabaseStore();
const policyStore = usePolicyStore();
@@ -172,6 +254,20 @@ const databaseOfPolicy = (policy: Policy) => {
return databaseStore.getDatabaseById(policy.resourceId as DatabaseId);
};
+const activePolicyList = computed(() => {
+ return state.policyList.filter(
+ (policy) =>
+ databaseOfPolicy(policy).instance.environment.tier === "PROTECTED"
+ );
+});
+
+const inactivePolicyList = computed(() => {
+ return state.policyList.filter(
+ (policy) =>
+ databaseOfPolicy(policy).instance.environment.tier === "UNPROTECTED"
+ );
+});
+
const prepareList = async () => {
state.isLoading = true;
@@ -180,8 +276,19 @@ const prepareList = async () => {
"DATABASE"
);
+ const allDatabaseList = await databaseStore.fetchDatabaseList();
+ state.databaseList = allDatabaseList
+ .filter((db) => db.instance.environment.tier === "PROTECTED")
+ .filter((db) => db.project.id !== DEFAULT_PROJECT_ID);
+
+ // For some policy related databases that are not in the state.databaseList,
+ // fetch them.
const databaseIdList = uniq(
- policyList.map((policy) => policy.resourceId as DatabaseId)
+ policyList
+ .map((policy) => policy.resourceId as DatabaseId)
+ .filter((databaseId) =>
+ state.databaseList.findIndex((db) => db.id === databaseId)
+ )
);
Promise.all(
@@ -189,6 +296,7 @@ const prepareList = async () => {
databaseStore.getOrFetchDatabaseById(databaseId)
)
);
+
state.policyList = policyList;
state.isLoading = false;