user(); $tenant = $reviewPack->tenant; if (! $user instanceof User || ! $tenant instanceof Tenant) { throw new NotFoundHttpException; } if (! $user->canAccessTenant($tenant)) { throw new NotFoundHttpException; } if (! $user->can(Capabilities::REVIEW_PACK_VIEW, $tenant)) { abort(403); } if ($reviewPack->status !== ReviewPackStatus::Ready->value) { throw new NotFoundHttpException; } if ($reviewPack->expires_at && $reviewPack->expires_at->isPast()) { throw new NotFoundHttpException; } $disk = Storage::disk($reviewPack->file_disk ?? 'exports'); if (! $disk->exists($reviewPack->file_path)) { throw new NotFoundHttpException; } app(WorkspaceAuditLogger::class)->log( workspace: $tenant->workspace, action: AuditActionId::ReviewPackDownloaded, context: [ 'metadata' => [ 'review_pack_id' => (int) $reviewPack->getKey(), 'tenant_review_id' => $reviewPack->tenant_review_id !== null ? (int) $reviewPack->tenant_review_id : null, 'source_surface' => (string) $request->query('source_surface', 'review_pack'), ], ], actor: $user, resourceType: 'review_pack', resourceId: (string) $reviewPack->getKey(), targetLabel: sprintf('Review pack #%d', (int) $reviewPack->getKey()), tenant: $tenant, operationRunId: $reviewPack->operation_run_id, ); $filename = sprintf( 'review-pack-%s-%s.zip', $tenant?->external_id ?? 'unknown', $reviewPack->generated_at?->format('Y-m-d') ?? now()->format('Y-m-d'), ); return $disk->download($reviewPack->file_path, $filename, [ 'X-Review-Pack-SHA256' => $reviewPack->sha256 ?? '', ]); } }