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: feature guard for frontend (#513)
ecmadao71af62c49810
diff --git a/api/plan.go b/api/plan.goindex d387dd7cc6..ec6ae2dcb4 100644--- a/api/plan.go+++ b/api/plan.go@@ -1,5 +1,7 @@package api+import "fmt"+// PlanType is the type for a plan.type PlanType int@@ -120,6 +122,50 @@ func (e FeatureType) String() string {return ""}+// Name returns a readable name of the feature+func (e FeatureType) Name() string {+ switch e {+ case FeatureBackwardCompatibilty:+ return "Backward compatibility"+ case FeatureSchemaDrift:+ return "Schema drift"+ case FeatureTaskScheduleTime:+ return "Task schedule time"+ case FeatureMultiTenancy:+ return "Multi-tenancy"+ case FeatureDBAWorkflow:+ return "DBA workflow"+ case FeatureDataSource:+ return "Data source"+ case FeatureApprovalPolicy:+ return "Approval policy"+ case FeatureBackupPolicy:+ return "Backup policy"+ case FeatureRBAC:+ return "RBAC"+ case Feature3rdPartyLogin:+ return "3rd party login"+ }+ return ""+}++// AccessErrorMessage returns a error message with feature name and minimum supported plan.+func (e FeatureType) AccessErrorMessage() string {+ plan := e.minimumSupportedPlan()+ return fmt.Sprintf("%s is a %s feature, please upgrade to access it.", e.Name(), plan.String())+}++// minimumSupportedPlan will find the minimum plan which support the target feature.+func (e FeatureType) minimumSupportedPlan() PlanType {+ for i, enabled := range FeatureMatrix[e] {+ if enabled {+ return PlanType(i)+ }+ }++ return ENTERPRISE+}+// FeatureMatrix is a map from the a particular feature to the respective enablement of a particular planvar FeatureMatrix = map[FeatureType][3]bool{"bb.feature.backward-compatibility": {false, true, true},diff --git a/frontend/src/components/FeatureModal.vue b/frontend/src/components/FeatureModal.vuenew file mode 100644index 0000000000..7e374f0b0d--- /dev/null+++ b/frontend/src/components/FeatureModal.vue@@ -0,0 +1,87 @@+<template>+ <BBModal+ :title="$t('subscription.disabled-feature')"+ @close="$emit('cancel')"+ >+ <div>+ <div class="flex items-start">+ <div+ class="mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-yellow-100 sm:mx-0 sm:h-10 sm:w-10"+ >+ <!-- Heroicons name: outline/exclamation -->+ <heroicons-outline:exclamation class="h-6 w-6 text-yellow-600" />+ </div>+ <h3+ id="modal-headline"+ class="ml-4 flex self-center text-lg leading-6 font-medium text-gray-900"+ >+ {{ featureTitle }}+ </h3>+ </div>+ <div class="mt-5">+ <p class="whitespace-pre-wrap">+ {{ featureDesc }}+ </p>+ </div>+ <div class="mt-3">+ <p class="whitespace-pre-wrap">{{ $t("subscription.trial") }}*</p>+ <p class="text-gray-500 whitespace-pre-wrap text-sm">+ {{ $t("subscription.trial-comment") }}+ </p>+ </div>+ <div class="mt-7 flex justify-end">+ <button+ type="button"+ class="btn-normal mt-3 px-4 py-2 sm:mt-0 sm:w-auto"+ @click.prevent="$emit('cancel')"+ >+ {{ $t("common.dismiss") }}+ </button>+ <button+ type="button"+ class="sm:ml-3 inline-flex justify-center w-full rounded-md border border-transparent shadow-sm px-4 py-2 bg-error text-base font-medium text-white hover:bg-error-hover focus:outline-none focus-visible:ring-2 focus:ring-offset-2 focus:ring-red-500 sm:w-auto sm:text-sm btn-primary"+ @click.prevent="ok"+ >+ {{ $t("common.learn-more") }}+ </button>+ </div>+ </div>+ </BBModal>+</template>++<script lang="ts">+import { PropType } from "vue";+import { FeatureType } from "../types";+import { useI18n } from "vue-i18n";+import { useRouter } from "vue-router";++export default {+ props: {+ feature: {+ required: true,+ type: String as PropType<FeatureType>,+ },+ },+ emits: ["cancel"],+ setup(props, { emit }) {+ const { t } = useI18n();+ const router = useRouter();++ const cancel = () => {+ emit("cancel");+ };++ const ok = () => {+ router.push({ name: "setting.workspace.subscription" });+ };++ const featureKey = props.feature.split(".").join("-");++ return {+ ok,+ featureDesc: t(`subscription.features.${featureKey}.desc`),+ featureTitle: t(`subscription.features.${featureKey}.title`),+ };+ },+};+</script>diff --git a/frontend/src/components/Issue/IssueSidebar.vue b/frontend/src/components/Issue/IssueSidebar.vueindex 7498ec1877..669694e8d0 100644--- a/frontend/src/components/Issue/IssueSidebar.vue+++ b/frontend/src/components/Issue/IssueSidebar.vue@@ -94,8 +94,8 @@/></div></template>-- <div>++ <div><h2 class="textlabel flex items-center"><span class="mr-1">{{ $t("common.when") }}</span><div class="tooltip-wrapper">@@ -122,15 +122,7 @@class="w-full"type="datetime"clearable- @update:value="- (newTimestampMiliSec) => {- // n-date-picker would pass timestamp in milisecond.- // We divide it by 1000 to get timestamp in second- const newTs = newTimestampMiliSec / 1000;- state.earliestAllowedTs = newTs;- $emit('update-earliest-allowed-time', newTs);- }- "+ @update:value="updateEarliestAllowedTs"/><span v-else class="textfield col-span-2">{{@@ -256,6 +248,11 @@(subscriberId) => $emit('remove-subscriber-id', subscriberId)"/>+ <FeatureModal+ v-if="state.showFeatureModal"+ :feature="'bb.feature.task-schedule-time'"+ @cancel="state.showFeatureModal = false"+ /></aside></template>@@ -272,6 +269,7 @@ import IssueStatusIcon from "./IssueStatusIcon.vue";import IssueSubscriberPanel from "./IssueSubscriberPanel.vue";import InstanceEngineIcon from "../InstanceEngineIcon.vue";import { DatabaseLabels } from "../DatabaseLabels";+import FeatureModal from "../FeatureModal.vue";import { InputField } from "../../plugins";import {@@ -298,6 +296,7 @@ dayjs.extend(isSameOrAfter);// eslint-disable-next-line @typescript-eslint/no-empty-interfaceinterface LocalState {earliestAllowedTs: number | null;+ showFeatureModal: boolean;}export default defineComponent({@@ -312,6 +311,7 @@ export default defineComponent({IssueStatusIcon,IssueSubscriberPanel,InstanceEngineIcon,+ FeatureModal,},props: {issue: {@@ -363,6 +363,7 @@ export default defineComponent({const now = new Date();const state = reactive<LocalState>({earliestAllowedTs: props.task.earliestAllowedTs,+ showFeatureModal: false,});watch(@@ -526,6 +527,21 @@ export default defineComponent({const isDayPassed = (ts: number) => !dayjs(ts).isSameOrAfter(now, "day");+ const updateEarliestAllowedTs = (newTimestampMiliSec: number) => {+ if (+ !store.getters["subscription/feature"]("bb.feature.task-schedule-time")+ ) {+ state.showFeatureModal = true;+ return;+ }++ // n-date-picker would pass timestamp in milisecond.+ // We divide it by 1000 to get timestamp in second+ const newTs = newTimestampMiliSec / 1000;+ state.earliestAllowedTs = newTs;+ emit("update-earliest-allowed-time", newTs);+ };+return {EMPTY_ID,state,@@ -545,6 +561,7 @@ export default defineComponent({showDatabaseCreationLabel,clickDatabase,isDayPassed,+ updateEarliestAllowedTs,};},});diff --git a/frontend/src/locales/en.yml b/frontend/src/locales/en.ymlindex 83ecd8c9d6..e3d14d0726 100644--- a/frontend/src/locales/en.yml+++ b/frontend/src/locales/en.yml@@ -1135,3 +1135,10 @@ subscription:sensitive-placeholder: Paste your license here - write onlyupload-license: Upload licenseplan-compare: Compare features between different plans+ disabled-feature: This is a premium feature in subscription plan+ trial: You can start a trial with $7 for 7 days.+ trial-comment: Only enabled for the first payment. You can cancel the subscription at any time.+ features:+ bb.feature.task-schedule-time:+ name: Set task schedule time+ desc: Set task schedule time allows you to set a specific time to run your tasks.diff --git a/frontend/src/locales/zh-CN.yml b/frontend/src/locales/zh-CN.ymlindex 59216467f3..82d658b551 100644--- a/frontend/src/locales/zh-CN.yml+++ b/frontend/src/locales/zh-CN.yml@@ -1004,3 +1004,10 @@ subscription:sensitive-placeholder: 粘贴您的证书 - 仅写入upload-license: 上传证书plan-compare: 比较不同版本的功能,寻找适合您的方案+ disabled-feature: 这是一个订阅版高级功能+ trial: 您可以以 $7 的价格试用 7 天+ trial-comment: 仅首次付费可以试用,可随时退款。+ features:+ bb-feature-task-schedule-time:+ title: 设定任务执行时间+ desc: 「设定任务执行时间」可以将任务设定在特定时间执行diff --git a/server/issue.go b/server/issue.goindex b9e8b91e1d..803464d045 100644--- a/server/issue.go+++ b/server/issue.go@@ -359,6 +359,9 @@ func (s *Server) createIssue(ctx context.Context, issueCreate *api.IssueCreate,}for _, taskCreate := range stageCreate.TaskList {+ if taskCreate.EarliestAllowedTs != 0 && !s.feature(api.FeatureTaskScheduleTime) {+ return nil, fmt.Errorf(api.FeatureTaskScheduleTime.AccessErrorMessage())+ }taskCreate.CreatorID = creatorIDtaskCreate.PipelineID = createdPipeline.IDtaskCreate.StageID = createdStage.ID@@ -763,6 +766,13 @@ func (s *Server) createPipelineFromIssue(ctx context.Context, issueCreate *api.Iif err := json.Unmarshal([]byte(issueCreate.CreateContext), &m); err != nil {return nil, err}+ if !s.feature(api.FeatureTaskScheduleTime) {+ for _, detail := range m.UpdateSchemaDetailList {+ if detail.EarliestAllowedTs != 0 {+ return nil, echo.NewHTTPError(http.StatusForbidden, api.FeatureTaskScheduleTime.AccessErrorMessage())+ }+ }+ }pc := &api.PipelineCreate{}switch m.MigrationType {case db.Baseline:diff --git a/server/task.go b/server/task.goindex b4f481befb..332a7f97bd 100644--- a/server/task.go+++ b/server/task.go@@ -42,6 +42,10 @@ func (s *Server) registerTaskRoutes(g *echo.Group) {return echo.NewHTTPError(http.StatusBadRequest, "Malformatted update task request").SetInternal(err)}+ if taskPatch.EarliestAllowedTs != nil && !s.feature(api.FeatureTaskScheduleTime) {+ return echo.NewHTTPError(http.StatusForbidden, api.FeatureTaskScheduleTime.AccessErrorMessage())+ }+taskFind := &api.TaskFind{ID: &taskID,}