Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: enable branding (#948)
ecmadao71ef5dff8e77
diff --git a/api/plan.go b/api/plan.goindex 7318c487af..158998653b 100644--- a/api/plan.go+++ b/api/plan.go@@ -94,6 +94,11 @@ const (//// Currently, we only support GitLab EE/CE auth.Feature3rdPartyAuth FeatureType = "bb.feature.3rd-party-auth"++ // Branding+ //+ // Currently, we only support customizing the logo.+ FeatureBranding FeatureType = "bb.feature.branding")func (e FeatureType) String() string {@@ -118,6 +123,8 @@ func (e FeatureType) String() string {return "bb.feature.rbac"case Feature3rdPartyAuth:return "bb.feature.3rd-party-auth"+ case FeatureBranding:+ return "bb.feature.branding"}return ""}@@ -145,6 +152,8 @@ func (e FeatureType) Name() string {return "RBAC"case Feature3rdPartyAuth:return "3rd party auth"+ case FeatureBranding:+ return "Branding"}return ""}@@ -178,6 +187,7 @@ var FeatureMatrix = map[FeatureType][3]bool{"bb.feature.backup-policy": {false, true, true},"bb.feature.rbac": {false, true, true},"bb.feature.3rd-party-auth": {false, true, true},+ "bb.feature.branding": {false, true, true},}// Plan is the API message for a plan.diff --git a/api/setting.go b/api/setting.goindex dc2e9523e3..cbfdcfd782 100644--- a/api/setting.go+++ b/api/setting.go@@ -11,6 +11,8 @@ type SettingName stringconst (// SettingAuthSecret is the setting name for auth secret.SettingAuthSecret SettingName = "bb.auth.secret"+ // SettingBrandingLogo is the setting name for branding logo.+ SettingBrandingLogo SettingName = "bb.branding.logo")// SettingRaw is the store model for an Setting.diff --git a/bin/server/cmd/root.go b/bin/server/cmd/root.goindex f511149540..c7f0676977 100644--- a/bin/server/cmd/root.go+++ b/bin/server/cmd/root.go@@ -324,6 +324,21 @@ func initSetting(ctx context.Context, settingService api.SettingService) (*confireturn result, nil}+func initBranding(ctx context.Context, settingService api.SettingService) error {+ configCreate := &api.SettingCreate{+ CreatorID: api.SystemBotID,+ Name: api.SettingBrandingLogo,+ Value: "",+ Description: "The branding logo image in base64 string format.",+ }+ _, err := settingService.CreateSettingIfNotExist(ctx, configCreate)+ if err != nil {+ return err+ }++ return nil+}+// Run will run the main server.func (m *Main) Run(ctx context.Context) error {ctx, cancel := context.WithCancel(ctx)@@ -352,6 +367,11 @@ func (m *Main) Run(ctx context.Context) error {return fmt.Errorf("failed to init config: %w", err)}+ err = initBranding(ctx, settingService)+ if err != nil {+ return fmt.Errorf("failed to init branding: %w", err)+ }+m.db = dbs := server.NewServer(m.l, m.lvl, version, host, m.profile.port, frontendHost, frontendPort, m.profile.datastorePort, m.profile.mode, m.profile.dataDir, m.profile.backupRunnerInterval, config.secret, readonly, demo, debug)diff --git a/frontend/src/components/PricingTable.vue b/frontend/src/components/PricingTable.vueindex ee04222780..183a82c226 100644--- a/frontend/src/components/PricingTable.vue+++ b/frontend/src/components/PricingTable.vue@@ -397,7 +397,7 @@ export default {const onButtonClick = (plan: Plan) => {if (plan.type === PlanType.TEAM) {- window.open("https://hub.bytebase.com/pricing", "__blank");+ window.open("https://hub.bytebase.com/pricing?plan=team&source=console.subscription", "__blank");} else if (plan.type === PlanType.ENTERPRISE) {window.open("mailto:[email protected]?subject=Request for enterprise plan"diff --git a/frontend/src/locales/en.yml b/frontend/src/locales/en.ymlindex dbef3f29f2..a50e7c0fbf 100644--- a/frontend/src/locales/en.yml+++ b/frontend/src/locales/en.yml@@ -323,6 +323,7 @@ settings:select-logo: Upload a filedrag-logo: or drag herelogo-upload-tip: "{extension} up to {size} MiB"+ logo-upload-succeed: Successfully updated the logoactivity:name: Namecomment: Comment@@ -1343,6 +1344,10 @@ subscription:rbac: RBAC (Owner, DBA, Developer role)3rd-party-auth: Login with GitLab accountsync-members-from-vcs: Sync project membership from the linked GitLab project+ branding:+ title: Branding+ features:+ branding-logo: Customize the logoplan:title: Plantry: Try Teamdiff --git a/frontend/src/locales/zh-CN.yml b/frontend/src/locales/zh-CN.ymlindex 6a6e55ac5a..6d0309aa2e 100644--- a/frontend/src/locales/zh-CN.yml+++ b/frontend/src/locales/zh-CN.yml@@ -312,6 +312,7 @@ settings:select-logo: 选择drag-logo: 或拖拽文件logo-upload-tip: 支持 {extension} 类型文件,不能大于 {size} MiB+ logo-upload-succeed: Logo 更新完成activity:name: 名称comment: 评论@@ -1182,6 +1183,10 @@ subscription:rbac: RBAC 权限管理3rd-party-auth: 通过 GitLab 登录sync-members-from-vcs: 从 GitLab 同步成员信息+ branding:+ title: 自定义品牌信息+ features:+ branding-logo: 自定义 Logoplan:title: 版本try: 试用团队版diff --git a/frontend/src/types/plan.ts b/frontend/src/types/plan.tsindex e852b611b5..3c103ed716 100644--- a/frontend/src/types/plan.ts+++ b/frontend/src/types/plan.ts@@ -98,6 +98,12 @@ export const FEATURE_SECTIONS = ["sync-members-from-vcs",],},+ {+ id: "branding",+ features: [+ "branding-logo",+ ],+ },];export const FREE_PLAN: Plan = {@@ -190,6 +196,7 @@ export const TEAM_PLAN: Plan = {{ id: "rbac" },{ id: "3rd-party-auth" },{ id: "sync-members-from-vcs" },+ { id: "branding-logo" },],};@@ -240,5 +247,6 @@ export const ENTERPRISE_PLAN: Plan = {{ id: "rbac" },{ id: "3rd-party-auth" },{ id: "sync-members-from-vcs" },+ { id: "branding-logo" },],};diff --git a/frontend/src/types/setting.ts b/frontend/src/types/setting.tsindex c04b179855..56cd44e564 100644--- a/frontend/src/types/setting.ts+++ b/frontend/src/types/setting.ts@@ -17,3 +17,5 @@ export type Setting = {value: string;description: string;};++export const brandingLogoSettingName: SettingName = "bb.branding.logo";\ No newline at end of filediff --git a/frontend/src/views/DashboardHeader.vue b/frontend/src/views/DashboardHeader.vueindex fc08358c7c..a40edb17d7 100644--- a/frontend/src/views/DashboardHeader.vue+++ b/frontend/src/views/DashboardHeader.vue@@ -116,7 +116,17 @@<heroicons-outline:translate class="w-6 h-6" /></div><div class="ml-2">- <ProfileDropdown />+ <div+ class="flex justify-center items-center bg-gray-100 rounded-3xl"+ :class="logoUrl ? 'p-2' : ''"+ >+ <img+ v-if="logoUrl"+ class="h-7 mr-4 ml-2 bg-no-repeat bg-contain bg-center"+ :src="logoUrl"+ />+ <ProfileDropdown />+ </div></div><div class="ml-2 -mr-2 flex sm:hidden"><!-- Mobile menu button -->@@ -186,6 +196,7 @@ import { useI18n } from "vue-i18n";import ProfileDropdown from "../components/ProfileDropdown.vue";import { InboxSummary, UNKNOWN_ID } from "../types";+import { Setting, brandingLogoSettingName } from "../types/setting";import { isDBAOrOwner, isDev } from "../utils";import { useLanguage } from "../composables/useLanguage";@@ -220,6 +231,17 @@ export default defineComponent({return isDev();});+ const prepareBranding = () => {+ store.dispatch("setting/fetchSetting");+ };++ const logoUrl = computed((): string | undefined => {+ const brandingLogoSetting: Setting = store.getters["setting/settingByName"](brandingLogoSettingName);+ return brandingLogoSetting?.value;+ })++ watchEffect(prepareBranding);+const prepareInboxSummary = () => {// It will also be called when user logoutif (currentUser.value.id != UNKNOWN_ID) {@@ -353,6 +375,7 @@ export default defineComponent({return {state,+ logoUrl,currentUser,currentPlan,showDBAItem,diff --git a/frontend/src/views/SettingSidebar.vue b/frontend/src/views/SettingSidebar.vueindex 5e8d818811..9f3d90b376 100644--- a/frontend/src/views/SettingSidebar.vue+++ b/frontend/src/views/SettingSidebar.vue@@ -36,7 +36,6 @@</div><div class="space-y-1"><router-link- v-if="isDev()"to="/setting/general"class="outline-item group w-full flex items-center pl-11 pr-2 py-2">diff --git a/frontend/src/views/SettingWorkspaceGeneral.vue b/frontend/src/views/SettingWorkspaceGeneral.vueindex 8915f4717e..32d937b17d 100644--- a/frontend/src/views/SettingWorkspaceGeneral.vue+++ b/frontend/src/views/SettingWorkspaceGeneral.vue@@ -91,6 +91,8 @@import { computed, reactive } from "vue";import { useStore } from "vuex";import { isOwner } from "../utils";+import { Setting, brandingLogoSettingName } from "../types/setting";+import { useI18n } from "vue-i18n";interface LocalState {displayName?: string;@@ -101,26 +103,24 @@ interface LocalState {}const maxFileSizeInMiB = 2;+const supportImageExtensions = [+ ".jpg",+ ".jpeg",+ ".png",+ ".webp",+ ".svg",+];-// getImageUrlFromBase64String will convert the image base64 string to the HTML image url.-const getImageUrlFromBase64String = (- base64String: string | undefined-): string => {- if (!base64String) return "";-- const decodedData = window.atob(base64String);- const uInt8Array = new Uint8Array(decodedData.length);-- // Insert all character code into uInt8Array- for (let i = 0; i < decodedData.length; ++i) {- uInt8Array[i] = decodedData.charCodeAt(i);- }-- const blob = new Blob([uInt8Array]);- return URL.createObjectURL(blob);-};+// convertFileToBase64 will convert a file into base64 string.+const convertFileToBase64 = (file: File) => new Promise((resolve, reject) => {+ const reader = new FileReader();+ reader.readAsDataURL(file);+ reader.onload = () => resolve(reader.result);+ reader.onerror = error => reject(error);+});const store = useStore();+const { t } = useI18n();const state = reactive<LocalState>({displayName: "",@@ -130,6 +130,12 @@ const state = reactive<LocalState>({showFeatureModal: false,});+store.dispatch("setting/fetchSetting")+ .then(() => {+ const brandingLogoSetting: Setting = store.getters["setting/settingByName"](brandingLogoSettingName);+ state.logoUrl = brandingLogoSetting.value;+ });+const currentUser = computed(() => store.getters["auth/currentUser"]());const allowEdit = computed((): boolean => {@@ -140,36 +146,51 @@ const valid = computed((): boolean => {return !!state.displayName || !!state.logoFile});-const changed = computed((): boolean => {- return false;-});-const allowSave = computed((): boolean => {- return allowEdit.value && changed.value && valid.value;+ return allowEdit.value && state.logoFile !== null && valid.value && !state.loading;});const hasBrandingFeature = computed((): boolean => {return store.getters["subscription/feature"]("bb.feature.branding");});-const uploadLogo = () => {+const uploadLogo = async () => {+ if (!allowSave.value) {+ return;+ }if (!hasBrandingFeature.value) {state.showFeatureModal = true;return;}- // TODO: upload logo+ if (!state.logoFile) {+ return;+ }++ state.loading = true;++ try {+ const fileInBase64 = await convertFileToBase64(state.logoFile);+ const setting: Setting = await store.dispatch("setting/updateSettingByName", {+ name: brandingLogoSettingName,+ value: fileInBase64,+ });++ state.logoFile = null;+ state.logoUrl = setting.value;++ store.dispatch("notification/pushNotification", {+ module: "bytebase",+ style: "SUCCESS",+ title: t("settings.general.workspace.logo-upload-succeed"),+ });++ } finally {+ state.loading = false;+ }};const onLogoSelect = (file: File) => {state.logoFile = file;state.logoUrl = URL.createObjectURL(file);};--const supportImageExtensions = [- ".jpg",- ".jpeg",- ".png",- ".webp",- ".svg",-];</script>diff --git a/frontend/src/views/SettingWorkspaceSubscription.vue b/frontend/src/views/SettingWorkspaceSubscription.vueindex 80338dc67f..cef133bb93 100644--- a/frontend/src/views/SettingWorkspaceSubscription.vue+++ b/frontend/src/views/SettingWorkspaceSubscription.vue@@ -4,7 +4,7 @@{{ $t("subscription.description") }}<aclass="text-accent"- href="https://hub.bytebase.com/pricing"+ href="https://hub.bytebase.com/pricing?plan=team&source=console.subscription"target="__blank">{{ $t("subscription.description-highlight") }}diff --git a/server/setting.go b/server/setting.goindex 336ac7cb81..22d8293bfc 100644--- a/server/setting.go+++ b/server/setting.go@@ -13,7 +13,9 @@ import (var (// Some settings contain secret info so we only return settings that are needed by the client.- whitelistSettings = []api.SettingName{}+ whitelistSettings = []api.SettingName{+ api.SettingBrandingLogo,+ })func (s *Server) registerSettingRoutes(g *echo.Group) {@@ -56,6 +58,11 @@ func (s *Server) registerSettingRoutes(g *echo.Group) {Name: api.SettingName(c.Param("name")),UpdaterID: c.Get(getPrincipalIDContextKey()).(int),}++ if settingPatch.Name == api.SettingBrandingLogo && !s.feature(api.FeatureBranding) {+ return echo.NewHTTPError(http.StatusForbidden, api.FeatureBranding.AccessErrorMessage())+ }+if err := jsonapi.UnmarshalPayload(c.Request().Body, settingPatch); err != nil {return echo.NewHTTPError(http.StatusBadRequest, "Malformatted update setting request").SetInternal(err)}@@ -69,7 +76,7 @@ func (s *Server) registerSettingRoutes(g *echo.Group) {}c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)- if err := jsonapi.MarshalPayload(c.Response().Writer, setting); err != nil {+ if err := jsonapi.MarshalPayload(c.Response().Writer, setting.ToSetting()); err != nil {return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal setting response").SetInternal(err)}return nil