All files / src/app/api/odrl/scope route.ts

100% Statements 8/8
100% Branches 5/5
100% Functions 1/1
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27        1x                   5x 5x   4x 4x         5x 4x    
import { NextResponse } from "next/server";
import { requireAuth, isAuthError } from "@/lib/auth-guard";
import { resolveOdrlScope, userToParticipantId } from "@/lib/odrl-engine";
 
export const dynamic = "force-dynamic";
 
/**
 * GET /api/odrl/scope
 *
 * Returns the caller's effective ODRL scope: permissions, prohibitions,
 * accessible datasets, temporal limits, and policy IDs. Used by the
 * query page to display the policy scope indicator.
 */
export async function GET() {
  const auth = await requireAuth();
  if (isAuthError(auth)) return auth;
 
  const { session } = auth;
  const participantId = userToParticipantId(
    session.user.email ?? session.user.name ?? session.user.id,
    session.roles,
  );
 
  const scope = await resolveOdrlScope(participantId);
  return NextResponse.json(scope);
}