-
-
Notifications
You must be signed in to change notification settings - Fork 168
fix: moderation preview scope, comment vote races, and email link origin #1344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NiallJoeMaher
wants to merge
9
commits into
develop
Choose a base branch
from
fix/moderation-preview-votes-and-email-links
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0d5afb3
fix: moderation preview scope, comment vote races, and email link origin
NiallJoeMaher 7037484
fix: address review of the consolidated fixes
NiallJoeMaher 97df7e7
ci(e2e): serve a production build instead of the dev server
NiallJoeMaher 38175d8
fix: review round three, and build the app inside the e2e webServer
NiallJoeMaher ae07553
ci(e2e): trust the request host when serving the production build
NiallJoeMaher 724cda9
test(e2e): let the suite point at a throwaway database
NiallJoeMaher f44d55b
test(e2e): enable moderation, fix the sidebar viewport, centralise th…
NiallJoeMaher dbc6355
test(e2e): give the bookmark specs their own fixture per browser project
NiallJoeMaher fd12b29
test(e2e): check the card's content link, not its first anchor
NiallJoeMaher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| import Link from "next/link"; | ||
| import { notFound } from "next/navigation"; | ||
| import { ArrowLeftIcon } from "@heroicons/react/24/outline"; | ||
| import { and, eq } from "drizzle-orm"; | ||
| import z from "zod"; | ||
| import { db } from "@/server/db"; | ||
| import { posts, user, post_tags, tag } from "@/server/db/schema"; | ||
| import { PostBody, renderPostBody } from "@/components/ContentDetail/PostBody"; | ||
| import { getCamelCaseFromLower } from "@/utils/utils"; | ||
| import { safeExternalHref } from "@/utils/url"; | ||
| import { moderationPreviewFilter } from "@/server/lib/postVisibility"; | ||
|
|
||
| export const metadata = { | ||
| title: "Preview - Codú Admin", | ||
| description: "Read a submission before approving or declining it", | ||
| robots: { index: false, follow: false }, | ||
| }; | ||
|
|
||
| type Props = { params: Promise<{ postId: string }> }; | ||
|
|
||
| // Read-only preview of a submission, for deciding whether it belongs on the | ||
| // site. It deliberately lives inside `(admin)` rather than exposing unpublished | ||
| // posts on the public reader routes: moderators need to READ a post, not vote, | ||
| // bookmark or comment on one that may be about to be rejected — and admins | ||
| // should still see the public site exactly as readers do. | ||
| // | ||
| // The body renders through the same `PostBody` the reader uses, so what a | ||
| // moderator approves is what readers will get. | ||
| // | ||
| // Admin-role gate is enforced in app/(admin)/layout.tsx. | ||
| export default async function Page({ params }: Props) { | ||
| const { postId } = await params; | ||
|
|
||
| // posts.id is a uuid column, so a mistyped or truncated id would make | ||
| // Postgres throw a cast error (a 500) before the not-found check below. | ||
| if (!z.string().uuid().safeParse(postId).success) notFound(); | ||
|
|
||
| const [rows, tags] = await Promise.all([ | ||
| db | ||
| .select({ | ||
| id: posts.id, | ||
| title: posts.title, | ||
| body: posts.body, | ||
| excerpt: posts.excerpt, | ||
| type: posts.type, | ||
| status: posts.status, | ||
| externalUrl: posts.externalUrl, | ||
| coverImage: posts.coverImage, | ||
| readingTime: posts.readingTime, | ||
| moderationNote: posts.moderationNote, | ||
| authorUsername: user.username, | ||
| }) | ||
| .from(posts) | ||
| .leftJoin(user, eq(posts.authorId, user.id)) | ||
| // Submitted work only. A moderator has business reading anything that | ||
| // entered the pipeline; a private draft is not that. | ||
| .where(and(eq(posts.id, postId), moderationPreviewFilter())) | ||
| .limit(1), | ||
| db | ||
| .select({ title: tag.title, slug: tag.slug }) | ||
| .from(post_tags) | ||
| .innerJoin(tag, eq(post_tags.tagId, tag.id)) | ||
| .where(eq(post_tags.postId, postId)), | ||
| ]); | ||
|
|
||
| const record = rows[0]; | ||
| if (!record) notFound(); | ||
|
|
||
| const renderedBody = renderPostBody(record.body); | ||
| const externalHref = safeExternalHref(record.externalUrl); | ||
| // Member-supplied, like externalUrl — same scheme guard applies. | ||
| const coverHref = safeExternalHref(record.coverImage); | ||
|
|
||
| return ( | ||
| <div className="mx-auto max-w-3xl px-0 py-4 sm:px-4 sm:py-8"> | ||
| <div className="mb-6 flex items-center gap-4"> | ||
| <Link | ||
| href="/admin/moderation" | ||
| className="rounded-lg p-2 text-muted transition-colors hover:bg-elevated hover:text-fg" | ||
| > | ||
| <ArrowLeftIcon className="h-5 w-5" /> | ||
| </Link> | ||
| <div className="min-w-0"> | ||
| <p className="eyebrow"> | ||
| <span className="slash">{"// "}</span>preview | ||
| </p> | ||
| <h1 className="mt-1 font-display text-2xl font-extrabold tracking-tight text-fg"> | ||
| {record.title || "Untitled"} | ||
| </h1> | ||
| <p className="mt-1 font-mono text-xs text-faint"> | ||
| {record.type} · {record.status} · @ | ||
| {record.authorUsername ?? "unknown"} | ||
| {record.readingTime ? ` · ${record.readingTime} min read` : ""} | ||
| </p> | ||
| </div> | ||
| </div> | ||
|
|
||
| {record.moderationNote && ( | ||
| <p className="mb-6 rounded-lg border border-hairline bg-inset p-3 text-sm text-muted"> | ||
| <span className="font-medium text-fg">Flagged:</span>{" "} | ||
| {record.moderationNote} | ||
| </p> | ||
| )} | ||
|
|
||
| {record.excerpt && ( | ||
| <p className="mb-6 text-base text-muted">{record.excerpt}</p> | ||
| )} | ||
|
|
||
| {/* The cover image is the most visible part of a post on feed and profile | ||
| cards, so a moderator has to see it before approving — clean body copy | ||
| under an abusive image would otherwise sail through. */} | ||
| {coverHref && ( | ||
| // eslint-disable-next-line @next/next/no-img-element | ||
| <img | ||
| src={coverHref} | ||
| alt="" | ||
| className="mb-6 max-h-80 w-full rounded-lg border border-hairline object-cover" | ||
| /> | ||
| )} | ||
|
|
||
| {/* A link submission is judged on both halves: the member's own framing | ||
| above, and the destination. rel/noreferrer keep the admin surface out | ||
| of the referrer of a page that is under review precisely because it | ||
| may be hostile. */} | ||
| {record.type === "link" && | ||
| (externalHref ? ( | ||
| <p className="mb-6 break-all font-mono text-sm"> | ||
| <span className="text-faint">{"// destination "}</span> | ||
| <a | ||
| href={externalHref} | ||
| target="_blank" | ||
| rel="noopener noreferrer nofollow" | ||
| className="text-accent underline" | ||
| > | ||
| {externalHref} | ||
| </a> | ||
| </p> | ||
| ) : ( | ||
| <p className="mb-6 font-mono text-sm text-danger"> | ||
| {"// destination missing or not a http(s) URL: "} | ||
| {record.externalUrl ?? "none"} | ||
| </p> | ||
| ))} | ||
|
|
||
| {tags.length > 0 && ( | ||
| <div className="mb-6 flex flex-wrap gap-2"> | ||
| {tags.map((t) => ( | ||
| <span | ||
| key={t.title} | ||
| className="rounded-sm border border-hairline px-2.5 py-0.5 font-mono text-xs text-muted" | ||
| > | ||
| {getCamelCaseFromLower(t.title)} | ||
| </span> | ||
| ))} | ||
| </div> | ||
| )} | ||
|
|
||
| {record.body ? ( | ||
| <article className="prose max-w-none dark:prose-invert"> | ||
| <PostBody | ||
| {...renderedBody} | ||
| emptyFallback={ | ||
| <p className="font-mono text-sm text-faint"> | ||
| {"// body is empty"} | ||
| </p> | ||
| } | ||
| /> | ||
| </article> | ||
| ) : ( | ||
| <p className="font-mono text-sm text-faint">{"// no body submitted"}</p> | ||
| )} | ||
|
|
||
| <p className="mt-8 font-mono text-xs text-faint"> | ||
| {"// read-only — approve or decline from the queue"} | ||
| </p> | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Provide alternative text for the cover image.
alt=""marks the image as decorative, but the surrounding comment states that moderators must review the cover image before approval. Screen-reader users will not receive any information about this required content. Use stored image alternative text, or at least expose a non-empty label until that metadata is available.Proposed fix
<img src={coverHref} - alt="" + alt="Cover image" className="mb-6 max-h-80 w-full rounded-lg border border-hairline object-cover" />📝 Committable suggestion
🤖 Prompt for AI Agents