Skip to content

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

feat: use subscription store instead of plan store (#496)

ecmadao06e0bb337114
diff --git a/enterprise/service/license.go b/enterprise/service/license.go
index dc4b3cec40..2da0673b02 100644
--- a/enterprise/service/license.go
+++ b/enterprise/service/license.go
@@ -5,6 +5,7 @@ import (
"io/ioutil"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
enterpriseAPI "github.com/bytebase/bytebase/enterprise/api"
"github.com/bytebase/bytebase/enterprise/config"
"github.com/golang-jwt/jwt/v4"
@@ -44,28 +45,28 @@ func (s *licenseService) LoadLicense() (*enterpriseAPI.License, error) {
token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
if _, ok := token.Method.(*jwt.SigningMethodRSA); !ok {
- return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
+ return nil, common.Errorf(common.Invalid, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]))
}
kid, ok := token.Header["kid"].(string)
if !ok || kid != s.config.Version {
- return nil, fmt.Errorf("version '%v' is not valid. expect %s", token.Header["kid"], s.config.Version)
+ return nil, common.Errorf(common.Invalid, fmt.Errorf("version '%v' is not valid. expect %s", token.Header["kid"], s.config.Version))
}
key, err := jwt.ParseRSAPublicKeyFromPEM([]byte(s.config.PublicKey))
if err != nil {
- return nil, err
+ return nil, common.Errorf(common.Invalid, err)
}
return key, nil
})
if err != nil {
- return nil, err
+ return nil, common.Errorf(common.Invalid, err)
}
claims, ok := token.Claims.(jwt.MapClaims)
if !ok || !token.Valid {
- return nil, fmt.Errorf("invalid token")
+ return nil, common.Errorf(common.Invalid, fmt.Errorf("invalid token"))
}
return s.parseClaims(claims)
@@ -75,37 +76,37 @@ func (s *licenseService) LoadLicense() (*enterpriseAPI.License, error) {
func (s *licenseService) parseClaims(claims jwt.MapClaims) (*enterpriseAPI.License, error) {
err := claims.Valid()
if err != nil {
- return nil, err
+ return nil, common.Errorf(common.Invalid, err)
}
exp, ok := claims["exp"].(int64)
if !ok {
- return nil, fmt.Errorf("exp is not valid, found '%v'", claims["exp"])
+ return nil, common.Errorf(common.Invalid, fmt.Errorf("exp is not valid, found '%v'", claims["exp"]))
}
iss, ok := claims["iss"].(string)
if !ok || iss != s.config.Issuer {
- return nil, fmt.Errorf("iss is not valid, expect %s but found '%v'", s.config.Issuer, claims["iss"])
+ return nil, common.Errorf(common.Invalid, fmt.Errorf("iss is not valid, expect %s but found '%v'", s.config.Issuer, claims["iss"]))
}
instance, ok := claims["instance"].(int)
if !ok || instance < s.config.MinimumInstance {
- return nil, fmt.Errorf("license instance count '%v' is not valid, minimum instance requirement is %d", claims["instance"], s.config.MinimumInstance)
+ return nil, common.Errorf(common.Invalid, fmt.Errorf("license instance count '%v' is not valid, minimum instance requirement is %d", claims["instance"], s.config.MinimumInstance))
}
plan, ok := claims["plan"].(string)
if !ok {
- return nil, fmt.Errorf("plan is not valid, found '%v'", claims["plan"])
+ return nil, common.Errorf(common.Invalid, fmt.Errorf("plan is not valid, found '%v'", claims["plan"]))
}
planType, err := convertPlanType(plan)
if err != nil {
- return nil, fmt.Errorf("plan type %q is not valid", planType)
+ return nil, common.Errorf(common.Invalid, fmt.Errorf("plan type %q is not valid", planType))
}
aud, ok := claims["aud"].(string)
if !ok || aud == "" {
- return nil, fmt.Errorf("aud is not valid, found '%v'", claims["aud"])
+ return nil, common.Errorf(common.Invalid, fmt.Errorf("aud is not valid, found '%v'", claims["aud"]))
}
license := &enterpriseAPI.License{
@@ -116,7 +117,7 @@ func (s *licenseService) parseClaims(claims jwt.MapClaims) (*enterpriseAPI.Licen
}
if err := license.Valid(); err != nil {
- return nil, err
+ return nil, common.Errorf(common.Invalid, err)
}
return license, nil
@@ -125,7 +126,10 @@ func (s *licenseService) parseClaims(claims jwt.MapClaims) (*enterpriseAPI.Licen
func (s *licenseService) readLicense() (string, error) {
token, err := ioutil.ReadFile(s.config.StorePath)
if err != nil {
- return "", fmt.Errorf("cannot read license from %s, error %w", s.config.StorePath, err)
+ return "", common.Errorf(
+ common.NotFound,
+ fmt.Errorf("cannot read license from %s, error %w", s.config.StorePath, err),
+ )
}
return string(token), nil
diff --git a/frontend/src/components/DatabaseOverviewPanel.vue b/frontend/src/components/DatabaseOverviewPanel.vue
index 2b947675b1..38f3c1f5a0 100644
--- a/frontend/src/components/DatabaseOverviewPanel.vue
+++ b/frontend/src/components/DatabaseOverviewPanel.vue
@@ -211,7 +211,7 @@ export default {
);
const hasDataSourceFeature = computed(() =>
- store.getters["plan/feature"]("bb.feature.data-source")
+ store.getters["subscription/feature"]("bb.feature.data-source")
);
const tableList = computed(() => {
diff --git a/frontend/src/components/MemberAddOrInvite.vue b/frontend/src/components/MemberAddOrInvite.vue
index 065fe7b62c..63b3b3f66d 100644
--- a/frontend/src/components/MemberAddOrInvite.vue
+++ b/frontend/src/components/MemberAddOrInvite.vue
@@ -139,7 +139,7 @@ export default {
});
const hasAdminFeature = computed(() =>
- store.getters["plan/feature"]("bb.feature.rbac")
+ store.getters["subscription/feature"]("bb.feature.rbac")
);
const state = reactive<LocalState>({
diff --git a/frontend/src/components/MemberTable.vue b/frontend/src/components/MemberTable.vue
index 1b0d673ab0..2027b7e6a4 100644
--- a/frontend/src/components/MemberTable.vue
+++ b/frontend/src/components/MemberTable.vue
@@ -131,7 +131,7 @@ export default {
const currentUser = computed(() => store.getters["auth/currentUser"]());
const hasAdminFeature = computed(() =>
- store.getters["plan/feature"]("bb.feature.rbac")
+ store.getters["subscription/feature"]("bb.feature.rbac")
);
const state = reactive<LocalState>({});
diff --git a/frontend/src/components/PricingTable.vue b/frontend/src/components/PricingTable.vue
index 840d1437f9..c6b591c264 100644
--- a/frontend/src/components/PricingTable.vue
+++ b/frontend/src/components/PricingTable.vue
@@ -102,13 +102,15 @@
<script lang="ts">
import { reactive, computed, PropType } from "vue";
-import { Plan, Subscription, PlanType } from "../types";
import {
+ Plan,
+ Subscription,
+ PlanType,
FEATURE_SECTIONS,
FREE_PLAN,
TEAM_PLAN,
ENTERPRISE_PLAN,
-} from "../store/modules/plan";
+} from "../types";
interface LocalState {
isMonthly: boolean;
diff --git a/frontend/src/components/ProjectMemberPanel.vue b/frontend/src/components/ProjectMemberPanel.vue
index 0382aaf99c..aa97440ae5 100644
--- a/frontend/src/components/ProjectMemberPanel.vue
+++ b/frontend/src/components/ProjectMemberPanel.vue
@@ -117,7 +117,7 @@ export default {
});
const hasAdminFeature = computed(() =>
- store.getters["plan/feature"]("bb.feature.rbac")
+ store.getters["subscription/feature"]("bb.feature.rbac")
);
const allowAddMember = computed(() => {
diff --git a/frontend/src/components/ProjectMemberTable.vue b/frontend/src/components/ProjectMemberTable.vue
index 6b4380d1e0..abe49fe1d4 100644
--- a/frontend/src/components/ProjectMemberTable.vue
+++ b/frontend/src/components/ProjectMemberTable.vue
@@ -112,7 +112,7 @@ export default {
const currentUser = computed(() => store.getters["auth/currentUser"]());
const hasAdminFeature = computed(() =>
- store.getters["plan/feature"]("bb.feature.rbac")
+ store.getters["subscription/feature"]("bb.feature.rbac")
);
const state = reactive<LocalState>({});
diff --git a/frontend/src/components/ProjectSelect.vue b/frontend/src/components/ProjectSelect.vue
index cc8f175f42..ec0db5ff2c 100644
--- a/frontend/src/components/ProjectSelect.vue
+++ b/frontend/src/components/ProjectSelect.vue
@@ -114,7 +114,7 @@ export default defineComponent({
watchEffect(prepareProjectList);
const hasAdminFeature = computed(() =>
- store.getters["plan/feature"]("bb.feature.rbac")
+ store.getters["subscription/feature"]("bb.feature.rbac")
);
const projectList = computed((): Project[] => {
diff --git a/frontend/src/components/Quickstart.vue b/frontend/src/components/Quickstart.vue
index 9251d13ab8..14e13c9330 100644
--- a/frontend/src/components/Quickstart.vue
+++ b/frontend/src/components/Quickstart.vue
@@ -112,7 +112,7 @@ export default defineComponent({
name: computed(() => t("quick-start.visit-instance")),
link: "/instance",
allowDBA: true,
- allowDeveloper: !store.getters["plan/feature"]("bb.feature.dba-workflow"),
+ allowDeveloper: !store.getters["subscription/feature"]("bb.feature.dba-workflow"),
done: computed(() => {
return store.getters["uistate/introStateByKey"]("instance.visit");
}),
diff --git a/frontend/src/main.ts b/frontend/src/main.ts
index d83433f953..ff8df076d1 100644
--- a/frontend/src/main.ts
+++ b/frontend/src/main.ts
@@ -58,9 +58,9 @@ axios.interceptors.response.use(
if (isDev() && response.config.url!.startsWith("/api")) {
console.debug(
response.config.method?.toUpperCase() +
- " " +
- response.config.url +
- " response",
+ " " +
+ response.config.url +
+ " response",
JSON.stringify(response.data, null, 2)
);
}
@@ -88,7 +88,9 @@ axios.interceptors.response.use(
style: "CRITICAL",
title: error.response.data.message,
// If server enables --debug, then the response will include the detailed error.
- description: error.response.data.error ? error.response.data.error : undefined,
+ description: error.response.data.error
+ ? error.response.data.error
+ : undefined,
});
}
} else if (error.code == "ECONNABORTED") {
@@ -112,7 +114,7 @@ axios.interceptors.response.use(
// We use finally because we always want to mount the app regardless of the error.
Promise.all([
store.dispatch("actuator/fetchInfo"),
- store.dispatch("plan/fetchCurrentPlan"),
+ store.dispatch("subscription/fetchSubscription"),
store.dispatch("auth/restoreUser"),
]).finally(() => {
const app = createApp(App);
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index 85f802c4e2..6b932721e5 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -93,7 +93,7 @@ const routes: Array<RouteRecordRaw> = [
meta: {
quickActionListByRole: () => {
const ownerList: QuickActionType[] = store.getters[
- "plan/feature"
+ "subscription/feature"
]("bb.feature.dba-workflow")
? [
"quickaction.bb.database.schema.update",
@@ -113,7 +113,7 @@ const routes: Array<RouteRecordRaw> = [
"quickaction.bb.user.manage",
];
const dbaList: QuickActionType[] = store.getters[
- "plan/feature"
+ "subscription/feature"
]("bb.feature.dba-workflow")
? [
"quickaction.bb.database.schema.update",
@@ -131,7 +131,7 @@ const routes: Array<RouteRecordRaw> = [
"quickaction.bb.project.create",
];
const developerList: QuickActionType[] = store.getters[
- "plan/feature"
+ "subscription/feature"
]("bb.feature.dba-workflow")
? [
"quickaction.bb.database.schema.update",
@@ -568,7 +568,7 @@ const routes: Array<RouteRecordRaw> = [
title: () => t("common.database"),
quickActionListByRole: () => {
const ownerList: QuickActionType[] = store.getters[
- "plan/feature"
+ "subscription/feature"
]("bb.feature.dba-workflow")
? [
"quickaction.bb.database.schema.update",
@@ -582,7 +582,7 @@ const routes: Array<RouteRecordRaw> = [
"quickaction.bb.database.create",
];
const dbaList: QuickActionType[] = store.getters[
- "plan/feature"
+ "subscription/feature"
]("bb.feature.dba-workflow")
? [
"quickaction.bb.database.schema.update",
@@ -596,7 +596,7 @@ const routes: Array<RouteRecordRaw> = [
"quickaction.bb.database.create",
];
const developerList: QuickActionType[] = store.getters[
- "plan/feature"
+ "subscription/feature"
]("bb.feature.dba-workflow")
? [
"quickaction.bb.database.schema.update",
@@ -863,7 +863,7 @@ router.beforeEach((to, from, next) => {
if (to.name === "workspace.instance") {
if (
- !store.getters["plan/feature"]("bb.feature.dba-workflow") ||
+ !store.getters["subscription/feature"]("bb.feature.dba-workflow") ||
isDBAOrOwner(currentUser.role)
) {
next();
@@ -878,7 +878,7 @@ router.beforeEach((to, from, next) => {
if (to.name?.toString().startsWith("workspace.database.datasource")) {
if (
- !store.getters["plan/feature"]("bb.feature.data-source") ||
+ !store.getters["subscription/feature"]("bb.feature.data-source") ||
!isDBAOrOwner(currentUser.role)
) {
next({
diff --git a/frontend/src/store/modules/plan.ts b/frontend/src/store/modules/plan.ts
deleted file mode 100644
index dc45e2d4b2..0000000000
--- a/frontend/src/store/modules/plan.ts
+++ /dev/null
@@ -1,211 +0,0 @@
-import axios from "axios";
-import { Plan, FeatureType, PlanPatch, PlanState, PlanType } from "../../types";
-
-// A map from the a particular feature to the respective enablement of a particular plan
-// Make sure this is consistent with the matrix in plan.go
-//
-// TODO: fetch the matrix from the backend instead of duplicating it here or use a JSON/YAML file
-// so that it can be shared between frontend/backend.
-export const FEATURE_MATRIX: Map<FeatureType, boolean[]> = new Map([
- // Change Workflow
- ["bb.feature.backward-compatibility", [false, true, true]],
- ["bb.feature.schema-drift", [false, true, true]],
- ["bb.feature.task-schedule-time", [false, true, true]],
- ["bb.feature.multi-tenancy", [false, true, true]],
- ["bb.feature.dba-workflow", [false, false, true]],
- ["bb.feature.data-source", [false, false, false]],
- // Policy Control
- ["bb.feature.approval-policy", [false, true, true]],
- ["bb.feature.backup-policy", [false, true, true]],
- // Admin & Security
- ["bb.feature.rbac", [false, true, true]],
- ["bb.feature.3rd-party-login", [false, true, true]],
-]);
-
-export const FEATURE_SECTIONS = [
- {
- id: "Database Management",
- features: [
- "Instance",
- "Schema change",
- "Migration history",
- "SQL Editor",
- "Database backup/restore",
- "Archiving",
- "SQL check",
- "Anomaly detection",
- "Review and backup policy",
- "Multi-Region / Multi-Tenancy",
- ],
- },
- {
- id: "Collaboration",
- features: [
- "UI based SQL review",
- "GitOps workflow",
- "SQL review commenting",
- "IM integration",
- "Inbox notification",
- ],
- },
- {
- id: "Admin & Security",
- features: ["Activity Log", "RBAC"],
- },
-];
-
-export const FREE_PLAN: Plan = {
- // Plan meta data
- type: PlanType.FREE,
- trialDays: 0,
- unitPrice: 0,
- trialPrice: 0,
- freeInstanceCount: 1,
- pricePerInstancePerMonth: 0,
- // Plan desc and feature
- title: "Free",
- description: "The essentials to provide your best work for clients.",
- features: [
- { id: "Instance", content: "1" },
- { id: "Schema change" },
- { id: "Migration history" },
- { id: "SQL Editor" },
- { id: "Database backup/restore" },
- { id: "Archiving" },
- { id: "SQL check", content: "Basic" },
- { id: "Anomaly detection", content: "Basic" },
- { id: "UI based SQL review" },
- { id: "GitOps workflow" },
- { id: "SQL review commenting" },
- { id: "IM integration" },
- { id: "Inbox notification" },
- { id: "Activity Log" },
- { id: "UI based SQL review" },
- ],
-};
-
-export const TEAM_PLAN: Plan = {
- // Plan meta data
- type: PlanType.TEAM,
- trialDays: 7,
- unitPrice: 1740,
- trialPrice: 7,
- freeInstanceCount: 5,
- pricePerInstancePerMonth: 29,
- // Plan desc and feature
- title: "Team",
- description: "A plan that scales with your rapidly growing business.",
- features: [
- { id: "Instance", content: "5" },
- { id: "Schema change" },
- { id: "Migration history" },
- { id: "SQL Editor" },
- { id: "Database backup/restore" },
- { id: "Archiving" },
- {
- id: "SQL check",
- content: "Advanced (e.g. Backward compatibility check)",
- },
- { id: "Anomaly detection", content: "Advanced (e.g. Drift detection)" },
- { id: "Review and backup policy" },
- { id: "UI based SQL review" },
- { id: "GitOps workflow" },
- { id: "SQL review commenting" },
- { id: "IM integration" },
- { id: "Inbox notification" },
- { id: "Activity Log" },
- { id: "RBAC" },
- ],
-};
-
-export const ENTERPRISE_PLAN: Plan = {
- // Plan meta data
- type: PlanType.ENTERPRISE,
- trialDays: 7,
- unitPrice: 0,
- trialPrice: 0,
- freeInstanceCount: 5,
- pricePerInstancePerMonth: 29,
- // Plan desc and feature
- title: "Enterprise",
- description: "Dedicated support and infrastructure for your company.",
- features: [
- { id: "Instance", content: "Customized" },
- { id: "Schema change" },
- { id: "Migration history" },
- { id: "SQL Editor" },
- { id: "Database backup/restore" },
- { id: "Archiving" },
- {
- id: "SQL check",
- content: "Advanced (e.g. Backward compatibility check)",
- },
- { id: "Anomaly detection", content: "Advanced (e.g. Drift detection)" },
- { id: "Review and backup policy" },
- { id: "Multi-Region / Multi-Tenancy" },
- { id: "UI based SQL review" },
- { id: "GitOps workflow" },
- { id: "SQL review commenting" },
- { id: "IM integration" },
- { id: "Inbox notification" },
- { id: "Activity Log" },
- { id: "RBAC" },
- ],
-};
-
-const state: () => PlanState = () => ({
- plan: PlanType.TEAM,
-});
-
-const getters = {
- currentPlan: (state: PlanState) => (): PlanType => {
- return state.plan;
- },
-
- feature:
- (state: PlanState, getters: any) =>
- (type: FeatureType): boolean => {
- return FEATURE_MATRIX.get(type)![getters["currentPlan"]()];
- },
-};
-
-const actions = {
- async fetchCurrentPlan({ commit }: any): Promise<PlanType> {
- const data = (await axios.get(`/api/plan`)).data.data;
- const plan = data.attributes.type;
- commit("setCurrentPlan", plan);
- return plan;
- },
-
- async changePlan({ commit }: any, newPlan: PlanType) {
- const planPatch: PlanPatch = {
- type: newPlan,
- };
- const data = (
- await axios.patch(`/api/plan`, {
- data: {
- type: "planPatch",
- attributes: planPatch,
- },
- })
- ).data.data;
-
- const updatedPlan = data.attributes.type;
- commit("setCurrentPlan", updatedPlan);
- return updatedPlan;
- },
-};
-
-const mutations = {
- setCurrentPlan(state: PlanState, newPlan: PlanType) {
- state.plan = newPlan;
- },
-};
-
-export default {
- namespaced: true,
- state,
- getters,
- actions,
- mutations,
-};
diff --git a/frontend/src/store/modules/subscription.ts b/frontend/src/store/modules/subscription.ts
index 4c763c7275..3c62f96b0a 100644
--- a/frontend/src/store/modules/subscription.ts
+++ b/frontend/src/store/modules/subscription.ts
@@ -3,9 +3,9 @@ import {
Subscription,
FeatureType,
PlanType,
+ FEATURE_MATRIX,
SubscriptionState,
} from "../../types";
-import { FEATURE_MATRIX } from "./plan";
const state: () => SubscriptionState = () => ({
subscription: undefined,
diff --git a/frontend/src/types/plan.ts b/frontend/src/types/plan.ts
index 7bf95cbc39..9194693eee 100644
--- a/frontend/src/types/plan.ts
+++ b/frontend/src/types/plan.ts
@@ -37,3 +37,155 @@ export interface Plan {
description: string;
features: { id: string; content?: string }[];
}
+
+// A map from the a particular feature to the respective enablement of a particular plan
+// Make sure this is consistent with the matrix in plan.go
+//
+// TODO: fetch the matrix from the backend instead of duplicating it here or use a JSON/YAML file
+// so that it can be shared between frontend/backend.
+export const FEATURE_MATRIX: Map<FeatureType, boolean[]> = new Map([
+ // Change Workflow
+ ["bb.feature.backward-compatibility", [false, true, true]],
+ ["bb.feature.schema-drift", [false, true, true]],
+ ["bb.feature.task-schedule-time", [false, true, true]],
+ ["bb.feature.multi-tenancy", [false, true, true]],
+ ["bb.feature.dba-workflow", [false, false, true]],
+ ["bb.feature.data-source", [false, false, false]],
+ // Policy Control
+ ["bb.feature.approval-policy", [false, true, true]],
+ ["bb.feature.backup-policy", [false, true, true]],
+ // Admin & Security
+ ["bb.feature.rbac", [false, true, true]],
+ ["bb.feature.3rd-party-login", [false, true, true]],
+]);
+
+export const FEATURE_SECTIONS = [
+ {
+ id: "Database Management",
+ features: [
+ "Instance",
+ "Schema change",
+ "Migration history",
+ "SQL Editor",
+ "Database backup/restore",
+ "Archiving",
+ "SQL check",
+ "Anomaly detection",
+ "Review and backup policy",
+ "Multi-Region / Multi-Tenancy",
+ ],
+ },
+ {
+ id: "Collaboration",
+ features: [
+ "UI based SQL review",
+ "GitOps workflow",
+ "SQL review commenting",
+ "IM integration",
+ "Inbox notification",
+ ],
+ },
+ {
+ id: "Admin & Security",
+ features: ["Activity Log", "RBAC"],
+ },
+];
+
+export const FREE_PLAN: Plan = {
+ // Plan meta data
+ type: PlanType.FREE,
+ trialDays: 0,
+ unitPrice: 0,
+ trialPrice: 0,
+ freeInstanceCount: 1,
+ pricePerInstancePerMonth: 0,
+ // Plan desc and feature
+ title: "Free",
+ description: "The essentials to provide your best work for clients.",
+ features: [
+ { id: "Instance", content: "1" },
+ { id: "Schema change" },
+ { id: "Migration history" },
+ { id: "SQL Editor" },
+ { id: "Database backup/restore" },
+ { id: "Archiving" },
+ { id: "SQL check", content: "Basic" },
+ { id: "Anomaly detection", content: "Basic" },
+ { id: "UI based SQL review" },
+ { id: "GitOps workflow" },
+ { id: "SQL review commenting" },
+ { id: "IM integration" },
+ { id: "Inbox notification" },
+ { id: "Activity Log" },
+ { id: "UI based SQL review" },
+ ],
+};
+
+export const TEAM_PLAN: Plan = {
+ // Plan meta data
+ type: PlanType.TEAM,
+ trialDays: 7,
+ unitPrice: 1740,
+ trialPrice: 7,
+ freeInstanceCount: 5,
+ pricePerInstancePerMonth: 29,
+ // Plan desc and feature
+ title: "Team",
+ description: "A plan that scales with your rapidly growing business.",
+ features: [
+ { id: "Instance", content: "5" },
+ { id: "Schema change" },
+ { id: "Migration history" },
+ { id: "SQL Editor" },
+ { id: "Database backup/restore" },
+ { id: "Archiving" },
+ {
+ id: "SQL check",
+ content: "Advanced (e.g. Backward compatibility check)",
+ },
+ { id: "Anomaly detection", content: "Advanced (e.g. Drift detection)" },
+ { id: "Review and backup policy" },
+ { id: "UI based SQL review" },
+ { id: "GitOps workflow" },
+ { id: "SQL review commenting" },
+ { id: "IM integration" },
+ { id: "Inbox notification" },
+ { id: "Activity Log" },
+ { id: "RBAC" },
+ ],
+};
+
+export const ENTERPRISE_PLAN: Plan = {
+ // Plan meta data
+ type: PlanType.ENTERPRISE,
+ trialDays: 7,
+ unitPrice: 0,
+ trialPrice: 0,
+ freeInstanceCount: 5,
+ pricePerInstancePerMonth: 29,
+ // Plan desc and feature
+ title: "Enterprise",
+ description: "Dedicated support and infrastructure for your company.",
+ features: [
+ { id: "Instance", content: "Customized" },
+ { id: "Schema change" },
+ { id: "Migration history" },
+ { id: "SQL Editor" },
+ { id: "Database backup/restore" },
+ { id: "Archiving" },
+ {
+ id: "SQL check",
+ content: "Advanced (e.g. Backward compatibility check)",
+ },
+ { id: "Anomaly detection", content: "Advanced (e.g. Drift detection)" },
+ { id: "Review and backup policy" },
+ { id: "Multi-Region / Multi-Tenancy" },
+ { id: "UI based SQL review" },
+ { id: "GitOps workflow" },
+ { id: "SQL review commenting" },
+ { id: "IM integration" },
+ { id: "Inbox notification" },
+ { id: "Activity Log" },
+ { id: "RBAC" },
+ ],
+};
diff --git a/frontend/src/utils/role.ts b/frontend/src/utils/role.ts
index 38450e9081..30d185c2a8 100644
--- a/frontend/src/utils/role.ts
+++ b/frontend/src/utils/role.ts
@@ -9,12 +9,12 @@ export function registerStoreWithRoleUtil(theStore: Store<any>) {
// Returns true if admin feature is NOT supported or the principal is OWNER
export function isOwner(role: RoleType): boolean {
- return !store.getters["plan/feature"]("bb.feature.rbac") || role == "OWNER";
+ return !store.getters["subscription/feature"]("bb.feature.rbac") || role == "OWNER";
}
// Returns true if admin feature is NOT supported or the principal is DBA
export function isDBA(role: RoleType): boolean {
- return !store.getters["plan/feature"]("bb.feature.rbac") || role == "DBA";
+ return !store.getters["subscription/feature"]("bb.feature.rbac") || role == "DBA";
}
export function isDBAOrOwner(role: RoleType): boolean {
@@ -23,7 +23,7 @@ export function isDBAOrOwner(role: RoleType): boolean {
// Returns true if admin feature is NOT supported or the principal is DEVELOPER
export function isDeveloper(role: RoleType): boolean {
- return !store.getters["plan/feature"]("bb.feature.rbac") || role == "DEVELOPER";
+ return !store.getters["subscription/feature"]("bb.feature.rbac") || role == "DEVELOPER";
}
export function roleName(role: RoleType): string {
@@ -39,11 +39,11 @@ export function roleName(role: RoleType): string {
// Project Role
export function isProjectOwner(role: ProjectRoleType): boolean {
- return !store.getters["plan/feature"]("bb.feature.rbac") || role == "OWNER";
+ return !store.getters["subscription/feature"]("bb.feature.rbac") || role == "OWNER";
}
export function isProjectDeveloper(role: ProjectRoleType): boolean {
- return !store.getters["plan/feature"]("bb.feature.rbac") || role == "DEVELOPER";
+ return !store.getters["subscription/feature"]("bb.feature.rbac") || role == "DEVELOPER";
}
export function projectRoleName(role: ProjectRoleType): string {
diff --git a/frontend/src/views/DashboardHeader.vue b/frontend/src/views/DashboardHeader.vue
index d4e73e0e6a..915782a493 100644
--- a/frontend/src/views/DashboardHeader.vue
+++ b/frontend/src/views/DashboardHeader.vue
@@ -215,7 +215,9 @@ export default defineComponent({
const currentUser = computed(() => store.getters["auth/currentUser"]());
- const currentPlan = computed(() => store.getters["plan/currentPlan"]());
+ const currentPlan = computed(() =>
+ store.getters["subscription/currentPlan"]()
+ );
const showDBAItem = computed((): boolean => {
return isDBAOrOwner(currentUser.value.role);
@@ -268,16 +270,18 @@ export default defineComponent({
});
};
+ // TODO: Do we still need this?
+ // Maybe we need to change the UX, redirect user to subscription page?
const switchToFree = () => {
- store.dispatch("plan/changePlan", PlanType.FREE);
+ store.dispatch("subscription/changePlan", PlanType.FREE);
};
const switchToTeam = () => {
- store.dispatch("plan/changePlan", PlanType.TEAM);
+ store.dispatch("subscription/changePlan", PlanType.TEAM);
};
const switchToEnterprise = () => {
- store.dispatch("plan/changePlan", PlanType.ENTERPRISE);
+ store.dispatch("subscription/changePlan", PlanType.ENTERPRISE);
};
const kbarActions = computed(() => [
diff --git a/frontend/src/views/InstanceDetail.vue b/frontend/src/views/InstanceDetail.vue
index 3310f1430d..9450ffad7e 100644
--- a/frontend/src/views/InstanceDetail.vue
+++ b/frontend/src/views/InstanceDetail.vue
@@ -252,7 +252,7 @@ export default {
});
const hasDataSourceFeature = computed(() =>
- store.getters["plan/feature"]("bb.feature.data-source")
+ store.getters["subscription/feature"]("bb.feature.data-source")
);
const databaseList = computed(() => {
diff --git a/frontend/src/views/ProfileDashboard.vue b/frontend/src/views/ProfileDashboard.vue
index 0102f9d4fe..1b14530970 100644
--- a/frontend/src/views/ProfileDashboard.vue
+++ b/frontend/src/views/ProfileDashboard.vue
@@ -192,7 +192,7 @@ export default {
);
const hasAdminFeature = computed(() =>
- store.getters["plan/feature"]("bb.feature.rbac")
+ store.getters["subscription/feature"]("bb.feature.rbac")
);
const principal = computed(() => {
diff --git a/frontend/src/views/SettingWorkspaceMember.vue b/frontend/src/views/SettingWorkspaceMember.vue
index 7c4b59e91e..542279fef0 100644
--- a/frontend/src/views/SettingWorkspaceMember.vue
+++ b/frontend/src/views/SettingWorkspaceMember.vue
@@ -39,7 +39,7 @@ export default {
const currentUser = computed(() => store.getters["auth/currentUser"]());
const hasAdminFeature = computed(() =>
- store.getters["plan/feature"]("bb.feature.rbac")
+ store.getters["subscription/feature"]("bb.feature.rbac")
);
const prepareMemberList = () => {
diff --git a/frontend/src/views/SqlEditor/EditorHeader.vue b/frontend/src/views/SqlEditor/EditorHeader.vue
index 4017a37c00..956ec2ac5b 100644
--- a/frontend/src/views/SqlEditor/EditorHeader.vue
+++ b/frontend/src/views/SqlEditor/EditorHeader.vue
@@ -116,11 +116,11 @@ export default defineComponent({
const currentUser = computed(() => store.getters["auth/currentUser"]());
- const currentPlan = computed(() => store.getters["plan/currentPlan"]());
+ const currentPlan = computed(() => store.getters["subscription/currentPlan"]());
const showDBAItem = computed((): boolean => {
return (
- !store.getters["plan/feature"]("bb.feature.dba-workflow") ||
+ !store.getters["subscription/feature"]("bb.feature.dba-workflow") ||
isDBAOrOwner(currentUser.value.role)
);
});
diff --git a/server/acl.go b/server/acl.go
index f88effebec..8c096bba11 100644
--- a/server/acl.go
+++ b/server/acl.go
@@ -32,6 +32,11 @@ func aclMiddleware(l *zap.Logger, s *Server, ce *casbin.Enforcer, next echo.Hand
}
method := c.Request().Method
+ // Skip GET /subscription request
+ if common.HasPrefixes(c.Path(), "/api/subscription") && method == "GET" {
+ return next(c)
+ }
+
if readonly && method != "GET" {
return echo.NewHTTPError(http.StatusMethodNotAllowed, "Server is in readonly mode")
}
diff --git a/server/jwt.go b/server/jwt.go
index 23a33a815d..cd30546451 100644
--- a/server/jwt.go
+++ b/server/jwt.go
@@ -171,6 +171,12 @@ func JWTMiddleware(l *zap.Logger, p api.PrincipalService, next echo.HandlerFunc,
return next(c)
}
+ method := c.Request().Method
+ // Skip GET /subscription request
+ if common.HasPrefixes(c.Path(), "/api/subscription") && method == "GET" {
+ return next(c)
+ }
+
cookie, err := c.Cookie(accessTokenCookieName)
if err != nil {
return echo.NewHTTPError(http.StatusUnauthorized, "Missing access token")
diff --git a/server/subscription.go b/server/subscription.go
index 224551d903..db0cf6bed4 100644
--- a/server/subscription.go
+++ b/server/subscription.go
@@ -4,6 +4,8 @@ import (
"net/http"
"time"
+ "github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
enterprise "github.com/bytebase/bytebase/enterprise/api"
enterpriseAPI "github.com/bytebase/bytebase/enterprise/api"
"github.com/google/jsonapi"
@@ -13,14 +15,22 @@ import (
func (s *Server) registerSubscriptionRoutes(g *echo.Group) {
g.GET("/subscription", func(c echo.Context) error {
+ subscription := &enterpriseAPI.Subscription{
+ Plan: api.FREE,
+ // -1 means not expire, just for free plan
+ ExpiresTs: -1,
+ InstanceCount: 5,
+ }
+
license, err := s.loadLicense()
if err != nil {
- return echo.NewHTTPError(http.StatusBadRequest, "Failed to load subscription").SetInternal(err)
- }
- subscription := &enterpriseAPI.Subscription{
- Plan: license.Plan,
- ExpiresTs: license.ExpiresTs,
- InstanceCount: license.InstanceCount,
+ s.l.Error("Failed to get valid license for subscription", zap.String("error", err.Error()))
+ } else {
+ subscription = &enterpriseAPI.Subscription{
+ Plan: license.Plan,
+ ExpiresTs: license.ExpiresTs,
+ InstanceCount: license.InstanceCount,
+ }
}
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
@@ -62,7 +72,11 @@ func (s *Server) registerSubscriptionRoutes(g *echo.Group) {
func (server *Server) loadLicense() (*enterprise.License, error) {
license, err := server.LicenseService.LoadLicense()
if err != nil {
- server.l.Warn("Failed to load license", zap.String("error", err.Error()))
+ if common.ErrorCode(err) == common.NotFound {
+ server.l.Debug("Failed to find license", zap.String("error", err.Error()))
+ } else {
+ server.l.Warn("Failed to load valid license", zap.String("error", err.Error()))
+ }
return nil, err
}