feat: add editorial album permissions
This commit is contained in:
1 parent
0fe2c80cda
commit
4af86f6eb9
5 files changed
+633
No files matched your search
@@ -0,0 +1,97 @@
|
||||
import Image from "next/image";
|
||||
import Link from "next/link";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { notFound } from "next/navigation";
|
||||
|
||||
import { db } from "@/db/client";
|
||||
import { editorialAccounts } from "@/db/schema";
|
||||
import { albumGrantService } from "@/modules/albums/grants";
|
||||
|
||||
import { grantAlbumAction, revokeAlbumAction } from "./actions";
|
||||
|
||||
export default async function EditorialAlbumsPage({
|
||||
params,
|
||||
}: Readonly<{ params: Promise<{ id: string }> }>) {
|
||||
const { id } = await params;
|
||||
const [editorial] = await db
|
||||
.select({ id: editorialAccounts.id, name: editorialAccounts.name })
|
||||
.from(editorialAccounts)
|
||||
.where(eq(editorialAccounts.id, id))
|
||||
.limit(1);
|
||||
if (!editorial) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
const albumResult = await albumGrantService
|
||||
.listAssignableAlbums(editorial.id)
|
||||
.then((albums) => ({ albums, unavailable: false }))
|
||||
.catch(() => ({ albums: [], unavailable: true }));
|
||||
|
||||
if (albumResult.unavailable) {
|
||||
return (
|
||||
<section className="content-section" aria-labelledby="albums-title">
|
||||
<p className="eyebrow">Redaktion · Albumrechte</p>
|
||||
<h1 id="albums-title">Alben für {editorial.name}</h1>
|
||||
<p role="status">
|
||||
Die Immich-Alben sind momentan nicht erreichbar. Bereits bestehende Zuweisungen bleiben
|
||||
unverändert.
|
||||
</p>
|
||||
<p>
|
||||
<Link href={`/admin/redaktionen/${editorial.id}`}>Zurück zur Redaktion</Link>
|
||||
</p>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="content-section" aria-labelledby="albums-title">
|
||||
<p className="eyebrow">Redaktion · Albumrechte</p>
|
||||
<h1 id="albums-title">Alben für {editorial.name}</h1>
|
||||
<p>
|
||||
Nur Alben, die der technische Immich-Zugang lesen kann, lassen sich zuweisen.
|
||||
</p>
|
||||
<p>
|
||||
<Link href={`/admin/redaktionen/${editorial.id}`}>Zurück zur Redaktion</Link>
|
||||
</p>
|
||||
|
||||
{albumResult.albums.length === 0 ? (
|
||||
<p>Derzeit sind keine zuweisbaren Alben vorhanden.</p>
|
||||
) : (
|
||||
<ul aria-label="Zuweisbare Immich-Alben">
|
||||
{albumResult.albums.map((album) => {
|
||||
const action = album.isGranted ? revokeAlbumAction : grantAlbumAction;
|
||||
return (
|
||||
<li key={album.id}>
|
||||
<article aria-labelledby={`album-${album.id}`}>
|
||||
{album.albumThumbnailAssetId ? (
|
||||
<Image
|
||||
alt={`Titelbild von ${album.albumName}`}
|
||||
height={120}
|
||||
src={`/api/assets/${encodeURIComponent(album.albumThumbnailAssetId)}/thumbnail`}
|
||||
width={160}
|
||||
/>
|
||||
) : (
|
||||
<div aria-label="Kein Albumcover verfügbar" role="img">
|
||||
Kein Cover
|
||||
</div>
|
||||
)}
|
||||
<h2 id={`album-${album.id}`}>{album.albumName}</h2>
|
||||
<p>{album.assetCount} Fotos</p>
|
||||
<p>
|
||||
Status: <strong>{album.isGranted ? "Zugewiesen" : "Nicht zugewiesen"}</strong>
|
||||
</p>
|
||||
<form action={action.bind(null, editorial.id)}>
|
||||
<input name="immichAlbumId" type="hidden" value={album.id} />
|
||||
<button type="submit">
|
||||
{album.isGranted ? "Zuweisung aufheben" : "Album zuweisen"}
|
||||
</button>
|
||||
</form>
|
||||
</article>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user