feat: refine admin access management
This commit is contained in:
parent
dded6d1927
commit
a69d37a672
9 changed files with 265 additions and 83 deletions
|
|
@ -8,6 +8,7 @@ import { assertStaffSession } from "@/lib/auth-server"
|
|||
import { isAdmin } from "@/lib/authz"
|
||||
import { env } from "@/lib/env"
|
||||
import { prisma } from "@/lib/prisma"
|
||||
import { canReactivateInvite } from "@/lib/invite-policies"
|
||||
import { computeInviteStatus, normalizeInvite, type NormalizedInvite } from "@/server/invite-utils"
|
||||
|
||||
type InviteAction = "revoke" | "reactivate"
|
||||
|
|
@ -17,8 +18,6 @@ type InvitePayload = {
|
|||
reason?: string
|
||||
}
|
||||
|
||||
const REVOKE_RETENTION_MS = 7 * 24 * 60 * 60 * 1000
|
||||
|
||||
async function syncInvite(invite: NormalizedInvite) {
|
||||
const convexUrl = env.NEXT_PUBLIC_CONVEX_URL
|
||||
if (!convexUrl) return
|
||||
|
|
@ -81,8 +80,7 @@ export async function PATCH(request: Request, context: { params: Promise<{ id: s
|
|||
if (!invite.revokedAt) {
|
||||
return NextResponse.json({ error: "Convite revogado sem data. Não é possível reativar." }, { status: 400 })
|
||||
}
|
||||
const revokedAtMs = invite.revokedAt.getTime()
|
||||
if (now.getTime() - revokedAtMs > REVOKE_RETENTION_MS) {
|
||||
if (!canReactivateInvite({ status, revokedAt: invite.revokedAt }, now)) {
|
||||
return NextResponse.json({ error: "Este convite foi revogado há mais de 7 dias" }, { status: 400 })
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue