Skip to content

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

chore: list issue with permission (#8432)

ecmadaoeefa2e0d6ab2
diff --git a/frontend/src/components/AdvancedSearch.vue b/frontend/src/components/AdvancedSearch.vue
index 72f7aeedf8..dda3a12a27 100644
--- a/frontend/src/components/AdvancedSearch.vue
+++ b/frontend/src/components/AdvancedSearch.vue
@@ -73,6 +73,7 @@ import {
DatabaseV1Name,
} from "@/components/v2";
import {
+ useCurrentUserV1,
useProjectV1ListByCurrentUser,
useInstanceV1List,
useSearchDatabaseV1List,
@@ -89,6 +90,7 @@ import {
environmentV1Name,
extractProjectResourceName,
extractInstanceResourceName,
+ hasWorkspacePermissionV1,
} from "@/utils";
export type SearchScopeId =
@@ -98,7 +100,8 @@ export type SearchScopeId =
| "type"
| "creator"
| "assignee"
- | "subscriber";
+ | "subscriber"
+ | "principal";
export interface SearchParams {
query: string;
@@ -158,11 +161,12 @@ const buildSearchTextByParams = (params: SearchParams | undefined): string => {
const state = reactive<LocalState>({
searchText: buildSearchTextByParams(props.params),
- showSearchScopes: false,
+ showSearchScopes: props.autofocus,
});
const inputRef = ref<InstanceType<typeof NInput>>();
const userStore = useUserStore();
const databaseV1Store = useDatabaseV1Store();
+const currentUserV1 = useCurrentUserV1();
watch(
() => state.showSearchScopes,
@@ -189,10 +193,17 @@ const principalSearchOptions = computed(() => {
});
});
+const hasPermission = computed(() => {
+ return hasWorkspacePermissionV1(
+ "bb.permission.workspace.manage-issue",
+ currentUserV1.value.userRole
+ );
+});
+
// fullScopes provides full search scopes and options.
// we need this as the source of truth.
const fullScopes = computed((): SearchScope[] => {
- return [
+ const scopes: SearchScope[] = [
{
id: "project",
title: t("issue.advanced-search.scope.project.title"),
@@ -260,25 +271,36 @@ const fullScopes = computed((): SearchScope[] => {
},
],
},
- {
- id: "creator",
- title: t("issue.advanced-search.scope.creator.title"),
- description: t("issue.advanced-search.scope.creator.description"),
- options: principalSearchOptions.value,
- },
- {
- id: "assignee",
- title: t("issue.advanced-search.scope.assignee.title"),
- description: t("issue.advanced-search.scope.assignee.description"),
- options: principalSearchOptions.value,
- },
- {
- id: "subscriber",
- title: t("issue.advanced-search.scope.subscriber.title"),
- description: t("issue.advanced-search.scope.subscriber.description"),
- options: principalSearchOptions.value,
- },
];
+ if (hasPermission.value) {
+ scopes.push(
+ {
+ id: "creator",
+ title: t("issue.advanced-search.scope.creator.title"),
+ description: t("issue.advanced-search.scope.creator.description"),
+ options: principalSearchOptions.value,
+ },
+ {
+ id: "assignee",
+ title: t("issue.advanced-search.scope.assignee.title"),
+ description: t("issue.advanced-search.scope.assignee.description"),
+ options: principalSearchOptions.value,
+ },
+ {
+ id: "subscriber",
+ title: t("issue.advanced-search.scope.subscriber.title"),
+ description: t("issue.advanced-search.scope.subscriber.description"),
+ options: principalSearchOptions.value,
+ },
+ {
+ id: "principal",
+ title: t("issue.advanced-search.scope.principal.title"),
+ description: t("issue.advanced-search.scope.principal.description"),
+ options: principalSearchOptions.value,
+ }
+ );
+ }
+ return scopes;
});
// filteredScopes will filter search options by chosed scope.
@@ -331,6 +353,21 @@ const searchScopes = computed((): SearchScope[] => {
if (existedScope.has(scope.id)) {
return false;
}
+ // The principal scope cannot used with creator/assignee/subscriber
+ if (scope.id === "principal") {
+ return (
+ !existedScope.has("creator") &&
+ !existedScope.has("assignee") &&
+ !existedScope.has("subscriber")
+ );
+ }
+ if (
+ scope.id === "creator" ||
+ scope.id === "assignee" ||
+ scope.id === "subscriber"
+ ) {
+ return !existedScope.has("principal");
+ }
return true;
});
});
diff --git a/frontend/src/components/IssueV1/components/WaitingForMyApprovalIssueTableV1.vue b/frontend/src/components/IssueV1/components/WaitingForMyApprovalIssueTableV1.vue
index f6ee2bbcc2..13103916dc 100644
--- a/frontend/src/components/IssueV1/components/WaitingForMyApprovalIssueTableV1.vue
+++ b/frontend/src/components/IssueV1/components/WaitingForMyApprovalIssueTableV1.vue
@@ -4,7 +4,7 @@
:session-key="sessionKey"
:page-size="20"
:issue-filter="{
- project: 'projects/-',
+ project,
query: '',
statusList: [IssueStatus.OPEN],
}"
@@ -29,6 +29,7 @@ import PagedIssueTableV1 from "./PagedIssueTableV1.vue";
defineProps<{
sessionKey: string;
+ project: string;
}>();
const currentUserName = computed(() => useAuthStore().currentUser.name);
diff --git a/frontend/src/components/ProjectOverviewPanel.vue b/frontend/src/components/ProjectOverviewPanel.vue
index ff1f07986f..4229cbe51c 100644
--- a/frontend/src/components/ProjectOverviewPanel.vue
+++ b/frontend/src/components/ProjectOverviewPanel.vue
@@ -82,11 +82,7 @@
<WaitingForMyApprovalIssueTableV1
v-if="hasCustomApprovalFeature"
session-key="project-waiting-approval"
- method="LIST"
- :issue-filter="{
- ...commonIssueFilter,
- statusList: [IssueStatus.OPEN],
- }"
+ :project="commonIssueFilter.project"
>
<template #table="{ issueList, loading }">
<IssueTableV1
@@ -163,9 +159,11 @@
import { reactive, PropType, computed, watch } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
-import { featureToRef } from "@/store";
+import { featureToRef, useCurrentUserV1 } from "@/store";
+import { userNamePrefix } from "@/store/modules/v1/common";
import { IssueStatus } from "@/types/proto/v1/issue_service";
import { Project } from "@/types/proto/v1/project_service";
+import { hasWorkspacePermissionV1 } from "@/utils";
import { ComposedIssue, IssueFilter } from "../types";
import IssueTableV1 from "./IssueV1/components/IssueTableV1.vue";
import PagedIssueTableV1 from "./IssueV1/components/PagedIssueTableV1.vue";
@@ -196,8 +194,15 @@ const state = reactive<LocalState>({
});
const { t } = useI18n();
const router = useRouter();
+const currentUserV1 = useCurrentUserV1();
const hasCustomApprovalFeature = featureToRef("bb.feature.custom-approval");
+const hasPermission = computed(() => {
+ return hasWorkspacePermissionV1(
+ "bb.permission.workspace.manage-issue",
+ currentUserV1.value.userRole
+ );
+});
const tabItemList = computed((): TabFilterItem<TabValue>[] => {
const WAITING_APPROVAL: TabFilterItem<TabValue> = {
@@ -213,9 +218,14 @@ const tabItemList = computed((): TabFilterItem<TabValue>[] => {
});
const commonIssueFilter = computed((): IssueFilter => {
+ let principal = "";
+ if (!hasPermission.value) {
+ principal = `${userNamePrefix}${currentUserV1.value.email}`;
+ }
return {
project: props.project.name,
query: "",
+ principal,
};
});
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index d4cecb8fc3..b3fe59c3fd 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -850,6 +850,10 @@
"subscriber": {
"title": "Subscriber",
"description": "Search by the issue subscriber"
+ },
+ "principal": {
+ "title": "Related Principal",
+ "description": "Search by the issue creator, assignee or subscriber"
}
}
},
@@ -1611,7 +1615,7 @@
"view-all": "View all",
"view-all-closed": "View all closed",
"recent-activity": "Recent @.lower:{'common.activities'}",
- "in-progress": "In progress",
+ "in-progress": "In Progress",
"recently-closed": "Recently Closed",
"info-slot-content": "Bytebase periodically syncs the instance schema. Newly synced databases are first placed here. User should transfer them to the proper application project.",
"no-db-prompt": "No database belongs to this project. You can add database by clicking {newDb} or {transferInDb} from the top action bar."
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 1545fe42af..4839d262e4 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -849,6 +849,10 @@
"subscriber": {
"title": "Abonado",
"description": "Buscar por suscriptor del problema"
+ },
+ "principal": {
+ "title": "Director relacionado",
+ "description": "Búsqueda por creador del problema, cesionario o suscriptor"
}
}
},
@@ -1610,7 +1614,7 @@
"view-all": "Ver todo",
"view-all-closed": "Ver todos los cerrados",
"recent-activity": "Actividades recientes @.lower:{'common.activities'}",
- "in-progress": "En progreso",
+ "in-progress": "En curso",
"recently-closed": "Recientemente cerrado",
"info-slot-content": "Bytebase sincroniza periódicamente el esquema de la instancia. Las bases de datos recién sincronizadas se colocan aquí primero. El usuario debe transferirlas al proyecto de aplicación adecuado.",
"no-db-prompt": "No hay bases de datos que pertenezcan a este proyecto. Puedes agregar bases de datos haciendo clic en {newDb} o {transferInDb} desde la barra de acciones superior."
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 5fd3f25fb4..f3b401cb45 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -847,6 +847,10 @@
"subscriber": {
"title": "订阅人",
"description": "根据工单订阅人搜索"
+ },
+ "principal": {
+ "title": "相关用户",
+ "description": "工单的创建人、发布人,或者订阅人"
}
}
},
diff --git a/frontend/src/views/Home.vue b/frontend/src/views/Home.vue
index 8ee3906d7c..41c88b9131 100644
--- a/frontend/src/views/Home.vue
+++ b/frontend/src/views/Home.vue
@@ -17,6 +17,7 @@
<WaitingForMyApprovalIssueTableV1
v-if="hasCustomApprovalFeature"
session-key="home-waiting-approval"
+ :project="commonIssueFilter.project"
>
<template #table="{ issueList, loading }">
<IssueTableV1
@@ -38,7 +39,7 @@
:issue-filter="{
...commonIssueFilter,
statusList: [IssueStatus.OPEN],
- assignee: `users/${currentUserV1.email}`,
+ assignee: `${userNamePrefix}${currentUserV1.email}`,
}"
:page-size="OPEN_ISSUE_LIST_PAGE_SIZE"
>
@@ -62,7 +63,7 @@
:issue-filter="{
...commonIssueFilter,
statusList: [IssueStatus.OPEN],
- creator: `users/${currentUserV1.email}`,
+ creator: `${userNamePrefix}${currentUserV1.email}`,
}"
:page-size="OPEN_ISSUE_LIST_PAGE_SIZE"
>
@@ -86,7 +87,7 @@
:issue-filter="{
...commonIssueFilter,
statusList: [IssueStatus.OPEN],
- subscriber: `users/${currentUserV1.email}`,
+ subscriber: `${userNamePrefix}${currentUserV1.email}`,
}"
:page-size="OPEN_ISSUE_LIST_PAGE_SIZE"
>
@@ -111,7 +112,7 @@
:issue-filter="{
...commonIssueFilter,
statusList: [IssueStatus.DONE, IssueStatus.CANCELED],
- principal: `users/${currentUserV1.email}`,
+ principal: `${userNamePrefix}${currentUserV1.email}`,
}"
:page-size="MAX_CLOSED_ISSUE"
:hide-load-more="true"
@@ -214,6 +215,7 @@ import {
featureToRef,
useCurrentUserV1,
} from "@/store";
+import { userNamePrefix } from "@/store/modules/v1/common";
import { IssueStatus } from "@/types/proto/v1/issue_service";
import { ComposedIssue, IssueFilter, planTypeToString } from "../types";
import { extractUserUID } from "../utils";
diff --git a/frontend/src/views/IssueDashboard.vue b/frontend/src/views/IssueDashboard.vue
index f95e29bea8..133d512929 100644
--- a/frontend/src/views/IssueDashboard.vue
+++ b/frontend/src/views/IssueDashboard.vue
@@ -69,7 +69,6 @@
<div v-show="state.tab === 'CLOSED'" class="mt-2">
<!-- show all DONE and CANCELED issues with pageSize=10 -->
<PagedIssueTableV1
- v-if="showClosed"
session-key="dashboard-closed"
method="SEARCH"
:issue-filter="{
@@ -105,7 +104,13 @@ import AdvancedSearch, {
import IssueTableV1 from "@/components/IssueV1/components/IssueTableV1.vue";
import PagedIssueTableV1 from "@/components/IssueV1/components/PagedIssueTableV1.vue";
import { SearchBox, TabFilterItem } from "@/components/v2";
-import { useProjectV1Store, useDatabaseV1Store, hasFeature } from "@/store";
+import {
+ useCurrentUserV1,
+ useProjectV1Store,
+ useUserStore,
+ useDatabaseV1Store,
+ hasFeature,
+} from "@/store";
import {
projectNamePrefix,
userNamePrefix,
@@ -113,7 +118,11 @@ import {
} from "@/store/modules/v1/common";
import { UNKNOWN_ID, IssueFilter, ComposedIssue } from "@/types";
import { IssueStatus } from "@/types/proto/v1/issue_service";
-import { projectV1Slug, extractProjectResourceName } from "@/utils";
+import {
+ projectV1Slug,
+ extractProjectResourceName,
+ hasWorkspacePermissionV1,
+} from "@/utils";
const TABS = ["OPEN", "CLOSED"] as const;
@@ -131,10 +140,15 @@ const route = useRoute();
const { t } = useI18n();
const projectV1Store = useProjectV1Store();
const databaseV1Store = useDatabaseV1Store();
-
-const statusList = computed((): string[] =>
- route.query.status ? (route.query.status as string).split(",") : []
-);
+const userStore = useUserStore();
+const currentUserV1 = useCurrentUserV1();
+
+const hasPermission = computed(() => {
+ return hasWorkspacePermissionV1(
+ "bb.permission.workspace.manage-issue",
+ currentUserV1.value.userRole
+ );
+});
const autofocus = computed((): boolean => {
return !!route.query.autofocus;
@@ -142,23 +156,28 @@ const autofocus = computed((): boolean => {
const initSearchParams = computed((): SearchParams => {
const projectName = project.value?.name ?? "";
+ const userEmail = selectedPrincipal.value?.email ?? "";
const query = (route.query.query as string) ?? "";
- if (!projectName) {
- return {
- query,
- scopes: [],
- };
- }
- return {
+ const params: SearchParams = {
query,
- scopes: [
- {
- id: "project",
- value: extractProjectResourceName(projectName),
- },
- ],
+ scopes: [],
};
+
+ if (projectName) {
+ params.scopes.push({
+ id: "project",
+ value: extractProjectResourceName(projectName),
+ });
+ }
+ if (userEmail && hasPermission.value) {
+ params.scopes.push({
+ id: "principal",
+ value: userEmail,
+ });
+ }
+
+ return params;
});
const state = reactive<LocalState>({
@@ -180,13 +199,6 @@ const project = computed(() => {
return undefined;
});
-const showOpen = computed(
- () => statusList.value.length === 0 || statusList.value.includes("open")
-);
-const showClosed = computed(
- () => statusList.value.length === 0 || statusList.value.includes("closed")
-);
-
const tabItemList = computed((): TabFilterItem<TabValue>[] => {
const OPEN: TabFilterItem<TabValue> = {
value: "OPEN",
@@ -196,14 +208,7 @@ const tabItemList = computed((): TabFilterItem<TabValue>[] => {
value: "CLOSED",
label: t("issue.table.closed"),
};
- const list: TabFilterItem<TabValue>[] = [];
- if (showOpen.value) {
- list.push(OPEN);
- }
- if (showClosed.value) {
- list.push(CLOSED);
- }
- return list;
+ return [OPEN, CLOSED];
});
// timeRangeLimitForFreePlanInTs is the search time limit in ts format.
@@ -244,6 +249,14 @@ const selectedProjectId = computed((): string | undefined => {
return project ? (project as string) : undefined;
});
+const selectedPrincipal = computed(() => {
+ const { user } = route.query;
+ if (!user) {
+ return;
+ }
+ return userStore.getUserById(user as string);
+});
+
const filter = (issue: ComposedIssue) => {
const keyword = state.filterText.trim().toLowerCase();
if (keyword) {
@@ -293,6 +306,10 @@ watchEffect(() => {
});
onMounted(() => {
+ const status = ((route.query.status ?? "") as string).toUpperCase() ?? "OPEN";
+ if (status === "CLOSED") {
+ state.tab = "CLOSED";
+ }
state.searchParams = initSearchParams.value;
});
@@ -326,12 +343,10 @@ const issueFilter = computed((): IssueFilter => {
database = db.name;
}
}
- return {
+
+ const filter: IssueFilter = {
query,
instance: getValueFromIssueFilter(instanceNamePrefix, "instance"),
- creator: getValueFromIssueFilter(userNamePrefix, "creator"),
- assignee: getValueFromIssueFilter(userNamePrefix, "assignee"),
- subscriber: getValueFromIssueFilter(userNamePrefix, "subscriber"),
database,
project: `${projectNamePrefix}${projectScope?.value ?? "-"}`,
createdTsAfter: selectedTimeRange.value
@@ -342,5 +357,15 @@ const issueFilter = computed((): IssueFilter => {
: undefined,
type: typeScope?.value,
};
+
+ if (!hasPermission.value) {
+ filter.principal = `${userNamePrefix}${currentUserV1.value.email}`;
+ } else {
+ filter.principal = getValueFromIssueFilter(userNamePrefix, "principal");
+ filter.creator = getValueFromIssueFilter(userNamePrefix, "creator");
+ filter.assignee = getValueFromIssueFilter(userNamePrefix, "assignee");
+ filter.subscriber = getValueFromIssueFilter(userNamePrefix, "subscriber");
+ }
+ return filter;
});
</script>