Skip to content

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

chore: retire use projects by current user (#10490)

boojack48b4f4802323
diff --git a/frontend/.vscode/settings.json b/frontend/.vscode/settings.json
index 474cc06b95..6c45780c07 100644
--- a/frontend/.vscode/settings.json
+++ b/frontend/.vscode/settings.json
@@ -14,7 +14,7 @@
"vue"
],
"editor.codeActionsOnSave": {
- "source.fixAll.eslint": true
+ "source.fixAll.eslint": "explicit"
},
"files.associations": {
"*.vue": "vue"
diff --git a/frontend/src/components/CustomApproval/Settings/components/common/utils.ts b/frontend/src/components/CustomApproval/Settings/components/common/utils.ts
index bf2bbcee03..97079a4643 100644
--- a/frontend/src/components/CustomApproval/Settings/components/common/utils.ts
+++ b/frontend/src/components/CustomApproval/Settings/components/common/utils.ts
@@ -2,7 +2,7 @@ import { uniq, without } from "lodash-es";
import type { SelectOption } from "naive-ui";
import { type Factor, SQLTypeList } from "@/plugins/cel";
import { t, te } from "@/plugins/i18n";
-import { useEnvironmentV1Store, useProjectV1ListByCurrentUser } from "@/store";
+import { useEnvironmentV1Store, useProjectV1List } from "@/store";
import {
engineName,
PresetRiskLevelList,
@@ -140,7 +140,7 @@ const getEnvironmentIdOptions = () => {
};
const getProjectIdOptions = () => {
- const { projectList } = useProjectV1ListByCurrentUser();
+ const { projectList } = useProjectV1List();
return projectList.value
.filter((proj) => proj.name != DEFAULT_PROJECT_V1_NAME)
.map<SelectOption>((proj) => {
diff --git a/frontend/src/components/IssueV1/components/IssueSearch/useSearchScopeOptions.ts b/frontend/src/components/IssueV1/components/IssueSearch/useSearchScopeOptions.ts
index d0dc1764e8..7b0a1a6b06 100644
--- a/frontend/src/components/IssueV1/components/IssueSearch/useSearchScopeOptions.ts
+++ b/frontend/src/components/IssueV1/components/IssueSearch/useSearchScopeOptions.ts
@@ -15,10 +15,10 @@ import {
useCurrentUserV1,
useDatabaseV1Store,
useInstanceV1List,
- useProjectV1ListByCurrentUser,
useSearchDatabaseV1List,
useUserStore,
useEnvironmentV1List,
+ useProjectV1List,
} from "@/store";
import { SYSTEM_BOT_EMAIL, UNKNOWN_ID } from "@/types";
import { engineToJSON } from "@/types/proto/v1/common";
@@ -55,7 +55,7 @@ export const useSearchScopeOptions = (
const userStore = useUserStore();
const databaseV1Store = useDatabaseV1Store();
const environmentList = useEnvironmentV1List(false /* !showDeleted */);
- const { projectList } = useProjectV1ListByCurrentUser();
+ const { projectList } = useProjectV1List();
const { instanceList } = useInstanceV1List(false /* !showDeleted */);
const { databaseList } = useSearchDatabaseV1List({
parent: "instances/-",
diff --git a/frontend/src/components/KBar/useProjectActions.ts b/frontend/src/components/KBar/useProjectActions.ts
index f58b5487e6..c67a3ccb26 100644
--- a/frontend/src/components/KBar/useProjectActions.ts
+++ b/frontend/src/components/KBar/useProjectActions.ts
@@ -2,7 +2,7 @@ import { Action, defineAction, useRegisterActions } from "@bytebase/vue-kbar";
import { computed } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
-import { useCurrentUserV1, useProjectV1ListByCurrentUser } from "@/store";
+import { useCurrentUserV1, useProjectV1List } from "@/store";
import { DEFAULT_PROJECT_ID } from "@/types";
import { isMemberOfProjectV1 } from "@/utils";
@@ -10,7 +10,7 @@ export const useProjectActions = () => {
const { t } = useI18n();
const router = useRouter();
const me = useCurrentUserV1();
- const { projectList } = useProjectV1ListByCurrentUser();
+ const { projectList } = useProjectV1List();
const accessibleProjectList = computed(() => {
return projectList.value.filter((project) => {
diff --git a/frontend/src/components/Project/ProjectSwitchModal.vue b/frontend/src/components/Project/ProjectSwitchModal.vue
index 7967539733..e65d8ef65a 100644
--- a/frontend/src/components/Project/ProjectSwitchModal.vue
+++ b/frontend/src/components/Project/ProjectSwitchModal.vue
@@ -54,7 +54,7 @@ import { useI18n } from "vue-i18n";
import { useRecentProjects } from "@/components/Project/useRecentProjects";
import { SearchBox, ProjectV1Table } from "@/components/v2";
import { Drawer } from "@/components/v2";
-import { useProjectV1ListByCurrentUser } from "@/store";
+import { useProjectV1List } from "@/store";
import {
DEFAULT_PROJECT_ID,
UNKNOWN_PROJECT_NAME,
@@ -83,7 +83,7 @@ const state = reactive<LocalState>({
showCreateDrawer: false,
selectedTab: "all",
});
-const { projectList } = useProjectV1ListByCurrentUser();
+const { projectList } = useProjectV1List();
const { recentViewProjects } = useRecentProjects();
onMounted(() => {
diff --git a/frontend/src/components/QuickActionPanel.vue b/frontend/src/components/QuickActionPanel.vue
index 3cd80ca010..5c233a80f0 100644
--- a/frontend/src/components/QuickActionPanel.vue
+++ b/frontend/src/components/QuickActionPanel.vue
@@ -125,9 +125,9 @@ import {
useInstanceV1Store,
useCommandStore,
useCurrentUserIamPolicy,
- useProjectV1ListByCurrentUser,
useSubscriptionV1Store,
useProjectV1Store,
+ useProjectV1List,
} from "@/store";
import { projectNamePrefix } from "@/store/modules/v1/common";
import {
@@ -196,7 +196,7 @@ const project = computed(() => {
// Only show alter schema and change data if the user has permission to alter schema of at least one project.
const shouldShowAlterDatabaseEntries = computed(() => {
- const { projectList } = useProjectV1ListByCurrentUser();
+ const { projectList } = useProjectV1List();
const currentUserIamPolicy = useCurrentUserIamPolicy();
return projectList.value
.map((project) => {
diff --git a/frontend/src/components/SensitiveData/components/utils.ts b/frontend/src/components/SensitiveData/components/utils.ts
index 0f4fc05848..261116f299 100644
--- a/frontend/src/components/SensitiveData/components/utils.ts
+++ b/frontend/src/components/SensitiveData/components/utils.ts
@@ -9,7 +9,7 @@ import {
import {
useEnvironmentV1Store,
useInstanceV1List,
- useProjectV1ListByCurrentUser,
+ useProjectV1List,
useSettingV1Store,
} from "@/store";
import { DEFAULT_PROJECT_V1_NAME } from "@/types";
@@ -62,7 +62,7 @@ export const getInstanceIdOptions = () => {
};
export const getProjectIdOptions = () => {
- const { projectList } = useProjectV1ListByCurrentUser();
+ const { projectList } = useProjectV1List();
return projectList.value
.filter((proj) => proj.name != DEFAULT_PROJECT_V1_NAME)
.map<SelectOption>((proj) => {
diff --git a/frontend/src/components/v2/Select/ProjectSelect.vue b/frontend/src/components/v2/Select/ProjectSelect.vue
index 7779099ead..5c4b36c636 100644
--- a/frontend/src/components/v2/Select/ProjectSelect.vue
+++ b/frontend/src/components/v2/Select/ProjectSelect.vue
@@ -18,11 +18,7 @@ import { intersection } from "lodash-es";
import { NSelect, SelectOption } from "naive-ui";
import { computed, watchEffect } from "vue";
import { useI18n } from "vue-i18n";
-import {
- useCurrentUserV1,
- useProjectV1Store,
- useProjectV1ListByCurrentUser,
-} from "@/store";
+import { useCurrentUserV1, useProjectV1Store, useProjectV1List } from "@/store";
import { DEFAULT_PROJECT_ID, UNKNOWN_ID, unknownProject } from "@/types";
import { State } from "@/types/proto/v1/common";
import {
@@ -81,7 +77,7 @@ const hasWorkspaceManageProjectPermission = computed(() =>
hasWorkspacePermissionV2(currentUserV1.value, "bb.projects.list")
);
-const { projectList } = useProjectV1ListByCurrentUser();
+const { projectList } = useProjectV1List();
const rawProjectList = computed(() => {
return projectList.value.filter((project) => {
diff --git a/frontend/src/store/modules/v1/project.ts b/frontend/src/store/modules/v1/project.ts
index a4764e135c..1c16db73a7 100644
--- a/frontend/src/store/modules/v1/project.ts
+++ b/frontend/src/store/modules/v1/project.ts
@@ -12,7 +12,6 @@ import {
UNKNOWN_ID,
UNKNOWN_PROJECT_NAME,
} from "@/types";
-import { User } from "@/types/proto/v1/auth_service";
import { State } from "@/types/proto/v1/common";
import { Project } from "@/types/proto/v1/project_service";
import { hasWorkspacePermissionV2 } from "@/utils";
@@ -62,21 +61,6 @@ export const useProjectV1Store = defineStore("project_v1", () => {
(project) => project.state === State.ACTIVE
);
};
- const getProjectListByUser = (user: User, showDeleted = false) => {
- const canManageProject = hasWorkspacePermissionV2(user, "bb.projects.list");
- const projectList = getProjectList(showDeleted);
- if (canManageProject) {
- return projectList;
- }
-
- return projectList.filter((project) => {
- return project.iamPolicy.bindings.some((binding) => {
- return binding.members.some((email) => {
- return email === `user:${unref(user).email}`;
- });
- });
- });
- };
const getProjectByName = (name: string) => {
if (name === EMPTY_PROJECT_NAME) return emptyProject();
if (name === UNKNOWN_PROJECT_NAME) return unknownProject();
@@ -154,7 +138,6 @@ export const useProjectV1Store = defineStore("project_v1", () => {
projectMapByName,
projectList,
getProjectList,
- getProjectListByUser,
upsertProjectMap,
getProjectByUID,
getProjectByName,
@@ -192,22 +175,6 @@ export const useProjectV1List = (
return { projectList, ready };
};
-export const useProjectV1ListByUser = (
- user: MaybeRef<User>,
- showDeleted: MaybeRef<boolean> = false
-) => {
- const store = useProjectV1Store();
- const { ready } = useProjectV1List(showDeleted);
- const projectList = computed(() => {
- return store.getProjectListByUser(unref(user), unref(showDeleted));
- });
- return { projectList, ready };
-};
-
-export const useProjectV1ListByCurrentUser = (
- showDeleted: MaybeRef<boolean> = false
-) => useProjectV1ListByUser(useCurrentUserV1(), showDeleted);
-
export const useProjectV1ByUID = (uid: MaybeRef<string>) => {
const store = useProjectV1Store();
const ready = ref(false);
diff --git a/frontend/src/utils/iam/permission.ts b/frontend/src/utils/iam/permission.ts
index bbd9cc480a..8464369eb2 100644
--- a/frontend/src/utils/iam/permission.ts
+++ b/frontend/src/utils/iam/permission.ts
@@ -1,8 +1,4 @@
-import {
- useActuatorV1Store,
- useProjectV1ListByUser,
- useRoleStore,
-} from "@/store";
+import { useActuatorV1Store, useProjectV1List, useRoleStore } from "@/store";
import {
ComposedProject,
PresetRoleType,
@@ -31,7 +27,7 @@ export const hasProjectPermissionV2 = (
): boolean => {
// If the project is not provided, then check if the user has the given permission on any project in the workspace.
if (!project) {
- const { projectList } = useProjectV1ListByUser(user);
+ const { projectList } = useProjectV1List();
return projectList.value.some((project) =>
hasProjectPermissionV2(project, user, permission)
);
@@ -74,7 +70,7 @@ export const hasWorkspaceLevelProjectPermission = (
user: User,
permission: ProjectPermission
): boolean => {
- const { projectList } = useProjectV1ListByUser(user);
+ const { projectList } = useProjectV1List();
return projectList.value.some((project) =>
hasProjectPermissionV2(project, user, permission)
);
diff --git a/frontend/src/views/Archive.vue b/frontend/src/views/Archive.vue
index 325a09e1f9..ed4932965a 100644
--- a/frontend/src/views/Archive.vue
+++ b/frontend/src/views/Archive.vue
@@ -46,7 +46,7 @@ import {
useEnvironmentV1Store,
useIdentityProviderStore,
useInstanceV1Store,
- useProjectV1ListByCurrentUser,
+ useProjectV1List,
} from "@/store";
import { State } from "@/types/proto/v1/common";
import { IdentityProvider } from "@/types/proto/v1/idp_service";
@@ -70,7 +70,7 @@ const state = reactive<LocalState>({
const currentUserV1 = useCurrentUserV1();
-const { projectList } = useProjectV1ListByCurrentUser(true /* showDeleted */);
+const { projectList } = useProjectV1List(true /* showDeleted */);
const prepareList = () => {
if (hasWorkspacePermissionV2(currentUserV1.value, "bb.instances.list")) {
diff --git a/frontend/src/views/DatabaseDashboard.vue b/frontend/src/views/DatabaseDashboard.vue
index 00261aae96..e0b285496f 100644
--- a/frontend/src/views/DatabaseDashboard.vue
+++ b/frontend/src/views/DatabaseDashboard.vue
@@ -69,7 +69,7 @@ import {
useDBGroupStore,
useDatabaseV1Store,
usePageMode,
- useProjectV1ListByCurrentUser,
+ useProjectV1List,
useUIStateStore,
} from "@/store";
import {
@@ -99,7 +99,7 @@ interface LocalState {
}
const uiStateStore = useUIStateStore();
-const { projectList } = useProjectV1ListByCurrentUser();
+const { projectList } = useProjectV1List();
const pageMode = usePageMode();
const state = reactive<LocalState>({
diff --git a/frontend/src/views/ExportCenter/index.vue b/frontend/src/views/ExportCenter/index.vue
index 3afad50e77..08265935ff 100644
--- a/frontend/src/views/ExportCenter/index.vue
+++ b/frontend/src/views/ExportCenter/index.vue
@@ -59,7 +59,7 @@ import {
useDatabaseV1Store,
useInstanceV1Store,
useProjectIamPolicyStore,
- useProjectV1ListByCurrentUser,
+ useProjectV1List,
useProjectV1Store,
} from "@/store";
import { UNKNOWN_ID, PresetRoleType } from "@/types";
@@ -84,7 +84,7 @@ const projectIamPolicyStore = useProjectIamPolicyStore();
const databaseStore = useDatabaseV1Store();
const projectStore = useProjectV1Store();
const instanceStore = useInstanceV1Store();
-const { projectList } = useProjectV1ListByCurrentUser();
+const { projectList } = useProjectV1List();
const state = reactive<LocalState>({
exportRecords: [],
showRequestExportPanel: false,
diff --git a/frontend/src/views/ProjectDashboard.vue b/frontend/src/views/ProjectDashboard.vue
index c92d18b5d9..2ecd958172 100644
--- a/frontend/src/views/ProjectDashboard.vue
+++ b/frontend/src/views/ProjectDashboard.vue
@@ -15,7 +15,7 @@
<script lang="ts" setup>
import { computed, onMounted, reactive } from "vue";
import { SearchBox, ProjectV1Table } from "@/components/v2";
-import { useUIStateStore, useProjectV1ListByCurrentUser } from "@/store";
+import { useUIStateStore, useProjectV1List } from "@/store";
import { DEFAULT_PROJECT_ID } from "@/types";
import { filterProjectV1ListByKeyword } from "@/utils";
@@ -26,7 +26,7 @@ interface LocalState {
const state = reactive<LocalState>({
searchText: "",
});
-const { projectList } = useProjectV1ListByCurrentUser();
+const { projectList } = useProjectV1List();
const filteredProjectList = computed(() => {
const list = projectList.value.filter(