Harden commands, plugin install and data paths
- Limit the terminal, build, relay and shell-open commands - Verify a signed plugin registry and pin plugin files by hash - Stop baking an API key into the binary; remove remote shelve - Keep open work on folder delete, unshelve and partial submit - Add Check Out, +l visibility and admin unlock - Run p4 with timeouts, threaded stderr, non-UTF-8 lines and batches Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
60
src/App.tsx
60
src/App.tsx
@ -4,7 +4,7 @@ import { getCurrentWindow } from "@tauri-apps/api/window";
|
||||
import { getCurrentWebview } from "@tauri-apps/api/webview";
|
||||
import { listen } from "@tauri-apps/api/event";
|
||||
import { isPermissionGranted, requestPermission, sendNotification } from "@tauri-apps/plugin-notification";
|
||||
import { open as openDialog } from "@tauri-apps/plugin-dialog";
|
||||
import { open as openDialog, ask as askDialog } from "@tauri-apps/plugin-dialog";
|
||||
import ModelViewer from "./ModelViewer";
|
||||
import CodeView from "./CodeView";
|
||||
import { useUpdater } from "./Updater";
|
||||
@ -584,8 +584,7 @@ function Workbench({ info, session, light, toggleTheme, themeId, setThemeId, lan
|
||||
const sameUser = (o.user || "").toLowerCase() === me;
|
||||
const sameClient = (o.client || "").toLowerCase() === myClient;
|
||||
if (sameUser && sameClient) continue; // it's my own checkout
|
||||
// `p4 opened -a` includes an `ourLock` field only when the file is locked
|
||||
const locked = (o as Record<string, unknown>).ourLock !== undefined;
|
||||
const locked = isHeld(o);
|
||||
map.set(dp, { user: o.user || "?", locked });
|
||||
}
|
||||
setOthers(map);
|
||||
@ -646,12 +645,11 @@ function Workbench({ info, session, light, toggleTheme, themeId, setThemeId, lan
|
||||
launch: () => { void launchUE(); },
|
||||
readLog: (tb?: number) => p4.ueLog(uprojectRef.current, tb ?? 200_000),
|
||||
},
|
||||
// Team bridge — presence + coordinator shelve tools; plugin owns the logic
|
||||
// Team bridge — presence; plugin owns the logic
|
||||
team: {
|
||||
whoami: () => (info ? { user: info.userName, client: info.clientName, root: info.clientRoot } : null),
|
||||
maxAccess: () => p4.protectsMax().catch(() => ""),
|
||||
openCount: () => p4.opened("").then((a) => a.length).catch(() => 0),
|
||||
shelveOpen: (desc: string) => p4.shelveOpen(desc),
|
||||
submitShelved: (change: string) => p4.submitShelved(change),
|
||||
relay: (url: string, method: string, body?: string, token?: string) => p4.relayHttp(url, method, body, token),
|
||||
},
|
||||
@ -1029,12 +1027,20 @@ function Workbench({ info, session, light, toggleTheme, themeId, setThemeId, lan
|
||||
// delete a folder — marks its files for delete (reviewable), removes fresh/local ones
|
||||
async function deleteFolder(path: string) {
|
||||
const name = splitPath(path).name || path;
|
||||
if (!(await confirm({ title: t("Delete folder “{name}”?", { name }), body: t("Every file under this folder is marked for delete. Nothing leaves the server until you Submit; freshly-added files are removed right away."), confirm: t("Delete"), danger: true }))) return;
|
||||
if (!(await confirm({ title: t("Delete folder “{name}”?", { name }), body: t("Every file under this folder is marked for delete. Nothing leaves the server until you Submit. A folder with open files is refused."), confirm: t("Delete"), danger: true }))) return;
|
||||
try { const r = await p4.deleteFolder(path); flash(r.length ? t("Marked {n} file(s) for delete — Submit to remove the folder.", { n: r.length }) : t("Folder removed.")); await refresh(); }
|
||||
catch (e) { flash(String(e), true); }
|
||||
}
|
||||
// right-click on a folder in the File Tree → folder operations
|
||||
function folderMenu(n: FsEntry, e: ReactMouseEvent) {
|
||||
if (!n.isDir) {
|
||||
openCtx(e, [
|
||||
{ label: t("Check out"), icon: I.lock, act: () => checkOut([n.path]) },
|
||||
{ label: t("Open in Explorer"), icon: I.reveal, act: () => reveal(n.path) },
|
||||
{ label: t("Copy path"), icon: I.copy, act: () => copyText(n.path, t("Path")) },
|
||||
]);
|
||||
return;
|
||||
}
|
||||
const isDepot = n.path.startsWith("//");
|
||||
openCtx(e, [
|
||||
{ label: t("New folder / project…"), icon: I.folder, act: () => newFolder(n.path) },
|
||||
@ -1310,7 +1316,7 @@ function Workbench({ info, session, light, toggleTheme, themeId, setThemeId, lan
|
||||
const isCode = isCodeFile(splitPath(dp).name);
|
||||
openCtx(e, [
|
||||
{ label: targets.length > 1 ? t("Discard changes · {n} files", { n: targets.length }) : t("Discard changes"), icon: I.trash, danger: true, act: () => discard(targets) },
|
||||
{ label: t("Lock (exclusive)"), icon: I.lock, act: () => lockFiles(dps, true) },
|
||||
{ label: t("Lock against submit"), icon: I.lock, act: () => lockFiles(dps, true) },
|
||||
{ label: t("Unlock"), icon: I.unlock, act: () => lockFiles(dps, false) },
|
||||
{ label: t("Set exclusive-lock type (+l)"), icon: I.lock, act: () => setExclusiveType(dps) },
|
||||
...(workOffline ? [{ label: t("Make writable (offline edit)"), icon: I.unlock, act: () => makeWritable(targets) }] : []),
|
||||
@ -1327,6 +1333,15 @@ function Workbench({ info, session, light, toggleTheme, themeId, setThemeId, lan
|
||||
try { await (lock ? p4.lock(dps) : p4.unlock(dps)); flash(lock ? t("Locked {n} file(s).", { n: dps.length }) : t("Unlocked {n} file(s).", { n: dps.length })); await refresh(); }
|
||||
catch (e) { flash(String(e), true); }
|
||||
}
|
||||
// `p4 edit`; an exclusive (+l) file held elsewhere comes back without a record
|
||||
async function checkOut(paths: string[]) {
|
||||
try {
|
||||
const r = await p4.edit(paths);
|
||||
const all = r.length >= paths.length;
|
||||
flash(all ? t("{n} file(s) checked out.", { n: r.length }) : t("Checked out {n} of {total}. The rest are held by someone else.", { n: r.length, total: paths.length }), !all);
|
||||
await refresh();
|
||||
} catch (e) { flash(String(e), true); }
|
||||
}
|
||||
// switch opened files to an exclusive-lock file type (+l) so only one person edits them
|
||||
async function setExclusiveType(dps: string[]) {
|
||||
if (!dps.length) return;
|
||||
@ -1389,6 +1404,16 @@ function Workbench({ info, session, light, toggleTheme, themeId, setThemeId, lan
|
||||
const showBlame = (spec: string, name: string) => setModal({ kind: "blame", spec, name });
|
||||
|
||||
async function doResolve(mode: "am" | "ay" | "at", file = "") {
|
||||
if (mode !== "am") {
|
||||
const name = file ? splitPath(file).name : t("{n} files", { n: needResolve.length });
|
||||
const theirs = mode === "at";
|
||||
if (!(await confirm({
|
||||
title: theirs ? t("Accept theirs for {name}?", { name }) : t("Accept yours for {name}?", { name }),
|
||||
body: theirs ? t("Your local changes in these files are replaced by the server version.") : t("Changes made on the server are dropped and your version wins."),
|
||||
confirm: theirs ? t("Accept theirs") : t("Accept yours"),
|
||||
danger: true,
|
||||
}))) return;
|
||||
}
|
||||
try {
|
||||
await p4.resolveFile(file, mode);
|
||||
const rest = await p4.resolveList();
|
||||
@ -2552,6 +2577,12 @@ function SearchModal({ scope, onClose, onOpenEditor, onReveal, onCopy }: { scope
|
||||
}
|
||||
|
||||
/* ---------------- file locks viewer — who has what locked/open across the depot ---------------- */
|
||||
// held by someone: a `p4 lock`, or an open of an exclusive (+l) file type
|
||||
function isHeld(f: OpenedFile): boolean {
|
||||
const r = f as Record<string, unknown>;
|
||||
return r.ourLock !== undefined || /\+\w*l/.test(String(r.type || ""));
|
||||
}
|
||||
|
||||
// the File Locks list (bar + rows), reused by the modal AND the dockable panel
|
||||
function LocksPanel({ me, onReveal, onFlash, onUnlock }: { me: string; onReveal: (dp: string) => void; onFlash: (t: string, e?: boolean) => void; onUnlock: (dp: string) => void }) {
|
||||
const [files, setFiles] = useState<OpenedFile[]>([]);
|
||||
@ -2559,8 +2590,9 @@ function LocksPanel({ me, onReveal, onFlash, onUnlock }: { me: string; onReveal:
|
||||
const [q, setQ] = useState("");
|
||||
const [lockedOnly, setLockedOnly] = useState(true);
|
||||
const load = () => { setBusy(true); p4.openedAll("").then(setFiles).catch((e) => { onFlash(String(e), true); setFiles([]); }).finally(() => setBusy(false)); };
|
||||
useEffect(() => { load(); }, []); // eslint-disable-line
|
||||
const isLocked = (f: OpenedFile) => (f as Record<string, unknown>).ourLock !== undefined;
|
||||
const [admin, setAdmin] = useState(false);
|
||||
useEffect(() => { load(); p4.protectsMax().then((a) => setAdmin(/^(admin|super)$/i.test(a))).catch(() => {}); }, []); // eslint-disable-line
|
||||
const isLocked = isHeld;
|
||||
const s = q.trim().toLowerCase();
|
||||
const rows = files.filter((f) => (!lockedOnly || isLocked(f)) && (!s || (f.depotFile || "").toLowerCase().includes(s) || (f.user || "").toLowerCase().includes(s)));
|
||||
return (
|
||||
@ -2578,12 +2610,14 @@ function LocksPanel({ me, onReveal, onFlash, onUnlock }: { me: string; onReveal:
|
||||
const sp = splitPath(dp);
|
||||
const locked = isLocked(f);
|
||||
const mine = (f.user || "").toLowerCase() === me.toLowerCase();
|
||||
const hasLock = (f as Record<string, unknown>).ourLock !== undefined; // `p4 unlock` can't release a +l open
|
||||
return (
|
||||
<div key={dp + (f.client || "")} className="srch-row">
|
||||
<span className={"held" + (locked ? " locked" : "")} style={{ marginRight: 4 }}>{locked ? I.lock : I.unlock}</span>
|
||||
<span className="srch-body"><span className="n">{sp.name}</span><span className="p">{sp.dir}</span></span>
|
||||
<span className="lk-who">{f.user}{mine ? " · " + t("you") : ""}<span className="lk-client">{f.client}</span></span>
|
||||
{locked && mine && <button className="rslv-act" title={t("Unlock")} onClick={() => { onUnlock(dp); setTimeout(load, 400); }}>{t("Unlock")}</button>}
|
||||
{hasLock && mine && <button className="rslv-act" title={t("Unlock")} onClick={() => { onUnlock(dp); setTimeout(load, 400); }}>{t("Unlock")}</button>}
|
||||
{hasLock && !mine && admin && <button className="rslv-act" title={t("Force unlock")} onClick={() => { p4.unlockForce([dp]).then(load).catch((e) => onFlash(String(e), true)); }}>{t("Force unlock")}</button>}
|
||||
<button className="srch-act" title={t("Open in Explorer")} onClick={() => onReveal(dp)}>{I.folder}</button>
|
||||
</div>
|
||||
);
|
||||
@ -2832,7 +2866,7 @@ function ExpNode({ node, depth, load, max, onReveal, onFlash, onOpen, onMenu }:
|
||||
const childMax = Math.max(1, ...(kids || []).map((k) => k.size));
|
||||
return (
|
||||
<div className="exp-node">
|
||||
<div className={"exp-row" + (node.isDir || onOpen ? " dir" : "")} style={{ paddingLeft: 10 + depth * 15 }} onClick={activate} onContextMenu={(e) => { if (node.isDir && onMenu) { e.preventDefault(); e.stopPropagation(); onMenu(node, e); } }} title={node.path}>
|
||||
<div className={"exp-row" + (node.isDir || onOpen ? " dir" : "")} style={{ paddingLeft: 10 + depth * 15 }} onClick={activate} onContextMenu={(e) => { if (onMenu) { e.preventDefault(); e.stopPropagation(); onMenu(node, e); } }} title={node.path}>
|
||||
<span className="exp-caret">{node.isDir ? (busy ? <span className="ldr sm" /> : <span className={"chevi" + (open ? " open" : "")}>{I.chevron}</span>) : null}</span>
|
||||
<span className="exp-ic">{node.isDir ? I.folder : FILE_GLYPH}</span>
|
||||
<span className="exp-name">{node.name}</span>
|
||||
@ -3391,8 +3425,10 @@ function PluginsModal({ onClose, onReload, onFlash, embedded }: { onClose?: () =
|
||||
const loadReg = () => { setRegBusy(true); setRegErr(""); fetchRegistry().then(setReg).catch((e) => setRegErr(String(e))).finally(() => setRegBusy(false)); };
|
||||
useEffect(() => { load(); loadReg(); p4.pluginsDirPath().then(setDir).catch(() => {}); const k = (e: KeyboardEvent) => e.key === "Escape" && onClose?.(); document.addEventListener("keydown", k); return () => document.removeEventListener("keydown", k); }, []); // eslint-disable-line
|
||||
async function installReg(entry: RegistryEntry) {
|
||||
const perms = (entry.permissions || []).join(", ") || "—";
|
||||
if (!(await askDialog(t("A plugin runs with full access to this app, including your Perforce session. Declared permissions: {perms}.", { perms }), { title: t("Install plugin “{name}”?", { name: entry.name }), kind: "warning" }))) return;
|
||||
setInstalling(entry.id);
|
||||
try { await installFromRegistry(entry); load(); await onReload(); onFlash(t("Installed plugin “{id}”.", { id: entry.name })); }
|
||||
try { await installFromRegistry(entry); await p4.pluginSetEnabled(entry.id, true); load(); await onReload(); onFlash(t("Installed plugin “{id}”.", { id: entry.name })); }
|
||||
catch (e) { onFlash(String(e), true); }
|
||||
finally { setInstalling(""); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user