Skip to content

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

chore: update the trial plan api (#3251)

ecmadao1c4a751caeef
diff --git a/api/plan.go b/api/plan.go
index be75a78272..28e3b2e12e 100644
--- a/api/plan.go
+++ b/api/plan.go
@@ -230,6 +230,13 @@ type PlanPatch struct {
Type PlanType `jsonapi:"attr,type"`
}
+// TrialPlanCreate is the API message for creating a trial plan.
+type TrialPlanCreate struct {
+ Type PlanType `jsonapi:"attr,type"`
+ Days int `jsonapi:"attr,days"`
+ InstanceCount int `jsonapi:"attr,instanceCount"`
+}
+
// PlanLimit is the type for plan limits.
type PlanLimit int
diff --git a/frontend/src/store/modules/subscription.ts b/frontend/src/store/modules/subscription.ts
index 6b054e45c4..1304149971 100644
--- a/frontend/src/store/modules/subscription.ts
+++ b/frontend/src/store/modules/subscription.ts
@@ -13,8 +13,9 @@ import {
export const useSubscriptionStore = defineStore("subscription", {
state: (): SubscriptionState => ({
subscription: undefined,
- trialingDays: 7,
+ trialingDays: 14,
trialingPlan: PlanType.ENTERPRISE,
+ trialingInstanceCount: 999,
}),
getters: {
currentPlan(state): PlanType {
@@ -107,7 +108,18 @@ export const useSubscriptionStore = defineStore("subscription", {
return subscription;
},
async trialSubscription() {
- const data = (await axios.post(`/api/subscription/trial`)).data.data;
+ const data = (
+ await axios.post(`/api/subscription/trial`, {
+ data: {
+ type: "TrialPlanCreate",
+ attributes: {
+ type: this.trialingPlan,
+ days: this.trialingDays,
+ instanceCount: this.trialingInstanceCount,
+ },
+ },
+ })
+ ).data.data;
const subscription = data.attributes as Subscription;
this.setSubscription(subscription);
return subscription;
diff --git a/frontend/src/types/subscription.ts b/frontend/src/types/subscription.ts
index ab0444a8a6..7b580ac39f 100644
--- a/frontend/src/types/subscription.ts
+++ b/frontend/src/types/subscription.ts
@@ -12,4 +12,5 @@ export interface SubscriptionState {
subscription: Subscription | undefined;
trialingDays: number;
trialingPlan: PlanType;
+ trialingInstanceCount: number;
}
diff --git a/server/subscription.go b/server/subscription.go
index 3091a1503b..e39aaf2386 100644
--- a/server/subscription.go
+++ b/server/subscription.go
@@ -18,15 +18,6 @@ import (
enterpriseAPI "github.com/bytebase/bytebase/enterprise/api"
)
-const (
- // freeTrialPlan is the subscription plan for free trial.
- freeTrialPlan = api.ENTERPRISE
- // freeTrialInstanceCount is the instance count for free trial.
- freeTrialInstanceCount = 999
- // freeTrialDays is the trialing days for free trial.
- freeTrialDays = 7
-)
-
func (s *Server) registerSubscriptionRoutes(g *echo.Group) {
g.GET("/subscription", func(c echo.Context) error {
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
@@ -61,12 +52,16 @@ func (s *Server) registerSubscriptionRoutes(g *echo.Group) {
})
g.POST("/subscription/trial", func(c echo.Context) error {
+ create := &api.TrialPlanCreate{}
+ 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: freeTrialInstanceCount,
- // trial 7 days
- ExpiresTs: time.Now().Unix() + freeTrialDays*24*60*60,
- IssuedTs: time.Now().Unix(),
- Plan: freeTrialPlan,
+ InstanceCount: create.InstanceCount,
+ ExpiresTs: time.Now().AddDate(0, 0, create.Days).Unix(),
+ IssuedTs: time.Now().Unix(),
+ Plan: create.Type,
// the subject format for license should be {org id in hub}.{subscription id in hub}
// as we just need to simply generate the trialing license in console, we can use the workspace id instead.
Subject: fmt.Sprintf("%s.%s", s.workspaceID, ""),
@@ -81,7 +76,7 @@ func (s *Server) registerSubscriptionRoutes(g *echo.Group) {
ctx := c.Request().Context()
if _, err := s.store.CreateSettingIfNotExist(ctx, &api.SettingCreate{
- CreatorID: api.SystemBotID,
+ CreatorID: c.Get(getPrincipalIDContextKey()).(int),
Name: api.SettingEnterpriseTrial,
Value: string(value),
Description: "The trialing license.",