Skip to content

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

chore: use batchGetUsres (#16100)

boojackc2f41282cf28
diff --git a/frontend/src/components/IssueV1/components/CurrentApproverV1.vue b/frontend/src/components/IssueV1/components/CurrentApproverV1.vue
index 40acd6e25d..b9528ec319 100644
--- a/frontend/src/components/IssueV1/components/CurrentApproverV1.vue
+++ b/frontend/src/components/IssueV1/components/CurrentApproverV1.vue
@@ -65,7 +65,7 @@ const userStore = useUserStore();
const wrappedSteps = useWrappedReviewStepsV1(toRef(props, "issue"), context);
const currentStep = computed(() => {
- return wrappedSteps.value?.find(
+ return wrappedSteps.value.find(
(step) => step.status === "CURRENT" || step.status === "REJECTED"
);
});
diff --git a/frontend/src/components/IssueV1/components/Sidebar/ReviewSection/ReviewSection.vue b/frontend/src/components/IssueV1/components/Sidebar/ReviewSection/ReviewSection.vue
index 38fe946af0..ff20ce03d8 100644
--- a/frontend/src/components/IssueV1/components/Sidebar/ReviewSection/ReviewSection.vue
+++ b/frontend/src/components/IssueV1/components/Sidebar/ReviewSection/ReviewSection.vue
@@ -50,7 +50,7 @@
</NButton>
</div>
<Timeline
- v-else-if="wrappedSteps && wrappedSteps.length > 0"
+ v-else-if="wrappedSteps.length > 0"
:steps="wrappedSteps"
class="mt-1"
/>
diff --git a/frontend/src/components/IssueV1/logic/review.ts b/frontend/src/components/IssueV1/logic/review.ts
index 9e2943ec08..84a778a17f 100644
--- a/frontend/src/components/IssueV1/logic/review.ts
+++ b/frontend/src/components/IssueV1/logic/review.ts
@@ -1,9 +1,9 @@
import { computed, unref, watchEffect } from "vue";
import {
candidatesOfApprovalStepV1,
- batchGetOrFetchUsers,
useCurrentUserV1,
userNamePrefix,
+ useUserStore,
} from "@/store";
import type {
ReviewFlow,
@@ -12,7 +12,11 @@ import type {
WrappedReviewStep,
} from "@/types";
import { emptyFlow } from "@/types";
-import type { ApprovalNode, Issue } from "@/types/proto/v1/issue_service";
+import type {
+ ApprovalNode,
+ ApprovalStep,
+ Issue,
+} from "@/types/proto/v1/issue_service";
import {
ApprovalNode_Type,
Issue_Approver_Status,
@@ -95,6 +99,7 @@ export const useWrappedReviewStepsV1 = (
issue: MaybeRef<ComposedIssue>,
context: ReviewContext
) => {
+ const userStore = useUserStore();
const currentUser = useCurrentUserV1();
// Format: users/{email}
const currentUserName = computed(
@@ -105,14 +110,13 @@ export const useWrappedReviewStepsV1 = (
const { flow } = context;
const approvers = flow.value.approvers;
const steps = flow.value.template.flow?.steps;
- await batchGetOrFetchUsers(
- steps?.map((_, i) => approvers[i]?.principal) ?? []
- );
+ const distinctUsers = steps?.map((_, i) => approvers[i]?.principal) ?? [];
+ await userStore.batchGetUsers(distinctUsers);
});
return computed(() => {
const { flow, done } = context;
- const steps = flow.value.template.flow?.steps;
+ const steps = flow.value.template.flow?.steps || [];
const approvers = flow.value.approvers;
const currentStepIndex = flow.value.currentStepIndex ?? -1;
@@ -141,9 +145,7 @@ export const useWrappedReviewStepsV1 = (
return approvers[index]?.principal;
};
- const candidatesOfStep = (index: number) => {
- const step = steps?.[index];
- if (!step) return [];
+ const candidatesOfStep = (step: ApprovalStep) => {
const users = candidatesOfApprovalStepV1(unref(issue), step);
if (isUserIncludedInList(currentUserName.value, users)) {
const idx = users.indexOf(currentUserName.value);
@@ -155,12 +157,12 @@ export const useWrappedReviewStepsV1 = (
return users;
};
- return steps?.map<WrappedReviewStep>((step, index) => ({
+ return steps.map<WrappedReviewStep>((step, index) => ({
index,
step,
status: statusOfStep(index),
approver: approverOfStep(index),
- candidates: candidatesOfStep(index),
+ candidates: candidatesOfStep(step),
}));
});
};
diff --git a/frontend/src/components/Member/MembersBindingSelect.vue b/frontend/src/components/Member/MembersBindingSelect.vue
index d9bdefc5df..d47c80a34b 100644
--- a/frontend/src/components/Member/MembersBindingSelect.vue
+++ b/frontend/src/components/Member/MembersBindingSelect.vue
@@ -70,7 +70,6 @@ import {
extractGroupEmail,
useUserStore,
useGroupStore,
- batchGetOrFetchUsers,
extractUserId,
} from "@/store";
import { groupNamePrefix } from "@/store/modules/v1/common";
@@ -119,7 +118,7 @@ onMounted(() => {
});
watchEffect(async () => {
- await batchGetOrFetchUsers(
+ await userStore.batchGetUsers(
props.value.map((binding) =>
binding.startsWith(groupBindingPrefix) ? "" : binding
)
diff --git a/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseOperations.vue b/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseOperations.vue
index 27c4bcc621..988374a710 100644
--- a/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseOperations.vue
+++ b/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseOperations.vue
@@ -3,11 +3,11 @@
v-bind="$attrs"
class="text-sm flex flex-col lg:flex-row items-start lg:items-center bg-blue-100 py-3 px-4 text-main gap-y-2 gap-x-4 overflow-x-auto"
>
- {{
+ <span class="whitespace-nowrap">{{
$t("database.selected-n-databases", {
n: databases.length,
})
- }}
+ }}</span>
<div class="flex items-center">
<template v-for="action in actions" :key="action.text">
<NTooltip :disabled="!action.disabled || !action.tooltip(action.text)">
diff --git a/frontend/src/components/v2/Model/Instance/InstanceV1Table/InstanceOperations.vue b/frontend/src/components/v2/Model/Instance/InstanceV1Table/InstanceOperations.vue
index eebd8a003a..6567abd21a 100644
--- a/frontend/src/components/v2/Model/Instance/InstanceV1Table/InstanceOperations.vue
+++ b/frontend/src/components/v2/Model/Instance/InstanceV1Table/InstanceOperations.vue
@@ -3,11 +3,13 @@
v-bind="$attrs"
class="text-sm flex flex-col lg:flex-row items-start lg:items-center bg-blue-100 py-3 px-4 text-main gap-y-2 gap-x-4 overflow-x-auto"
>
- {{
- $t("instance.selected-n-instances", {
- n: instanceList.length,
- })
- }}
+ <span class="whitespace-nowrap">
+ {{
+ $t("instance.selected-n-instances", {
+ n: instanceList.length,
+ })
+ }}
+ </span>
<div class="flex items-center">
<template v-for="action in actions" :key="action.text">
<component :is="action.render()" v-if="action.render" />
diff --git a/frontend/src/store/modules/release.ts b/frontend/src/store/modules/release.ts
index 0b4b0c69a4..6065b5921a 100644
--- a/frontend/src/store/modules/release.ts
+++ b/frontend/src/store/modules/release.ts
@@ -7,7 +7,7 @@ import { isValidReleaseName, unknownRelease, unknownUser } from "@/types";
import { State } from "@/types/proto/v1/common";
import type { DeepPartial, Release } from "@/types/proto/v1/release_service";
import { DEFAULT_PAGE_SIZE } from "./common";
-import { useUserStore, batchGetOrFetchUsers } from "./user";
+import { useUserStore } from "./user";
import { useProjectV1Store, batchGetOrFetchProjects } from "./v1";
import { getProjectNameReleaseId, projectNamePrefix } from "./v1/common";
@@ -121,8 +121,7 @@ export const useReleaseByName = (name: MaybeRef<string>) => {
export const batchComposeRelease = async (releaseList: Release[]) => {
const userStore = useUserStore();
-
- await batchGetOrFetchUsers(releaseList.map((release) => release.creator));
+ await userStore.batchGetUsers(releaseList.map((release) => release.creator));
const composedReleaseList = releaseList.map((release) => {
const composed = release as ComposedRelease;
diff --git a/frontend/src/store/modules/rollout.ts b/frontend/src/store/modules/rollout.ts
index 92935ebda6..49cfcffa42 100644
--- a/frontend/src/store/modules/rollout.ts
+++ b/frontend/src/store/modules/rollout.ts
@@ -6,7 +6,7 @@ import type { MaybeRef, Pagination, ComposedRollout } from "@/types";
import { isValidRolloutName, unknownRollout, unknownUser } from "@/types";
import type { Rollout } from "@/types/proto/v1/rollout_service";
import { DEFAULT_PAGE_SIZE } from "./common";
-import { useUserStore, batchGetOrFetchUsers } from "./user";
+import { useUserStore } from "./user";
import { useProjectV1Store, batchGetOrFetchProjects } from "./v1";
import { getProjectNameRolloutId, projectNamePrefix } from "./v1/common";
@@ -89,7 +89,7 @@ export const useRolloutByName = (name: MaybeRef<string>) => {
export const batchComposeRollout = async (rolloutList: Rollout[]) => {
const userStore = useUserStore();
- await batchGetOrFetchUsers(rolloutList.map((rollout) => rollout.creator));
+ await userStore.batchGetUsers(rolloutList.map((rollout) => rollout.creator));
const composedRolloutList = rolloutList.map((rollout) => {
const composed = rollout as ComposedRollout;
diff --git a/frontend/src/store/modules/user.ts b/frontend/src/store/modules/user.ts
index 5aa448deec..57c56dc1f9 100644
--- a/frontend/src/store/modules/user.ts
+++ b/frontend/src/store/modules/user.ts
@@ -137,6 +137,26 @@ export const useUserStore = defineStore("user", () => {
return setUser(restoredUser);
};
+ const batchGetUsers = async (userNameList: string[]) => {
+ const distinctList = uniq(userNameList)
+ .filter(Boolean)
+ .map((name) => ensureUserFullName(name))
+ .filter(
+ (name) =>
+ isValidUserName(name) && getUserByIdentifier(name) === undefined
+ );
+ if (distinctList.length === 0) {
+ return [];
+ }
+ const { users } = await userServiceClient.batchGetUsers({
+ names: distinctList,
+ });
+ for (const user of users) {
+ setUser(user);
+ }
+ return users;
+ };
+
const getOrFetchUserByIdentifier = async (
identifier: string,
silent = true
@@ -177,6 +197,7 @@ export const useUserStore = defineStore("user", () => {
fetchUserList,
createUser,
updateUser,
+ batchGetUsers,
getOrFetchUserByIdentifier,
getUserByIdentifier,
archiveUser,
@@ -184,19 +205,6 @@ export const useUserStore = defineStore("user", () => {
};
});
-export const batchGetOrFetchUsers = async (userNameList: string[]) => {
- const userStore = useUserStore();
- const distinctList = uniq(userNameList);
- await Promise.all(
- distinctList.map((userName) => {
- if (!isValidUserName(userName)) {
- return;
- }
- return userStore.getOrFetchUserByIdentifier(userName, true /* silent */);
- })
- );
-};
-
export const getUpdateMaskFromUsers = (
origin: User,
update: User | Partial<User>
diff --git a/frontend/src/store/modules/v1/changelist.ts b/frontend/src/store/modules/v1/changelist.ts
index deef31266d..3535bcc183 100644
--- a/frontend/src/store/modules/v1/changelist.ts
+++ b/frontend/src/store/modules/v1/changelist.ts
@@ -9,7 +9,7 @@ import type {
ListChangelistsRequest,
} from "@/types/proto/v1/changelist_service";
import { ResourceComposer, isChangelogChangeSource } from "@/utils";
-import { batchGetOrFetchUsers } from "../user";
+import { useUserStore } from "../user";
import { useChangelogStore } from "./changelog";
import { useSheetV1Store } from "./sheet";
@@ -20,7 +20,7 @@ export const useChangelistStore = defineStore("changelist", () => {
changelists: Changelist[],
compose: boolean
) => {
- await batchGetOrFetchUsers(
+ await useUserStore().batchGetUsers(
changelists.map((changelist) => changelist.creator)
);
for (let i = 0; i < changelists.length; i++) {
diff --git a/frontend/src/store/modules/v1/experimental-issue.ts b/frontend/src/store/modules/v1/experimental-issue.ts
index 594dd2d9a0..0b44114b14 100644
--- a/frontend/src/store/modules/v1/experimental-issue.ts
+++ b/frontend/src/store/modules/v1/experimental-issue.ts
@@ -5,7 +5,7 @@ import {
planServiceClient,
rolloutServiceClient,
} from "@/grpcweb";
-import { useProjectV1Store, useUserStore, batchGetOrFetchUsers } from "@/store";
+import { useProjectV1Store, useUserStore } from "@/store";
import type { ComposedIssue, ComposedProject, ComposedTaskRun } from "@/types";
import {
emptyIssue,
@@ -38,7 +38,7 @@ export const composeIssue = async (
userStore
.getOrFetchUserByIdentifier(rawIssue.creator)
.then((user) => user ?? unknownUser()),
- batchGetOrFetchUsers(rawIssue.subscribers),
+ userStore.batchGetUsers(rawIssue.subscribers),
]);
const issue: ComposedIssue = {
diff --git a/frontend/src/store/modules/v1/group.ts b/frontend/src/store/modules/v1/group.ts
index 7ec6f016e8..ace7f02e15 100644
--- a/frontend/src/store/modules/v1/group.ts
+++ b/frontend/src/store/modules/v1/group.ts
@@ -4,7 +4,7 @@ import { computed, reactive } from "vue";
import { groupServiceClient } from "@/grpcweb";
import type { Group } from "@/types/proto/v1/group_service";
import { hasWorkspacePermissionV2 } from "@/utils";
-import { batchGetOrFetchUsers } from "../user";
+import { useUserStore } from "../user";
import { groupNamePrefix } from "./common";
export const extractGroupEmail = (emailResource: string) => {
@@ -33,7 +33,7 @@ export const useGroupStore = defineStore("group", () => {
});
const composeGroup = async (group: Group) => {
- await batchGetOrFetchUsers(group.members.map((m) => m.member));
+ await useUserStore().batchGetUsers(group.members.map((m) => m.member));
groupMapByName.set(group.name, group);
};
diff --git a/frontend/src/store/modules/v1/issue.ts b/frontend/src/store/modules/v1/issue.ts
index a1bc265434..9657d10877 100644
--- a/frontend/src/store/modules/v1/issue.ts
+++ b/frontend/src/store/modules/v1/issue.ts
@@ -4,13 +4,18 @@ import { defineStore } from "pinia";
import type { WatchCallback } from "vue";
import { ref, watch } from "vue";
import { issueServiceClient } from "@/grpcweb";
-import type { ComposedIssue, IssueFilter } from "@/types";
+import {
+ SYSTEM_BOT_EMAIL,
+ type ComposedIssue,
+ type IssueFilter,
+} from "@/types";
import type { ApprovalStep } from "@/types/proto/v1/issue_service";
import {
issueStatusToJSON,
ApprovalNode_Type,
} from "@/types/proto/v1/issue_service";
import { memberMapToRolesInProjectIAM } from "@/utils";
+import { userNamePrefix } from "./common";
import {
shallowComposeIssue,
type ComposeIssueConfig,
@@ -137,8 +142,13 @@ export const candidatesOfApprovalStepV1 = (
return uniq(
candidates.filter((user) => {
- if (!issue.projectEntity.allowSelfApproval) {
- return user !== issue.creator;
+ // Exclude system bot user.
+ if (user === `${userNamePrefix}${SYSTEM_BOT_EMAIL}`) {
+ return false;
+ }
+ // If the project does not allow self-approval, exclude the creator.
+ if (!issue.projectEntity.allowSelfApproval && user === issue.creator) {
+ return false;
}
return true;
})
diff --git a/frontend/src/store/modules/v1/projectIamPolicy.ts b/frontend/src/store/modules/v1/projectIamPolicy.ts
index d071e120f0..d307337032 100644
--- a/frontend/src/store/modules/v1/projectIamPolicy.ts
+++ b/frontend/src/store/modules/v1/projectIamPolicy.ts
@@ -17,7 +17,7 @@ import { getUserEmailListInBinding } from "@/utils";
import { convertFromExpr } from "@/utils/issue/cel";
import { useCurrentUserV1 } from "../auth";
import { useRoleStore } from "../role";
-import { batchGetOrFetchUsers } from "../user";
+import { useUserStore } from "../user";
import { usePermissionStore } from "./permission";
export const useProjectIamPolicyStore = defineStore(
@@ -31,7 +31,7 @@ export const useProjectIamPolicyStore = defineStore(
list.push(...binding.members);
return list;
}, [] as string[]);
- await batchGetOrFetchUsers(members);
+ await useUserStore().batchGetUsers(members);
};
const setIamPolicy = async (project: string, policy: IamPolicy) => {
diff --git a/frontend/src/store/modules/v1/worksheet.ts b/frontend/src/store/modules/v1/worksheet.ts
index b8dbe252df..2f354f70dc 100644
--- a/frontend/src/store/modules/v1/worksheet.ts
+++ b/frontend/src/store/modules/v1/worksheet.ts
@@ -17,7 +17,7 @@ import {
} from "@/utils";
import { useCurrentUserV1 } from "../auth";
import { useSQLEditorTabStore } from "../sqlEditor";
-import { useUserStore, batchGetOrFetchUsers } from "../user";
+import { useUserStore } from "../user";
import { extractUserId } from "./common";
import { useDatabaseV1Store, batchGetOrFetchDatabases } from "./database";
import { useProjectV1Store, batchGetOrFetchProjects } from "./project";
@@ -84,7 +84,7 @@ export const useWorkSheetStore = defineStore("worksheet_v1", () => {
batchGetOrFetchDatabases(
worksheets.map((worksheet) => worksheet.database)
),
- batchGetOrFetchUsers(worksheets.map((worksheet) => worksheet.creator)),
+ userStore.batchGetUsers(worksheets.map((worksheet) => worksheet.creator)),
]);
for (const worksheet of worksheets) {
await setCache(worksheet, "BASIC");
diff --git a/frontend/src/store/modules/workspaceApprovalSetting.ts b/frontend/src/store/modules/workspaceApprovalSetting.ts
index 397e501821..ae48101cf7 100644
--- a/frontend/src/store/modules/workspaceApprovalSetting.ts
+++ b/frontend/src/store/modules/workspaceApprovalSetting.ts
@@ -2,7 +2,7 @@ import { cloneDeep } from "lodash-es";
import { defineStore } from "pinia";
import { ref } from "vue";
import { settingServiceClient } from "@/grpcweb";
-import type { LocalApprovalConfig, LocalApprovalRule } from "@/types";
+import { type LocalApprovalConfig, type LocalApprovalRule } from "@/types";
import type { Risk_Source } from "@/types/proto/v1/risk_service";
import type { Setting } from "@/types/proto/v1/setting_service";
import {
@@ -10,7 +10,7 @@ import {
buildWorkspaceApprovalSetting,
seedWorkspaceApprovalSetting,
} from "@/utils";
-import { batchGetOrFetchUsers } from "./user";
+import { useUserStore } from "./user";
import { useGracefulRequest } from "./utils";
const SETTING_NAME = "settings/bb.workspace.approval";
@@ -30,7 +30,7 @@ export const useWorkspaceApprovalSettingStore = defineStore(
if (_config.rules.length === 0) {
_config.rules.push(...seedWorkspaceApprovalSetting());
}
- await batchGetOrFetchUsers(
+ await useUserStore().batchGetUsers(
_config.rules.map((rule) => rule.template?.creator ?? "")
);
config.value = await resolveLocalApprovalConfig(_config);
diff --git a/frontend/src/utils/v1/advanced-search/issue/ui-filter.ts b/frontend/src/utils/v1/advanced-search/issue/ui-filter.ts
index 0c56969c4f..5034b91437 100644
--- a/frontend/src/utils/v1/advanced-search/issue/ui-filter.ts
+++ b/frontend/src/utils/v1/advanced-search/issue/ui-filter.ts
@@ -33,7 +33,7 @@ export const filterIssueByApprover = (
const reviewContext = extractReviewContext(issue);
const steps = useWrappedReviewStepsV1(issue, reviewContext);
- const currentStep = steps.value?.find((step) => step.status === "CURRENT");
+ const currentStep = steps.value.find((step) => step.status === "CURRENT");
if (!currentStep) return false;
// We support "approver:{email}" by now
// Planning to support "approver:[{email_1}, {email_2}, ...]" and
diff --git a/frontend/src/views/SettingWorkspaceAuditLog.vue b/frontend/src/views/SettingWorkspaceAuditLog.vue
index 052d207b53..fde563bf53 100644
--- a/frontend/src/views/SettingWorkspaceAuditLog.vue
+++ b/frontend/src/views/SettingWorkspaceAuditLog.vue
@@ -54,8 +54,8 @@ import {
featureToRef,
useAuditLogStore,
batchGetOrFetchProjects,
- batchGetOrFetchUsers,
pushNotification,
+ useUserStore,
} from "@/store";
import { projectNamePrefix } from "@/store/modules/v1/common";
import { type SearchAuditLogsParams } from "@/types";
@@ -111,7 +111,7 @@ const fetchAuditLog = async ({
return `${projectNamePrefix}${projectResourceId}`;
})
);
- await batchGetOrFetchUsers(auditLogs.map((log) => log.user));
+ await useUserStore().batchGetUsers(auditLogs.map((log) => log.user));
return { nextPageToken, list: auditLogs };
};
diff --git a/frontend/src/views/SettingWorkspaceMailDelivery.vue b/frontend/src/views/SettingWorkspaceMailDelivery.vue
index 9ec0bffc5b..b5df1da612 100644
--- a/frontend/src/views/SettingWorkspaceMailDelivery.vue
+++ b/frontend/src/views/SettingWorkspaceMailDelivery.vue
@@ -90,7 +90,7 @@
<NInput
v-model:value="state.mailDeliverySetting.username"
class="text-main w-full h-max mt-2"
- :placeholder="'[email protected]'"
+ :placeholder="SYSTEM_BOT_EMAIL"
/>
</div>
<div class="min-w-max w-80">
@@ -197,6 +197,7 @@ import { BBSpin, BBTextField } from "@/bbkit";
import FormLayout from "@/components/v2/Form/FormLayout.vue";
import { pushNotification } from "@/store";
import { useWorkspaceMailDeliverySettingStore } from "@/store/modules/workspaceMailDeliverySetting";
+import { SYSTEM_BOT_EMAIL } from "@/types";
import type { SMTPMailDeliverySettingValue } from "@/types/proto/v1/setting_service";
import {
SMTPMailDeliverySettingValue_Authentication,
diff --git a/frontend/src/views/project/ProjectAuditLogDashboard.vue b/frontend/src/views/project/ProjectAuditLogDashboard.vue
index 84a1b75f18..f91281a8c6 100644
--- a/frontend/src/views/project/ProjectAuditLogDashboard.vue
+++ b/frontend/src/views/project/ProjectAuditLogDashboard.vue
@@ -55,8 +55,8 @@ import PagedTable from "@/components/v2/Model/PagedTable.vue";
import {
featureToRef,
useAuditLogStore,
- batchGetOrFetchUsers,
pushNotification,
+ useUserStore,
} from "@/store";
import { type SearchAuditLogsParams } from "@/types";
import type { AuditLog } from "@/types/proto/v1/audit_log_service";
@@ -116,7 +116,7 @@ const fetchAuditLog = async ({
pageToken,
pageSize,
});
- await batchGetOrFetchUsers(auditLogs.map((log) => log.user));
+ await useUserStore().batchGetUsers(auditLogs.map((log) => log.user));
return { nextPageToken, list: auditLogs };
};