Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions changelog.d/bulk-visibility.md
Original file line number Diff line number Diff line change
@@ -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)).
3 changes: 2 additions & 1 deletion docs/access.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 1 addition & 0 deletions docs/requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 15 additions & 1 deletion nextjs-frontend/__tests__/library-catalogue.test.ts
Original file line number Diff line number Diff line change
@@ -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>): RecordingSummary =>
Expand Down Expand Up @@ -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({});
});
});
43 changes: 40 additions & 3 deletions nextjs-frontend/components/library/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 };
}
39 changes: 38 additions & 1 deletion nextjs-frontend/components/library/bulk-bar.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -63,6 +75,7 @@ export function BulkBar({
onReprocess,
onExport,
onCatalogue,
onVisibility,
onMove,
onPlace,
placeReason,
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -136,6 +154,25 @@ export function BulkBar({
}
/>
)}
{onVisibility &&
(notOwner.count ? (
<BarButton icon={Eye} label="Visibility" onClick={() => undefined} disabledReason={visibilityReason} />
) : (
<Menu>
<MenuTrigger className={actionCls}>
<Eye aria-hidden />
Visibility
</MenuTrigger>
<MenuContent align="center">
<MenuLabel>Who sees them</MenuLabel>
{ACCESS.map((a) => (
<MenuItem key={a.value} onSelect={() => onVisibility(a.value)}>
{a.label} · {a.hint}
</MenuItem>
))}
</MenuContent>
</Menu>
))}
<Menu>
<MenuTrigger className={actionCls}>
<Download aria-hidden />
Expand Down
1 change: 1 addition & 0 deletions nextjs-frontend/components/library/library-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
16 changes: 16 additions & 0 deletions nextjs-frontend/components/library/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, number[]> {
const out: Record<string, number[]> = {};
for (const r of rows) {
const was = r.access ?? "private";
if (was !== to) (out[was] ??= []).push(r.id);
}
return out;
}
Loading