Skip to content

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

chore: allow workspace owner/dba to edit sql statement of issues (#6857)

Liu Ji9a3e79f290ae
diff --git a/frontend/src/components/Issue/logic/TenantModeProvider.ts b/frontend/src/components/Issue/logic/TenantModeProvider.ts
index 758f2659af..b2f87b3fc4 100644
--- a/frontend/src/components/Issue/logic/TenantModeProvider.ts
+++ b/frontend/src/components/Issue/logic/TenantModeProvider.ts
@@ -6,6 +6,7 @@ import {
useTaskStore,
useSheetStatementByUid,
useDatabaseV1Store,
+ useCurrentUserV1,
} from "@/store";
import {
Issue,
@@ -26,7 +27,12 @@ import {
useCommonLogic,
} from "./common";
import { provideIssueLogic, useIssueLogic } from "./index";
-import { getBacktracePayloadWithIssue, sheetIdOfTask } from "@/utils";
+import {
+ extractUserUID,
+ getBacktracePayloadWithIssue,
+ hasWorkspacePermissionV1,
+ sheetIdOfTask,
+} from "@/utils";
import { getProjectPathByLegacyProject } from "@/store/modules/v1/common";
import {
Sheet_Visibility,
@@ -41,6 +47,7 @@ export default defineComponent({
const { create, issue, selectedTask, createIssue, onStatusChanged } =
useIssueLogic();
const route = useRoute();
+ const currentUser = useCurrentUserV1();
const databaseStore = useDatabaseV1Store();
const sheetV1Store = useSheetV1Store();
const projectV1Store = useProjectV1Store();
@@ -54,8 +61,26 @@ export default defineComponent({
if (create.value) {
return true;
}
+
const tasks = flattenTaskList<Task>(issue.value);
- return tasks.every((task) => isTaskEditable(task));
+ if (!tasks.every((task) => isTaskEditable(task))) {
+ return false;
+ }
+
+ if (
+ hasWorkspacePermissionV1(
+ "bb.permission.workspace.manage-issue",
+ currentUser.value.userRole
+ )
+ ) {
+ return true;
+ }
+
+ const creatorUID = String((issue.value as Issue).creator.id);
+ if (creatorUID === extractUserUID(currentUser.value.name)) {
+ return true;
+ }
+ return false;
});
// In tenant mode, the entire issue shares only one SQL statement
diff --git a/frontend/src/components/Issue/logic/common.ts b/frontend/src/components/Issue/logic/common.ts
index 40d817d0f3..21471921a8 100644
--- a/frontend/src/components/Issue/logic/common.ts
+++ b/frontend/src/components/Issue/logic/common.ts
@@ -37,6 +37,7 @@ import {
defer,
extractUserUID,
getBacktracePayloadWithIssue,
+ hasWorkspacePermissionV1,
isDev,
isTaskTriggeredByVCS,
taskCheckRunSummary,
@@ -190,19 +191,35 @@ export const useCommonLogic = () => {
if (issueEntity.status !== "OPEN") {
return false;
}
+
+ if (!isTaskEditable(selectedTask.value as Task)) {
+ return false;
+ }
+
if (
- String(issueEntity.creator.id) !==
+ String(issueEntity.creator.id) ===
extractUserUID(currentUserV1.value.name)
) {
- if (isTaskTriggeredByVCS(selectedTask.value as Task)) {
- // If an issue is triggered by VCS, its creator will be 1 (SYSTEM_BOT_ID)
- // We should "Allow" current user to edit the statement (via VCS).
- return true;
- }
- return false;
+ return true;
+ }
+
+ if (
+ hasWorkspacePermissionV1(
+ "bb.permission.workspace.manage-issue",
+ currentUserV1.value.userRole
+ )
+ ) {
+ // Workspace OWNER/DBA are always allowed to edit.
+ return true;
+ }
+
+ if (isTaskTriggeredByVCS(selectedTask.value as Task)) {
+ // If an issue is triggered by VCS, its creator will be 1 (SYSTEM_BOT_ID)
+ // We should "Allow" current user to edit the statement (via VCS).
+ return true;
}
- return isTaskEditable(selectedTask.value as Task);
+ return false;
});
const updateStatement = async (newStatement: string) => {