Skip to content

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

fix: users can always start the trial whatever his current plan is (#5677)

ecmadao6151e01d18bd
diff --git a/backend/api/v1/subscription_service.go b/backend/api/v1/subscription_service.go
index e0bea66a42..337de50f2e 100644
--- a/backend/api/v1/subscription_service.go
+++ b/backend/api/v1/subscription_service.go
@@ -116,46 +116,19 @@ func (s *SubscriptionService) TrialSubscription(ctx context.Context, request *v1
}
principalID := ctx.Value(common.PrincipalIDContextKey).(int)
- settingName := api.SettingEnterpriseTrial
- settings, err := s.store.FindSetting(ctx, &api.SettingFind{
- Name: &settingName,
- })
- if err != nil {
- return nil, status.Errorf(codes.Internal, "failed to list settings: %v", err.Error())
+ if _, err := s.store.UpsertSettingV2(ctx, &store.SetSettingMessage{
+ Name: api.SettingEnterpriseTrial,
+ Value: string(value),
+ }, principalID); err != nil {
+ return nil, status.Errorf(codes.Internal, "failed to create license: %v", err.Error())
}
- if len(settings) == 0 {
- // We will create a new setting named SettingEnterpriseTrial to store the free trial license.
- _, created, err := s.store.CreateSettingIfNotExistV2(ctx, &store.SettingMessage{
- Name: api.SettingEnterpriseTrial,
- Value: string(value),
- Description: "The trialing license.",
- }, principalID)
- if err != nil {
- return nil, status.Errorf(codes.Internal, "failed to create license: %v", err.Error())
- }
-
- if created && subscription.Trialing {
- // 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.licenseService.StoreLicense(ctx, &enterpriseAPI.SubscriptionPatch{
- UpdaterID: principalID,
- License: "",
- }); err != nil {
- return nil, status.Errorf(codes.Internal, "failed to remove license: %v", err.Error())
- }
- }
- } else {
- // Update the existed free trial.
- if _, err := s.store.PatchSetting(ctx, &api.SettingPatch{
- UpdaterID: principalID,
- Name: api.SettingEnterpriseTrial,
- Value: string(value),
- }); err != nil {
- return nil, status.Errorf(codes.Internal, "failed to patch license: %v", err.Error())
- }
+ // we need to override the SettingEnterpriseLicense with an empty value to get the valid free trial.
+ if err := s.licenseService.StoreLicense(ctx, &enterpriseAPI.SubscriptionPatch{
+ UpdaterID: principalID,
+ License: "",
+ }); err != nil {
+ return nil, status.Errorf(codes.Internal, "failed to remove license: %v", err.Error())
}
s.licenseService.RefreshCache(ctx)
diff --git a/frontend/src/components/PricingTable/PricingTable.vue b/frontend/src/components/PricingTable/PricingTable.vue
index f78cae9a5a..c7693b9890 100644
--- a/frontend/src/components/PricingTable/PricingTable.vue
+++ b/frontend/src/components/PricingTable/PricingTable.vue
@@ -75,9 +75,10 @@
</button>
<div
v-if="plan.canTrial && subscriptionStore.canTrial"
- class="font-bold text-sm my-2 text-center"
+ class="font-bold text-sm my-2 text-center underline cursor-pointer"
+ @click="emit('on-trial')"
>
- {{ $t("subscription.free-trial") }}
+ {{ $t("subscription.start-free-trial") }}
</div>
</div>
</td>
@@ -139,16 +140,8 @@
<tr class="border-t border-gray-200">
<th class="sr-only" scope="row">Choose your plan</th>
<td v-for="plan in plans" :key="plan.type" class="py-5 px-6">
- <a
- v-if="plan.type == PlanType.ENTERPRISE"
- class="block w-full bg-gray-800 border border-gray-800 rounded-md py-2 text-lg font-semibold text-white text-center hover:bg-gray-900"
- target="__blank"
- :href="enterprisePlanFormLink"
- >
- {{ $t("subscription.button.contact-us") }}
- </a>
<button
- v-else-if="plan.buttonText"
+ v-if="plan.buttonText"
class="block w-full bg-gray-800 border border-gray-800 rounded-md py-2 text-lg font-semibold text-white text-center hover:bg-gray-900"
@click="onButtonClick(plan)"
>
@@ -219,9 +212,10 @@
</button>
<div
v-if="plan.canTrial && subscriptionStore.canTrial"
- class="font-bold text-sm my-2 text-center"
+ class="font-bold text-sm my-2 text-center underline cursor-pointer"
+ @click="emit('on-trial')"
>
- {{ $t("subscription.free-trial") }}
+ {{ $t("subscription.start-free-trial") }}
</div>
<div v-if="plan.isAvailable" class="px-4 py-8 text-right text-gray-500">
@@ -271,21 +265,8 @@
</template>
</tbody>
</table>
- <a
- v-if="plan.type == PlanType.ENTERPRISE"
- :class="[
- plan.highlight
- ? 'border-indigo-500 text-white bg-indigo-500 hover:bg-indigo-600 hover:border-indigo-600'
- : 'border-accent text-accent hover:bg-accent',
- 'mt-8 block w-full border rounded-md py-4 text-lg font-semibold text-center hover:text-white whitespace-nowrap overflow-hidden',
- ]"
- target="__blank"
- :href="enterprisePlanFormLink"
- >
- {{ $t("subscription.button.contact-us") }}
- </a>
<button
- v-else-if="plan.buttonText"
+ v-if="plan.buttonText"
type="button"
:class="[
plan.highlight
@@ -377,23 +358,14 @@ const getButtonText = (plan: Plan): string => {
}
break;
case PlanType.ENTERPRISE:
- if (subscriptionStore.currentPlan === PlanType.FREE) {
- return t("subscription.button.free-trial", {
- days: subscriptionStore.trialingDays,
- });
- }
- if (subscriptionStore.currentPlan === PlanType.TEAM) {
- return t("subscription.button.free-trial", {
- days: subscriptionStore.trialingDays,
- });
- }
if (subscriptionStore.currentPlan === PlanType.ENTERPRISE) {
if (subscriptionStore.isTrialing) {
return t("subscription.button.contact-us");
}
return t("subscription.button.view-subscription");
+ } else {
+ return t("subscription.button.contact-us");
}
- break;
}
return "";
};
@@ -424,7 +396,7 @@ const onButtonClick = (plan: Plan) => {
);
}
} else {
- emit("on-trial");
+ window.open(enterprisePlanFormLink, "__blank");
}
}
};
diff --git a/frontend/src/locales/subscription/en-US.json b/frontend/src/locales/subscription/en-US.json
index 3445e82734..660df6183d 100644
--- a/frontend/src/locales/subscription/en-US.json
+++ b/frontend/src/locales/subscription/en-US.json
@@ -3,6 +3,7 @@
"unlimited": "Unlimited",
"instance-count": "Instance count",
"expires-at": "Expires at",
+ "start-free-trial": "Start free trial",
"free-trial": "You can start a free trial for 14 days - no credit card required",
"purchase-license": "Purchase a License",
"sensitive-placeholder": "Paste your license here - write only",
diff --git a/frontend/src/locales/subscription/zh-CN.json b/frontend/src/locales/subscription/zh-CN.json
index cb13525649..dabe2be9ce 100644
--- a/frontend/src/locales/subscription/zh-CN.json
+++ b/frontend/src/locales/subscription/zh-CN.json
@@ -3,6 +3,7 @@
"unlimited": "无限制",
"instance-count": "实例数",
"expires-at": "过期时间",
+ "start-free-trial": "开始免费试用",
"free-trial": "您可以免费试用 14 天 - 无需信用卡或预付费",
"purchase-license": "购买证书",
"sensitive-placeholder": "粘贴您的证书 - 仅写入",