fix(project-trust): list restricted projects in Project Trust settings (#4257)

A project with a restricted decision stays restricted inside a trusted location, but the settings page didn't list those decisions. The page now lists restricted projects with a Trust button, and the location hint says restricted projects are excluded. Fixes #4156.
This commit is contained in:
l0ng-ai
2026-11-18 19:03:39 +08:00
committed by GitHub
parent 6efece99a4
commit 6a41509fd2
5 changed files with 61 additions and 6 deletions
+27 -1
View File
@@ -140,6 +140,14 @@ function TrustSettings() {
setError(String(e));
}
};
const trust = async (path: string) => {
try {
await call(commands.projectTrustSet(path, true, false));
await refresh();
} catch (e) {
setError(String(e));
}
};
const addLocation = async () => {
try {
const { open } = await import("@/platform/dialog");
@@ -169,6 +177,24 @@ function TrustSettings() {
</Button>
</div>
))}
{decisions?.restricted.length ? (
<>
<h3>
<T>Restricted projects</T>
</h3>
<p className={styles.hint}>
<T>These projects open in Restricted Mode, even inside a trusted location.</T>
</p>
{decisions.restricted.map((path) => (
<div className={styles.row} key={path}>
<span className={styles.path}>{path}</span>
<Button onClick={() => void trust(path)}>
<T>Trust</T>
</Button>
</div>
))}
</>
) : null}
<div className={styles.sectionHead}>
<h3>
<T>Trusted locations</T>
@@ -178,7 +204,7 @@ function TrustSettings() {
</Button>
</div>
<p className={styles.hint}>
<T>Every project inside a trusted location is trusted without asking.</T>
<T>Every project inside a trusted location is trusted without asking, unless it is a restricted project.</T>
</p>
{decisions?.locations.map((path) => (
<div className={styles.row} key={path}>
+5 -1
View File
@@ -58,9 +58,13 @@
justify-content: space-between;
gap: var(--space-3);
}
.sectionHead h3 {
.content h3 {
margin: 0;
}
.content > h3,
.sectionHead {
margin-top: var(--space-3);
}
.hint {
color: var(--fg-secondary);
}
+19 -1
View File
@@ -1,5 +1,5 @@
import { afterEach, beforeEach, expect, it, vi } from "vitest";
import { act, fireEvent, render, screen } from "@testing-library/react";
import { act, fireEvent, render, screen, waitFor } from "@testing-library/react";
import { confirmProjectTrust } from "@/platform/projectTrust";
import { executeAction } from "@/platform/actions";
import { emitLocalIdeEvent } from "@/platform/ipc";
@@ -165,6 +165,24 @@ it("adds a picked folder as a trusted location from settings", async () => {
expect(addLocation).toHaveBeenCalledTimes(1);
});
it("lists restricted projects, which a trusted location doesn't cover, and trusts one from settings", async () => {
const Page = useSettingsPages.getState().pages.get("projectTrust")!.component!;
listDecisions.mockResolvedValue({
status: "ok",
data: { projects: [], locations: ["/projects"], restricted: ["/projects/app"] },
});
render(<Page />);
expect(await screen.findByRole("heading", { name: "Restricted projects" })).toBeTruthy();
listDecisions.mockResolvedValue({
status: "ok",
data: { projects: ["/projects/app"], locations: ["/projects"], restricted: [] },
});
fireEvent.click(screen.getByRole("button", { name: "Trust" }));
await waitFor(() => expect(screen.queryByRole("heading", { name: "Restricted projects" })).toBeNull());
expect(decide).toHaveBeenCalledWith("/projects/app", true, false);
expect(screen.getByText("/projects/app")).toBeTruthy();
});
it.each(["Trust Project", "Preview in Restricted Mode"])(
"keeps a local opening's trust decision on the client: %s",
async (button) => {
+5 -1
View File
@@ -2479,5 +2479,9 @@
"Align key-value pairs": "Align key-value pairs",
"Align consecutive assignments": "Align consecutive assignments",
"Lines up => in multi-line arrays and = in consecutive assignments after the language server or PHP-CS-Fixer formats the file; for a selection, only its lines.": "Lines up => in multi-line arrays and = in consecutive assignments after the language server or PHP-CS-Fixer formats the file; for a selection, only its lines.",
"Are you sure you want to delete {name}?": "Are you sure you want to delete {name}?"
"Are you sure you want to delete {name}?": "Are you sure you want to delete {name}?",
"Every project inside a trusted location is trusted without asking, unless it is a restricted project.": "Every project inside a trusted location is trusted without asking, unless it is a restricted project.",
"Restricted projects": "Restricted projects",
"These projects open in Restricted Mode, even inside a trusted location.": "These projects open in Restricted Mode, even inside a trusted location.",
"Trust": "Trust"
}
+5 -2
View File
@@ -3793,7 +3793,6 @@
"(empty line)": "(空行)",
"Name cannot be empty": "名称不能为空",
"Every scope needs a name": "每个范围都需要名称",
"Every project inside a trusted location is trusted without asking.": "受信任的位置内的每个项目都会被信任,不再询问。",
"Scopes": "范围",
"Add Scope": "添加范围",
"Remove Scope": "移除范围",
@@ -8854,5 +8853,9 @@
"Align key-value pairs": "对齐键值对",
"Align consecutive assignments": "对齐连续赋值",
"Lines up => in multi-line arrays and = in consecutive assignments after the language server or PHP-CS-Fixer formats the file; for a selection, only its lines.": "在语言服务器或 PHP-CS-Fixer 格式化文件后,对齐多行数组中的 => 和连续赋值语句中的 =;格式化选区时只对齐选中的行。",
"Are you sure you want to delete {name}?": "确定要删除 {name} 吗?"
"Are you sure you want to delete {name}?": "确定要删除 {name} 吗?",
"Every project inside a trusted location is trusted without asking, unless it is a restricted project.": "受信任的位置内的每个项目都会被信任,不再询问;受限项目除外。",
"Restricted projects": "受限项目",
"These projects open in Restricted Mode, even inside a trusted location.": "这些项目即使位于受信任的位置内,也以受限模式打开。",
"Trust": "信任"
}