Skip to content

Commit 8ebec72

Browse files
committed
guest report visible to guest
1 parent 356631d commit 8ebec72

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

src/components/interactive/ReportCard.tsx

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,21 @@ export default function ReportCard() {
164164
const reportData = json.data ?? null;
165165

166166
// Check access control: only allow the creator of the submission to view the report
167-
if (reportData && currentUser) {
167+
// Exception: reports generated by guests (EXTERNAL.guest_user_id) are publicly viewable
168+
if (reportData) {
168169
const submissionUserId = reportData.submission?.user_created?.id;
169-
if (submissionUserId && submissionUserId !== currentUser.id) {
170-
throw new Error("Access denied. You can only view reports for your own submissions.");
170+
const isGuestReport = submissionUserId === EXTERNAL.guest_user_id;
171+
172+
if (!isGuestReport) {
173+
// For non-guest reports, enforce strict access control
174+
if (!currentUser) {
175+
throw new Error("Please log in to view this report.");
176+
}
177+
if (submissionUserId && submissionUserId !== currentUser.id) {
178+
throw new Error("Access denied. You can only view reports for your own submissions.");
179+
}
171180
}
172-
} else if (reportData && !currentUser) {
173-
throw new Error("Please log in to view this report.");
181+
// Guest reports are accessible to everyone, no additional checks needed
174182
}
175183

176184
setReport(reportData);
@@ -292,17 +300,10 @@ export default function ReportCard() {
292300
return (
293301
<>
294302
<Card className="w-full">
295-
<CardHeader className="relative">
303+
<CardHeader>
296304
<CardTitle className="text-center">
297305
Role Fit Index Report
298306
</CardTitle>
299-
<Button
300-
onClick={handlePrint}
301-
className="absolute top-1/2 right-6 -translate-y-1/2 flex items-center gap-2"
302-
>
303-
<Download className="h-4 w-4" />
304-
Download PDF
305-
</Button>
306307
</CardHeader>
307308
<CardContent className="space-y-8">
308309
{/* Header */}
@@ -509,6 +510,17 @@ export default function ReportCard() {
509510
</LoginMask>
510511
</div>
511512
</div>
513+
514+
{/* Download Button */}
515+
<div className="flex justify-center pt-4">
516+
<Button
517+
onClick={handlePrint}
518+
className="flex items-center gap-2"
519+
>
520+
<Download className="h-4 w-4" />
521+
Download PDF
522+
</Button>
523+
</div>
512524
</CardContent>
513525
</Card>
514526

src/constant.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export const EXTERNAL = {
22
onboarding_form_url: "https://form.typeform.com/to/FOz4fXGm",
33
directus_url: "https://directus.bounteer.com",
44
directus_key: "dZtMfEuzhzUS0YATh0pOZfBAdOYlhowE", // guest account
5+
guest_user_id: "f25f8ce7-e4c9-40b8-ab65-40cde3409f27", // guest user id
56
auth_idp_key: "logto",
67
auth_idp_logput_url: "https://logto-app.bounteer.com/oidc/session/end?post_logout_redirect_uri=https://bounteer.com"
78
}

0 commit comments

Comments
 (0)