Skip to content

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

feat(frontend): IM integration setting (#3306)

boojack3234d18a58fc
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 3295ea6433..a5f3888666 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -322,6 +322,7 @@
"workspace": "Workspace",
"general": "General",
"members": "Members",
+ "im-integration": "IM Integration",
"version-control": "Version Control",
"subscription": "Subscription",
"labels": "Labels",
@@ -380,6 +381,9 @@
},
"system-bot": "System Bot"
},
+ "im-integration": {
+ "feishu-updated-tip": "Successfully updated the Feishu integration"
+ },
"general": {
"workspace": {
"branding": "Branding",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index f96bf908aa..f791683c8e 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -322,6 +322,7 @@
"workspace": "工作空间",
"general": "通用",
"members": "成员",
+ "im-integration": "IM 集成管理",
"version-control": "版本控制",
"subscription": "订阅",
"labels": "标签",
@@ -380,6 +381,9 @@
},
"system-bot": "机器人助手"
},
+ "im-integration": {
+ "feishu-updated-tip": "飞书配置更新成功"
+ },
"general": {
"workspace": {
"branding": "品牌",
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index edd64a3362..bf1fc388b9 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -344,6 +344,14 @@ const routes: Array<RouteRecordRaw> = [
component: () => import("../views/SettingWorkspaceMember.vue"),
props: true,
},
+ {
+ path: "im-integration",
+ name: "setting.workspace.im-integration",
+ meta: { title: () => t("settings.sidebar.im-integration") },
+ component: () =>
+ import("../views/SettingWorkspaceIMIntegration.vue"),
+ props: true,
+ },
{
path: "version-control",
name: "setting.workspace.version-control",
diff --git a/frontend/src/types/setting.ts b/frontend/src/types/setting.ts
index 393c5f4573..f4a0e45cde 100644
--- a/frontend/src/types/setting.ts
+++ b/frontend/src/types/setting.ts
@@ -1,7 +1,7 @@
import { SettingId } from "./id";
import { Principal } from "./principal";
-export type SettingName = string;
+export type SettingName = "bb.branding.logo" | "bb.app.im";
export type Setting = {
id: SettingId;
@@ -18,4 +18,13 @@ export type Setting = {
description: string;
};
-export const brandingLogoSettingName: SettingName = "bb.branding.logo";
+type IMType = "im.feishu";
+
+export interface SettingAppIMValue {
+ imType: IMType;
+ appId: string;
+ appSecret: string;
+ externalApproval: {
+ enabled: boolean;
+ };
+}
diff --git a/frontend/src/utils/role.ts b/frontend/src/utils/role.ts
index 299d82d148..26380b9035 100644
--- a/frontend/src/utils/role.ts
+++ b/frontend/src/utils/role.ts
@@ -11,6 +11,7 @@ export type WorkspacePermissionType =
| "bb.permission.workspace.manage-project"
| "bb.permission.workspace.manage-sql-review-policy"
| "bb.permission.workspace.manage-member"
+ | "bb.permission.workspace.manage-im-integration"
| "bb.permission.workspace.manage-vcs-provider"
| "bb.permission.workspace.manage-general"
// Can execute admininstrive queries such as "SHOW PROCESSLIST"
@@ -32,6 +33,7 @@ export const WORKSPACE_PERMISSION_MATRIX: Map<
["bb.permission.workspace.manage-member", [false, false, true]],
["bb.permission.workspace.manage-vcs-provider", [false, false, true]],
["bb.permission.workspace.manage-general", [false, false, true]],
+ ["bb.permission.workspace.manage-im-integration", [false, true, true]],
["bb.permission.workspace.admin-sql-editor", [false, true, true]],
]);
diff --git a/frontend/src/views/DashboardHeader.vue b/frontend/src/views/DashboardHeader.vue
index 30351ff109..d0ae5f1643 100644
--- a/frontend/src/views/DashboardHeader.vue
+++ b/frontend/src/views/DashboardHeader.vue
@@ -222,7 +222,6 @@ import { useI18n } from "vue-i18n";
import ProfileDropdown from "../components/ProfileDropdown.vue";
import { UNKNOWN_ID } from "../types";
-import { brandingLogoSettingName } from "../types/setting";
import { hasWorkspacePermission, isDev } from "../utils";
import { useLanguage } from "../composables/useLanguage";
import {
@@ -295,9 +294,8 @@ export default defineComponent({
};
const logoUrl = computed((): string | undefined => {
- const brandingLogoSetting = settingStore.getSettingByName(
- brandingLogoSettingName
- );
+ const brandingLogoSetting =
+ settingStore.getSettingByName("bb.branding.logo");
return brandingLogoSetting?.value;
});
diff --git a/frontend/src/views/SettingSidebar.vue b/frontend/src/views/SettingSidebar.vue
index 65a43284d6..543843e360 100644
--- a/frontend/src/views/SettingSidebar.vue
+++ b/frontend/src/views/SettingSidebar.vue
@@ -67,6 +67,12 @@
class="outline-item group w-full flex items-center pl-11 pr-2 py-2"
>{{ $t("settings.sidebar.labels") }}</router-link
>
+ <router-link
+ v-if="showIMIntegrationItem"
+ to="/setting/im-integration"
+ class="outline-item group w-full flex items-center pl-11 pr-2 py-2"
+ >{{ $t("settings.sidebar.im-integration") }}</router-link
+ >
<router-link
v-if="showVCSItem"
to="/setting/version-control"
@@ -104,84 +110,46 @@
</nav>
</template>
-<script lang="ts">
-import { computed, defineComponent, reactive } from "vue";
+<script lang="ts" setup>
+import { computed } from "vue";
import { useRouter } from "vue-router";
-import { hasWorkspacePermission, isDev } from "../utils";
+import { hasWorkspacePermission } from "../utils";
import { useCurrentUser, useRouterStore } from "@/store";
-interface LocalState {
- collapseState: boolean;
-}
-
-export default defineComponent({
- name: "SettingSidebar",
- props: {
- vcsSlug: {
- default: "",
- type: String,
- },
- sqlReviewPolicySlug: {
- default: "",
- type: String,
- },
- },
- setup() {
- const routerStore = useRouterStore();
- const router = useRouter();
-
- const state = reactive<LocalState>({
- collapseState: true,
- });
-
- const currentUser = useCurrentUser();
+const routerStore = useRouterStore();
+const router = useRouter();
- const showDebugItem = computed((): boolean => {
- return hasWorkspacePermission(
- "bb.permission.workspace.debug",
- currentUser.value.role
- );
- });
+const currentUser = useCurrentUser();
- const showProjectItem = computed((): boolean => {
- return hasWorkspacePermission(
- "bb.permission.workspace.manage-project",
- currentUser.value.role
- );
- });
-
- const showVCSItem = computed((): boolean => {
- return hasWorkspacePermission(
- "bb.permission.workspace.manage-vcs-provider",
- currentUser.value.role
- );
- });
-
- const goBack = () => {
- router.push(routerStore.backPath());
- };
+const showDebugItem = computed((): boolean => {
+ return hasWorkspacePermission(
+ "bb.permission.workspace.debug",
+ currentUser.value.role
+ );
+});
- const toggleCollapse = () => {
- state.collapseState = !state.collapseState;
- };
+const showProjectItem = computed((): boolean => {
+ return hasWorkspacePermission(
+ "bb.permission.workspace.manage-project",
+ currentUser.value.role
+ );
+});
- const integrationList = [
- {
- name: "Slack",
- link: "/setting/integration/slack",
- },
- ];
+const showIMIntegrationItem = computed((): boolean => {
+ return hasWorkspacePermission(
+ "bb.permission.workspace.manage-im-integration",
+ currentUser.value.role
+ );
+});
- return {
- state,
- isDev,
- integrationList,
- showDebugItem,
- showProjectItem,
- showVCSItem,
- goBack,
- toggleCollapse,
- };
- },
+const showVCSItem = computed((): boolean => {
+ return hasWorkspacePermission(
+ "bb.permission.workspace.manage-vcs-provider",
+ currentUser.value.role
+ );
});
+
+const goBack = () => {
+ router.push(routerStore.backPath());
+};
</script>
diff --git a/frontend/src/views/SettingWorkspaceGeneral.vue b/frontend/src/views/SettingWorkspaceGeneral.vue
index fbdde1f07e..b1be6ccde7 100644
--- a/frontend/src/views/SettingWorkspaceGeneral.vue
+++ b/frontend/src/views/SettingWorkspaceGeneral.vue
@@ -95,7 +95,6 @@
<script lang="ts" setup>
import { computed, reactive } from "vue";
import { hasWorkspacePermission } from "../utils";
-import { brandingLogoSettingName } from "../types/setting";
import { useI18n } from "vue-i18n";
import {
featureToRef,
@@ -136,9 +135,8 @@ const state = reactive<LocalState>({
});
settingStore.fetchSetting().then(() => {
- const brandingLogoSetting = settingStore.getSettingByName(
- brandingLogoSettingName
- )!;
+ const brandingLogoSetting =
+ settingStore.getSettingByName("bb.branding.logo")!;
state.logoUrl = brandingLogoSetting.value;
});
@@ -180,7 +178,7 @@ const uploadLogo = async () => {
try {
const fileInBase64 = await convertFileToBase64(state.logoFile);
const setting = await useSettingStore().updateSettingByName({
- name: brandingLogoSettingName,
+ name: "bb.branding.logo",
value: fileInBase64,
});
diff --git a/frontend/src/views/SettingWorkspaceIMIntegration.vue b/frontend/src/views/SettingWorkspaceIMIntegration.vue
new file mode 100644
index 0000000000..f2a66afd72
--- /dev/null
+++ b/frontend/src/views/SettingWorkspaceIMIntegration.vue
@@ -0,0 +1,100 @@
+<template>
+ <div class="w-full mt-4 space-y-4">
+ <div class="w-full flex flex-col justify-start items-start space-y-2">
+ <div class="w-full flex flex-row justify-start items-center">
+ <div class="flex flex-row justify-start items-center">
+ <img class="w-10 h-auto" src="../assets/feishu-logo.png" alt="" />
+ <span class="ml-2 text-lg font-medium">{{
+ $t("common.feishu")
+ }}</span>
+ </div>
+ <button
+ v-if="!state.feishuSetting"
+ type="button"
+ class="btn-primary ml-3 inline-flex justify-center py-2 px-4"
+ @click.prevent="createFeishuIntegration"
+ >
+ {{ $t("common.create") }}
+ </button>
+ </div>
+ <div
+ v-if="state.feishuSetting"
+ class="w-full flex flex-col justify-start items-start space-y-2"
+ >
+ <div class="textlabel">{{ $t("common.application") }} ID</div>
+ <BBTextField
+ class="w-128 max-w-full mb-2"
+ :placeholder="'ex. cli_a3c48b4c45f933xz'"
+ :value="state.feishuSetting.appId"
+ @input="(e: any) => state.feishuSetting!.appId = e.target.value"
+ />
+ <div class="mt-4 textlabel">Secret</div>
+ <BBTextField
+ class="w-128 max-w-full mb-2"
+ :placeholder="'ex. MTOc5YmoRYJyDfRXHUzSBeXzTu3w3I3G'"
+ :value="state.feishuSetting.appSecret"
+ @input="(e: any) => state.feishuSetting!.appSecret = e.target.value"
+ />
+ <button
+ type="button"
+ class="btn-primary inline-flex justify-center py-2 px-4 mt-2"
+ @click.prevent="updateFeishuIntegration"
+ >
+ {{ $t("common.update") }}
+ </button>
+ </div>
+ </div>
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { onMounted, reactive } from "vue";
+import { pushNotification, useSettingStore } from "@/store";
+import { SettingAppIMValue } from "@/types/setting";
+import { useI18n } from "vue-i18n";
+
+interface LocalState {
+ feishuSetting?: SettingAppIMValue;
+}
+
+const { t } = useI18n();
+const state = reactive<LocalState>({});
+const settingStore = useSettingStore();
+
+onMounted(() => {
+ const setting = settingStore.getSettingByName("bb.app.im");
+ if (setting) {
+ const appIMValue = JSON.parse(setting.value || "{}") as SettingAppIMValue;
+ if (appIMValue.imType === "im.feishu") {
+ state.feishuSetting = appIMValue;
+ }
+ }
+});
+
+const createFeishuIntegration = async () => {
+ state.feishuSetting = {
+ imType: "im.feishu",
+ appId: "",
+ appSecret: "",
+ externalApproval: {
+ enabled: true,
+ },
+ };
+ await settingStore.updateSettingByName({
+ name: "bb.app.im",
+ value: JSON.stringify(state.feishuSetting),
+ });
+};
+
+const updateFeishuIntegration = async () => {
+ await settingStore.updateSettingByName({
+ name: "bb.app.im",
+ value: JSON.stringify(state.feishuSetting),
+ });
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("settings.im-integration.feishu-updated-tip"),
+ });
+};
+</script>
diff --git a/server/setting.go b/server/setting.go
index d3e1414daf..a3a2f3f42b 100644
--- a/server/setting.go
+++ b/server/setting.go
@@ -15,6 +15,7 @@ var (
// Some settings contain secret info so we only return settings that are needed by the client.
whitelistSettings = []api.SettingName{
api.SettingBrandingLogo,
+ api.SettingAppIM,
}
)