Skip to content

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

chore: implement allow self-approval setting (#14888)

boojack7c106509e057
diff --git a/backend/api/v1/issue_service.go b/backend/api/v1/issue_service.go
index 69d5960a53..2fd788c165 100644
--- a/backend/api/v1/issue_service.go
+++ b/backend/api/v1/issue_service.go
@@ -739,7 +739,7 @@ func (s *IssueService) ApproveIssue(ctx context.Context, request *v1pb.ApproveIs
return nil, status.Errorf(codes.Internal, "failed to get workspace policy, error: %v", err)
}
- canApprove, err := isUserReviewer(ctx, s.store, step, user, policy.Policy, workspacePolicy.Policy)
+ canApprove, err := isUserReviewer(ctx, s.store, issue, step, user, policy.Policy, workspacePolicy.Policy)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to check if principal can approve step, error: %v", err)
}
@@ -960,7 +960,7 @@ func (s *IssueService) RejectIssue(ctx context.Context, request *v1pb.RejectIssu
return nil, status.Errorf(codes.Internal, "failed to get workspace policy, error: %v", err)
}
- canApprove, err := isUserReviewer(ctx, s.store, step, user, policy.Policy, workspacePolicy.Policy)
+ canApprove, err := isUserReviewer(ctx, s.store, issue, step, user, policy.Policy, workspacePolicy.Policy)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to check if principal can reject step, error: %v", err)
}
@@ -1595,7 +1595,7 @@ func canRequestIssue(issueCreator *store.UserMessage, user *store.UserMessage) b
return issueCreator.ID == user.ID
}
-func isUserReviewer(ctx context.Context, stores *store.Store, step *storepb.ApprovalStep, user *store.UserMessage, policies ...*storepb.IamPolicy) (bool, error) {
+func isUserReviewer(ctx context.Context, stores *store.Store, issue *store.IssueMessage, step *storepb.ApprovalStep, user *store.UserMessage, policies ...*storepb.IamPolicy) (bool, error) {
if len(step.Nodes) != 1 {
return false, errors.Errorf("expecting one node but got %v", len(step.Nodes))
}
@@ -1607,6 +1607,11 @@ func isUserReviewer(ctx context.Context, stores *store.Store, step *storepb.Appr
return false, errors.Errorf("expecting ANY_IN_GROUP node type but got %v", node.Type)
}
+ // Check project policy about self approval.
+ if !issue.Project.Setting.AllowSelfApproval && issue.Creator.ID == user.ID {
+ return false, errors.Errorf("creator cannot self approve")
+ }
+
roles := utils.GetUserFormattedRolesMap(ctx, stores, user, policies...)
switch val := node.Payload.(type) {
diff --git a/frontend/src/components/IssueV1/components/HeaderSection/Actions/review/IssueReviewButtonGroup.vue b/frontend/src/components/IssueV1/components/HeaderSection/Actions/review/IssueReviewButtonGroup.vue
index 541ec16da5..94a7f8dd0a 100644
--- a/frontend/src/components/IssueV1/components/HeaderSection/Actions/review/IssueReviewButtonGroup.vue
+++ b/frontend/src/components/IssueV1/components/HeaderSection/Actions/review/IssueReviewButtonGroup.vue
@@ -62,8 +62,11 @@ const shouldShowApproveOrReject = computed(() => {
return false;
}
- // Do not show review actions for the creator.
- if (currentUser.value.email === extractUserEmail(issue.value.creator)) {
+ // Hide review actions if self-approval is disabled.
+ if (
+ !issue.value.projectEntity.allowSelfApproval &&
+ currentUser.value.email === extractUserEmail(issue.value.creator)
+ ) {
return false;
}
diff --git a/frontend/src/components/IssueV1/components/Sidebar/ReviewSection/Timeline.vue b/frontend/src/components/IssueV1/components/Sidebar/ReviewSection/Timeline.vue
index bafee491f9..c73bb4bb53 100644
--- a/frontend/src/components/IssueV1/components/Sidebar/ReviewSection/Timeline.vue
+++ b/frontend/src/components/IssueV1/components/Sidebar/ReviewSection/Timeline.vue
@@ -21,7 +21,10 @@
</span>
</template>
</i18n-t>
- <li class="whitespace-pre-wrap">
+ <li
+ v-if="!issue.projectEntity.allowSelfApproval"
+ class="whitespace-pre-wrap"
+ >
{{
$t(
"custom-approval.issue-review.issue-creators-cannot-approve-their-own-issue"
@@ -90,6 +93,7 @@ import {
NPopover,
NPerformantEllipsis,
} from "naive-ui";
+import { useIssueContext } from "@/components/IssueV1/logic";
import type { WrappedReviewStep } from "@/types";
import { type User } from "@/types/proto/v1/auth_service";
import type { ApprovalStep } from "@/types/proto/v1/issue_service";
@@ -103,6 +107,8 @@ defineProps<{
steps: WrappedReviewStep[];
}>();
+const { issue } = useIssueContext();
+
const isExternalApprovalStep = (step: ApprovalStep) => {
return !!step.nodes[0]?.externalNodeId;
};
diff --git a/frontend/src/components/Project/Settings/ProjectIssueRelatedSettingPanel.vue b/frontend/src/components/Project/Settings/ProjectIssueRelatedSettingPanel.vue
index f023fedbff..fe643d7f5d 100644
--- a/frontend/src/components/Project/Settings/ProjectIssueRelatedSettingPanel.vue
+++ b/frontend/src/components/Project/Settings/ProjectIssueRelatedSettingPanel.vue
@@ -81,6 +81,19 @@
}}
</p>
</div>
+ <div>
+ <NCheckbox
+ v-model:checked="state.allowSelfApproval"
+ size="large"
+ :disabled="!allowUpdateIssueProjectSetting"
+ :label="$t('project.settings.issue-related.allow-self-approval.self')"
+ />
+ <p class="text-sm text-gray-400 pl-6 ml-0.5">
+ {{
+ $t("project.settings.issue-related.allow-self-approval.description")
+ }}
+ </p>
+ </div>
<div>
<NCheckbox
v-model:checked="state.autoEnableBackup"
@@ -112,11 +125,17 @@
v-model:checked="state.postgresDatabaseTenantMode"
size="large"
:disabled="!allowUpdateIssueProjectSetting"
- :label="$t('project.settings.issue-related.postgres-database-tenant-mode.self')"
+ :label="
+ $t(
+ 'project.settings.issue-related.postgres-database-tenant-mode.self'
+ )
+ "
/>
<p class="text-sm text-gray-400 pl-6 ml-0.5">
{{
- $t("project.settings.issue-related.postgres-database-tenant-mode.description")
+ $t(
+ "project.settings.issue-related.postgres-database-tenant-mode.description"
+ )
}}
</p>
</div>
@@ -149,6 +168,7 @@ interface LocalState {
autoResolveIssue: boolean;
forceIssueLabels: boolean;
enforceIssueTitle: boolean;
+ allowSelfApproval: boolean;
autoEnableBackup: boolean;
skipBackupErrors: boolean;
postgresDatabaseTenantMode: boolean;
@@ -162,6 +182,7 @@ const getInitialLocalState = (): LocalState => {
autoResolveIssue: project.autoResolveIssue,
forceIssueLabels: project.forceIssueLabels,
enforceIssueTitle: project.enforceIssueTitle,
+ allowSelfApproval: project.allowSelfApproval,
autoEnableBackup: project.autoEnableBackup,
skipBackupErrors: project.skipBackupErrors,
postgresDatabaseTenantMode: project.postgresDatabaseTenantMode,
@@ -272,13 +293,21 @@ const getUpdateMask = () => {
if (state.enforceIssueTitle !== props.project.enforceIssueTitle) {
mask.push("enforce_issue_title");
}
+ if (state.allowSelfApproval !== props.project.allowSelfApproval) {
+ mask.push("allow_self_approval");
+ }
if (!isEqual(state.autoEnableBackup, props.project.autoEnableBackup)) {
mask.push("auto_enable_backup");
}
if (!isEqual(state.skipBackupErrors, props.project.skipBackupErrors)) {
mask.push("skip_backup_errors");
}
- if (!isEqual(state.postgresDatabaseTenantMode, props.project.postgresDatabaseTenantMode)) {
+ if (
+ !isEqual(
+ state.postgresDatabaseTenantMode,
+ props.project.postgresDatabaseTenantMode
+ )
+ ) {
mask.push("postgres_database_tenant_mode");
}
return mask;
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 2540942297..cb0b52d81c 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -2187,6 +2187,10 @@
"self": "Enforce issue title",
"description": "Enforce issue title to be non-empty and created by user instead of auto generated."
},
+ "allow-self-approval": {
+ "self": "Allow self approval",
+ "description": "Allow the issue creator to approve the issue."
+ },
"default-backup-behavior": {
"self": "Default backup behavior",
"description": "The default backup behavior when creating data changing issues.",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index fcbf30da3e..25f83cc65d 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -2187,6 +2187,10 @@
"self": "Hacer cumplir el título del problema",
"description": "Exigir que el título del problema no esté vacío y que lo cree el usuario en lugar de generarse automáticamente."
},
+ "allow-self-approval": {
+ "self": "Permitir la autoaprobación",
+ "description": "Permitir que el creador del problema apruebe el problema."
+ },
"default-backup-behavior": {
"self": "Comportamiento de copia de seguridad predeterminado",
"description": "El comportamiento de copia de seguridad predeterminado al crear problemas de cambio de datos.",
@@ -3898,4 +3902,4 @@
"last-visit": "Última visita",
"changelog-for-version": "Registro de cambios para {version}"
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 94a4bce485..65ae7e7acb 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -2187,6 +2187,10 @@
"self": "問題のタイトルを強制する",
"description": "問題のタイトルが空でないこと、および自動生成ではなくユーザーが作成することを強制します。"
},
+ "allow-self-approval": {
+ "self": "自己承認を許可する",
+ "description": "問題の作成者が問題を承認できるようにします。"
+ },
"default-backup-behavior": {
"self": "デフォルトのバックアップ動作",
"description": "データ変更の問題を作成するときのデフォルトのバックアップ動作。",
@@ -3898,4 +3902,4 @@
"last-visit": "最終訪問",
"changelog-for-version": "{version} の変更履歴"
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index cd1415678b..24a5fdfb0e 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -2187,6 +2187,10 @@
"self": "要求手动输入工单标题",
"description": "工单标题必须由用户输入而不是自动生成。"
},
+ "allow-self-approval": {
+ "self": "允许创建者审批",
+ "description": "允许创建者审批自己创建的工单。"
+ },
"default-backup-behavior": {
"self": "默认备份行为",
"description": "创建数据更改问题时的默认备份行为。",
diff --git a/frontend/src/store/modules/v1/issue.ts b/frontend/src/store/modules/v1/issue.ts
index 94ac459970..5276f6cd8d 100644
--- a/frontend/src/store/modules/v1/issue.ts
+++ b/frontend/src/store/modules/v1/issue.ts
@@ -217,8 +217,8 @@ export const candidatesOfApprovalStepV1 = (
(user) =>
user.userType === UserType.USER &&
user.state === State.ACTIVE &&
- // TODO(steven): handle this with project setting about whether to include creator.
- user.email !== extractUserEmail(issue.creator)
+ (issue.projectEntity.allowSelfApproval ||
+ user.email !== extractUserEmail(issue.creator))
)
.map((user) => user.name)
);