Route work-product clicks through a resolver IPC
Filesystem work products store `external_id` as a workspace-relative
path so artifacts survive a workspace-root move, but the renderer was
handing that relative fragment straight to `shell.openPath`, which
needs an absolute managed path. Clicks flickered into a failed open.
Add a dedicated `openWorkProduct({ companyId, id })` IPC backed by
`resolveWorkProductTarget` on the DB layer. The resolver joins the
work-product row back to its originating task → workspace (or run →
workspace for taskless runs), composes an absolute path, and rejects
any relative fragment that would escape the workspace root. The
renderer now passes the work product's id — path resolution stays on
the main process where the managed-path policy already lives.
This commit is contained in:
1 parent
1a0fdc6f31
commit
ff9a52324e
7 files changed
+113
-8
No files matched your search
@@ -51,6 +51,35 @@ export function registerCoreReadHandlers({
|
||||
return error ? fail("OPEN_PATH_FAILED", error) : ok(true);
|
||||
});
|
||||
|
||||
/**
|
||||
* openWorkProduct resolves a work_product row to a concrete absolute
|
||||
* path (or URL) before handing off to the OS shell. The DocumentCenter
|
||||
* can no longer forward `externalId` straight into `openPath`: that
|
||||
* column stores a workspace-relative path so artifacts survive a
|
||||
* workspace-root move, but `shell.openPath` wants an absolute managed
|
||||
* path. The DB resolver joins the work_product back to its originating
|
||||
* task → workspace (or run → workspace for taskless runs) so the path
|
||||
* we hand to the shell is always inside the currently-mounted managed
|
||||
* tree and passes `canOpenPath` validation.
|
||||
*/
|
||||
registerHandle(IPC_CHANNELS.openWorkProduct, async (_event, payload) => {
|
||||
const parsed = entityGetterSchema.safeParse(payload);
|
||||
if (!parsed.success) return fail("INVALID_PAYLOAD", "openWorkProduct requires { companyId, id }.");
|
||||
const companyError = ensureCompanyExists(parsed.data.companyId);
|
||||
if (companyError) return companyError;
|
||||
const target = db.resolveWorkProductTarget(parsed.data.id, parsed.data.companyId);
|
||||
if (!target) return fail("WORK_PRODUCT_NOT_FOUND", "Work product not found or its workspace is unresolved.");
|
||||
if (target.kind === "url") {
|
||||
const error = await shell.openExternal(target.value).then(() => "").catch((err: unknown) => err instanceof Error ? err.message : String(err));
|
||||
return error ? fail("OPEN_PATH_FAILED", error) : ok(true);
|
||||
}
|
||||
if (!db.canOpenPath(target.value)) {
|
||||
return fail("OPEN_PATH_FORBIDDEN", "The requested path is outside the managed desktop workspace.");
|
||||
}
|
||||
const error = await shell.openPath(target.value);
|
||||
return error ? fail("OPEN_PATH_FAILED", error) : ok(true);
|
||||
});
|
||||
|
||||
registerHandle(IPC_CHANNELS.backupProfile, async () => {
|
||||
const result = await dialog.showOpenDialog({
|
||||
properties: ["openDirectory", "createDirectory"],
|
||||
|
||||
Reference in new issue
Block a user