Skip to content

Self-hosted workflows for coding-agent delivery. Orchestrate CodeBuddy, Codex and Claude Code with scripts and human approval gates. Includes Local workflows for coding assistants.

fix(chatbot): explain repository permissions in quick access before the last step (#141)

Robert062263c9e46cb007
diff --git a/chatbot/src/QuickAccessWizard.jsx b/chatbot/src/QuickAccessWizard.jsx
index 7470677b..b662186b 100644
--- a/chatbot/src/QuickAccessWizard.jsx
+++ b/chatbot/src/QuickAccessWizard.jsx
@@ -10,7 +10,7 @@ import React, {
import { createPortal } from "react-dom";
import HarnessIcon from "./HarnessIcon";
import SlidingTabs from "./SlidingTabs";
-import { api, canChatInProject, write } from "./api";
+import { api, canChatInProject, canManageProjectRepos, write } from "./api";
import { usePanelPresence } from "./usePanelPresence";
import {
CODEBUDDY_ENVIRONMENTS,
@@ -854,6 +854,13 @@ export default function QuickAccessWizard({
[editableProjects, selectedProjectId],
);
+ // A member can work in a shared project (e.g. the welcome project) without
+ // owning it; binding a repository there would only fail at the last step.
+ const repoBindBlocked =
+ projectMode === "existing" &&
+ Boolean(currentProject) &&
+ !canManageProjectRepos(currentProject, storedUser || user);
+
const projectRepos = useMemo(
() =>
currentProject
@@ -1263,6 +1270,12 @@ export default function QuickAccessWizard({
setError("请选择一个项目,或切换到新建项目。");
return;
}
+ if (bindRepoNow && repoUrl.trim() && repoBindBlocked) {
+ setError(
+ `你不是「${currentProject?.name || "该项目"}」的 Owner,不能为它绑定仓库。请新建自己的项目并绑定,或关闭「绑定仓库」继续体验。`,
+ );
+ return;
+ }
if (bindRepoNow && repoUrl.trim() && !parsedRepo) {
setError(
"仓库地址无法识别,请粘贴 GitHub 仓库链接(https://github.com/owner/repo)或 github:owner/repo。",
@@ -1320,7 +1333,7 @@ export default function QuickAccessWizard({
}
let boundRepo = defaultRepo;
- if (bindRepoNow && parsedRepo && targetProject?.id) {
+ if (bindRepoNow && parsedRepo && targetProject?.id && !repoBindBlocked) {
const existingRepo = (repositories || []).find(
(repo) =>
repo.projectId === targetProject.id &&
@@ -2059,6 +2072,39 @@ export default function QuickAccessWizard({
>
<div className="qa-collapse-inner">
<div className="qa-cred-body">
+ {repoBindBlocked ? (
+ <div
+ className="qa-hint is-warn qa-repo-permission"
+ role="note"
+ >
+ <p>
+ 「{currentProject?.name}」是已有项目,只有它的
+ Owner 或平台管理员可以绑定仓库。你可以:
+ </p>
+ <div className="qa-repo-permission-actions">
+ <button
+ type="button"
+ className="qa-link-btn"
+ onClick={() => {
+ setError("");
+ setProjectMode("create");
+ }}
+ >
+ 新建自己的项目并绑定
+ </button>
+ <button
+ type="button"
+ className="qa-link-btn"
+ onClick={() => {
+ setError("");
+ setBindRepoNow(false);
+ }}
+ >
+ 跳过绑定,继续体验
+ </button>
+ </div>
+ </div>
+ ) : null}
<div className="qa-repo-grid">
<label className="qa-field">
<span className="qa-label">
@@ -2261,11 +2307,11 @@ export default function QuickAccessWizard({
<span className="qa-dot is-ok" />
<span>
{projectMode === "create"
- ? newProjectName || "新项目"
- : currentProject?.name || "当前项目"}
+ ? `新建项目「${newProjectName || "新项目"}」`
+ : `使用已有项目「${currentProject?.name || "当前项目"}」`}
{" · "}
- {bindRepoNow && parsedRepo
- ? parsedRepo.name
+ {bindRepoNow && parsedRepo && !repoBindBlocked
+ ? `绑定 ${parsedRepo.name}`
: defaultRepo?.name || "运行时指定仓库"}
</span>
</dd>
diff --git a/chatbot/src/api.js b/chatbot/src/api.js
index d2784515..39838a9a 100644
--- a/chatbot/src/api.js
+++ b/chatbot/src/api.js
@@ -249,6 +249,16 @@ export function canChatInProject(project, user) {
project.ownerId === user.id || members.some((m) => m.userId === user.id)
);
}
+// Mirrors canManageProjectRepositories on the server: only the project owner
+// or a platform admin may bind repositories. Without a signed-in user the
+// server decides (open deployments allow it), so this only says no when it
+// knows the answer.
+export function canManageProjectRepos(project, user) {
+ if (!project || !user || user.isGuest) return true;
+ if (user.isPlatformAdmin) return true;
+ if (String(user.platformRole || "").toLowerCase() === "admin") return true;
+ return Boolean(project.ownerId) && Number(project.ownerId) === Number(user.id);
+}
export const UNJOINED_PROJECTS_SECTION = "未加入的项目";
// Projects the user can chat in keep their original order; the rest follow
// under their own section without a per-row explanation.
diff --git a/chatbot/src/quick-access-wizard.css b/chatbot/src/quick-access-wizard.css
index 7762ea5f..c8092066 100644
--- a/chatbot/src/quick-access-wizard.css
+++ b/chatbot/src/quick-access-wizard.css
@@ -1018,6 +1018,44 @@
color: var(--qa-warn-text);
}
+.qa-repo-permission {
+ margin-bottom: 12px;
+ padding: 10px 12px;
+ border-radius: 10px;
+ background: var(--qa-warn-soft);
+}
+
+.qa-repo-permission p {
+ margin: 0;
+}
+
+.qa-repo-permission-actions {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 6px 14px;
+ margin-top: 6px;
+}
+
+.qa-link-btn {
+ padding: 0;
+ border: 0;
+ background: none;
+ color: var(--qa-accent-text);
+ font: inherit;
+ font-weight: 600;
+ cursor: pointer;
+}
+
+.qa-link-btn:hover {
+ text-decoration: underline;
+}
+
+.qa-link-btn:focus-visible {
+ outline: 2px solid var(--qa-accent);
+ outline-offset: 2px;
+ border-radius: 4px;
+}
+
.qa-hint code,
.qa-repo-default-row code {
padding: 1px 5px;
diff --git a/chatbot/tests/quick-access-wizard.test.jsx b/chatbot/tests/quick-access-wizard.test.jsx
index de391508..a40638db 100644
--- a/chatbot/tests/quick-access-wizard.test.jsx
+++ b/chatbot/tests/quick-access-wizard.test.jsx
@@ -379,3 +379,81 @@ describe("QuickAccessWizard", () => {
mockState.failClone = false;
});
});
+
+describe("QuickAccessWizard repository permission (#122)", () => {
+ const welcome = {
+ id: "welcome", key: "WELCOME", name: "LoopForge 体验项目", ownerId: 99,
+ members: [{ userId: 1, role: "member" }], workflowId: "generic-backend-delivery",
+ };
+ const member = { ...user, isPlatformAdmin: false };
+ const renderWizard = () =>
+ render(
+ <QuickAccessWizard
+ open
+ user={member}
+ projects={[welcome]}
+ projectId="welcome"
+ sponsoredModel="m1"
+ onClose={vi.fn()}
+ onCompleted={vi.fn()}
+ onOpenView={vi.fn()}
+ />,
+ );
+ const openProjectStep = async (userAction) => {
+ await screen.findByRole("dialog");
+ await userAction.click(screen.getByRole("button", { name: "下一步" }));
+ await screen.findByText("项目与仓库", { selector: "h3" });
+ };
+
+ test("explains on the project step that a member cannot bind the shared project", async () => {
+ apiMock.mockImplementation(async (path) => {
+ if (path === "/api/projects") return [welcome];
+ if (path === "/api/users") return [member];
+ if (path === "/api/workflows") return [{ id: "generic-backend-delivery", name: "通用后端交付 SOP", generic: true, nodes: [] }];
+ return [];
+ });
+ writeMock.mockClear();
+ const userAction = userEvent.setup();
+ renderWizard();
+ await openProjectStep(userAction);
+ expect(screen.getByRole("note")).toHaveTextContent("只有它的 Owner 或平台管理员可以绑定仓库");
+ const input = screen.getByPlaceholderText("https://github.com/owner/repo");
+ await userAction.type(input, "https://github.com/team/repo");
+ await userAction.click(screen.getByRole("button", { name: "下一步" }));
+ // Blocked here, not on the last step, and nothing was written.
+ expect(await screen.findByText(/不能为它绑定仓库/)).toBeInTheDocument();
+ expect(screen.queryByText("默认角色与 SOP", { selector: "h3" })).toBeNull();
+ expect(writeMock).not.toHaveBeenCalledWith("/api/repositories", expect.anything());
+ expect(writeMock).not.toHaveBeenCalledWith("/api/repositories", expect.anything(), expect.anything());
+
+ // "Create my own project" keeps the typed repository.
+ await userAction.click(screen.getByRole("button", { name: "新建自己的项目并绑定" }));
+ expect(screen.getByRole("tab", { name: /新建项目/ })).toHaveAttribute("aria-selected", "true");
+ expect(screen.getByPlaceholderText("https://github.com/owner/repo")).toHaveValue("https://github.com/team/repo");
+ expect(screen.queryByRole("note")).toBeNull();
+ apiMock.mockReset();
+ });
+
+ test("skipping the binding continues with the shared project and writes no repository", async () => {
+ apiMock.mockImplementation(async (path) => {
+ if (path === "/api/projects") return [welcome];
+ if (path === "/api/users") return [member];
+ if (path === "/api/workflows") return [{ id: "generic-backend-delivery", name: "通用后端交付 SOP", generic: true, nodes: [] }];
+ return [];
+ });
+ writeMock.mockClear();
+ const userAction = userEvent.setup();
+ renderWizard();
+ await openProjectStep(userAction);
+ await userAction.type(screen.getByPlaceholderText("https://github.com/owner/repo"), "https://github.com/team/repo");
+ await userAction.click(screen.getByRole("button", { name: "跳过绑定,继续体验" }));
+ await userAction.click(screen.getByRole("button", { name: "下一步" }));
+ await screen.findByText("默认角色与 SOP", { selector: "h3" });
+ expect(screen.getByText(/使用已有项目「LoopForge 体验项目」/)).toBeInTheDocument();
+ expect(screen.queryByText(/绑定 repo/)).toBeNull();
+ await userAction.click(screen.getByRole("button", { name: "完成接入" }));
+ expect(await screen.findByText("快速接入已完成")).toBeInTheDocument();
+ expect(writeMock.mock.calls.some(([path]) => path === "/api/repositories")).toBe(false);
+ apiMock.mockReset();
+ });
+});