feat: implement hard delete, email notifications, watermark, and fix bulk download

This commit is contained in:
Leon Tonhäuser committed 2026-08-11 12:28:39 +02:00
1 parent 8dd1e10fea
commit 4667615ed0
15 files changed
+369 -65

No files matched your search

@@ -55,6 +55,13 @@ export async function archiveEditorialAction(editorialId: string): Promise<void>
redirect("/admin/redaktionen");
}
export async function hardDeleteEditorialAction(editorialId: string): Promise<void> {
await requireAdmin(new Headers(await headers()));
await editorialService.hardDeleteEditorial(editorialId);
revalidatePath("/admin/redaktionen");
redirect("/admin/redaktionen");
}
export async function suspendEditorialAction(editorialId: string): Promise<void> {
const admin = await requireAdmin(new Headers(await headers()));
await editorialService.transitionEditorialStatus({
@@ -22,20 +22,20 @@ type AlbumGridProps = {
editorialId: string;
grantAction: AlbumGridAction;
revokeAction: AlbumGridAction;
notifyAction: AlbumGridAction;
};
function AlbumCard({
album,
editorialId,
grantAction,
revokeAction,
}: {
album: AlbumGridProps["albums"][0];
type AlbumCardProps = {
album: AlbumGridProps["albums"][number];
editorialId: string;
grantAction: AlbumGridAction;
revokeAction: AlbumGridAction;
}) {
notifyAction: AlbumGridAction;
};
function AlbumCard({ album, editorialId, grantAction, revokeAction, notifyAction }: AlbumCardProps) {
const [isPending, startTransition] = useTransition();
const [notifyStatus, setNotifyStatus] = useState<"idle" | "pending" | "success" | "error">("idle");
const handleAction = (formData: FormData) => {
startTransition(async () => {
@@ -75,7 +75,7 @@ function AlbumCard({
{album.albumName}
</h2>
<p className="text-sm text-gray-500 mb-4">{album.assetCount} Fotos</p>
<div className="mt-auto">
<div className="mt-auto space-y-2">
<form action={handleAction}>
<input name="immichAlbumId" type="hidden" value={album.id} />
<button
@@ -90,13 +90,39 @@ function AlbumCard({
{isPending ? "Wird verarbeitet..." : album.isGranted ? "Zuweisung aufheben" : "Album zuweisen"}
</button>
</form>
{album.isGranted && (
<form action={(formData) => {
setNotifyStatus("pending");
notifyAction(editorialId, { ok: true, message: "" }, formData).then((res) => {
setNotifyStatus(res.ok ? "success" : "error");
setTimeout(() => setNotifyStatus("idle"), 3000);
});
}}>
<input name="albumName" type="hidden" value={album.albumName} />
<button
type="submit"
className={`w-full py-2 px-4 rounded-lg font-semibold text-sm transition-colors duration-200 border ${
notifyStatus === "success" ? "bg-green-50 text-green-700 border-green-200" :
notifyStatus === "error" ? "bg-red-50 text-red-700 border-red-200" :
"bg-white text-gray-700 hover:bg-gray-50 border-gray-200 focus:ring-2 focus:ring-gray-200 focus:outline-none"
}`}
disabled={notifyStatus === "pending" || notifyStatus === "success"}
>
{notifyStatus === "pending" ? "Wird gesendet..." :
notifyStatus === "success" ? "E-Mail gesendet!" :
notifyStatus === "error" ? "Fehler beim Senden" :
"Redaktion benachrichtigen"}
</button>
</form>
)}
</div>
</div>
</li>
);
}
export function AlbumGrid({ albums, editorialId, grantAction, revokeAction }: AlbumGridProps) {
export function AlbumGrid({ albums, editorialId, grantAction, revokeAction, notifyAction }: AlbumGridProps) {
const [search, setSearch] = useState("");
const filteredAlbums = albums.filter((album) =>
@@ -125,6 +151,7 @@ export function AlbumGrid({ albums, editorialId, grantAction, revokeAction }: Al
editorialId={editorialId}
grantAction={grantAction}
revokeAction={revokeAction}
notifyAction={notifyAction}
/>
))}
</ul>
@@ -5,6 +5,10 @@ import { headers } from "next/headers";
import { AlbumGrantError, albumGrantService } from "@/modules/albums/grants";
import { requireAdmin } from "@/modules/auth/principal";
import { emailService } from "@/modules/email/service";
import { db } from "@/db/client";
import { editorialAccounts } from "@/db/schema";
import { eq } from "drizzle-orm";
// Returned to the client form so failures surface as inline German text
// instead of an opaque Next.js error-digest page (a thrown server action
@@ -55,6 +59,37 @@ export async function revokeAlbumAction(
return INITIAL_RESULT;
}
export async function sendAlbumNotificationAction(
editorialId: string,
_prevState: AlbumActionResult,
formData: FormData,
): Promise<AlbumActionResult> {
await getAdminPrincipal();
const safeEditorialId = requiredId(editorialId);
const albumName = formData.get("albumName");
if (typeof albumName !== "string" || !albumName) {
return { ok: false, message: "Ungültiger Albumname." };
}
try {
const [editorial] = await db
.select({ loginEmail: editorialAccounts.loginEmail })
.from(editorialAccounts)
.where(eq(editorialAccounts.id, safeEditorialId));
if (!editorial) {
return { ok: false, message: "Redaktion nicht gefunden." };
}
await emailService.sendNewAlbumNotification(editorial.loginEmail, albumName);
return { ok: true, message: "Benachrichtigung erfolgreich gesendet." };
} catch (error) {
console.error("Failed to send album notification:", error);
return { ok: false, message: "E-Mail konnte nicht gesendet werden." };
}
}
async function getAdminPrincipal() {
return requireAdmin(new Headers(await headers()));
}
@@ -7,7 +7,7 @@ import { db } from "@/db/client";
import { editorialAccounts } from "@/db/schema";
import { albumGrantService } from "@/modules/albums/grants";
import { grantAlbumAction, revokeAlbumAction } from "./actions";
import { grantAlbumAction, revokeAlbumAction, sendAlbumNotificationAction } from "./actions";
import { loadAssignableAlbums } from "./page-content";
import { AlbumGrid } from "./AlbumGrid";
@@ -66,6 +66,7 @@ export default async function EditorialAlbumsPage({
editorialId={editorial.id}
grantAction={grantAlbumAction}
revokeAction={revokeAlbumAction}
notifyAction={sendAlbumNotificationAction}
/>
)}
</div>