Skip to content

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

chore: avoid hard code system bot (#12490)

ecmadao69c1f5730506
diff --git a/backend/api/gitops/webhook.go b/backend/api/gitops/webhook.go
index 50418a7dc9..43f4f8ecf5 100644
--- a/backend/api/gitops/webhook.go
+++ b/backend/api/gitops/webhook.go
@@ -22,7 +22,6 @@ import (
"github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/common/log"
- api "github.com/bytebase/bytebase/backend/legacyapi"
"github.com/bytebase/bytebase/backend/plugin/vcs"
"github.com/bytebase/bytebase/backend/store"
@@ -185,10 +184,10 @@ func (s *Service) createIssueFromPRInfo(ctx context.Context, project *store.Proj
user, err := s.store.GetUserByEmail(ctx, prInfo.email)
if err != nil {
slog.Error("failed to find user by email", slog.String("email", prInfo.email), log.BBError(err))
- return store.SystemBotUser
+ return s.store.GetSystemBotUser(ctx)
}
if user == nil {
- return store.SystemBotUser
+ return s.store.GetSystemBotUser(ctx)
}
return user
}()
@@ -227,7 +226,7 @@ func (s *Service) createIssueFromPRInfo(ctx context.Context, project *store.Proj
childCtx = context.WithValue(childCtx, common.UserContextKey, user)
childCtx = context.WithValue(childCtx, common.LoopbackContextKey, true)
plan, err := s.planService.CreatePlan(childCtx, &v1pb.CreatePlanRequest{
- Parent: fmt.Sprintf("projects/%s", project.ResourceID),
+ Parent: common.FormatProject(project.ResourceID),
Plan: &v1pb.Plan{
Title: prInfo.title,
Steps: steps,
@@ -242,12 +241,12 @@ func (s *Service) createIssueFromPRInfo(ctx context.Context, project *store.Proj
return nil, errors.Wrapf(err, "failed to create plan")
}
issue, err := s.issueService.CreateIssue(childCtx, &v1pb.CreateIssueRequest{
- Parent: fmt.Sprintf("projects/%s", project.ResourceID),
+ Parent: common.FormatProject(project.ResourceID),
Issue: &v1pb.Issue{
Title: prInfo.title,
Description: prInfo.description,
Type: v1pb.Issue_DATABASE_CHANGE,
- Assignee: fmt.Sprintf("users/%s", api.SystemBotEmail),
+ Assignee: common.FormatUserEmail(s.store.GetSystemBotUser(ctx).Email),
Plan: plan.Name,
},
})
@@ -255,7 +254,7 @@ func (s *Service) createIssueFromPRInfo(ctx context.Context, project *store.Proj
return nil, errors.Wrapf(err, "failed to create issue")
}
if _, err := s.rolloutService.CreateRollout(childCtx, &v1pb.CreateRolloutRequest{
- Parent: fmt.Sprintf("projects/%s", project.ResourceID),
+ Parent: common.FormatProject(project.ResourceID),
Rollout: &v1pb.Rollout{
Plan: plan.Name,
},
diff --git a/backend/api/v1/issue_service.go b/backend/api/v1/issue_service.go
index ff0fc08331..929e4689df 100644
--- a/backend/api/v1/issue_service.go
+++ b/backend/api/v1/issue_service.go
@@ -914,7 +914,7 @@ func (s *IssueService) ApproveIssue(ctx context.Context, request *v1pb.ApproveIs
}
s.webhookManager.CreateEvent(ctx, &webhook.Event{
- Actor: store.SystemBotUser,
+ Actor: s.store.GetSystemBotUser(ctx),
Type: webhook.EventTypeIssueApprovalCreate,
Comment: "",
Issue: webhook.NewIssue(issue),
@@ -936,7 +936,7 @@ func (s *IssueService) ApproveIssue(ctx context.Context, request *v1pb.ApproveIs
// notify issue approved
s.webhookManager.CreateEvent(ctx, &webhook.Event{
- Actor: store.SystemBotUser,
+ Actor: s.store.GetSystemBotUser(ctx),
Type: webhook.EventTypeIssueApprovalPass,
Comment: "",
Issue: webhook.NewIssue(issue),
@@ -984,7 +984,7 @@ func (s *IssueService) ApproveIssue(ctx context.Context, request *v1pb.ApproveIs
return errors.Wrap(err, "failed to check if the approval is approved")
}
if approved {
- if err := webhook.ChangeIssueStatus(ctx, s.store, s.webhookManager, issue, api.IssueDone, store.SystemBotUser, ""); err != nil {
+ if err := webhook.ChangeIssueStatus(ctx, s.store, s.webhookManager, issue, api.IssueDone, s.store.GetSystemBotUser(ctx), ""); err != nil {
return errors.Wrap(err, "failed to update issue status")
}
}
diff --git a/backend/api/v1/project_service.go b/backend/api/v1/project_service.go
index ce51812847..2dae5a670d 100644
--- a/backend/api/v1/project_service.go
+++ b/backend/api/v1/project_service.go
@@ -705,7 +705,7 @@ func (s *ProjectService) TestWebhook(ctx context.Context, request *v1pb.TestWebh
Link: fmt.Sprintf("%s/project/%s/webhook/%s", setting.ExternalUrl, fmt.Sprintf("%s-%d", slug.Make(project.Title), project.UID), fmt.Sprintf("%s-%d", slug.Make(webhook.Title), webhook.ID)),
CreatorID: api.SystemBotID,
CreatorName: "Bytebase",
- CreatorEmail: api.SystemBotEmail,
+ CreatorEmail: s.store.GetSystemBotUser(ctx).Email,
CreatedTs: time.Now().Unix(),
Issue: &webhookplugin.Issue{
ID: 1,
diff --git a/backend/runner/approval/runner.go b/backend/runner/approval/runner.go
index bd166bf5e0..adc8566c48 100644
--- a/backend/runner/approval/runner.go
+++ b/backend/runner/approval/runner.go
@@ -188,7 +188,7 @@ func (r *Runner) findApprovalTemplateForIssue(ctx context.Context, issue *store.
if err := utils.UpdateProjectPolicyFromGrantIssue(ctx, r.store, issue, payload.GrantRequest); err != nil {
return false, err
}
- if err := webhook.ChangeIssueStatus(ctx, r.store, r.webhookManager, issue, api.IssueDone, store.SystemBotUser, ""); err != nil {
+ if err := webhook.ChangeIssueStatus(ctx, r.store, r.webhookManager, issue, api.IssueDone, r.store.GetSystemBotUser(ctx), ""); err != nil {
return false, errors.Wrap(err, "failed to update issue status")
}
}
@@ -250,7 +250,7 @@ func (r *Runner) findApprovalTemplateForIssue(ctx context.Context, issue *store.
return errors.Wrapf(err, "failed to get rollout policy")
}
r.webhookManager.CreateEvent(ctx, &webhook.Event{
- Actor: store.SystemBotUser,
+ Actor: r.store.GetSystemBotUser(ctx),
Type: webhook.EventTypeIssueRolloutReady,
Comment: "",
Issue: webhook.NewIssue(issue),
@@ -274,7 +274,7 @@ func (r *Runner) findApprovalTemplateForIssue(ctx context.Context, issue *store.
return nil
}
r.webhookManager.CreateEvent(ctx, &webhook.Event{
- Actor: store.SystemBotUser,
+ Actor: r.store.GetSystemBotUser(ctx),
Type: webhook.EventTypeIssueApprovalCreate,
Comment: "",
Issue: webhook.NewIssue(issue),
diff --git a/backend/runner/relay/runner.go b/backend/runner/relay/runner.go
index 69b981fa24..23520e9ab6 100644
--- a/backend/runner/relay/runner.go
+++ b/backend/runner/relay/runner.go
@@ -307,7 +307,7 @@ func (r *Runner) ApproveExternalApprovalNode(ctx context.Context, issueUID int)
return nil
}
r.webhookManager.CreateEvent(ctx, &webhook.Event{
- Actor: store.SystemBotUser,
+ Actor: r.store.GetSystemBotUser(ctx),
Type: webhook.EventTypeIssueApprovalCreate,
Comment: "",
Issue: webhook.NewIssue(issue),
@@ -334,7 +334,7 @@ func (r *Runner) ApproveExternalApprovalNode(ctx context.Context, issueUID int)
return errors.Wrap(err, "failed to check if the approval is approved")
}
if approved {
- if err := webhook.ChangeIssueStatus(ctx, r.store, r.webhookManager, issue, api.IssueDone, store.SystemBotUser, ""); err != nil {
+ if err := webhook.ChangeIssueStatus(ctx, r.store, r.webhookManager, issue, api.IssueDone, r.store.GetSystemBotUser(ctx), ""); err != nil {
return errors.Wrap(err, "failed to update issue status")
}
}
diff --git a/backend/runner/taskrun/schedulerv2.go b/backend/runner/taskrun/schedulerv2.go
index c2ac521c2b..d7e4b077a9 100644
--- a/backend/runner/taskrun/schedulerv2.go
+++ b/backend/runner/taskrun/schedulerv2.go
@@ -231,7 +231,7 @@ func (s *SchedulerV2) scheduleAutoRolloutTask(ctx context.Context, taskUID int)
}
s.webhookManager.CreateEvent(ctx, &webhook.Event{
- Actor: store.SystemBotUser,
+ Actor: s.store.GetSystemBotUser(ctx),
Type: webhook.EventTypeTaskRunStatusUpdate,
Comment: "",
Issue: webhook.NewIssue(issue),
@@ -667,7 +667,7 @@ func (s *SchedulerV2) ListenTaskSkippedOrDone(ctx context.Context) {
// create "stage ends" activity.
if err := func() error {
s.webhookManager.CreateEvent(ctx, &webhook.Event{
- Actor: store.SystemBotUser,
+ Actor: s.store.GetSystemBotUser(ctx),
Type: webhook.EventTypeStageStatusUpdate,
Comment: "",
Issue: webhook.NewIssue(issue),
@@ -691,7 +691,7 @@ func (s *SchedulerV2) ListenTaskSkippedOrDone(ctx context.Context) {
return errors.Wrapf(err, "failed to get rollout policy")
}
s.webhookManager.CreateEvent(ctx, &webhook.Event{
- Actor: store.SystemBotUser,
+ Actor: s.store.GetSystemBotUser(ctx),
Type: webhook.EventTypeIssueRolloutReady,
Comment: "",
Issue: webhook.NewIssue(issue),
@@ -738,7 +738,7 @@ func (s *SchedulerV2) ListenTaskSkippedOrDone(ctx context.Context) {
}
s.webhookManager.CreateEvent(ctx, &webhook.Event{
- Actor: store.SystemBotUser,
+ Actor: s.store.GetSystemBotUser(ctx),
Type: webhook.EventTypeIssueStatusUpdate,
Comment: "",
Issue: webhook.NewIssue(updatedIssue),
@@ -772,7 +772,7 @@ func (s *SchedulerV2) createActivityForTaskRunStatusUpdate(ctx context.Context,
return nil
}
s.webhookManager.CreateEvent(ctx, &webhook.Event{
- Actor: store.SystemBotUser,
+ Actor: s.store.GetSystemBotUser(ctx),
Type: webhook.EventTypeTaskRunStatusUpdate,
Comment: "",
Issue: webhook.NewIssue(issue),
diff --git a/backend/store/principal.go b/backend/store/principal.go
index be0146cbf1..618dbca018 100644
--- a/backend/store/principal.go
+++ b/backend/store/principal.go
@@ -3,6 +3,7 @@ package store
import (
"context"
"fmt"
+ "log/slog"
"strings"
"time"
@@ -11,11 +12,12 @@ import (
"google.golang.org/protobuf/encoding/protojson"
"github.com/bytebase/bytebase/backend/common"
+ "github.com/bytebase/bytebase/backend/common/log"
api "github.com/bytebase/bytebase/backend/legacyapi"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
-var SystemBotUser = &UserMessage{
+var systemBotUser = &UserMessage{
ID: api.SystemBotID,
Name: "Bytebase",
Email: api.SystemBotEmail,
@@ -62,11 +64,21 @@ type UserMessage struct {
Phone string
}
+// GetSystemBotUser gets the system bot.
+func (s *Store) GetSystemBotUser(ctx context.Context) *UserMessage {
+ user, err := s.GetUserByID(ctx, api.SystemBotID)
+ if err != nil {
+ slog.Error("failed to find system bot", slog.Int("id", api.SystemBotID), log.BBError(err))
+ return systemBotUser
+ }
+ if user == nil {
+ return systemBotUser
+ }
+ return user
+}
+
// GetUserByID gets the user by ID.
func (s *Store) GetUserByID(ctx context.Context, id int) (*UserMessage, error) {
- if id == api.SystemBotID {
- return SystemBotUser, nil
- }
if v, ok := s.userIDCache.Get(id); ok {
return v, nil
}
diff --git a/frontend/src/components/AuditLog/AuditLogSearch/AuditLogSearch.vue b/frontend/src/components/AuditLog/AuditLogSearch/AuditLogSearch.vue
index b8a1725b59..8256998ce2 100644
--- a/frontend/src/components/AuditLog/AuditLogSearch/AuditLogSearch.vue
+++ b/frontend/src/components/AuditLog/AuditLogSearch/AuditLogSearch.vue
@@ -32,7 +32,7 @@ import YouTag from "@/components/misc/YouTag.vue";
import { ProjectV1Name } from "@/components/v2";
import ALL_METHODS from "@/grpcweb/methods";
import { useCurrentUserV1, useProjectV1List, useUserStore } from "@/store";
-import { SYSTEM_BOT_EMAIL } from "@/types";
+import { SYSTEM_BOT_USER_NAME } from "@/types";
import { AuditLog_Severity } from "@/types/proto/v1/audit_log_service";
import { Workflow } from "@/types/proto/v1/project_service";
import {
@@ -80,7 +80,7 @@ const principalSearchValueOptions = computed(() => {
if (user.name === me.value.name) {
children.push(<YouTag />);
}
- if (user.email === SYSTEM_BOT_EMAIL) {
+ if (user.name === SYSTEM_BOT_USER_NAME) {
children.push(<SystemBotTag />);
}
return <div class="flex items-center gap-x-1">{children}</div>;
diff --git a/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/ActionCreator.vue b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/ActionCreator.vue
index 7e1e4cbe65..de2ca125b6 100644
--- a/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/ActionCreator.vue
+++ b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/ActionCreator.vue
@@ -1,7 +1,7 @@
<template>
<component
:is="isLink ? 'router-link' : 'span'"
- v-if="userEmail !== SYSTEM_BOT_EMAIL"
+ v-if="userEmail !== userStore.systemBotUser?.email"
v-bind="bindings"
class="font-medium text-main whitespace-nowrap"
:class="[isLink && 'hover:underline']"
@@ -20,7 +20,6 @@
import { computed } from "vue";
import SystemBotTag from "@/components/misc/SystemBotTag.vue";
import { usePageMode, useUserStore } from "@/store";
-import { SYSTEM_BOT_EMAIL } from "@/types";
import { extractUserResourceName } from "@/utils";
const props = defineProps<{
@@ -29,13 +28,14 @@ const props = defineProps<{
}>();
const pageMode = usePageMode();
+const userStore = useUserStore();
const userEmail = computed(() => {
return extractUserResourceName(props.creator);
});
const user = computed(() => {
- return useUserStore().getUserByEmail(userEmail.value);
+ return userStore.getUserByEmail(userEmail.value);
});
const isLink = computed(() => {
diff --git a/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/ActionIcon.vue b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/ActionIcon.vue
index 5c50347f4f..fdd1d7e5e5 100644
--- a/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/ActionIcon.vue
+++ b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/ActionIcon.vue
@@ -110,7 +110,6 @@ import {
useUserStore,
type ComposedIssueComment,
} from "@/store";
-import { SYSTEM_BOT_EMAIL } from "@/types";
import {
IssueComment_Approval,
IssueComment_Approval_Status,
@@ -140,9 +139,11 @@ const props = defineProps<{
issueComment: ComposedIssueComment;
}>();
+const userStore = useUserStore();
+
const user = computed(() => {
const email = extractUserResourceName(props.issueComment.creator);
- return useUserStore().getUserByEmail(email);
+ return userStore.getUserByEmail(email);
});
const icon = computed((): ActionIconType => {
@@ -205,7 +206,8 @@ const icon = computed((): ActionIconType => {
// Otherwise, show avatar icon based on the creator.
}
- return extractUserResourceName(issueComment.creator) == SYSTEM_BOT_EMAIL
+ return extractUserResourceName(issueComment.creator) ==
+ userStore.systemBotUser?.email
? "system"
: "avatar";
});
diff --git a/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/ActionSentence.vue b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/ActionSentence.vue
index 05574bcf40..ff96fea2c2 100644
--- a/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/ActionSentence.vue
+++ b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/ActionSentence.vue
@@ -7,9 +7,12 @@ import dayjs from "dayjs";
import type { h } from "vue";
import { defineComponent } from "vue";
import { Translation, useI18n } from "vue-i18n";
-import { IssueCommentType, type ComposedIssueComment } from "@/store";
+import {
+ useUserStore,
+ IssueCommentType,
+ type ComposedIssueComment,
+} from "@/store";
import type { ComposedIssue } from "@/types";
-import { SYSTEM_BOT_EMAIL } from "@/types";
import {
IssueComment_Approval,
IssueComment_Approval_Status,
@@ -40,6 +43,7 @@ const props = defineProps<{
}>();
const { t } = useI18n();
+const userStore = useUserStore();
const renderActionSentence = () => {
const { issueComment, issue } = props;
@@ -225,7 +229,10 @@ const maybeAutomaticallyVerb = (
issueComment: ComposedIssueComment,
verb: string
): string => {
- if (extractUserResourceName(issueComment.creator) !== SYSTEM_BOT_EMAIL) {
+ if (
+ extractUserResourceName(issueComment.creator) !==
+ userStore.systemBotUser?.email
+ ) {
return verb;
}
return t("activity.sentence.xxx-automatically", {
@@ -242,7 +249,8 @@ type VerbTypeTarget = {
const renderVerbTypeTarget = (params: VerbTypeTarget, props: object = {}) => {
const keypath =
- extractUserResourceName(params.issueComment.creator) === SYSTEM_BOT_EMAIL
+ extractUserResourceName(params.issueComment.creator) ===
+ userStore.systemBotUser?.email
? "activity.sentence.verb-type-target-by-system-bot"
: "activity.sentence.verb-type-target-by-people";
diff --git a/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/IssueCommentAction.vue b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/IssueCommentAction.vue
index 3c93f128ba..177712fe04 100644
--- a/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/IssueCommentAction.vue
+++ b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentView/IssueCommentAction.vue
@@ -5,7 +5,7 @@
<ActionCreator
v-if="
extractUserResourceName(issueComment.creator) !==
- SYSTEM_BOT_EMAIL ||
+ userStore.systemBotUser?.email ||
issueComment.type === IssueCommentType.USER_COMMENT
"
:creator="issueComment.creator"
@@ -66,10 +66,9 @@ import { useRouter } from "vue-router";
import { useIssueContext, databaseForTask } from "@/components/IssueV1/logic";
import { PROJECT_V1_ROUTE_ISSUE_DETAIL } from "@/router/dashboard/projectV1";
import { IssueCommentType, type ComposedIssueComment } from "@/store";
-import { useSheetV1Store } from "@/store";
+import { useSheetV1Store, useUserStore } from "@/store";
import { useGenerateRestoreSQL } from "@/store/modules/restore";
import type { ComposedIssue } from "@/types";
-import { SYSTEM_BOT_EMAIL } from "@/types";
import { Engine } from "@/types/proto/v1/common";
import { IssueComment_TaskPriorBackup } from "@/types/proto/v1/issue_service";
import type { IssueComment } from "@/types/proto/v1/issue_service";
@@ -92,6 +91,7 @@ const props = defineProps<{
const { selectedTask } = useIssueContext();
const router = useRouter();
+const userStore = useUserStore();
const coreDatabaseInfo = computed(() => {
return databaseForTask(props.issue, selectedTask.value);
@@ -159,5 +159,4 @@ const createRestoreIssue = async (comment: IssueComment) => {
query,
});
};
-
</script>
diff --git a/frontend/src/components/IssueV1/components/IssueSearch/useIssueSearchScopeOptions.ts b/frontend/src/components/IssueV1/components/IssueSearch/useIssueSearchScopeOptions.ts
index 66bdc2a52e..691d706fbc 100644
--- a/frontend/src/components/IssueV1/components/IssueSearch/useIssueSearchScopeOptions.ts
+++ b/frontend/src/components/IssueV1/components/IssueSearch/useIssueSearchScopeOptions.ts
@@ -12,7 +12,7 @@ import {
useUserStore,
useProjectV1List,
} from "@/store";
-import { SYSTEM_BOT_EMAIL, UNKNOWN_ID } from "@/types";
+import { SYSTEM_BOT_USER_NAME, UNKNOWN_ID } from "@/types";
import { Label } from "@/types/proto/v1/project_service";
import type { SearchParams, SearchScopeId } from "@/utils";
@@ -26,6 +26,7 @@ export type ScopeOption = {
export type ValueOption = {
value: string;
keywords: string[];
+ bot?: boolean;
custom?: boolean;
render: RenderFunction;
};
@@ -74,6 +75,7 @@ export const useIssueSearchScopeOptions = (
return {
value: user.email,
keywords: [user.email, user.title],
+ bot: user.name === SYSTEM_BOT_USER_NAME,
render: () => {
const children = [
h(BBAvatar, { size: "TINY", username: user.title }),
@@ -82,7 +84,7 @@ export const useIssueSearchScopeOptions = (
if (user.name === me.value.name) {
children.push(h(YouTag));
}
- if (user.email === SYSTEM_BOT_EMAIL) {
+ if (user.name === SYSTEM_BOT_USER_NAME) {
children.push(h(SystemBotTag));
}
return h("div", { class: "flex items-center gap-x-1" }, children);
@@ -146,9 +148,7 @@ export const useIssueSearchScopeOptions = (
id: "approver",
title: t("issue.advanced-search.scope.approver.title"),
description: t("issue.advanced-search.scope.approver.description"),
- options: principalSearchValueOptions.value.filter(
- (o) => o.value !== SYSTEM_BOT_EMAIL
- ),
+ options: principalSearchValueOptions.value.filter((o) => !o.bot),
},
{
id: "subscriber",
diff --git a/frontend/src/store/modules/user.ts b/frontend/src/store/modules/user.ts
index c0659fde04..2954b472a0 100644
--- a/frontend/src/store/modules/user.ts
+++ b/frontend/src/store/modules/user.ts
@@ -2,9 +2,14 @@ import { isEqual, isUndefined, orderBy } from "lodash-es";
import { defineStore } from "pinia";
import { computed, ref } from "vue";
import { authServiceClient } from "@/grpcweb";
-import type { PrincipalType } from "@/types";
-import { PresetRoleType, PRESET_WORKSPACE_ROLES } from "@/types";
-import { ALL_USERS_USER_EMAIL, allUsersUser } from "@/types";
+import {
+ type PrincipalType,
+ PresetRoleType,
+ PRESET_WORKSPACE_ROLES,
+ ALL_USERS_USER_EMAIL,
+ allUsersUser,
+ SYSTEM_BOT_USER_NAME,
+} from "@/types";
import type { UpdateUserRequest, User } from "@/types/proto/v1/auth_service";
import { UserType } from "@/types/proto/v1/auth_service";
import { State } from "@/types/proto/v1/common";
@@ -37,6 +42,12 @@ export const useUserStore = defineStore("user", () => {
);
});
+ const systemBotUser = computed(() => {
+ return activeUserList.value.find(
+ (user) => user.name === SYSTEM_BOT_USER_NAME
+ );
+ });
+
const workspaceLevelProjectMembers = computed(() => {
return activeUserList.value.filter((user) =>
user.roles.some((role) => !PRESET_WORKSPACE_ROLES.includes(role))
@@ -129,6 +140,7 @@ export const useUserStore = defineStore("user", () => {
userMapByName,
userList,
activeUserList,
+ systemBotUser,
workspaceLevelProjectMembers,
fetchUserList,
fetchUser,
diff --git a/frontend/src/utils/workspaceApprovalSetting.ts b/frontend/src/utils/workspaceApprovalSetting.ts
index cd2c411ae6..0f2f7daf77 100644
--- a/frontend/src/utils/workspaceApprovalSetting.ts
+++ b/frontend/src/utils/workspaceApprovalSetting.ts
@@ -8,9 +8,9 @@ import { userNamePrefix } from "@/store/modules/v1/common";
import type { ParsedApprovalRule, UnrecognizedApprovalRule } from "@/types";
import {
DEFAULT_RISK_LEVEL,
- SYSTEM_BOT_EMAIL,
unknownUser,
UNKNOWN_USER_NAME,
+ SYSTEM_BOT_EMAIL,
} from "@/types";
import type { LocalApprovalConfig, LocalApprovalRule } from "@/types";
import { PresetRiskLevelList, SupportedSourceList } from "@/types";
@@ -304,7 +304,7 @@ export const seedWorkspaceApprovalSetting = () => {
template: {
title,
description,
- creator: `${userNamePrefix}${SYSTEM_BOT_EMAIL}`,
+ creator: `${userNamePrefix}${useUserStore().systemBotUser?.email ?? SYSTEM_BOT_EMAIL}`,
flow: {
steps: roles.map((role) => ({
type: ApprovalStep_Type.ANY,
diff --git a/frontend/src/views/ProfileDashboard.vue b/frontend/src/views/ProfileDashboard.vue
index f2c326ee97..5cee844c19 100644
--- a/frontend/src/views/ProfileDashboard.vue
+++ b/frontend/src/views/ProfileDashboard.vue
@@ -260,7 +260,11 @@ import {
useCurrentUserV1,
useUserStore,
} from "@/store";
-import { unknownUser, SYSTEM_BOT_EMAIL, ALL_USERS_USER_EMAIL } from "@/types";
+import {
+ unknownUser,
+ SYSTEM_BOT_USER_NAME,
+ ALL_USERS_USER_EMAIL,
+} from "@/types";
import type { User } from "@/types/proto/v1/auth_service";
import { UpdateUserRequest, UserType } from "@/types/proto/v1/auth_service";
import { displayRoleTitle, hasWorkspacePermissionV2, sortRoles } from "@/utils";
@@ -344,7 +348,7 @@ const passwordMismatch = computed(() => {
// Besides, owner can also change anyone's info. This is for resetting password in case user forgets.
const allowEdit = computed(() => {
if (
- user.value.email === SYSTEM_BOT_EMAIL ||
+ user.value.name === SYSTEM_BOT_USER_NAME ||
user.value.email === ALL_USERS_USER_EMAIL
) {
return false;