Skip to content

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

chore: migrate to setting v1 gRPC api (#6113)

ecmadao510e7439a4e4
diff --git a/backend/api/v1/setting_service.go b/backend/api/v1/setting_service.go
index e91da4142f..a038c711c2 100644
--- a/backend/api/v1/setting_service.go
+++ b/backend/api/v1/setting_service.go
@@ -10,6 +10,7 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/encoding/protojson"
+ "google.golang.org/protobuf/reflect/protoreflect"
"github.com/google/cel-go/cel"
"github.com/pkg/errors"
@@ -144,10 +145,9 @@ func (s *SettingService) SetSetting(ctx context.Context, request *v1pb.SetSettin
var storeSettingValue string
switch apiSettingName {
case api.SettingWorkspaceProfile:
- settingValue := request.Setting.Value.GetWorkspaceProfileSettingValue().String()
payload := new(storepb.WorkspaceProfileSetting)
- if err := protojson.Unmarshal([]byte(settingValue), payload); err != nil {
- return nil, status.Errorf(codes.Internal, "failed to unmarshal setting value: %v for %s", err, apiSettingName)
+ if err := convertV1PbToStorePb(request.Setting.Value.GetWorkspaceProfileSettingValue(), payload); err != nil {
+ return nil, status.Errorf(codes.Internal, "failed to unmarshal setting value for %s with error: %v", err, apiSettingName)
}
if payload.ExternalUrl != "" {
externalURL, err := common.NormalizeExternalURL(payload.ExternalUrl)
@@ -156,15 +156,18 @@ func (s *SettingService) SetSetting(ctx context.Context, request *v1pb.SetSettin
}
payload.ExternalUrl = externalURL
}
- storeSettingValue = payload.String()
+ bytes, err := protojson.Marshal(payload)
+ if err != nil {
+ return nil, status.Errorf(codes.Internal, "failed to marshal setting for %s with error: %v", apiSettingName, err)
+ }
+ storeSettingValue = string(bytes)
case api.SettingWorkspaceApproval:
if !s.licenseService.IsFeatureEnabled(api.FeatureCustomApproval) {
return nil, status.Errorf(codes.PermissionDenied, api.FeatureCustomApproval.AccessErrorMessage())
}
- settingValue := request.Setting.Value.GetWorkspaceApprovalSettingValue().String()
payload := new(storepb.WorkspaceApprovalSetting)
- if err := protojson.Unmarshal([]byte(settingValue), payload); err != nil {
- return nil, status.Errorf(codes.Internal, "failed to unmarshal setting value: %v", err)
+ if err := convertV1PbToStorePb(request.Setting.Value.GetWorkspaceApprovalSettingValue(), payload); err != nil {
+ return nil, status.Errorf(codes.Internal, "failed to unmarshal setting value for %s with error: %v", err, apiSettingName)
}
e, err := cel.NewEnv(approval.ApprovalFactors...)
if err != nil {
@@ -182,7 +185,11 @@ func (s *SettingService) SetSetting(ctx context.Context, request *v1pb.SetSettin
return nil, status.Errorf(codes.InvalidArgument, "invalid approval template: %v, err: %v", rule.Template, err)
}
}
- storeSettingValue = settingValue
+ bytes, err := protojson.Marshal(payload)
+ if err != nil {
+ return nil, status.Errorf(codes.Internal, "failed to marshal setting for %s with error: %v", apiSettingName, err)
+ }
+ storeSettingValue = string(bytes)
case api.SettingWorkspaceMailDelivery:
apiValue := request.Setting.Value.GetSmtpMailDeliverySettingValue()
// We will fill the password read from the store if it is not set.
@@ -198,7 +205,7 @@ func (s *SettingService) SetSetting(ctx context.Context, request *v1pb.SetSettin
}
oldValue := new(storepb.SMTPMailDeliverySetting)
if err := protojson.Unmarshal([]byte(oldStoreSetting.Value), oldValue); err != nil {
- return nil, status.Errorf(codes.Internal, "failed to unmarshal setting value: %v", err)
+ return nil, status.Errorf(codes.Internal, "failed to unmarshal setting value for %s with error: %v", err, apiSettingName)
}
apiValue.Password = &oldValue.Password
}
@@ -234,7 +241,7 @@ func (s *SettingService) SetSetting(ctx context.Context, request *v1pb.SetSettin
}
bytes, err := protojson.Marshal(storeMailDeliveryValue)
if err != nil {
- return nil, status.Errorf(codes.Internal, "failed to marshal setting value: %v", err)
+ return nil, status.Errorf(codes.Internal, "failed to marshal setting value for %s with error: %v", err, apiSettingName)
}
storeSettingValue = string(bytes)
case api.SettingBrandingLogo:
@@ -243,12 +250,16 @@ func (s *SettingService) SetSetting(ctx context.Context, request *v1pb.SetSettin
}
storeSettingValue = request.Setting.Value.GetStringValue()
case api.SettingPluginAgent:
- settingValue := request.Setting.Value.GetAgentPluginSettingValue().String()
payload := new(storepb.AgentPluginSetting)
- if err := protojson.Unmarshal([]byte(settingValue), payload); err != nil {
- return nil, status.Errorf(codes.Internal, "failed to unmarshal setting value: %v for %s", err, apiSettingName)
+ if err := convertV1PbToStorePb(request.Setting.Value.GetAgentPluginSettingValue(), payload); err != nil {
+ return nil, status.Errorf(codes.Internal, "failed to unmarshal setting value for %s with error: %v", err, apiSettingName)
}
- storeSettingValue = payload.String()
+
+ bytes, err := protojson.Marshal(payload)
+ if err != nil {
+ return nil, status.Errorf(codes.Internal, "failed to marshal setting for %s with error: %v", apiSettingName, err)
+ }
+ storeSettingValue = string(bytes)
case api.SettingAppIM:
settingValue := request.Setting.Value.GetAppImSettingValue()
imType, err := convertToIMType(settingValue.ImType)
@@ -322,13 +333,24 @@ func (s *SettingService) SetSetting(ctx context.Context, request *v1pb.SetSettin
return settingMessage, nil
}
+func convertV1PbToStorePb(inputPB, outputPB protoreflect.ProtoMessage) error {
+ bytes, err := protojson.Marshal(inputPB)
+ if err != nil {
+ return status.Errorf(codes.Internal, "failed to marshal setting: %v", err)
+ }
+ if err := protojson.Unmarshal(bytes, outputPB); err != nil {
+ return status.Errorf(codes.Internal, "failed to unmarshal setting: %v", err)
+ }
+ return nil
+}
+
func convertToSettingMessage(setting *store.SettingMessage) (*v1pb.Setting, error) {
settingName := fmt.Sprintf("%s%s", settingNamePrefix, setting.Name)
switch setting.Name {
case api.SettingWorkspaceMailDelivery:
storeValue := new(storepb.SMTPMailDeliverySetting)
if err := protojson.Unmarshal([]byte(setting.Value), storeValue); err != nil {
- return nil, status.Errorf(codes.Internal, "failed to unmarshal setting value: %v", err)
+ return nil, status.Errorf(codes.Internal, "failed to unmarshal setting value for %s with error: %v", setting.Name, err)
}
return stripSensitiveData(&v1pb.Setting{
Name: settingName,
@@ -351,8 +373,12 @@ func convertToSettingMessage(setting *store.SettingMessage) (*v1pb.Setting, erro
})
case api.SettingAppIM:
apiValue := new(api.SettingAppIMValue)
- if err := json.Unmarshal([]byte(setting.Value), apiValue); err != nil {
- return nil, status.Errorf(codes.Internal, "failed to unmarshal setting value: %v", err)
+ stringValue := setting.Value
+ if stringValue == "" {
+ stringValue = "{}"
+ }
+ if err := json.Unmarshal([]byte(stringValue), apiValue); err != nil {
+ return nil, status.Errorf(codes.Internal, "failed to unmarshal setting value for %s with error: %v", setting.Name, err)
}
return &v1pb.Setting{
Name: settingName,
@@ -373,7 +399,7 @@ func convertToSettingMessage(setting *store.SettingMessage) (*v1pb.Setting, erro
case api.SettingPluginAgent:
v1Value := new(v1pb.AgentPluginSetting)
if err := protojson.Unmarshal([]byte(setting.Value), v1Value); err != nil {
- return nil, status.Errorf(codes.Internal, "failed to unmarshal setting value: %v", err)
+ return nil, status.Errorf(codes.Internal, "failed to unmarshal setting value for %s with error: %v", setting.Name, err)
}
return &v1pb.Setting{
Name: settingName,
@@ -386,7 +412,7 @@ func convertToSettingMessage(setting *store.SettingMessage) (*v1pb.Setting, erro
case api.SettingWorkspaceProfile:
v1Value := new(v1pb.WorkspaceProfileSetting)
if err := protojson.Unmarshal([]byte(setting.Value), v1Value); err != nil {
- return nil, status.Errorf(codes.Internal, "failed to unmarshal setting value: %v", err)
+ return nil, status.Errorf(codes.Internal, "failed to unmarshal setting value for %s with error: %v", setting.Name, err)
}
return &v1pb.Setting{
Name: settingName,
@@ -397,9 +423,18 @@ func convertToSettingMessage(setting *store.SettingMessage) (*v1pb.Setting, erro
},
}, nil
case api.SettingWorkspaceApproval:
- v1Value := new(v1pb.WorkspaceApprovalSetting)
- if err := protojson.Unmarshal([]byte(setting.Value), v1Value); err != nil {
- return nil, status.Errorf(codes.Internal, "failed to unmarshal setting value: %v", err)
+ storeValue := new(storepb.WorkspaceApprovalSetting)
+ if err := protojson.Unmarshal([]byte(setting.Value), storeValue); err != nil {
+ return nil, status.Errorf(codes.Internal, "failed to unmarshal setting value for %s with error: %v", setting.Name, err)
+ }
+ v1Value := &v1pb.WorkspaceApprovalSetting{}
+ for _, rule := range storeValue.Rules {
+ template := convertToApprovalTemplate(rule.Template)
+ template.Creator = fmt.Sprintf("%s%d", userNamePrefix, rule.Template.CreatorId)
+ v1Value.Rules = append(v1Value.Rules, &v1pb.WorkspaceApprovalSetting_Rule{
+ Expression: rule.Expression,
+ Template: template,
+ })
}
return &v1pb.Setting{
Name: settingName,
diff --git a/backend/server/server.go b/backend/server/server.go
index c4fa6695e9..8def31f95a 100644
--- a/backend/server/server.go
+++ b/backend/server/server.go
@@ -762,7 +762,7 @@ func (s *Server) getInitSetting(ctx context.Context, datastore *store.Store) (*w
// initial feishu app
if _, _, err := datastore.CreateSettingIfNotExistV2(ctx, &store.SettingMessage{
Name: api.SettingAppIM,
- Value: "",
+ Value: "{}",
Description: "",
}, api.SystemBotID); err != nil {
return nil, err
diff --git a/frontend/src/components/BytebaseLogo.vue b/frontend/src/components/BytebaseLogo.vue
index ec53e16005..de81f79941 100644
--- a/frontend/src/components/BytebaseLogo.vue
+++ b/frontend/src/components/BytebaseLogo.vue
@@ -26,12 +26,9 @@
<script lang="ts" setup>
import { computed } from "vue";
-import { useSettingStore } from "@/store";
-
-const settingStore = useSettingStore();
+import { useSettingV1Store } from "@/store/modules/v1/setting";
const customBrandingLogo = computed((): string | undefined => {
- const brandingLogoSetting = settingStore.getSettingByName("bb.branding.logo");
- return brandingLogoSetting?.value;
+ return useSettingV1Store().brandingLogo;
});
</script>
diff --git a/frontend/src/components/CustomApproval/Settings/components/CustomApproval/RulesPanel/types.ts b/frontend/src/components/CustomApproval/Settings/components/CustomApproval/RulesPanel/types.ts
index e8aba9132d..127f49153c 100644
--- a/frontend/src/components/CustomApproval/Settings/components/CustomApproval/RulesPanel/types.ts
+++ b/frontend/src/components/CustomApproval/Settings/components/CustomApproval/RulesPanel/types.ts
@@ -1,6 +1,6 @@
import { Expr } from "@/types/proto/google/api/expr/v1alpha1/syntax";
-import { WorkspaceApprovalSetting_Rule as ApprovalRule } from "@/types/proto/store/setting";
import { Risk_Source } from "@/types/proto/v1/risk_service";
+import { WorkspaceApprovalSetting_Rule as ApprovalRule } from "@/types/proto/v1/setting_service";
export type ParsedApprovalRule = {
source: Risk_Source;
diff --git a/frontend/src/components/GeneralSetting/AIAugmentationSetting.vue b/frontend/src/components/GeneralSetting/AIAugmentationSetting.vue
index 7e45291149..5eee7fda7f 100644
--- a/frontend/src/components/GeneralSetting/AIAugmentationSetting.vue
+++ b/frontend/src/components/GeneralSetting/AIAugmentationSetting.vue
@@ -112,17 +112,12 @@
<script lang="ts" setup>
import { computed, onMounted, reactive, ref, watchEffect } from "vue";
import { useI18n } from "vue-i18n";
-import {
- hasFeature,
- pushNotification,
- useCurrentUser,
- useSettingByName,
- useSettingStore,
-} from "@/store";
+import { hasFeature, pushNotification, useCurrentUser } from "@/store";
import { hasWorkspacePermission } from "@/utils";
import FeatureBadge from "@/components/FeatureBadge.vue";
import FeatureModal from "@/components/FeatureModal.vue";
import scrollIntoView from "scroll-into-view-if-needed";
+import { useSettingV1Store } from "@/store/modules/v1/setting";
interface LocalState {
openAIKey: string;
@@ -131,7 +126,7 @@ interface LocalState {
}
const { t } = useI18n();
-const settingStore = useSettingStore();
+const settingV1Store = useSettingV1Store();
const currentUser = useCurrentUser();
const containerRef = ref<HTMLDivElement>();
@@ -141,14 +136,16 @@ const state = reactive<LocalState>({
showFeatureModal: false,
});
-const openAIKeySetting = useSettingByName("bb.plugin.openai.key");
-const openAIEndpointSetting = useSettingByName("bb.plugin.openai.endpoint");
+const openAIKeySetting = settingV1Store.getSettingByName(
+ "bb.plugin.openai.key"
+);
+const openAIEndpointSetting = settingV1Store.getSettingByName(
+ "bb.plugin.openai.endpoint"
+);
watchEffect(() => {
- state.openAIKey = maskKey(openAIKeySetting.value?.value);
- state.openAIEndpoint = openAIEndpointSetting.value?.value
- ? openAIEndpointSetting.value?.value
- : "";
+ state.openAIKey = maskKey(openAIKeySetting?.value?.stringValue);
+ state.openAIEndpoint = openAIEndpointSetting?.value?.stringValue ?? "";
});
const allowEdit = computed((): boolean => {
@@ -160,12 +157,12 @@ const allowEdit = computed((): boolean => {
const allowSave = computed((): boolean => {
const openAIKeyUpdated =
- state.openAIKey !== maskKey(openAIKeySetting.value?.value) ||
+ state.openAIKey !== maskKey(openAIKeySetting?.value?.stringValue) ||
!state.openAIKey.includes("***");
return (
allowEdit.value &&
(openAIKeyUpdated ||
- state.openAIEndpoint !== openAIEndpointSetting.value?.value)
+ state.openAIEndpoint !== openAIEndpointSetting?.value?.stringValue)
);
});
@@ -192,18 +189,22 @@ const updateOpenAIKeyEndpoint = async () => {
}
if (
- state.openAIKey !== maskKey(openAIKeySetting.value?.value) ||
+ state.openAIKey !== maskKey(openAIKeySetting?.value?.stringValue) ||
!state.openAIKey.includes("***")
) {
- await settingStore.updateSettingByName({
+ await settingV1Store.upsertSetting({
name: "bb.plugin.openai.key",
- value: state.openAIKey,
+ value: {
+ stringValue: state.openAIKey,
+ },
});
}
- if (state.openAIEndpoint !== openAIEndpointSetting.value?.value) {
- await settingStore.updateSettingByName({
+ if (state.openAIEndpoint !== openAIEndpointSetting?.value?.stringValue) {
+ await settingV1Store.upsertSetting({
name: "bb.plugin.openai.endpoint",
- value: state.openAIEndpoint,
+ value: {
+ stringValue: state.openAIEndpoint,
+ },
});
}
pushNotification({
diff --git a/frontend/src/components/GeneralSetting/BrandingSetting.vue b/frontend/src/components/GeneralSetting/BrandingSetting.vue
index ae75290f53..328ea2ebe3 100644
--- a/frontend/src/components/GeneralSetting/BrandingSetting.vue
+++ b/frontend/src/components/GeneralSetting/BrandingSetting.vue
@@ -94,12 +94,8 @@
import { computed, reactive, watchEffect } from "vue";
import { hasWorkspacePermission } from "@/utils";
import { useI18n } from "vue-i18n";
-import {
- featureToRef,
- pushNotification,
- useCurrentUser,
- useSettingStore,
-} from "@/store";
+import { featureToRef, pushNotification, useCurrentUser } from "@/store";
+import { useSettingV1Store } from "@/store/modules/v1/setting";
interface LocalState {
displayName?: string;
@@ -121,7 +117,7 @@ const convertFileToBase64 = (file: File) =>
reader.onerror = (error) => reject(error);
});
-const settingStore = useSettingStore();
+const settingV1Store = useSettingV1Store();
const { t } = useI18n();
const state = reactive<LocalState>({
@@ -133,9 +129,7 @@ const state = reactive<LocalState>({
});
watchEffect(() => {
- const brandingLogoSetting =
- settingStore.getSettingByName("bb.branding.logo")!;
- state.logoUrl = brandingLogoSetting.value;
+ state.logoUrl = settingV1Store.brandingLogo;
});
const currentUser = useCurrentUser();
@@ -175,13 +169,15 @@ const uploadLogo = async () => {
try {
const fileInBase64 = await convertFileToBase64(state.logoFile);
- const setting = await settingStore.updateSettingByName({
+ const setting = await settingV1Store.upsertSetting({
name: "bb.branding.logo",
- value: fileInBase64,
+ value: {
+ stringValue: fileInBase64,
+ },
});
state.logoFile = null;
- state.logoUrl = setting.value;
+ state.logoUrl = setting.value?.stringValue;
pushNotification({
module: "bytebase",
diff --git a/frontend/src/components/GeneralSetting/NetworkSetting.vue b/frontend/src/components/GeneralSetting/NetworkSetting.vue
index 2b2a5c8678..d39762d270 100644
--- a/frontend/src/components/GeneralSetting/NetworkSetting.vue
+++ b/frontend/src/components/GeneralSetting/NetworkSetting.vue
@@ -60,16 +60,17 @@
<script lang="ts" setup>
import { computed, reactive, watchEffect } from "vue";
-import { pushNotification, useCurrentUser, useSettingStore } from "@/store";
+import { pushNotification, useCurrentUser } from "@/store";
import { hasWorkspacePermission } from "@/utils";
import { useI18n } from "vue-i18n";
+import { useSettingV1Store } from "@/store/modules/v1/setting";
interface LocalState {
externalUrl: string;
}
const { t } = useI18n();
-const settingStore = useSettingStore();
+const settingV1Store = useSettingV1Store();
const currentUser = useCurrentUser();
const state = reactive<LocalState>({
@@ -77,7 +78,7 @@ const state = reactive<LocalState>({
});
watchEffect(() => {
- state.externalUrl = settingStore.workspaceSetting?.externalUrl ?? "";
+ state.externalUrl = settingV1Store.workspaceProfileSetting?.externalUrl ?? "";
});
const allowEdit = computed((): boolean => {
@@ -91,7 +92,7 @@ const allowSave = computed((): boolean => {
return (
allowEdit.value &&
state.externalUrl !== "" &&
- state.externalUrl !== settingStore.workspaceSetting?.externalUrl
+ state.externalUrl !== settingV1Store.workspaceProfileSetting?.externalUrl
);
});
@@ -103,7 +104,7 @@ const updateExternalUrl = async () => {
if (!allowSave.value) {
return;
}
- await settingStore.updateWorkspaceProfile({
+ await settingV1Store.updateWorkspaceProfile({
externalUrl: state.externalUrl,
});
pushNotification({
@@ -112,6 +113,6 @@ const updateExternalUrl = async () => {
title: t("settings.general.workspace.config-updated"),
});
- state.externalUrl = settingStore.workspaceSetting?.externalUrl ?? "";
+ state.externalUrl = settingV1Store.workspaceProfileSetting?.externalUrl ?? "";
};
</script>
diff --git a/frontend/src/components/GeneralSetting/SecuritySetting.vue b/frontend/src/components/GeneralSetting/SecuritySetting.vue
index 1cb1212d2d..1ea2bc04f6 100644
--- a/frontend/src/components/GeneralSetting/SecuritySetting.vue
+++ b/frontend/src/components/GeneralSetting/SecuritySetting.vue
@@ -109,8 +109,6 @@ import {
featureToRef,
pushNotification,
useCurrentUser,
- useSettingByName,
- useSettingStore,
useActuatorStore,
useUserStore,
} from "@/store";
@@ -119,20 +117,20 @@ import { useI18n } from "vue-i18n";
import { FeatureType } from "@/types";
import { UserType } from "@/types/proto/v1/auth_service";
import { State } from "@/types/proto/v1/common";
+import { useSettingV1Store } from "@/store/modules/v1/setting";
interface LocalState {
featureNameForModal?: FeatureType;
}
const state = reactive<LocalState>({});
const { t } = useI18n();
-const settingStore = useSettingStore();
+const settingV1Store = useSettingV1Store();
const currentUser = useCurrentUser();
const userStore = useUserStore();
const actuatorStore = useActuatorStore();
const { isSaaSMode } = storeToRefs(actuatorStore);
const hasWatermarkFeature = featureToRef("bb.feature.branding");
-const watermarkSetting = useSettingByName("bb.workspace.watermark");
const has2FAFeature = featureToRef("bb.feature.2fa");
const hasDisallowSignupFeature = featureToRef("bb.feature.disallow-signup");
@@ -143,13 +141,16 @@ const allowEdit = computed((): boolean => {
);
});
const watermarkEnabled = computed((): boolean => {
- return watermarkSetting.value?.value === "1";
+ return (
+ settingV1Store.getSettingByName("bb.workspace.watermark")?.value
+ ?.stringValue === "1"
+ );
});
const disallowSignupEnabled = computed((): boolean => {
- return settingStore.workspaceSetting?.disallowSignup ?? false;
+ return settingV1Store.workspaceProfileSetting?.disallowSignup ?? false;
});
const require2FAEnabled = computed((): boolean => {
- return settingStore.workspaceSetting?.require2fa ?? false;
+ return settingV1Store.workspaceProfileSetting?.require2fa ?? false;
});
const handleDisallowSignupToggle = async (on: boolean) => {
@@ -157,7 +158,7 @@ const handleDisallowSignupToggle = async (on: boolean) => {
state.featureNameForModal = "bb.feature.disallow-signup";
return;
}
- await settingStore.updateWorkspaceProfile({
+ await settingV1Store.updateWorkspaceProfile({
disallowSignup: on,
});
pushNotification({
@@ -196,7 +197,7 @@ const handleRequire2FAToggle = async (on: boolean) => {
}
}
- await settingStore.updateWorkspaceProfile({
+ await settingV1Store.updateWorkspaceProfile({
require2fa: on,
});
pushNotification({
@@ -212,9 +213,11 @@ const handleWatermarkToggle = async (on: boolean) => {
return;
}
const value = on ? "1" : "0";
- await settingStore.updateSettingByName({
+ await settingV1Store.upsertSetting({
name: "bb.workspace.watermark",
- value,
+ value: {
+ stringValue: value,
+ },
});
pushNotification({
module: "bytebase",
diff --git a/frontend/src/components/InstanceForm.vue b/frontend/src/components/InstanceForm.vue
index 684d1f4838..2106b099d8 100644
--- a/frontend/src/components/InstanceForm.vue
+++ b/frontend/src/components/InstanceForm.vue
@@ -614,7 +614,6 @@ import {
useDatabaseStore,
useDataSourceStore,
useInstanceStore,
- useSettingStore,
useActuatorStore,
useSQLStore,
} from "@/store";
@@ -632,6 +631,7 @@ import {
import { useInstanceV1Store } from "@/store/modules/v1/instance";
import { instanceNamePrefix } from "@/store/modules/v1/common";
import ResourceIdField from "@/components/v2/Form/ResourceIdField.vue";
+import { useSettingV1Store } from "@/store/modules/v1/setting";
const props = defineProps({
instance: {
@@ -677,7 +677,7 @@ const instanceV1Store = useInstanceV1Store();
const dataSourceStore = useDataSourceStore();
const currentUser = useCurrentUser();
const sqlStore = useSQLStore();
-const settingStore = useSettingStore();
+const settingV1Store = useSettingV1Store();
const actuatorStore = useActuatorStore();
const state = reactive<LocalState>({
@@ -753,7 +753,7 @@ onMounted(async () => {
adminDataSource.value.options.srv = false;
adminDataSource.value.options.authenticationDatabase = "";
}
- await settingStore.fetchSetting();
+ await settingV1Store.fetchSettingList();
});
watch(
@@ -775,10 +775,10 @@ const engineList = computed(() => {
});
const outboundIpList = computed(() => {
- if (!settingStore.workspaceSetting) {
+ if (!settingV1Store.workspaceProfileSetting) {
return "";
}
- return settingStore.workspaceSetting.outboundIpList.join(",");
+ return settingV1Store.workspaceProfileSetting.outboundIpList.join(",");
});
const EngineIconPath = {
diff --git a/frontend/src/components/Issue/AssigneeAttentionButton.vue b/frontend/src/components/Issue/AssigneeAttentionButton.vue
index 238b89bd32..86b4b4df4d 100644
--- a/frontend/src/components/Issue/AssigneeAttentionButton.vue
+++ b/frontend/src/components/Issue/AssigneeAttentionButton.vue
@@ -34,19 +34,15 @@ import { computed } from "vue";
import { useI18n } from "vue-i18n";
import { NTooltip } from "naive-ui";
-import {
- pushNotification,
- useCurrentUser,
- useIssueStore,
- useSettingStore,
-} from "@/store";
+import { pushNotification, useCurrentUser, useIssueStore } from "@/store";
import { useIssueLogic } from "./logic";
import { Issue } from "@/types";
-import { SettingAppIMValue } from "@/types/setting";
+import { useSettingV1Store } from "@/store/modules/v1/setting";
+import { AppIMSetting_IMType } from "@/types/proto/v1/setting_service";
const { t } = useI18n();
const currentUser = useCurrentUser();
-const settingStore = useSettingStore();
+const settingV1Store = useSettingV1Store();
const { create, project, issue } = useIssueLogic();
const showNotifyAssignee = computed(() => {
@@ -79,17 +75,15 @@ const isAssigneeAttentionOn = computed(() => {
const externalApprovalSetting = computed(
(): { enabled: boolean; type: string } => {
- const setting = settingStore.getSettingByName("bb.app.im");
- if (setting) {
- const appFeishuValue = JSON.parse(
- setting.value || "{}"
- ) as SettingAppIMValue;
- if (appFeishuValue.imType === "im.feishu") {
- return {
- type: "feishu",
- enabled: appFeishuValue.externalApproval.enabled,
- };
- }
+ const setting = settingV1Store.getSettingByName("bb.app.im");
+ if (
+ setting?.value?.appImSettingValue?.imType === AppIMSetting_IMType.FEISHU
+ ) {
+ return {
+ type: "feishu",
+ enabled:
+ setting?.value?.appImSettingValue.externalApproval?.enabled ?? false,
+ };
}
return {
enabled: false,
diff --git a/frontend/src/components/ProfileBrandingLogo.vue b/frontend/src/components/ProfileBrandingLogo.vue
index 5a8417af54..92a3d0571f 100644
--- a/frontend/src/components/ProfileBrandingLogo.vue
+++ b/frontend/src/components/ProfileBrandingLogo.vue
@@ -14,12 +14,9 @@
<script lang="ts" setup>
import { computed } from "vue";
-import { useSettingStore } from "@/store";
-
-const settingStore = useSettingStore();
+import { useSettingV1Store } from "@/store/modules/v1/setting";
const customBrandingLogo = computed((): string | undefined => {
- const brandingLogoSetting = settingStore.getSettingByName("bb.branding.logo");
- return brandingLogoSetting?.value;
+ return useSettingV1Store().brandingLogo;
});
</script>
diff --git a/frontend/src/components/ProvideDashboardContext.vue b/frontend/src/components/ProvideDashboardContext.vue
index b94f4007d2..6cd2c6d4d0 100644
--- a/frontend/src/components/ProvideDashboardContext.vue
+++ b/frontend/src/components/ProvideDashboardContext.vue
@@ -8,7 +8,6 @@ import {
useMemberStore,
useRoleStore,
usePrincipalStore,
- useSettingStore,
useUIStateStore,
useLegacyProjectStore,
useDebugStore,
@@ -16,12 +15,13 @@ import {
} from "@/store";
import { defineComponent } from "vue";
import { DEFAULT_PROJECT_ID } from "../types";
+import { useSettingV1Store } from "@/store/modules/v1/setting";
export default defineComponent({
name: "ProvideDashboardContext",
async setup() {
await Promise.all([
- useSettingStore().fetchSetting(),
+ useSettingV1Store().fetchSettingList(),
// Fetch so MemberSelect can have the data.
useMemberStore().fetchMemberList(),
useRoleStore().fetchRoleList(),
diff --git a/frontend/src/components/ProvideSQLEditorContext.vue b/frontend/src/components/ProvideSQLEditorContext.vue
index 78549e2e12..5134338225 100644
--- a/frontend/src/components/ProvideSQLEditorContext.vue
+++ b/frontend/src/components/ProvideSQLEditorContext.vue
@@ -16,7 +16,6 @@ import {
useInstanceStore,
pushNotification,
useConnectionTreeStore,
- useSettingStore,
useProjectV1Store,
} from "@/store";
import {
@@ -44,6 +43,7 @@ import {
PolicyType,
PolicyResourceType,
} from "@/types/proto/v1/org_policy_service";
+import { useSettingV1Store } from "@/store/modules/v1/setting";
const route = useRoute();
const router = useRouter();
@@ -391,7 +391,7 @@ onMounted(async () => {
await setConnectionFromQuery();
await sqlEditorStore.fetchQueryHistoryList();
await useDebugStore().fetchDebug();
- await useSettingStore().fetchSetting();
+ await useSettingV1Store().fetchSettingList();
syncURLWithConnection();
});
diff --git a/frontend/src/components/SlowQuery/Panel/IndexAdvisor.vue b/frontend/src/components/SlowQuery/Panel/IndexAdvisor.vue
index ab7c089abe..83824c060d 100644
--- a/frontend/src/components/SlowQuery/Panel/IndexAdvisor.vue
+++ b/frontend/src/components/SlowQuery/Panel/IndexAdvisor.vue
@@ -53,8 +53,9 @@ import { useRouter } from "vue-router";
import { databaseServiceClient } from "@/grpcweb";
import { getErrorCode } from "@/utils/grpcweb";
import { Status } from "nice-grpc-common";
-import { featureToRef, hasFeature, useSettingStore } from "@/store";
+import { featureToRef, hasFeature } from "@/store";
import FeatureBadge from "@/components/FeatureBadge.vue";
+import { useSettingV1Store } from "@/store/modules/v1/setting";
const props = defineProps<{
slowQueryLog: ComposedSlowQueryLog;
@@ -76,14 +77,14 @@ const state = reactive<LocalState>({
createIndexStatement: "",
showFeatureModal: false,
});
-const settingStore = useSettingStore();
+const settingV1Store = useSettingV1Store();
const hasIndexAdvisorFeature = featureToRef("bb.feature.index-advisor");
const hasOpenAIKeySetup = computed(() => {
- const openAIKeySetting = settingStore.getSettingByName(
+ const openAIKeySetting = settingV1Store.getSettingByName(
"bb.plugin.openai.key"
);
if (openAIKeySetting) {
- return openAIKeySetting.value !== "";
+ return openAIKeySetting.value?.stringValue !== "";
}
return false;
});
diff --git a/frontend/src/components/misc/Watermark.vue b/frontend/src/components/misc/Watermark.vue
index c52523f62e..a33551bbaf 100644
--- a/frontend/src/components/misc/Watermark.vue
+++ b/frontend/src/components/misc/Watermark.vue
@@ -22,22 +22,23 @@
import { computed } from "vue";
import { NWatermark } from "naive-ui";
-import { featureToRef, useCurrentUser, useSettingByName } from "@/store";
+import { featureToRef, useCurrentUser } from "@/store";
import { UNKNOWN_ID } from "@/types";
+import { useSettingV1Store } from "@/store/modules/v1/setting";
const GAP = 320;
const SIZE = 16;
const PADDING = 6;
const currentUser = useCurrentUser();
-const setting = useSettingByName("bb.workspace.watermark");
+const setting = useSettingV1Store().getSettingByName("bb.workspace.watermark");
const hasWatermarkFeature = featureToRef("bb.feature.watermark");
const lines = computed(() => {
const user = currentUser.value;
if (user.id === UNKNOWN_ID) return [];
if (!hasWatermarkFeature.value) return [];
- if (setting.value?.value !== "1") return [];
+ if (setting?.value?.stringValue !== "1") return [];
const lines: string[] = [];
lines.push(`${user.name} (${user.id})`);
diff --git a/frontend/src/plugins/ai/components/AIChatToSQL.vue b/frontend/src/plugins/ai/components/AIChatToSQL.vue
index 49c18c516c..eb0aad8199 100644
--- a/frontend/src/plugins/ai/components/AIChatToSQL.vue
+++ b/frontend/src/plugins/ai/components/AIChatToSQL.vue
@@ -14,11 +14,11 @@ import {
useCurrentTab,
useInstanceById,
useMetadataByDatabaseId,
- useSettingByName,
} from "@/store";
import ChatPanel from "./ChatPanel.vue";
import MockInputPlaceholder from "./MockInputPlaceholder.vue";
import { Connection } from "@/types";
+import { useSettingV1Store } from "@/store/modules/v1/setting";
type LocalState = {
showHistoryDialog: boolean;
@@ -37,10 +37,17 @@ const state = reactive<LocalState>({
showHistoryDialog: false,
});
-const openAIKeySetting = useSettingByName("bb.plugin.openai.key");
-const openAIEndpointSetting = useSettingByName("bb.plugin.openai.endpoint");
-const openAIKey = computed(() => openAIKeySetting.value?.value ?? "");
-const openAIEndpoint = computed(() => openAIEndpointSetting.value?.value ?? "");
+const settingV1Store = useSettingV1Store();
+const openAIKeySetting = settingV1Store.getSettingByName(
+ "bb.plugin.openai.key"
+);
+const openAIEndpointSetting = settingV1Store.getSettingByName(
+ "bb.plugin.openai.endpoint"
+);
+const openAIKey = computed(() => openAIKeySetting?.value?.stringValue ?? "");
+const openAIEndpoint = computed(
+ () => openAIEndpointSetting?.value?.stringValue ?? ""
+);
const tab = useCurrentTab();
const instance = useInstanceById(
diff --git a/frontend/src/store/modules/index.ts b/frontend/src/store/modules/index.ts
index 30336b7b64..1cb68f92dd 100644
--- a/frontend/src/store/modules/index.ts
+++ b/frontend/src/store/modules/index.ts
@@ -25,7 +25,6 @@ export * from "./principal";
export * from "./project";
export * from "./repository";
export * from "./router";
-export * from "./setting";
export * from "./sheet";
export * from "./stage";
export * from "./sql";
diff --git a/frontend/src/store/modules/setting.ts b/frontend/src/store/modules/setting.ts
deleted file mode 100644
index 9a60c2f124..0000000000
--- a/frontend/src/store/modules/setting.ts
+++ /dev/null
@@ -1,106 +0,0 @@
-import { computed, unref } from "vue";
-import { defineStore } from "pinia";
-import axios from "axios";
-import { MaybeRef, ResourceObject, SettingState } from "@/types";
-import { Setting, SettingName } from "@/types/setting";
-import { WorkspaceProfileSetting } from "@/types/proto/store/setting";
-import { useActuatorStore } from "./actuator";
-
-function convert(
- setting: ResourceObject,
- includedList: ResourceObject[]
-): Setting {
- return {
- ...(setting.attributes as Omit<Setting, "id">),
- id: parseInt(setting.id),
- };
-}
-
-export const useSettingStore = defineStore("setting", {
- state: (): SettingState => ({
- settingByName: new Map(),
- }),
- getters: {
- workspaceSetting(state): WorkspaceProfileSetting | undefined {
- const setting = state.settingByName.get("bb.workspace.profile");
- if (!setting || !setting.value) {
- return;
- }
-
- return WorkspaceProfileSetting.fromJSON(JSON.parse(setting.value));
- },
- },
- actions: {
- getSettingByName(name: SettingName) {
- return this.settingByName.get(name);
- },
- setSettingByName({
- name,
- setting,
- }: {
- name: SettingName;
- setting: Setting;
- }) {
- this.settingByName.set(name, setting);
- },
- async fetchSetting(): Promise<Setting[]> {
- const data = (await axios.get(`/api/setting`)).data;
- const settingList = data.data.map((setting: ResourceObject) => {
- return convert(setting, data.included);
- });
- for (const setting of settingList) {
- this.setSettingByName({ name: setting.name, setting });
- }
- return settingList;
- },
- async updateSettingByName({
- name,
- value,
- }: {
- name: SettingName;
- value: string;
- }): Promise<Setting> {
- const data = (
- await axios.patch(`/api/setting/${name}`, {
- data: {
- type: "settingPatch",
- attributes: {
- value,
- },
- },
- })
- ).data;
-
- const setting = convert(data.data, data.included);
- this.setSettingByName({ name: setting.name, setting });
-
- return setting;
- },
- async updateWorkspaceProfile(payload: object): Promise<void> {
- if (!this.workspaceSetting) {
- return;
- }
- const profileSetting: WorkspaceProfileSetting = {
- disallowSignup: this.workspaceSetting.disallowSignup,
- externalUrl: this.workspaceSetting.externalUrl,
- require2fa: this.workspaceSetting.require2fa,
- outboundIpList: this.workspaceSetting.outboundIpList,
- ...payload,
- };
- await this.updateSettingByName({
- name: "bb.workspace.profile",
- value: JSON.stringify(profileSetting),
- });
- // Fetch the latest server info.
- await useActuatorStore().fetchServerInfo();
- },
- },
-});
-
-export const useSettingByName = (name: MaybeRef<SettingName>) => {
- const store = useSettingStore();
-
- return computed(() => {
- return store.getSettingByName(unref(name));
- });
-};
diff --git a/frontend/src/store/modules/v1/common.ts b/frontend/src/store/modules/v1/common.ts
index b9a3209e13..809ae18e9a 100644
--- a/frontend/src/store/modules/v1/common.ts
+++ b/frontend/src/store/modules/v1/common.ts
@@ -13,6 +13,7 @@ export const instanceNamePrefix = "instances/";
export const databaseNamePrefix = "databases/";
export const idpNamePrefix = "idps/";
export const policyNamePrefix = "policies/";
+export const settingNamePrefix = "settings/";
export const getNameParentTokens = (
name: string,
diff --git a/frontend/src/store/modules/v1/setting.ts b/frontend/src/store/modules/v1/setting.ts
new file mode 100644
index 0000000000..4ef69a07f8
--- /dev/null
+++ b/frontend/src/store/modules/v1/setting.ts
@@ -0,0 +1,92 @@
+import { defineStore } from "pinia";
+import { settingServiceClient } from "@/grpcweb";
+import {
+ Setting,
+ Value as SettingValue,
+ WorkspaceProfileSetting,
+} from "@/types/proto/v1/setting_service";
+import { settingNamePrefix } from "@/store/modules/v1/common";
+import { SettingName } from "@/types/setting";
+import { useActuatorStore } from "../actuator";
+
+interface SettingState {
+ settingMapByName: Map<string, Setting>;
+}
+
+export const useSettingV1Store = defineStore("setting_v1", {
+ state: (): SettingState => ({
+ settingMapByName: new Map(),
+ }),
+ getters: {
+ workspaceProfileSetting(state): WorkspaceProfileSetting | undefined {
+ const setting = state.settingMapByName.get(
+ `${settingNamePrefix}bb.workspace.profile`
+ );
+ return setting?.value?.workspaceProfileSettingValue;
+ },
+ brandingLogo(state): string | undefined {
+ const setting = state.settingMapByName.get(
+ `${settingNamePrefix}bb.branding.logo`
+ );
+ return setting?.value?.stringValue;
+ },
+ },
+ actions: {
+ getSettingByName(name: SettingName) {
+ return this.settingMapByName.get(`${settingNamePrefix}${name}`);
+ },
+ async fetchSettingByName(name: SettingName) {
+ const setting = await settingServiceClient.getSetting({ name });
+ this.settingMapByName.set(setting.name, setting);
+ setting.value;
+ },
+ async fetchSettingList() {
+ const { settings } = await settingServiceClient.listSettings({});
+ for (const setting of settings) {
+ this.settingMapByName.set(setting.name, setting);
+ }
+ },
+ async upsertSetting({
+ name,
+ value,
+ validateOnly = false,
+ }: {
+ name: SettingName;
+ value: SettingValue;
+ validateOnly?: boolean;
+ }) {
+ const resp = await settingServiceClient.setSetting({
+ setting: {
+ name: `${settingNamePrefix}${name}`,
+ value,
+ },
+ validateOnly,
+ });
+ this.settingMapByName.set(resp.name, resp);
+ return resp;
+ },
+ async updateWorkspaceProfile(payload: object): Promise<void> {
+ console.log("updateWorkspaceProfile");
+ console.log(payload);
+ console.log(this.workspaceProfileSetting);
+ if (!this.workspaceProfileSetting) {
+ return;
+ }
+ const profileSetting: WorkspaceProfileSetting = {
+ disallowSignup: this.workspaceProfileSetting.disallowSignup,
+ externalUrl: this.workspaceProfileSetting.externalUrl,
+ require2fa: this.workspaceProfileSetting.require2fa,
+ outboundIpList: this.workspaceProfileSetting.outboundIpList,
+ ...payload,
+ };
+ await this.upsertSetting({
+ name: "bb.workspace.profile",
+ value: {
+ workspaceProfileSettingValue: profileSetting,
+ },
+ });
+ // Fetch the latest server info.
+ await useActuatorStore().fetchServerInfo();
+ },
+ },
+});
diff --git a/frontend/src/store/modules/workspaceApprovalSetting.ts b/frontend/src/store/modules/workspaceApprovalSetting.ts
index 29c683677f..c25c65affc 100644
--- a/frontend/src/store/modules/workspaceApprovalSetting.ts
+++ b/frontend/src/store/modules/workspaceApprovalSetting.ts
@@ -3,7 +3,6 @@ import { ref } from "vue";
import { cloneDeep } from "lodash-es";
import { settingServiceClient } from "@/grpcweb";
-import { WorkspaceApprovalSetting } from "@/types/proto/store/setting";
import { Setting } from "@/types/proto/v1/setting_service";
import type { LocalApprovalConfig, LocalApprovalRule } from "@/types";
import {
@@ -26,13 +25,13 @@ export const useWorkspaceApprovalSettingStore = defineStore(
});
const setConfigSetting = (setting: Setting) => {
- const _config = WorkspaceApprovalSetting.fromJSON(
- JSON.parse(setting.value?.stringValue || "{}")
- );
- if (_config.rules.length === 0) {
- _config.rules.push(...seedWorkspaceApprovalSetting());
+ const _config = setting.value?.workspaceApprovalSettingValue;
+ if (_config) {
+ if (_config.rules.length === 0) {
+ _config.rules.push(...seedWorkspaceApprovalSetting());
+ }
+ config.value = resolveLocalApprovalConfig(_config);
}
- config.value = resolveLocalApprovalConfig(_config);
};
const fetchConfig = async () => {
@@ -52,7 +51,7 @@ export const useWorkspaceApprovalSettingStore = defineStore(
setting: {
name: SETTING_NAME,
value: {
- stringValue: JSON.stringify(setting),
+ workspaceApprovalSettingValue: setting,
},
},
});
diff --git a/frontend/src/types/proto/v1/review_service.ts b/frontend/src/types/proto/v1/review_service.ts
index 698eb777f3..937f11e440 100644
--- a/frontend/src/types/proto/v1/review_service.ts
+++ b/frontend/src/types/proto/v1/review_service.ts
@@ -217,6 +217,11 @@ export interface ApprovalTemplate {
flow?: ApprovalFlow;
title: string;
description: string;
+ /**
+ * The name of the creator.
+ * Format: users/{user}. {user} is a system-generated unique ID.
+ */
+ creator: string;
}
export interface ApprovalFlow {
@@ -1199,7 +1204,7 @@ export const Review_Approver = {
};
function createBaseApprovalTemplate(): ApprovalTemplate {
- return { flow: undefined, title: "", description: "" };
+ return { flow: undefined, title: "", description: "", creator: "" };
}
export const ApprovalTemplate = {
@@ -1213,6 +1218,9 @@ export const ApprovalTemplate = {
if (message.description !== "") {
writer.uint32(26).string(message.description);
}
+ if (message.creator !== "") {
+ writer.uint32(34).string(message.creator);
+ }
return writer;
},
@@ -1244,6 +1252,13 @@ export const ApprovalTemplate = {
message.description = reader.string();
continue;
+ case 4:
+ if (tag !== 34) {
+ break;
+ }
+
+ message.creator = reader.string();
+ continue;
}
if ((tag & 7) === 4 || tag === 0) {
break;
@@ -1258,6 +1273,7 @@ export const ApprovalTemplate = {
flow: isSet(object.flow) ? ApprovalFlow.fromJSON(object.flow) : undefined,
title: isSet(object.title) ? String(object.title) : "",
description: isSet(object.description) ? String(object.description) : "",
+ creator: isSet(object.creator) ? String(object.creator) : "",
};
},
@@ -1266,6 +1282,7 @@ export const ApprovalTemplate = {
message.flow !== undefined && (obj.flow = message.flow ? ApprovalFlow.toJSON(message.flow) : undefined);
message.title !== undefined && (obj.title = message.title);
message.description !== undefined && (obj.description = message.description);
+ message.creator !== undefined && (obj.creator = message.creator);
return obj;
},
@@ -1280,6 +1297,7 @@ export const ApprovalTemplate = {
: undefined;
message.title = object.title ?? "";
message.description = object.description ?? "";
+ message.creator = object.creator ?? "";
return message;
},
};
diff --git a/frontend/src/types/setting.ts b/frontend/src/types/setting.ts
index e279aeea78..92eb04cf36 100644
--- a/frontend/src/types/setting.ts
+++ b/frontend/src/types/setting.ts
@@ -1,5 +1,3 @@
-import { SettingId } from "./id";
-
export type SettingName =
| "bb.branding.logo"
| "bb.app.im"
@@ -8,23 +6,3 @@ export type SettingName =
| "bb.workspace.approval"
| "bb.plugin.openai.key"
| "bb.plugin.openai.endpoint";
-
-export type Setting = {
- id: SettingId;
-
- // Domain specific fields
- name: SettingName;
- value: string;
- description: string;
-};
-
-type IMType = "im.feishu";
-
-export interface SettingAppIMValue {
- imType: IMType;
- appId: string;
- appSecret: string;
- externalApproval: {
- enabled: boolean;
- };
-}
diff --git a/frontend/src/types/workspaceApprovalSetting.ts b/frontend/src/types/workspaceApprovalSetting.ts
index 29e21067e6..b5791c676e 100644
--- a/frontend/src/types/workspaceApprovalSetting.ts
+++ b/frontend/src/types/workspaceApprovalSetting.ts
@@ -1,6 +1,6 @@
import { SimpleExpr } from "@/plugins/cel";
import type { Risk_Source } from "@/types/proto/v1/risk_service";
-import type { ApprovalTemplate } from "./proto/store/approval";
+import { ApprovalTemplate } from "@/types/proto/v1/review_service";
export type LocalApprovalRule = {
uid: string;
diff --git a/frontend/src/utils/workspaceApprovalSetting.ts b/frontend/src/utils/workspaceApprovalSetting.ts
index 31a0aba34d..83208f96e3 100644
--- a/frontend/src/utils/workspaceApprovalSetting.ts
+++ b/frontend/src/utils/workspaceApprovalSetting.ts
@@ -9,10 +9,6 @@ import {
UnrecognizedApprovalRule,
} from "@/types";
import { ParsedExpr } from "@/types/proto/google/api/expr/v1alpha1/syntax";
-import {
- WorkspaceApprovalSetting,
- WorkspaceApprovalSetting_Rule as ApprovalRule,
-} from "@/types/proto/store/setting";
import { Risk_Source } from "@/types/proto/v1/risk_service";
import {
LocalApprovalConfig,
@@ -30,6 +26,7 @@ import {
ApprovalStep_Type,
} from "@/types/proto/v1/review_service";
import { usePrincipalStore } from "@/store";
+import { getUserId } from "@/store/modules/v1/common";
import {
buildCELExpr,
EqualityExpr,
@@ -38,6 +35,10 @@ import {
SimpleExpr,
} from "@/plugins/cel";
import { displayRoleTitle } from "./role";
+import {
+ WorkspaceApprovalSetting,
+ WorkspaceApprovalSetting_Rule as ApprovalRule,
+} from "@/types/proto/v1/setting_service";
export const approvalNodeGroupValueText = (group: ApprovalNode_GroupValue) => {
const name = approvalNode_GroupValueToJSON(group);
@@ -316,11 +317,8 @@ export const seedWorkspaceApprovalSetting = () => {
};
export const creatorOfRule = (rule: LocalApprovalRule) => {
- const creatorId = rule.template.creatorId ?? UNKNOWN_ID;
- if (creatorId === UNKNOWN_ID) return unknown("PRINCIPAL");
- if (creatorId === SYSTEM_BOT_ID) {
- return usePrincipalStore().principalById(creatorId);
- }
-
- return usePrincipalStore().principalById(creatorId);
+ const creatorName = rule.template.creator ?? `${UNKNOWN_ID}`;
+ if (creatorName === `${UNKNOWN_ID}`) return unknown("PRINCIPAL");
+ const userId = getUserId(creatorName);
+ return usePrincipalStore().principalById(userId);
};
diff --git a/frontend/src/views/BannerUpgradeSubscription.vue b/frontend/src/views/BannerUpgradeSubscription.vue
index 30a9843836..97d2baaea7 100644
--- a/frontend/src/views/BannerUpgradeSubscription.vue
+++ b/frontend/src/views/BannerUpgradeSubscription.vue
@@ -62,7 +62,6 @@ import { reactive } from "vue";
import {
useIdentityProviderStore,
useInstanceStore,
- useSettingStore,
useSubscriptionStore,
} from "@/store";
import { onMounted } from "vue";
@@ -73,6 +72,7 @@ import { EnvironmentTier } from "@/types/proto/v1/environment_service";
import { useI18n } from "vue-i18n";
import { PlanType } from "@/types/proto/v1/subscription_service";
import { useRouter } from "vue-router";
+import { useSettingV1Store } from "@/store/modules/v1/setting";
interface LocalState {
showModal: boolean;
@@ -86,7 +86,7 @@ const state = reactive<LocalState>({
});
const idpStore = useIdentityProviderStore();
-const settingStore = useSettingStore();
+const settingV1Store = useSettingV1Store();
const instanceStore = useInstanceStore();
const environmentV1Store = useEnvironmentV1Store();
@@ -123,23 +123,22 @@ const overusedEnterprisePlanFeatureList = computed(() => {
if (idpStore.identityProviderList.length > 0) {
list.push("bb.feature.sso");
}
- const brandingSetting = settingStore.getSettingByName("bb.branding.logo");
- if (brandingSetting && brandingSetting.value) {
+ if (settingV1Store.brandingLogo) {
list.push("bb.feature.branding");
}
- const watermarkSetting = settingStore.getSettingByName(
+ const watermarkSetting = settingV1Store.getSettingByName(
"bb.workspace.watermark"
);
- if (watermarkSetting && watermarkSetting.value === "1") {
+ if (watermarkSetting && watermarkSetting.value?.stringValue === "1") {
list.push("bb.feature.watermark");
}
- if (settingStore.workspaceSetting?.disallowSignup ?? false) {
+ if (settingV1Store.workspaceProfileSetting?.disallowSignup ?? false) {
list.push("bb.feature.disallow-signup");
}
- if (settingStore.workspaceSetting?.require2fa ?? false) {
+ if (settingV1Store.workspaceProfileSetting?.require2fa ?? false) {
list.push("bb.feature.2fa");
}
- const openAIKeySetting = settingStore.getSettingByName(
+ const openAIKeySetting = settingV1Store.getSettingByName(
"bb.plugin.openai.key"
);
if (openAIKeySetting && openAIKeySetting.value) {
@@ -173,7 +172,7 @@ onMounted(() => {
Promise.all([
idpStore.fetchIdentityProviderList(),
- settingStore.fetchSetting(),
+ settingV1Store.fetchSettingList(),
environmentV1Store.fetchEnvironments(),
instanceStore.fetchInstanceList(),
]).catch(() => {
diff --git a/frontend/src/views/SettingWorkspaceGeneral.vue b/frontend/src/views/SettingWorkspaceGeneral.vue
index 1dab839597..e564f01ee6 100644
--- a/frontend/src/views/SettingWorkspaceGeneral.vue
+++ b/frontend/src/views/SettingWorkspaceGeneral.vue
@@ -16,12 +16,13 @@ import {
NetworkSetting,
AIAugmentationSetting,
} from "@/components/GeneralSetting";
-import { useActuatorStore, useSettingStore } from "@/store";
+import { useActuatorStore } from "@/store";
+import { useSettingV1Store } from "@/store/modules/v1/setting";
const actuatorStore = useActuatorStore();
onMounted(async () => {
- await useSettingStore().fetchSetting();
+ await useSettingV1Store().fetchSettingList();
});
const { isSaaSMode } = storeToRefs(actuatorStore);
</script>
diff --git a/frontend/src/views/SettingWorkspaceIMIntegration.vue b/frontend/src/views/SettingWorkspaceIMIntegration.vue
index 8f9453564d..8d4cc62e60 100644
--- a/frontend/src/views/SettingWorkspaceIMIntegration.vue
+++ b/frontend/src/views/SettingWorkspaceIMIntegration.vue
@@ -57,6 +57,7 @@
$t("settings.im-integration.enable")
}}</span>
<BBSwitch
+ v-if="state.feishuSetting.externalApproval"
:value="state.feishuSetting.externalApproval.enabled"
@toggle="onFeishuIntegrationEnableToggle"
/>
@@ -87,14 +88,18 @@
import { cloneDeep, isEqual } from "lodash-es";
import { computed, onMounted, reactive } from "vue";
import { useI18n } from "vue-i18n";
-import { featureToRef, pushNotification, useSettingStore } from "@/store";
-import { SettingAppIMValue } from "@/types/setting";
+import { featureToRef, pushNotification } from "@/store";
import { BBSwitch } from "@/bbkit";
import FeatureBadge from "@/components/FeatureBadge.vue";
+import { useSettingV1Store } from "@/store/modules/v1/setting";
+import {
+ AppIMSetting,
+ AppIMSetting_IMType,
+} from "@/types/proto/v1/setting_service";
interface LocalState {
- originFeishuSetting?: SettingAppIMValue;
- feishuSetting?: SettingAppIMValue;
+ originFeishuSetting?: AppIMSetting;
+ feishuSetting?: AppIMSetting;
showFeatureModal: boolean;
isLoading: boolean;
}
@@ -104,7 +109,7 @@ const state = reactive<LocalState>({
showFeatureModal: false,
isLoading: false,
});
-const settingStore = useSettingStore();
+const settingV1Store = useSettingV1Store();
const hasIMApprovalFeature = featureToRef("bb.feature.im.approval");
const feishuActionButtonText = computed(() => {
@@ -118,20 +123,16 @@ const allowFeishuActionButton = computed(() => {
});
onMounted(() => {
- const setting = settingStore.getSettingByName("bb.app.im");
- if (setting) {
- const appFeishuValue = JSON.parse(
- setting.value || "{}"
- ) as SettingAppIMValue;
- if (appFeishuValue.imType === "im.feishu") {
- state.originFeishuSetting = cloneDeep(appFeishuValue);
- state.feishuSetting = appFeishuValue;
- }
+ const setting = settingV1Store.getSettingByName("bb.app.im");
+ const appFeishuValue = setting?.value?.appImSettingValue;
+ if (appFeishuValue?.imType === AppIMSetting_IMType.FEISHU) {
+ state.originFeishuSetting = cloneDeep(appFeishuValue);
+ state.feishuSetting = appFeishuValue;
}
});
const onFeishuIntegrationEnableToggle = (status: boolean) => {
- if (state.feishuSetting) {
+ if (state.feishuSetting && state.feishuSetting.externalApproval) {
state.feishuSetting.externalApproval.enabled = status;
}
};
@@ -143,11 +144,12 @@ const createFeishuIntegration = () => {
}
state.feishuSetting = {
- imType: "im.feishu",
+ imType: AppIMSetting_IMType.FEISHU,
appId: "",
appSecret: "",
externalApproval: {
enabled: true,
+ approvalDefinitionId: "",
},
};
};
@@ -160,9 +162,11 @@ const updateFeishuIntegration = async () => {
state.isLoading = true;
try {
- await settingStore.updateSettingByName({
+ await settingV1Store.upsertSetting({
name: "bb.app.im",
- value: JSON.stringify(state.feishuSetting),
+ value: {
+ appImSettingValue: state.feishuSetting,
+ },
});
} catch (error) {
state.isLoading = false;
diff --git a/frontend/src/views/sql-editor/EditorHeader.vue b/frontend/src/views/sql-editor/EditorHeader.vue
index 17b42b7143..253c8123d3 100644
--- a/frontend/src/views/sql-editor/EditorHeader.vue
+++ b/frontend/src/views/sql-editor/EditorHeader.vue
@@ -96,8 +96,9 @@ import BytebaseLogo from "@/components/BytebaseLogo.vue";
import ProfileBrandingLogo from "@/components/ProfileBrandingLogo.vue";
import ProfileDropdown from "@/components/ProfileDropdown.vue";
import { UNKNOWN_ID } from "@/types";
-import { useCurrentUser, useInboxStore, useSettingStore } from "@/store";
+import { useCurrentUser, useInboxStore } from "@/store";
import { hasWorkspacePermission } from "@/utils";
+import { useSettingV1Store } from "@/store/modules/v1/setting";
interface LocalState {
showMobileMenu: boolean;
@@ -109,7 +110,7 @@ export default defineComponent({
setup() {
const { t, availableLocales, locale } = useI18n();
const inboxStore = useInboxStore();
- const settingStore = useSettingStore();
+ const settingV1Store = useSettingV1Store();
const router = useRouter();
const state = reactive<LocalState>({
@@ -119,9 +120,7 @@ export default defineComponent({
const currentUser = useCurrentUser();
const logoUrl = computed((): string | undefined => {
- const brandingLogoSetting =
- settingStore.getSettingByName("bb.branding.logo");
- return brandingLogoSetting?.value;
+ return settingV1Store.brandingLogo;
});
const showAuditLogItem = computed((): boolean => {
diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.md
index 289e7fdc4f..76eee469d8 100644
--- a/proto/gen/grpc-doc/v1/README.md
+++ b/proto/gen/grpc-doc/v1/README.md
@@ -4545,6 +4545,7 @@ TYPE_PROJECT_REPOSITORY_PUSH represents Bytebase receiving a push event from the
| flow | [ApprovalFlow](#bytebase-v1-ApprovalFlow) | | |
| title | [string](#string) | | |
| description | [string](#string) | | |
+| creator | [string](#string) | | The name of the creator. Format: users/{user}. {user} is a system-generated unique ID. |
diff --git a/proto/generated-go/v1/review_service.pb.go b/proto/generated-go/v1/review_service.pb.go
index 581a0bea6e..e2ab315688 100644
--- a/proto/generated-go/v1/review_service.pb.go
+++ b/proto/generated-go/v1/review_service.pb.go
@@ -863,6 +863,9 @@ type ApprovalTemplate struct {
Flow *ApprovalFlow `protobuf:"bytes,1,opt,name=flow,proto3" json:"flow,omitempty"`
Title string `protobuf:"bytes,2,opt,name=title,proto3" json:"title,omitempty"`
Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"`
+ // The name of the creator.
+ // Format: users/{user}. {user} is a system-generated unique ID.
+ Creator string `protobuf:"bytes,4,opt,name=creator,proto3" json:"creator,omitempty"`
}
func (x *ApprovalTemplate) Reset() {
@@ -918,6 +921,13 @@ func (x *ApprovalTemplate) GetDescription() string {
return ""
}
+func (x *ApprovalTemplate) GetCreator() string {
+ if x != nil {
+ return x.Creator
+ }
+ return ""
+}
+
type ApprovalFlow struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@@ -1275,14 +1285,16 @@ var file_v1_review_service_proto_rawDesc = []byte{
0x16, 0x0a, 0x12, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43,
0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x50, 0x45, 0x4e, 0x44, 0x49,
0x4e, 0x47, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x41, 0x50, 0x50, 0x52, 0x4f, 0x56, 0x45, 0x44,
- 0x10, 0x02, 0x22, 0x79, 0x0a, 0x10, 0x41, 0x70, 0x70, 0x72, 0x6f, 0x76, 0x61, 0x6c, 0x54, 0x65,
- 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x12, 0x2d, 0x0a, 0x04, 0x66, 0x6c, 0x6f, 0x77, 0x18, 0x01,
- 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e,
- 0x76, 0x31, 0x2e, 0x41, 0x70, 0x70, 0x72, 0x6f, 0x76, 0x61, 0x6c, 0x46, 0x6c, 0x6f, 0x77, 0x52,
- 0x04, 0x66, 0x6c, 0x6f, 0x77, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x18, 0x02,
- 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x64,
- 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09,
- 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x3f, 0x0a,
+ 0x10, 0x02, 0x22, 0x98, 0x01, 0x0a, 0x10, 0x41, 0x70, 0x70, 0x72, 0x6f, 0x76, 0x61, 0x6c, 0x54,
+ 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x12, 0x2d, 0x0a, 0x04, 0x66, 0x6c, 0x6f, 0x77, 0x18,
+ 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65,
+ 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x70, 0x70, 0x72, 0x6f, 0x76, 0x61, 0x6c, 0x46, 0x6c, 0x6f, 0x77,
+ 0x52, 0x04, 0x66, 0x6c, 0x6f, 0x77, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x18,
+ 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x12, 0x20, 0x0a, 0x0b,
+ 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28,
+ 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1d,
+ 0x0a, 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x6f, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x42,
+ 0x03, 0xe0, 0x41, 0x03, 0x52, 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x6f, 0x72, 0x22, 0x3f, 0x0a,
0x0c, 0x41, 0x70, 0x70, 0x72, 0x6f, 0x76, 0x61, 0x6c, 0x46, 0x6c, 0x6f, 0x77, 0x12, 0x2f, 0x0a,
0x05, 0x73, 0x74, 0x65, 0x70, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x62,
0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x70, 0x70, 0x72, 0x6f,
diff --git a/proto/v1/review_service.proto b/proto/v1/review_service.proto
index 48af2abac2..2296c88298 100644
--- a/proto/v1/review_service.proto
+++ b/proto/v1/review_service.proto
@@ -177,6 +177,9 @@ message ApprovalTemplate {
ApprovalFlow flow = 1;
string title = 2;
string description = 3;
+ // The name of the creator.
+ // Format: users/{user}. {user} is a system-generated unique ID.
+ string creator = 4 [(google.api.field_behavior) = OUTPUT_ONLY];
}
message ApprovalFlow {