Skip to content

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

feat(frontend): disable create db button for project developers in enterprise plan (#1453)

Liu Ji7901827a6b9b
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index 7cd4f07939..cc75532759 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -21,9 +21,16 @@ import {
useIssueStore,
usePrincipalStore,
useRouterStore,
+ useSubscriptionStore,
} from "../store";
-import { Database, QuickActionType, Sheet, UNKNOWN_ID } from "../types";
-import { idFromSlug, isDBAOrOwner, isOwner } from "../utils";
+import {
+ Database,
+ PlanType,
+ QuickActionType,
+ Sheet,
+ UNKNOWN_ID,
+} from "../types";
+import { idFromSlug, isDBAOrOwner, isOwner, isProjectOwner } from "../utils";
// import PasswordReset from "../views/auth/PasswordReset.vue";
import Signin from "../views/auth/Signin.vue";
import Signup from "../views/auth/Signup.vue";
@@ -517,27 +524,51 @@ const routes: Array<RouteRecordRaw> = [
);
if (project.rowStatus == "NORMAL") {
+ const actionList: string[] = [];
+
const currentUser = useAuthStore().currentUser;
- let allowEditProject = false;
+ let allowAlterSchemaOrChangeData = false;
+ let allowCreateOrTransferDB = false;
if (isDBAOrOwner(currentUser.role)) {
- allowEditProject = true;
+ // Yes to workspace owner and DBA
+ allowAlterSchemaOrChangeData = true;
+ allowCreateOrTransferDB = true;
} else {
- for (const member of project.memberList) {
- if (member.principal.id == currentUser.id) {
- allowEditProject = true;
- break;
- }
+ const memberOfProject = project.memberList.find(
+ (m) => m.principal.id === currentUser.id
+ );
+ if (memberOfProject) {
+ // If current user is a member of this project
+ // we are allowed to alter schema and change data.
+ allowAlterSchemaOrChangeData = true;
+
+ const plan = useSubscriptionStore().currentPlan;
+ allowCreateOrTransferDB =
+ plan === PlanType.ENTERPRISE
+ ? // For ENTERPRISE plan, only
+ // - workspace owner and DBA
+ // - developers as the project owner
+ // can create/transfer DB.
+ // Other developers are not allowed.
+ isProjectOwner(memberOfProject.role)
+ : // For TEAM plan, all members of the project are allowed
+ true;
}
}
+ if (allowAlterSchemaOrChangeData) {
+ actionList.push(
+ "quickaction.bb.database.schema.update",
+ "quickaction.bb.database.data.update"
+ );
+ }
+
+ if (allowCreateOrTransferDB) {
+ actionList.push(
+ "quickaction.bb.database.create",
+ "quickaction.bb.project.database.transfer"
+ );
+ }
- const actionList: string[] = allowEditProject
- ? [
- "quickaction.bb.database.schema.update",
- "quickaction.bb.database.data.update",
- "quickaction.bb.database.create",
- "quickaction.bb.project.database.transfer",
- ]
- : [];
return new Map([
["OWNER", actionList],
["DBA", actionList],