Files
immich-redaktions-plugin/src/app/admin/alben/page-content.ts
T
Leon Tonhäuser 0931ffc777 feat: add admin albums tab with access overview and bulk grants
New /admin/alben page: all Immich albums with per-album editorial grant
chips (link + one-click revoke) and a bulk-grant form (multiple albums x
multiple editorials, select-all, search). bulkGrantAlbums validates album
existence once via listAlbums, skips already-active pairs, and commits
each pair in its own transaction with full audit attribution.
2026-09-01 17:17:02 +02:00

39 lines
1.3 KiB
TypeScript

import { asc, isNull } from "drizzle-orm";
import { db } from "@/db/client";
import { editorialAccounts } from "@/db/schema";
import {
AlbumGrantError,
albumGrantService,
type AlbumAccessOverviewAlbum,
} from "@/modules/albums/grants";
export type EditorialOption = { id: string; name: string };
export async function loadAlbumAccess(
service: Pick<typeof albumGrantService, "listAlbumAccessOverview"> = albumGrantService,
): Promise<{ albums: AlbumAccessOverviewAlbum[]; unavailable: boolean }> {
try {
const albums = await service.listAlbumAccessOverview();
return { albums, unavailable: false };
} catch (error) {
if (error instanceof AlbumGrantError && error.code === "IMMICH_UNAVAILABLE") {
return { albums: [], unavailable: true };
}
throw error;
}
}
/**
* Bulk-grant targets: every non-archived editorial. Archived accounts cannot
* log in anymore, so they stay out of the selection; grants they still hold
* remain visible in the overview.
*/
export async function loadAssignableEditorials(): Promise<EditorialOption[]> {
return db
.select({ id: editorialAccounts.id, name: editorialAccounts.name })
.from(editorialAccounts)
.where(isNull(editorialAccounts.archivedAt))
.orderBy(asc(editorialAccounts.name));
}