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.
39 lines
1.3 KiB
TypeScript
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));
|
|
}
|