Skip to content

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

chore: set trial plan to minimum required plan (#3326)

ecmadao43d17c7dc05d
diff --git a/frontend/src/bbkit/BBAttention.vue b/frontend/src/bbkit/BBAttention.vue
index 95032a0041..c02f24147d 100644
--- a/frontend/src/bbkit/BBAttention.vue
+++ b/frontend/src/bbkit/BBAttention.vue
@@ -31,9 +31,7 @@
class="mt-2 text-sm"
:class="`text-${color}-700`"
>
- <p>
- {{ $t(description) }}
- </p>
+ <p class="whitespace-pre-wrap">{{ $t(description) }}</p>
</div>
</div>
</div>
diff --git a/frontend/src/components/FeatureAttention.vue b/frontend/src/components/FeatureAttention.vue
index 62413baeda..d37e19c85f 100644
--- a/frontend/src/components/FeatureAttention.vue
+++ b/frontend/src/components/FeatureAttention.vue
@@ -3,21 +3,15 @@
:class="customClass"
:style="`WARN`"
:title="$t(`subscription.features.${featureKey}.title`)"
- :description="description"
- :action-text="
- subscriptionStore.canTrial
- ? $t('subscription.start-n-days-trial', {
- days: subscriptionStore.trialingDays,
- })
- : $t('subscription.upgrade')
- "
+ :description="descriptionText"
+ :action-text="actionText"
@click-action="onClick"
/>
</template>
<script lang="ts" setup>
-import { PropType } from "vue";
-import { FeatureType } from "../types";
+import { PropType, computed } from "vue";
+import { FeatureType, planTypeToString } from "@/types";
import { useRouter } from "vue-router";
import { useI18n } from "vue-i18n";
import { useSubscriptionStore, pushNotification } from "@/store";
@@ -42,17 +36,52 @@ const props = defineProps({
const router = useRouter();
const { t } = useI18n();
const subscriptionStore = useSubscriptionStore();
+const requiredPlan = subscriptionStore.getMinimumRequiredPlan(props.feature);
+
+const actionText = computed(() => {
+ if (!subscriptionStore.canTrial) {
+ return t("subscription.upgrade");
+ }
+ if (subscriptionStore.canUpgradeTrial) {
+ return t("subscription.upgrade-trial-button");
+ }
+ return t("subscription.start-n-days-trial", {
+ days: subscriptionStore.trialingDays,
+ });
+});
+
+const descriptionText = computed(() => {
+ const trialText = t("subscription.required-plan-with-trial", {
+ requiredPlan: t(
+ `subscription.plan.${planTypeToString(requiredPlan)}.title`
+ ),
+ startTrial: subscriptionStore.canUpgradeTrial
+ ? t("subscription.upgrade-trial").toLowerCase()
+ : t("subscription.trial-for-days", {
+ days: subscriptionStore.trialingDays,
+ }).toLowerCase(),
+ });
+
+ return `${props.description}\n${trialText}`;
+});
const onClick = () => {
if (subscriptionStore.canTrial) {
- subscriptionStore.trialSubscription().then(() => {
+ const isUpgrade = subscriptionStore.canUpgradeTrial;
+ subscriptionStore.trialSubscription(requiredPlan).then(() => {
pushNotification({
module: "bytebase",
style: "SUCCESS",
title: t("common.success"),
- description: t("subscription.successfully-start-trial", {
- days: subscriptionStore.trialingDays,
- }),
+ description: isUpgrade
+ ? t("subscription.successfully-upgrade-trial", {
+ plan: t(
+ `subscription.plan.${planTypeToString(requiredPlan)}.title`
+ ),
+ })
+ : t("subscription.successfully-start-trial", {
+ days: subscriptionStore.trialingDays,
+ }),
});
});
} else {
diff --git a/frontend/src/components/FeatureModal.vue b/frontend/src/components/FeatureModal.vue
index 7593f3f3ce..bc051e5674 100644
--- a/frontend/src/components/FeatureModal.vue
+++ b/frontend/src/components/FeatureModal.vue
@@ -22,7 +22,10 @@
</div>
<div class="mt-3">
<p class="whitespace-pre-wrap">
- <i18n-t keypath="subscription.required-plan-with-trial">
+ <i18n-t
+ v-if="subscriptionStore.canTrial"
+ keypath="subscription.required-plan-with-trial"
+ >
<template #requiredPlan>
<span class="font-bold text-accent">
{{
@@ -32,18 +35,28 @@
}}
</span>
</template>
- <template #startTrial>
+ <template v-if="subscriptionStore.canUpgradeTrial" #startTrial>
+ {{ $t("subscription.upgrade-trial").toLowerCase() }}
+ </template>
+ <template v-else #startTrial>
{{
- $t("subscription.trial-for-plan", {
- plan: $t(
- `subscription.plan.${planTypeToString(
- subscriptionStore.trialingPlan
- )}.title`
- ),
+ $t("subscription.trial-for-days", {
+ days: subscriptionStore.trialingDays,
}).toLowerCase()
}}
</template>
</i18n-t>
+ <i18n-t v-else keypath="subscription.require-subscription">
+ <template #requiredPlan>
+ <span class="font-bold text-accent">
+ {{
+ $t(
+ `subscription.plan.${planTypeToString(requiredPlan)}.title`
+ )
+ }}
+ </span>
+ </template>
+ </i18n-t>
</p>
</div>
<div class="mt-7 flex justify-end space-x-2">
@@ -55,18 +68,28 @@
{{ $t("common.dismiss") }}
</button>
- <button
- v-if="subscriptionStore.canTrial"
- type="button"
- class="btn-primary"
- @click.prevent="trialSubscription"
- >
- {{
- $t("subscription.start-n-days-trial", {
- days: subscriptionStore.trialingDays,
- })
- }}
- </button>
+ <template v-if="subscriptionStore.canTrial">
+ <button
+ v-if="subscriptionStore.canUpgradeTrial"
+ type="button"
+ class="btn-primary"
+ @click.prevent="trialSubscription"
+ >
+ {{ $t("subscription.upgrade-trial-button") }}
+ </button>
+ <button
+ v-else
+ type="button"
+ class="btn-primary"
+ @click.prevent="trialSubscription"
+ >
+ {{
+ $t("subscription.start-n-days-trial", {
+ days: subscriptionStore.trialingDays,
+ })
+ }}
+ </button>
+ </template>
<button v-else type="button" class="btn-primary" @click.prevent="ok">
{{ $t("common.learn-more") }}
</button>
@@ -104,14 +127,21 @@ const requiredPlan = subscriptionStore.getMinimumRequiredPlan(props.feature);
const featureKey = props.feature.split(".").join("-");
const trialSubscription = () => {
- subscriptionStore.trialSubscription().then(() => {
+ const isUpgrade = subscriptionStore.canUpgradeTrial;
+ subscriptionStore.trialSubscription(requiredPlan).then(() => {
pushNotification({
module: "bytebase",
style: "SUCCESS",
title: t("common.success"),
- description: t("subscription.successfully-start-trial", {
- days: subscriptionStore.trialingDays,
- }),
+ description: isUpgrade
+ ? t("subscription.successfully-upgrade-trial", {
+ plan: t(
+ `subscription.plan.${planTypeToString(requiredPlan)}.title`
+ ),
+ })
+ : t("subscription.successfully-start-trial", {
+ days: subscriptionStore.trialingDays,
+ }),
});
emit("cancel");
});
diff --git a/frontend/src/components/PricingTable/PricingTable.vue b/frontend/src/components/PricingTable/PricingTable.vue
index 425674851f..d479f403a6 100644
--- a/frontend/src/components/PricingTable/PricingTable.vue
+++ b/frontend/src/components/PricingTable/PricingTable.vue
@@ -64,7 +64,7 @@
{{ plan.buttonText }}
</button>
<div
- v-if="canTrial && plan.trialDays"
+ v-if="subscriptionStore.canTrial && plan.trialDays"
class="font-bold text-sm my-2 text-center"
>
{{ $t("subscription.free-trial") }}
@@ -91,7 +91,7 @@
Feature comparison
</caption>
<tbody class="border-t border-gray-200 divide-y divide-gray-200">
- <template v-for="section in sections" :key="section.type">
+ <template v-for="section in FEATURE_SECTIONS" :key="section.type">
<tr>
<th
class="bg-gray-50 py-3 pl-6 text-sm font-medium text-gray-900 text-left"
@@ -186,7 +186,7 @@
{{ plan.buttonText }}
</button>
<div
- v-if="canTrial && plan.trialDays"
+ v-if="subscriptionStore.canTrial && plan.trialDays"
class="font-bold text-sm my-2 text-center"
>
{{ $t("subscription.free-trial") }}
@@ -210,7 +210,7 @@
Feature comparison
</caption>
<tbody class="border-t border-gray-200 divide-y divide-gray-200">
- <template v-for="section in sections" :key="section.type">
+ <template v-for="section in FEATURE_SECTIONS" :key="section.type">
<tr>
<th
class="bg-gray-50 py-3 pl-6 text-sm font-medium text-gray-900 text-left"
@@ -256,8 +256,8 @@
</div>
</template>
-<script lang="ts">
-import { reactive, computed, watch, defineComponent } from "vue";
+<script lang="ts" setup>
+import { reactive, computed, watch } from "vue";
import { useI18n } from "vue-i18n";
import { Plan, PlanType, PLANS, FEATURE_SECTIONS } from "@/types";
import { useSubscriptionStore } from "@/store";
@@ -269,87 +269,72 @@ interface LocalState {
instanceCount: number;
}
-const minimumInstanceCount = 5;
-
-export default defineComponent({
- name: "PricingTable",
- components: { FeatureItem },
- setup() {
- const { t } = useI18n();
- const subscriptionStore = useSubscriptionStore();
- const state = reactive<LocalState>({
- isMonthly: false,
- instanceCount:
- subscriptionStore.subscription?.instanceCount ?? minimumInstanceCount,
- });
+const emit = defineEmits(["on-trial"]);
- watch(
- () => subscriptionStore.subscription,
- (val) =>
- (state.instanceCount = val?.instanceCount ?? minimumInstanceCount)
- );
+const minimumInstanceCount = 5;
- const plans = computed((): LocalPlan[] => {
- return PLANS.map((plan) => ({
- ...plan,
- image: new URL(
- `../../assets/plan-${plan.title.toLowerCase()}.png`,
- import.meta.url
- ).href,
- buttonText: getButtonText(plan),
- highlight: plan.type === PlanType.TEAM,
- isAvailable: plan.type === PlanType.TEAM,
- isFreePlan: plan.type === PlanType.FREE,
- label: t(`subscription.plan.${plan.title}.label`),
- pricePrefix:
- plan.type === PlanType.ENTERPRISE ? t("subscription.start-from") : "",
- priceUnit:
- plan.type === PlanType.ENTERPRISE
- ? t("subscription.price-unit-for-enterprise")
- : t("subscription.per-month"),
- }));
- });
+const { t } = useI18n();
+const subscriptionStore = useSubscriptionStore();
+const state = reactive<LocalState>({
+ isMonthly: false,
+ instanceCount:
+ subscriptionStore.subscription?.instanceCount ?? minimumInstanceCount,
+});
- const getButtonText = (plan: Plan): string => {
- if (plan.type === PlanType.FREE) return t("subscription.deploy");
- if (plan.type === PlanType.ENTERPRISE)
- return t("subscription.contact-us");
+watch(
+ () => subscriptionStore.subscription,
+ (val) => (state.instanceCount = val?.instanceCount ?? minimumInstanceCount)
+);
- if (subscriptionStore.isTrialing) return t("subscription.subscribe");
- if (plan.type === subscriptionStore.subscription?.plan)
- return t("subscription.upgrade");
- if (plan.trialDays) return t("subscription.start-trial");
+const plans = computed((): LocalPlan[] => {
+ return PLANS.map((plan) => ({
+ ...plan,
+ image: new URL(
+ `../../assets/plan-${plan.title.toLowerCase()}.png`,
+ import.meta.url
+ ).href,
+ buttonText: getButtonText(plan),
+ highlight: plan.type === PlanType.TEAM,
+ isAvailable: plan.type === PlanType.TEAM,
+ isFreePlan: plan.type === PlanType.FREE,
+ label: t(`subscription.plan.${plan.title}.label`),
+ pricePrefix:
+ plan.type === PlanType.ENTERPRISE ? t("subscription.start-from") : "",
+ priceUnit:
+ plan.type === PlanType.ENTERPRISE
+ ? t("subscription.price-unit-for-enterprise")
+ : t("subscription.per-month"),
+ }));
+});
- return t("subscription.subscribe");
- };
+const getButtonText = (plan: Plan): string => {
+ if (plan.type === PlanType.FREE) return t("subscription.deploy");
+ if (plan.type === PlanType.ENTERPRISE) return t("subscription.contact-us");
- const onButtonClick = (plan: Plan) => {
- if (plan.type === PlanType.TEAM) {
- window.open(
- "https://bytebase.com/pricing?source=console.subscription",
- "__blank"
- );
- } else if (plan.type === PlanType.ENTERPRISE) {
- window.open(
- "mailto:[email protected]?subject=Request for enterprise plan"
- );
- } else {
- window.open("https://bytebase.com/docs?source=console", "_self");
- }
- };
+ if (subscriptionStore.isTrialing) return t("subscription.subscribe");
+ if (plan.type === subscriptionStore.subscription?.plan)
+ return t("subscription.upgrade");
+ if (plan.trialDays) return t("subscription.start-trial");
- const canTrial = computed((): boolean => {
- return subscriptionStore.currentPlan === PlanType.FREE;
- });
+ return t("subscription.subscribe");
+};
- return {
- state,
- plans,
- canTrial,
- sections: FEATURE_SECTIONS,
- onButtonClick,
- minimumInstanceCount,
- };
- },
-});
+const onButtonClick = (plan: Plan) => {
+ if (plan.type === PlanType.TEAM) {
+ if (subscriptionStore.canTrial) {
+ emit("on-trial");
+ return;
+ }
+ window.open(
+ "https://bytebase.com/pricing?source=console.subscription",
+ "__blank"
+ );
+ } else if (plan.type === PlanType.ENTERPRISE) {
+ window.open(
+ "mailto:[email protected]?subject=Request for enterprise plan"
+ );
+ } else {
+ window.open("https://bytebase.com/docs?source=console", "_self");
+ }
+};
</script>
diff --git a/frontend/src/components/ProjectCreate.vue b/frontend/src/components/ProjectCreate.vue
index a95535992e..3214b8b557 100644
--- a/frontend/src/components/ProjectCreate.vue
+++ b/frontend/src/components/ProjectCreate.vue
@@ -57,6 +57,10 @@
value="TENANT"
/>
<label class="label">{{ $t("project.mode.tenant") }}</label>
+ <FeatureBadge
+ feature="bb.feature.multi-tenancy"
+ class="text-accent"
+ />
</div>
</div>
</div>
diff --git a/frontend/src/components/TrialModal.vue b/frontend/src/components/TrialModal.vue
index 880d1ca5a8..9f90b29d40 100644
--- a/frontend/src/components/TrialModal.vue
+++ b/frontend/src/components/TrialModal.vue
@@ -9,15 +9,18 @@
>
<div class="min-w-0 md:min-w-400">
<p class="whitespace-pre-wrap">
- {{
- $t("subscription.trial-for-plan", {
- plan: $t(
- `subscription.plan.${planTypeToString(
- subscriptionStore.trialingPlan
- )}.title`
- ),
- })
- }}*
+ <i18n-t keypath="subscription.trial-for-plan">
+ <template #days>
+ {{ subscriptionStore.trialingDays }}
+ </template>
+ <template #plan>
+ <span class="font-bold text-accent">
+ {{
+ $t(`subscription.plan.${planTypeToString(PlanType.TEAM)}.title`)
+ }}
+ </span>
+ </template>
+ </i18n-t>
</p>
<div class="mt-7 flex justify-end space-x-2">
<button
@@ -57,7 +60,7 @@
import { useRouter } from "vue-router";
import { useI18n } from "vue-i18n";
import { useSubscriptionStore, pushNotification } from "@/store";
-import { planTypeToString } from "@/types";
+import { PlanType, planTypeToString } from "@/types";
const emit = defineEmits(["cancel"]);
const { t } = useI18n();
@@ -69,7 +72,7 @@ const learnMore = () => {
};
const trialSubscription = () => {
- subscriptionStore.trialSubscription().then(() => {
+ subscriptionStore.trialSubscription(PlanType.TEAM).then(() => {
pushNotification({
module: "bytebase",
style: "SUCCESS",
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index a5f3888666..d00ad948ac 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1383,11 +1383,15 @@
"subscription": {
"description": "You can upload your Bytebase license to unlock team/enterprise features.",
"upload-license": "Upload license",
- "free-trial": "Free trial",
+ "upgrade-trial-button": "Upgrade trial",
"start-n-days-trial": "Start {days} days trial",
"successfully-start-trial": "Successfully start free trial for {days} days",
+ "successfully-upgrade-trial": "Successfully upgrade free trial to {plan}",
+ "require-subscription": "This feature requires {requiredPlan}, please purchase Bytebase license to unlock this feature.",
"required-plan-with-trial": "This feature requires {requiredPlan}, but {startTrial}.",
- "trial-for-plan": "You can start a free trial for {plan} - no credit card required",
+ "trial-for-plan": "You can start a free trial for {plan} with {days} days - no credit card required",
+ "trial-for-days": "You can start a free trial for {days} days - no credit card required",
+ "upgrade-trial": "You can upgrade your free trial to this plan",
"update": {
"success": {
"title": "Successfully updated license",
@@ -1432,7 +1436,7 @@
},
"bb-feature-sql-review": {
"title": "SQL review policy",
- "desc": "Customize the SQL review policy for different environments, can only use limited rules in the free plan. @:{'subscription.free-trial'}."
+ "desc": "Customize the SQL review policy for different environments, can only use limited rules in the free plan."
},
"bb-feature-vcs-sql-review": {
"title": "SQL Review in GitOps workflow",
@@ -1440,7 +1444,7 @@
},
"bb-feature-rbac": {
"title": "Role management",
- "desc": "Role management can assign a particular role (e.g. DBA) to a member. @:{'subscription.free-trial'}."
+ "desc": "Role management can assign a particular role (e.g. DBA) to a member."
},
"bb-feature-schema-drift": {
"title": "Schema drift",
@@ -1448,7 +1452,7 @@
},
"bb-feature-3rd-party-auth": {
"title": "3rd party authentication & authorization",
- "desc": "Bytebase supports 3rd-party authentication & authorization based on your VCS configuration. @:{'subscription.free-trial'}.",
+ "desc": "Bytebase supports 3rd-party authentication & authorization based on your VCS configuration.",
"login": "@:{'subscription.upgrade'} to unlock this feature"
},
"bb-feature-branding": {
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index f791683c8e..ba5df8a955 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1383,11 +1383,15 @@
"subscription": {
"description": "您可以在这里上传您购买的 Bytebase 证书来解锁团队版/企业版功能。",
"upload-license": "上传证书",
- "free-trial": "免费试用",
+ "upgrade-trial-button": "升级试用",
"start-n-days-trial": "开启 {days} 天试用",
"successfully-start-trial": "成功开启 {days} 天的免费试用",
+ "successfully-upgrade-trial": "成功升级为{plan}试用",
+ "require-subscription": "这个功能需要{requiredPlan}订阅,请购买的 Bytebase 证书来解锁该功能。",
"required-plan-with-trial": "这个功能需要{requiredPlan}订阅,但是{startTrial}。",
- "trial-for-plan": "您可以开启{plan}的免费试用 - 无需任何信用卡或预付费",
+ "trial-for-plan": "您可以开启{plan}的 {days} 天免费试用 - 无需任何信用卡或预付费",
+ "trial-for-days": "您可以开启 {days} 天的免费试用 - 无需任何信用卡或预付费",
+ "upgrade-trial": "您可以直接将现有的试用升级到这个版本",
"update": {
"success": {
"title": "证书更新成功",
@@ -1432,7 +1436,7 @@
},
"bb-feature-sql-review": {
"title": "Schema 审核策略",
- "desc": "给不同的环境定制 schema 审核策略,免费版仅可使用部分规则。@:{'subscription.free-trial'}。"
+ "desc": "给不同的环境定制 schema 审核策略,免费版仅可使用部分规则。"
},
"bb-feature-vcs-sql-review": {
"title": "GitOps 工作流中的 SQL 审核",
@@ -1440,7 +1444,7 @@
},
"bb-feature-rbac": {
"title": "角色管理",
- "desc": "「角色管理」可以赋予成员诸如 DBA 这样的特定角色。@:{'subscription.free-trial'}。"
+ "desc": "「角色管理」可以赋予成员诸如 DBA 这样的特定角色。"
},
"bb-feature-schema-drift": {
"title": "Schema 偏差",
@@ -1448,7 +1452,7 @@
},
"bb-feature-3rd-party-auth": {
"title": "第三方认证 & 授权",
- "desc": "Bytebase 可根据您配置的 VCS 来支持相应的第三方认证 & 授权。@:{'subscription.free-trial'}。",
+ "desc": "Bytebase 可根据您配置的 VCS 来支持相应的第三方认证 & 授权。",
"login": "请@:{'subscription.upgrade'}来开启该功能"
},
"bb-feature-branding": {
diff --git a/frontend/src/store/modules/subscription.ts b/frontend/src/store/modules/subscription.ts
index 99948445f5..1689a21655 100644
--- a/frontend/src/store/modules/subscription.ts
+++ b/frontend/src/store/modules/subscription.ts
@@ -14,7 +14,6 @@ export const useSubscriptionStore = defineStore("subscription", {
state: (): SubscriptionState => ({
subscription: undefined,
trialingDays: 14,
- trialingPlan: PlanType.ENTERPRISE,
trialingInstanceCount: 999,
}),
getters: {
@@ -65,9 +64,15 @@ export const useSubscriptionStore = defineStore("subscription", {
if (state.subscription.plan === PlanType.FREE) {
return true;
}
+ return this.canUpgradeTrial;
+ },
+ canUpgradeTrial(state): boolean {
+ if (!state.subscription) {
+ return false;
+ }
return (
state.subscription.trialing &&
- state.subscription.plan < state.trialingPlan
+ state.subscription.plan < PlanType.ENTERPRISE
);
},
},
@@ -75,6 +80,7 @@ export const useSubscriptionStore = defineStore("subscription", {
hasFeature(type: FeatureType) {
return !this.isExpired && FEATURE_MATRIX.get(type)![this.currentPlan];
},
+
getMinimumRequiredPlan(type: FeatureType): PlanType {
const matrix = FEATURE_MATRIX.get(type);
if (!Array.isArray(matrix)) {
@@ -116,13 +122,13 @@ export const useSubscriptionStore = defineStore("subscription", {
this.setSubscription(subscription);
return subscription;
},
- async trialSubscription() {
+ async trialSubscription(planType: PlanType) {
const data = (
await axios.post(`/api/subscription/trial`, {
data: {
type: "TrialPlanCreate",
attributes: {
- type: this.trialingPlan,
+ type: planType,
days: this.trialingDays,
instanceCount: this.trialingInstanceCount,
},
diff --git a/frontend/src/types/subscription.ts b/frontend/src/types/subscription.ts
index 7b580ac39f..b634e839dc 100644
--- a/frontend/src/types/subscription.ts
+++ b/frontend/src/types/subscription.ts
@@ -11,6 +11,5 @@ export interface Subscription {
export interface SubscriptionState {
subscription: Subscription | undefined;
trialingDays: number;
- trialingPlan: PlanType;
trialingInstanceCount: number;
}
diff --git a/frontend/src/views/SettingWorkspaceSubscription.vue b/frontend/src/views/SettingWorkspaceSubscription.vue
index 3ddc0b7bcd..824ca3e3bb 100644
--- a/frontend/src/views/SettingWorkspaceSubscription.vue
+++ b/frontend/src/views/SettingWorkspaceSubscription.vue
@@ -11,10 +11,7 @@
</a>
<span v-if="canTrial" class="ml-1">
{{ $t("common.or") }}
- <span
- class="text-accent cursor-pointer"
- @click="state.showTrialModal = true"
- >
+ <span class="text-accent cursor-pointer" @click="openTrialModal">
{{ $t("subscription.plan.try") }}
</span>
</span>
@@ -74,7 +71,7 @@
<div class="textinfolabel">
{{ $t("subscription.plan-compare") }}
</div>
- <PricingTable />
+ <PricingTable @on-trial="openTrialModal" />
</div>
<TrialModal
v-if="state.showTrialModal"
@@ -164,6 +161,10 @@ export default defineComponent({
return subscriptionStore.canTrial;
});
+ const openTrialModal = () => {
+ state.showTrialModal = true;
+ };
+
return {
state,
disabled,
@@ -173,6 +174,7 @@ export default defineComponent({
currentPlan,
instanceCount,
uploadLicense,
+ openTrialModal,
};
},
});
diff --git a/server/subscription.go b/server/subscription.go
index b2ec025015..889cd971c1 100644
--- a/server/subscription.go
+++ b/server/subscription.go
@@ -56,7 +56,6 @@ func (s *Server) registerSubscriptionRoutes(g *echo.Group) {
if err := jsonapi.UnmarshalPayload(c.Request().Body, create); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Malformed create trial request").SetInternal(err)
}
-
license := &enterpriseAPI.License{
InstanceCount: create.InstanceCount,
ExpiresTs: time.Now().AddDate(0, 0, create.Days).Unix(),
@@ -81,24 +80,48 @@ func (s *Server) registerSubscriptionRoutes(g *echo.Group) {
}
ctx := c.Request().Context()
- _, created, err := s.store.CreateSettingIfNotExist(ctx, &api.SettingCreate{
- CreatorID: c.Get(getPrincipalIDContextKey()).(int),
- Name: api.SettingEnterpriseTrial,
- Value: string(value),
- Description: "The trialing license.",
+ principalID := c.Get(getPrincipalIDContextKey()).(int)
+ settingName := api.SettingEnterpriseTrial
+ settings, err := s.store.FindSetting(ctx, &api.SettingFind{
+ Name: &settingName,
})
if err != nil {
- return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create license").SetInternal(err)
+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find setting").SetInternal(err)
}
- if created && upgradeTrial {
- // We need to override SettingEnterpriseLicense with empty value so that we can get the valid free trial.
+ if len(settings) == 0 {
+ // We will create a new setting named SettingEnterpriseTrial to store the free trial license.
+ _, created, err := s.store.CreateSettingIfNotExist(ctx, &api.SettingCreate{
+ CreatorID: principalID,
+ Name: api.SettingEnterpriseTrial,
+ Value: string(value),
+ Description: "The trialing license.",
+ })
+ if err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create license").SetInternal(err)
+ }
+
+ if created && upgradeTrial {
+ // For trial upgrade
+ // Case 1: Users just have the SettingEnterpriseTrial, don't upload their license in SettingEnterpriseLicense.
+ // Case 2: Users have the SettingEnterpriseLicense with team plan and trialing status.
+ // In both cases, we can override the SettingEnterpriseLicense with an empty value to get the valid free trial.
+ if _, err := s.store.PatchSetting(ctx, &api.SettingPatch{
+ UpdaterID: principalID,
+ Name: api.SettingEnterpriseLicense,
+ Value: "",
+ }); err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to remove license").SetInternal(err)
+ }
+ }
+ } else {
+ // Update the existed free trial.
if _, err := s.store.PatchSetting(ctx, &api.SettingPatch{
- UpdaterID: api.SystemBotID,
- Name: api.SettingEnterpriseLicense,
- Value: "",
+ UpdaterID: principalID,
+ Name: api.SettingEnterpriseTrial,
+ Value: string(value),
}); err != nil {
- return echo.NewHTTPError(http.StatusInternalServerError, "Failed to remove license").SetInternal(err)
+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to patch license").SetInternal(err)
}
}