Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Consolidate the isDBA and isOwner into a single method.
天舟aa2ef6d47162
diff --git a/frontend/src/components/EnvironmentForm.vue b/frontend/src/components/EnvironmentForm.vueindex 2410e0399f..6541142f4f 100644--- a/frontend/src/components/EnvironmentForm.vue+++ b/frontend/src/components/EnvironmentForm.vue@@ -74,6 +74,7 @@ import cloneDeep from "lodash-es/cloneDeep";import isEqual from "lodash-es/isEqual";import isEmpty from "lodash-es/isEmpty";import { Environment, EnvironmentNew } from "../types";+import { isDBA } from "../utils";interface LocalState {environment?: Environment | EnvironmentNew;@@ -115,9 +116,7 @@ export default {}const allowEdit = computed(() => {- return (- currentUser.value.role == "DBA" || currentUser.value.role == "OWNER"- );+ return isDBA(currentUser.value.role);});const valueChanged = computed(() => {diff --git a/frontend/src/components/ProfileDropdown.vue b/frontend/src/components/ProfileDropdown.vueindex a8b98e9e37..6bfa224839 100644--- a/frontend/src/components/ProfileDropdown.vue+++ b/frontend/src/components/ProfileDropdown.vue@@ -143,18 +143,6 @@ export default {});};- const isOwner = computed(() => {- return currentUser.value.role == "OWNER";- });-- const isDBA = computed(() => {- return currentUser.value.role == "DBA";- });-- const isDeveloper = computed(() => {- return currentUser.value.role == "DEVELOPER";- });-const switchToOwner = () => {store.dispatch("auth/login", {email: "[email protected]",@@ -180,9 +168,6 @@ export default {currentUser,resetQuickstart,logout,- isOwner,- isDBA,- isDeveloper,switchToOwner,switchToDBA,switchToDeveloper,diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.tsindex 211b34ab1b..9cd04a513b 100644--- a/frontend/src/router/index.ts+++ b/frontend/src/router/index.ts@@ -17,7 +17,7 @@ import Signup from "../views/auth/Signup.vue";import Activate from "../views/auth/Activate.vue";import PasswordReset from "../views/auth/PasswordReset.vue";import { store } from "../store";-import { isDev, idFromSlug } from "../utils";+import { isDev, idFromSlug, isDBA } from "../utils";import { Principal } from "../types";const HOME_MODULE = "workspace.home";@@ -475,7 +475,6 @@ export const router = createRouter({router.beforeEach((to, from, next) => {const loginUser: Principal = store.getters["auth/currentUser"]();- const isDBAorAbove = loginUser.role == "OWNER" || loginUser.role == "DBA";const isGuest = loginUser.id == "0";const fromModule = from.name@@ -537,7 +536,7 @@ router.beforeEach((to, from, next) => {}if (to.name?.toString().startsWith("workspace.instance")) {- if (isDBAorAbove) {+ if (isDBA(loginUser.role)) {next();} else {next({diff --git a/frontend/src/utils/database.ts b/frontend/src/utils/database.tsindex f0f9eadf8d..94d13ad582 100644--- a/frontend/src/utils/database.ts+++ b/frontend/src/utils/database.ts@@ -5,13 +5,14 @@ import {DataSourceType,Principal,} from "../types";+import { isDBA } from "./role";export function allowDatabaseAccess(database: Database,principal: Principal,type: DataSourceType): boolean {- if (principal.role == "DBA" || principal.role == "OWNER") {+ if (isDBA(principal.role)) {return true;}diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.tsindex f7be9ac9c8..4fde78e399 100644--- a/frontend/src/utils/index.ts+++ b/frontend/src/utils/index.ts@@ -1,6 +1,7 @@export * from "./env";export * from "./database";export * from "./link";+export * from "./role";export * from "./slug";export * from "./plan";export * from "./task";diff --git a/frontend/src/utils/role.ts b/frontend/src/utils/role.tsnew file mode 100644index 0000000000..f31334975b--- /dev/null+++ b/frontend/src/utils/role.ts@@ -0,0 +1,17 @@+import { RoleType } from "../types";+import { feature } from "./plan";++// Returns true if admin feature is NOT supported or the principal is OWNER+export function isOwner(role: RoleType): boolean {+ return !feature("bytebase.admin") || role == "OWNER";+}++// Returns true if admin feature is NOT supported or the principal DBA or OWNER+export function isDBA(role: RoleType): boolean {+ return !feature("bytebase.admin") || role == "DBA" || role == "OWNER";+}++// Returns true if admin feature is NOT supported or the principal is DEVELOPER+export function isDeveloper(role: RoleType): boolean {+ return !feature("bytebase.admin") || role == "DEVELOPER";+}diff --git a/frontend/src/views/DashboardHeader.vue b/frontend/src/views/DashboardHeader.vueindex 34bba882af..5f6e128342 100644--- a/frontend/src/views/DashboardHeader.vue+++ b/frontend/src/views/DashboardHeader.vue@@ -174,13 +174,6 @@ export default {const currentUser = computed(() => store.getters["auth/currentUser"]());- const role = computed(() => {- const role = currentUser.value.role;- return role == "DBA"- ? role- : role.charAt(0).toUpperCase() + role.slice(1).toLowerCase();- });-const switchToOwner = () => {store.dispatch("auth/login", {email: "[email protected]",@@ -205,7 +198,6 @@ export default {return {state,currentUser,- role,switchToOwner,switchToDBA,switchToDeveloper,diff --git a/frontend/src/views/DataSourceDetail.vue b/frontend/src/views/DataSourceDetail.vueindex 35bf8bb211..344f8e7da7 100644--- a/frontend/src/views/DataSourceDetail.vue+++ b/frontend/src/views/DataSourceDetail.vue@@ -164,7 +164,7 @@ import cloneDeep from "lodash-es/cloneDeep";import isEqual from "lodash-es/isEqual";import DataSourceConnectionPanel from "../components/DataSourceConnectionPanel.vue";import DataSourceMemberTable from "../components/DataSourceMemberTable.vue";-import { idFromSlug } from "../utils";+import { idFromSlug, isDBA } from "../utils";import { DataSource, Principal } from "../types";interface LocalState {@@ -206,9 +206,7 @@ export default {);const allowEdit = computed(() => {- return (- currentUser.value.role == "OWNER" || currentUser.value.role == "DBA"- );+ return isDBA(currentUser.value.role);});const allowSave = computed(() => {diff --git a/frontend/src/views/DatabaseDetail.vue b/frontend/src/views/DatabaseDetail.vueindex 30d3a40ac0..34b3c41aba 100644--- a/frontend/src/views/DatabaseDetail.vue+++ b/frontend/src/views/DatabaseDetail.vue@@ -112,9 +112,9 @@</div><div class="space-y-4"><div v-for="(ds, index) of item.list" :key="index">- <!-- Only displays the data source link for DBA and above. Since for now+ <!-- Only displays the data source link for DBA. Since for nowwe don't need to expose the data source concept to the end user -->- <div v-if="isDBAorAbove" class="relative mb-2">+ <div v-if="isCurrentUserDBA" class="relative mb-2"><divclass="absolute inset-0 flex items-center"aria-hidden="true"@@ -150,7 +150,7 @@ import { useRouter } from "vue-router";import DataSourceTable from "../components/DataSourceTable.vue";import DataSourceConnectionPanel from "../components/DataSourceConnectionPanel.vue";import PrincipalSelect from "../components/PrincipalSelect.vue";-import { idFromSlug } from "../utils";+import { idFromSlug, isDBA } from "../utils";import { PrincipalId, DataSource } from "../types";interface LocalState {@@ -198,15 +198,13 @@ export default {watchEffect(prepareDataSourceList);- const isDBAorAbove = computed(() => {- return (- currentUser.value.role == "DBA" || currentUser.value.role == "OWNER"- );+ const isCurrentUserDBA = computed((): boolean => {+ return isDBA(currentUser.value.role);});const allowChangeOwner = computed(() => {return (- currentUser.value.id == database.value.ownerId || isDBAorAbove.value+ currentUser.value.id == database.value.ownerId || isCurrentUserDBA.value);});@@ -215,8 +213,8 @@ export default {database.value.id).filter((dataSource: DataSource) => {return (- isDBAorAbove.value ||- // If the current user is not DBAorAbove, we will only show the granted data source.+ isCurrentUserDBA.value ||+ // If the current user is not DBA, we will only show the granted data source.dataSource.memberList.find((item) => {return item.principal.id == currentUser.value.id;})@@ -252,7 +250,7 @@ export default {return {state,database,- isDBAorAbove,+ isCurrentUserDBA,allowChangeOwner,readWriteDataSourceList,readOnlyDataSourceList,diff --git a/frontend/src/views/TaskSidebar.vue b/frontend/src/views/TaskSidebar.vueindex 15eb3b20eb..370d6c7fbe 100644--- a/frontend/src/views/TaskSidebar.vue+++ b/frontend/src/views/TaskSidebar.vue@@ -153,6 +153,7 @@ import {DatabaseFieldPayload,} from "../plugins";import { DatabaseId, EnvironmentId, Task } from "../types";+import { isDBA } from "../utils";interface LocalState {}@@ -198,16 +199,15 @@ export default {});const allowEditAssignee = computed(() => {- // We allow the current assignee or DBA/Owner to re-assign the task.- // Though only DBA/Owner can be assigned to the task, the current- // assignee might not have DBA/Owner role in case its role is revoked after+ // We allow the current assignee or DBA to re-assign the task.+ // Though only DBA can be assigned to the task, the current+ // assignee might not have DBA role in case its role is revoked after// being assigned to the task.return (props.new ||(props.task.status == "OPEN" &&(currentUser.value.id == props.task.assignee?.id ||- currentUser.value.role == "DBA" ||- currentUser.value.role == "OWNER"))+ isDBA(currentUser.value.role))));});