fix(slicer): drop the legacy library:read from the slice gate (#2725)

The desktop handoff accepted library:read alongside read_all/read_own, on
the reasoning that default groups do not carry it and requiring it would
lock out Operators and Viewers. The permission grants nothing in that
position: the slicer-token endpoint gates on
require_ownership_permission(LIBRARY_READ_ALL, LIBRARY_READ_OWN), and
neither that dependency nor User.has_permission expands the legacy name,
so a group holding only library:read gets a 403 there. It cannot reach
the File Manager to try, either - GET /library/folders gates on the same
pair - and the library:read -> library:read_own migration in
core/database.py runs only over the groups named in DEFAULT_GROUPS, so a
custom role that still carries it stays stuck rather than being upgraded.
custom role that still carries it stays stuck rather than being upgraded.

Accepting it only enabled a menu item the server refuses, and the failure
is indistinguishable from "no slicer installed" once the catch hands the
unauthenticated URL over. Removed, with the comment recording the reason
so the next reader does not re-add it, and a test that pins it.

---

refactor(slicer): share one sliceable-file-type rule (#2725)

The File Manager and the 3D preview decide the same thing about the same
file and each held its own list of extensions - which is how they came to
disagree, offering a desktop handoff for an STL whose own preview showed
"Open in Slicer" greyed out. Making the two lists identical fixed the
symptom and left the drift, so SLICEABLE_FILE_TYPES now lives in
utils/slicer.ts with isSliceableFileType for a stored file_type and
isSliceableFilename for a name.

The filename form still rules out the compound extensions explicitly,
since .gcode.3mf ends with .3mf; the type form does not need to, because
classify_file_type stores that one whole.

Both test files mocked the whole slicer module, which would have replaced
the new predicates with undefined - switched to importOriginal so only
openInSlicer is stubbed. That is the better shape regardless: the tests
now exercise the rule the component runs instead of a copy declared
beside them.

Carries the rebuilt bundle. The CSS hash moves with it - the split button
introduces Tailwind classes the previous build had no reason to emit.
This commit is contained in:
maziggy
2026-08-05 12:11:55 +02:00
parent f7f859b2ff
commit fb4c130bb2
9 changed files with 188 additions and 126 deletions
+6 -6
View File
@@ -7,7 +7,7 @@ import { GcodeViewer } from './GcodeViewer';
import { Button } from './Button';
import { api, withStreamToken } from '../api/client';
import { useToast } from '../contexts/ToastContext';
import { openInSlicer, resolveDesktopSlicer, type SlicerType } from '../utils/slicer';
import { isSliceableFileType, openInSlicer, resolveDesktopSlicer, type SlicerType } from '../utils/slicer';
import type { ArchivePlatesResponse, LibraryFilePlatesResponse, PlateMetadata } from '../types/plates';
type ViewTab = '3d' | 'gcode';
@@ -373,11 +373,11 @@ export function ModelViewerModal({ archiveId, libraryFileId, title, fileType, on
}, [isDraggingDivider, dividerHeight, minPlateHeight, minViewerPx, minViewerRatio]);
// Which file types can be handed to a desktop slicer via the URL protocol
// handler — and sliced in-app via the sidecar. Kept in step with
// `isSliceableFilename()` in FileManagerPage so a file's card-menu "Slice"
// and its 3D-preview slicer button never disagree on the same type.
const normalizedFileType = (fileType || '').toLowerCase();
const slicerReadyType = ['3mf', 'stl', 'step', 'stp'].includes(normalizedFileType);
// handler — and sliced in-app via the sidecar. Shares its list with
// `isSliceableFilename()`, which the File Manager's card menu and list row
// use, so a file's "Slice" action and its 3D-preview slicer button can no
// longer disagree about the same file.
const slicerReadyType = isSliceableFileType(fileType);
const canOpenInSlicer = isLibrary ? slicerReadyType : true;
// When the user has the in-app Slicer API enabled (Settings → Workflow →