From b453e87e43a6896184003316a170607a0a1a2379 Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Sun, 18 Oct 2026 07:14:40 +0000 Subject: [PATCH] feat(library): make the selected assets public, restricted or private at once Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QFUNzy1QZy5HhKAyJxTAYJ --- README.md | 3 +- changelog.d/bulk-visibility.md | 2 + docs/access.md | 3 +- docs/requirements.md | 1 + .../__tests__/library-catalogue.test.ts | 16 ++++++- nextjs-frontend/components/library/actions.ts | 43 +++++++++++++++++-- .../components/library/bulk-bar.tsx | 39 ++++++++++++++++- .../components/library/library-screen.tsx | 1 + nextjs-frontend/components/library/model.ts | 16 +++++++ 9 files changed, 117 insertions(+), 7 deletions(-) create mode 100644 changelog.d/bulk-visibility.md diff --git a/README.md b/README.md index 5ad3b99fe..a2102cb0a 100644 --- a/README.md +++ b/README.md @@ -273,7 +273,8 @@ listed under [In progress](#in-progress), and what comes next under [Planned](#p [usage analytics](docs/analytics.md); [checks](docs/requirements.md#watch-it-run)) - **Stay private and safe.** Passkeys instead of passwords (one at Lens's remote address added from a signed-in one with Open signed in), encryption at rest with a key per namespace, roles per namespace (viewer, editor, owner, or custom - roles made of permissions), email invitations, removing someone for good, and an audit log. Prompt injection meets + roles made of permissions), who sees each asset, set for many at once from the Library, email invitations, removing + someone for good, and an audit log. Prompt injection meets several layers: what the assistant reads (recordings, documents, web pages, tool results) reaches the model marked as data, not instructions, and text that reads like instructions to an AI is flagged (by free patterns, or an optional classifier model that runs on your machine and is fetched only when you pick it). Once an answer has read such text, diff --git a/changelog.d/bulk-visibility.md b/changelog.d/bulk-visibility.md new file mode 100644 index 000000000..991cf286d --- /dev/null +++ b/changelog.d/bulk-visibility.md @@ -0,0 +1,2 @@ +- **Visibility for many assets at once.** Owners select assets in the Library and pick Visibility › Public, Restricted + or Private; Undo puts each back as it was ([access](docs/access.md#an-assets-access)). diff --git a/docs/access.md b/docs/access.md index 790fcad1b..ec9f0c75c 100644 --- a/docs/access.md +++ b/docs/access.md @@ -17,7 +17,8 @@ closed part: whoever may see the asset's page sees it, as IIIF manifests always Publishing is for owners: they set an asset's access, open parts and featured flag (in its Access dialog, or through its metadata, bulk edits and reverts), and their namespace's default access and parts in its metadata -profile. Editors edit the rest of the metadata. Every change is kept in the metadata history and can be reverted. +profile. To change many at once, select them in the Library and pick Visibility › Public, Restricted or Private; +its toast's Undo puts each back as it was (agents: `POST /api/v1/metadata/bulk` with `set: {access}`). Editors edit the rest of the metadata. Every change is kept in the metadata history and can be reverted. Moving an asset to another namespace doesn't change who sees it: the access it had from its old namespace is pinned on it. diff --git a/docs/requirements.md b/docs/requirements.md index 57c571670..6fae2f12c 100644 --- a/docs/requirements.md +++ b/docs/requirements.md @@ -359,6 +359,7 @@ request, to another check that proves the same thing; loosening a requirement or | Remote access through a Cloudflare tunnel | [test_tunnel.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_tunnel.py) `test_remote_access_is_set_up_in_the_app`, `test_a_quick_tunnel_runs_in_one_process_and_stops_when_turned_off`, `test_a_managed_tunnel_is_made_routed_and_given_a_dns_record` | | The S3 and WebDAV shares and the MQTT hub at the web app's address (`/s3`, `/dav`, `/mqtt` over WebSockets), each off until turned on | [test_s3.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_s3.py) `test_at_the_web_apps_address_once_an_admin_allows_it`; [test_webdav.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_webdav.py) `test_at_the_web_apps_address_once_an_admin_allows_it`; [test_sensors.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_sensors.py) `test_broker_over_websockets`, `test_mqtt_over_websockets_takes_hub_logins_only`; [lens-relay.test.ts](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/lens-relay.test.ts) `relays any method, path and body to the share, and its answer back`, `passes the handshake on with the visitor and the prefix, then joins the two connections` | | The threat model's three files agree, and a change to the prose comes with its companions, without a line every change edits | [threat-model.yml](https://github.com/adeelahmad/lense/blob/main/.github/workflows/threat-model.yml) `validate`, `Validate the threat model`, `Test the validator`; [validate_threat_model.py](https://github.com/adeelahmad/lense/blob/main/ci/validate_threat_model.py); [test_validate_threat_model.py](https://github.com/adeelahmad/lense/blob/main/ci/test_validate_threat_model.py) `test_prose_change_without_companions_fails`, `test_two_changes_to_the_prose_merge_cleanly` | +| Owners make many assets public, restricted or private at once from the Library, with Undo putting each back | [library-catalogue.test.ts](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/library-catalogue.test.ts) `touches only those not there yet, and remembers how to put each back`; [test_access_settings.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_access_settings.py) `test_access_endpoint_and_defaults` | ## Use open standards diff --git a/nextjs-frontend/__tests__/library-catalogue.test.ts b/nextjs-frontend/__tests__/library-catalogue.test.ts index 596a59881..9cb6c08e1 100644 --- a/nextjs-frontend/__tests__/library-catalogue.test.ts +++ b/nextjs-frontend/__tests__/library-catalogue.test.ts @@ -1,5 +1,5 @@ import type { RecordingSummary } from "@/app/openapi-client/types.gen"; -import { catalogueRows, CATALOGUE_COLUMNS } from "@/components/library/model"; +import { catalogueRows, CATALOGUE_COLUMNS, visibilityGroups } from "@/components/library/model"; import { csvCell, toCsvText } from "@/lib/csv"; const row = (r: Partial): RecordingSummary => @@ -63,3 +63,17 @@ describe("the library's catalogue CSV", () => { ).toBe("a,b\n1,2\n"); }); }); + +describe("changing who sees the selection", () => { + it("touches only those not there yet, and remembers how to put each back", () => { + const rows = [ + { id: 1, access: "public" }, + { id: 2, access: "private" }, + { id: 3, access: null }, + { id: 4, access: "restricted" }, + ]; + expect(visibilityGroups(rows, "public")).toEqual({ private: [2, 3], restricted: [4] }); + expect(visibilityGroups(rows, "private")).toEqual({ public: [1], restricted: [4] }); + expect(visibilityGroups([{ id: 5, access: "public" }], "public")).toEqual({}); + }); +}); diff --git a/nextjs-frontend/components/library/actions.ts b/nextjs-frontend/components/library/actions.ts index b25f52ace..f5cceb251 100644 --- a/nextjs-frontend/components/library/actions.ts +++ b/nextjs-frontend/components/library/actions.ts @@ -4,10 +4,11 @@ import { useQueryClient } from "@tanstack/react-query"; import { useSession } from "next-auth/react"; import { useCallback } from "react"; -import { Jobs, Resources } from "@/app/openapi-client"; +import { Jobs, Metadata, Resources } from "@/app/openapi-client"; import type { RecordingSummary } from "@/app/openapi-client/types.gen"; import { useToast } from "@/components/ui/toast"; -import { catalogueRows, deletedToast, hasSound, movedToast } from "@/components/library/model"; +import { accessLabel } from "@/components/access/model"; +import { catalogueRows, deletedToast, hasSound, movedToast, visibilityGroups } from "@/components/library/model"; import { ApiError, data, useApiClient } from "@/lib/api/browser"; import { saveText, toCsvText } from "@/lib/csv"; import { plural } from "@/lib/format"; @@ -250,5 +251,41 @@ export function useRecordingActions() { [client, qc, refresh, toast], ); - return { retryJob, reprocess, exportMany, exportCatalogue, deleteMany, moveMany, retag }; + /** Who may see the rows, all at once (owners), with an Undo that puts each back as it was. */ + const setVisibility = useCallback( + async (rows: RecordingSummary[], to: "public" | "restricted" | "private") => { + const before = visibilityGroups(rows, to); + const ids = Object.values(before).flat(); + if (!ids.length) { + toast({ title: `They’re all ${accessLabel(to).toLowerCase()} already`, tone: "green" }); + return; + } + const apply = (recordings: number[], access: string) => + data(Metadata.bulkUpdateMetadata({ client, body: { recordings, set: { access }, dry_run: false } })); + try { + await apply(ids, to); + refresh(); + toast({ + title: `${plural(ids.length, "asset")} made ${accessLabel(to).toLowerCase()}`, + tone: "green", + action: { + label: "Undo", + onClick: () => { + void Promise.all(Object.entries(before).map(([was, back]) => apply(back, was))) + .then(() => { + refresh(); + toast({ title: "Put back as they were", tone: "green" }); + }) + .catch((e: Error) => toast({ title: "Couldn’t put them back", body: e.message, tone: "red" })); + }, + }, + }); + } catch (e) { + toast({ title: "Couldn’t change who sees them", body: (e as Error).message, tone: "red" }); + } + }, + [client, refresh, toast], + ); + + return { retryJob, reprocess, exportMany, exportCatalogue, setVisibility, deleteMany, moveMany, retag }; } diff --git a/nextjs-frontend/components/library/bulk-bar.tsx b/nextjs-frontend/components/library/bulk-bar.tsx index 22cf7a048..d7c763cda 100644 --- a/nextjs-frontend/components/library/bulk-bar.tsx +++ b/nextjs-frontend/components/library/bulk-bar.tsx @@ -1,8 +1,20 @@ "use client"; -import { Download, FolderInput, FolderTree, Podcast, RefreshCw, Tag, Trash2, X, type LucideIcon } from "lucide-react"; +import { + Download, + Eye, + FolderInput, + FolderTree, + Podcast, + RefreshCw, + Tag, + Trash2, + X, + type LucideIcon, +} from "lucide-react"; import { useEffect, useState, type ReactNode } from "react"; +import { ACCESS, type Access } from "@/components/access/model"; import { EXPORT_FORMATS, type ExportFormat } from "@/components/library/actions"; import { hasSound, tagsFromText, tagsOn } from "@/components/library/model"; import { Button } from "@/components/ui/button"; @@ -63,6 +75,7 @@ export function BulkBar({ onReprocess, onExport, onCatalogue, + onVisibility, onMove, onPlace, placeReason, @@ -82,6 +95,8 @@ export function BulkBar({ onExport: (fmt: ExportFormat) => void; /** Save the selection as one catalogue spreadsheet (CSV). */ onCatalogue?: () => void; + /** Make them all public, restricted or private (owners). */ + onVisibility?: (to: Access) => void; onMove: () => void; /** File them in a collection of their namespace. */ onPlace?: () => void; @@ -100,6 +115,9 @@ export function BulkBar({ const deleteReason = notOwner.count ? `Only owners delete assets. You don’t own ${notOwner.namespaces.join(", ")}: ${count(notOwner.count)} of ${count(selected)} selected can’t be deleted.` : undefined; + const visibilityReason = notOwner.count + ? `Only owners choose who sees assets. You don’t own ${notOwner.namespaces.join(", ")}: ${count(notOwner.count)} of ${count(selected)} selected can’t be changed.` + : undefined; const moveReason = notOwner.count ? `Only owners move assets out of their namespace. You don’t own ${notOwner.namespaces.join(", ")}: ${count(notOwner.count)} of ${count(selected)} selected can’t be moved.` : !moveTargets.length @@ -136,6 +154,25 @@ export function BulkBar({ } /> )} + {onVisibility && + (notOwner.count ? ( + undefined} disabledReason={visibilityReason} /> + ) : ( + + + + Visibility + + + Who sees them + {ACCESS.map((a) => ( + onVisibility(a.value)}> + {a.label} · {a.hint} + + ))} + + + ))} diff --git a/nextjs-frontend/components/library/library-screen.tsx b/nextjs-frontend/components/library/library-screen.tsx index fff287da6..3214d4c32 100644 --- a/nextjs-frontend/components/library/library-screen.tsx +++ b/nextjs-frontend/components/library/library-screen.tsx @@ -661,6 +661,7 @@ export function LibraryScreen({ onReprocess={() => setReprocessOpen(true)} onExport={(fmt) => actions.exportMany([...selected], fmt)} onCatalogue={() => actions.exportCatalogue(selectedRows)} + onVisibility={(to) => void actions.setVisibility(selectedRows, to)} onMove={() => setMoveOpen(true)} onPlace={() => setPlaceOpen(true)} placeReason={placeReason} diff --git a/nextjs-frontend/components/library/model.ts b/nextjs-frontend/components/library/model.ts index d8ec4e1c9..c56a851eb 100644 --- a/nextjs-frontend/components/library/model.ts +++ b/nextjs-frontend/components/library/model.ts @@ -559,3 +559,19 @@ export function catalogueRows(rows: RecordingSummary[], origin: string): string[ ]); return out; } + +/** + * The rows grouped by who may see them now ({public: [ids], private: [ids]}), leaving out those already at `to`: what + * a bulk visibility change touches, and how its Undo puts each back. + */ +export function visibilityGroups( + rows: readonly { id: number; access?: string | null }[], + to: string, +): Record { + const out: Record = {}; + for (const r of rows) { + const was = r.access ?? "private"; + if (was !== to) (out[was] ??= []).push(r.id); + } + return out; +}