Delning av böcker, skydd mot kolliderande ändringar och import från Word
Böcker kan delas med roller (läsare, redaktör, administratör), och behörigheten kontrolleras på servern. Formulär för poster, relationer och händelser skickar med version, och en krock visar vad som skiljer och låter användaren spara ändå eller ladda om. Ifyllda Word-mallar kan importeras med förhandsgranskning. Importerade ID flyttar nu räknaren. Migrering 0007. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bd269d70a5
commit
86fd435438
64 files changed
+4796
-235
No files matched your search
+12
-7
@@ -1,7 +1,9 @@
|
||||
import { cache } from "react";
|
||||
import { notFound, redirect } from "next/navigation";
|
||||
import { auth } from "@/auth";
|
||||
import { hasRole, type BookRole } from "./access";
|
||||
import { isAdminUser } from "./admin";
|
||||
import { bookAccess } from "./book-access";
|
||||
import { prisma } from "./db";
|
||||
|
||||
/**
|
||||
@@ -39,17 +41,20 @@ export async function requireAdmin() {
|
||||
return user;
|
||||
}
|
||||
|
||||
/** Hämtar boken om den tillhör inloggad användare, annars 404. */
|
||||
export async function requireBook(bookId: string) {
|
||||
/**
|
||||
* Hämtar boken om inloggad användare äger den eller har fått den delad, med minst rollen `min`.
|
||||
* Annars 404, så att man inte kan se vilka böcker som finns.
|
||||
*/
|
||||
export async function requireBook(bookId: string, min: BookRole = "VIEWER") {
|
||||
const user = await requireUser();
|
||||
const book = await prisma.book.findFirst({ where: { id: bookId, ownerId: user.id } });
|
||||
if (!book) notFound();
|
||||
return book;
|
||||
const access = await bookAccess(bookId, user.id);
|
||||
if (!access || !hasRole(access.role, min)) notFound();
|
||||
return access;
|
||||
}
|
||||
|
||||
/** Hämtar en post i boken, annars 404. */
|
||||
export async function requireEntity(bookId: string, entityId: string) {
|
||||
await requireBook(bookId);
|
||||
export async function requireEntity(bookId: string, entityId: string, min: BookRole = "VIEWER") {
|
||||
await requireBook(bookId, min);
|
||||
const entity = await prisma.entity.findFirst({ where: { id: entityId, bookId } });
|
||||
if (!entity) notFound();
|
||||
return entity;
|
||||
|
||||
Reference in new issue
Block a user