Repository navigation
feat(pages): report a public page, and let staff take one down #7886
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2b0a18c
Public pages can be reported, and staff can take one down
harshithmullapudi 86b41bd
Harden page takedown, and drop the reason enum so categories are not …
harshithmullapudi fa73165
Merge remote-tracking branch 'origin/main' into httpslinear.appsupers…
harshithmullapudi 48ec7ae
Renumber the page reports migration to 0128 after 0127_environments_r…
harshithmullapudi 7104c31
Merge main and regenerate i18n catalogs
harshithmullapudi 05686db
Address review: localize report errors, guard raced takedowns, fix it…
harshithmullapudi dcab87a
Merge main; renumber page reports migration to 0129 after 0128_drop_e…
harshithmullapudi 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
195 changes: 195 additions & 0 deletions
195
...pp/page/[slug]/components/PublicPageView/components/ReportPageDialog/ReportPageDialog.tsx
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,195 @@ | ||
| "use client"; | ||
|
|
||
| import { useLingui as useTranslation } from "@lingui/react"; | ||
| import { Trans, useLingui } from "@lingui/react/macro"; | ||
| import type { PageReportReason } from "@superset/db/enums"; | ||
| import { errorMessage } from "@superset/i18n/errors"; | ||
| import { Button } from "@superset/ui/button"; | ||
| import { | ||
| Dialog, | ||
| DialogContent, | ||
| DialogDescription, | ||
| DialogFooter, | ||
| DialogHeader, | ||
| DialogTitle, | ||
| DialogTrigger, | ||
| } from "@superset/ui/dialog"; | ||
| import { Input } from "@superset/ui/input"; | ||
| import { Label } from "@superset/ui/label"; | ||
| import { | ||
| Select, | ||
| SelectContent, | ||
| SelectItem, | ||
| SelectTrigger, | ||
| SelectValue, | ||
| } from "@superset/ui/select"; | ||
| import { Textarea } from "@superset/ui/textarea"; | ||
| import { useMutation } from "@tanstack/react-query"; | ||
| import { Flag } from "lucide-react"; | ||
| import { useState } from "react"; | ||
| import { useTRPC } from "@/trpc/react"; | ||
| import { REPORT_REASONS } from "./constants"; | ||
|
|
||
| interface ReportPageDialogProps { | ||
| slug: string; | ||
| signedIn: boolean; | ||
| } | ||
|
|
||
| export function ReportPageDialog({ slug, signedIn }: ReportPageDialogProps) { | ||
| const { t } = useLingui(); | ||
| const { _: translate } = useTranslation(); | ||
| const trpc = useTRPC(); | ||
| const [open, setOpen] = useState(false); | ||
| const [reason, setReason] = useState<PageReportReason | "">(""); | ||
| const [details, setDetails] = useState(""); | ||
| const [email, setEmail] = useState(""); | ||
|
|
||
| const report = useMutation(trpc.page.report.mutationOptions()); | ||
|
|
||
| const reset = () => { | ||
| setReason(""); | ||
| setDetails(""); | ||
| setEmail(""); | ||
| report.reset(); | ||
| }; | ||
|
|
||
| const submit = () => { | ||
| if (!reason) return; | ||
| report.mutate({ | ||
| slug, | ||
| reason, | ||
| details: details.trim() || undefined, | ||
| reporterEmail: !signedIn && email.trim() ? email.trim() : undefined, | ||
| }); | ||
| }; | ||
|
|
||
| return ( | ||
| <Dialog | ||
| open={open} | ||
| onOpenChange={(next) => { | ||
| setOpen(next); | ||
| if (!next) reset(); | ||
| }} | ||
| > | ||
| <DialogTrigger asChild> | ||
| <Button size="xs" variant="ghost" className="text-muted-foreground"> | ||
| <Flag className="size-3.5" /> | ||
| <Trans>Report</Trans> | ||
| </Button> | ||
| </DialogTrigger> | ||
| <DialogContent className="sm:max-w-md"> | ||
| {report.isSuccess ? ( | ||
| <> | ||
| <DialogHeader> | ||
| <DialogTitle> | ||
| <Trans>Thanks, we got it</Trans> | ||
| </DialogTitle> | ||
| <DialogDescription> | ||
| <Trans> | ||
| Someone on the Superset team will review this page. We only | ||
| follow up if we need more from you. | ||
| </Trans> | ||
| </DialogDescription> | ||
| </DialogHeader> | ||
| <DialogFooter> | ||
| <Button onClick={() => setOpen(false)}> | ||
| <Trans>Close</Trans> | ||
| </Button> | ||
| </DialogFooter> | ||
| </> | ||
| ) : ( | ||
| <> | ||
| <DialogHeader> | ||
| <DialogTitle> | ||
| <Trans>Report this page</Trans> | ||
| </DialogTitle> | ||
| <DialogDescription> | ||
| <Trans> | ||
| Tell us what is wrong with it. Reporting does not remove the | ||
| page on its own. | ||
| </Trans> | ||
| </DialogDescription> | ||
| </DialogHeader> | ||
|
|
||
| <div className="flex flex-col gap-4"> | ||
| <div className="flex flex-col gap-2"> | ||
| <Label htmlFor="report-reason"> | ||
| <Trans>What is wrong?</Trans> | ||
| </Label> | ||
| <Select | ||
| value={reason} | ||
| onValueChange={(value) => | ||
| setReason(value as PageReportReason) | ||
| } | ||
| > | ||
| <SelectTrigger id="report-reason"> | ||
| <SelectValue | ||
| placeholder={t({ message: "Pick a reason" })} | ||
| /> | ||
| </SelectTrigger> | ||
| <SelectContent> | ||
| {REPORT_REASONS.map(({ value, label }) => ( | ||
| <SelectItem key={value} value={value}> | ||
| {translate(label)} | ||
| </SelectItem> | ||
| ))} | ||
| </SelectContent> | ||
| </Select> | ||
| </div> | ||
|
|
||
| <div className="flex flex-col gap-2"> | ||
| <Label htmlFor="report-details"> | ||
| <Trans>Anything else? (optional)</Trans> | ||
| </Label> | ||
| <Textarea | ||
| id="report-details" | ||
| value={details} | ||
| maxLength={4000} | ||
| rows={4} | ||
| onChange={(event) => setDetails(event.target.value)} | ||
| placeholder={t({ | ||
| message: "What did you see on the page?", | ||
| })} | ||
| /> | ||
| </div> | ||
|
|
||
| {!signedIn && ( | ||
| <div className="flex flex-col gap-2"> | ||
| <Label htmlFor="report-email"> | ||
| <Trans>Your email (optional)</Trans> | ||
| </Label> | ||
| <Input | ||
| id="report-email" | ||
| type="email" | ||
| value={email} | ||
| onChange={(event) => setEmail(event.target.value)} | ||
| placeholder={t({ message: "you@example.com" })} | ||
| /> | ||
| </div> | ||
| )} | ||
|
|
||
| {report.isError && ( | ||
| <p className="text-destructive text-sm"> | ||
| {errorMessage(report.error)} | ||
| </p> | ||
| )} | ||
| </div> | ||
|
|
||
| <DialogFooter> | ||
| <Button variant="ghost" onClick={() => setOpen(false)}> | ||
| <Trans>Cancel</Trans> | ||
| </Button> | ||
| <Button onClick={submit} disabled={!reason || report.isPending}> | ||
| {report.isPending ? ( | ||
| <Trans>Sending…</Trans> | ||
| ) : ( | ||
| <Trans>Send report</Trans> | ||
| )} | ||
| </Button> | ||
| </DialogFooter> | ||
| </> | ||
| )} | ||
| </DialogContent> | ||
| </Dialog> | ||
| ); | ||
| } | ||
21 changes: 21 additions & 0 deletions
21
...eb/src/app/page/[slug]/components/PublicPageView/components/ReportPageDialog/constants.ts
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,21 @@ | ||
| import type { MessageDescriptor } from "@lingui/core"; | ||
| import { msg } from "@lingui/core/macro"; | ||
| import type { PageReportReason } from "@superset/db/enums"; | ||
|
|
||
| const REPORT_REASON_LABELS: Record<PageReportReason, MessageDescriptor> = { | ||
| malware_or_phishing: msg({ message: "Malware or phishing" }), | ||
| spam_or_scam: msg({ message: "Spam or a scam" }), | ||
| impersonation: msg({ message: "Impersonates someone" }), | ||
| sexual_content: msg({ message: "Sexual content" }), | ||
| violence_or_harassment: msg({ message: "Violence or harassment" }), | ||
| illegal_content: msg({ message: "Illegal content" }), | ||
| copyright: msg({ message: "Copyright or trademark" }), | ||
| other: msg({ message: "Something else" }), | ||
| }; | ||
|
|
||
| export const REPORT_REASONS = ( | ||
| Object.entries(REPORT_REASON_LABELS) as [ | ||
| PageReportReason, | ||
| MessageDescriptor, | ||
| ][] | ||
| ).map(([value, label]) => ({ value, label })); |
1 change: 1 addition & 0 deletions
1
apps/web/src/app/page/[slug]/components/PublicPageView/components/ReportPageDialog/index.ts
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 @@ | ||
| export { ReportPageDialog } from "./ReportPageDialog"; |
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,27 @@ | ||
| CREATE TYPE "public"."page_report_status" AS ENUM('open', 'upheld', 'dismissed');--> statement-breakpoint | ||
| CREATE TABLE "page_reports" ( | ||
| "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, | ||
| "page_id" uuid NOT NULL, | ||
| "reported_version" integer, | ||
| "reason" text NOT NULL, | ||
| "details" text, | ||
| "status" "page_report_status" DEFAULT 'open' NOT NULL, | ||
| "reported_by_user_id" uuid, | ||
| "reporter_email" text, | ||
| "reporter_ip_hash" text, | ||
| "reviewed_by_user_id" uuid, | ||
| "reviewed_at" timestamp with time zone, | ||
| "review_note" text, | ||
| "created_at" timestamp with time zone DEFAULT now() NOT NULL | ||
| ); | ||
| --> statement-breakpoint | ||
| ALTER TABLE "pages" ADD COLUMN "taken_down_at" timestamp with time zone;--> statement-breakpoint | ||
| ALTER TABLE "pages" ADD COLUMN "taken_down_by_user_id" uuid;--> statement-breakpoint | ||
| ALTER TABLE "pages" ADD COLUMN "taken_down_note" text;--> statement-breakpoint | ||
| ALTER TABLE "page_reports" ADD CONSTRAINT "page_reports_page_id_pages_id_fk" FOREIGN KEY ("page_id") REFERENCES "public"."pages"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint | ||
| ALTER TABLE "page_reports" ADD CONSTRAINT "page_reports_reported_by_user_id_users_id_fk" FOREIGN KEY ("reported_by_user_id") REFERENCES "auth"."users"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint | ||
| ALTER TABLE "page_reports" ADD CONSTRAINT "page_reports_reviewed_by_user_id_users_id_fk" FOREIGN KEY ("reviewed_by_user_id") REFERENCES "auth"."users"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint | ||
| CREATE INDEX "page_reports_status_created_at_idx" ON "page_reports" USING btree ("status","created_at" desc);--> statement-breakpoint | ||
| CREATE INDEX "page_reports_page_id_idx" ON "page_reports" USING btree ("page_id");--> statement-breakpoint | ||
| CREATE INDEX "page_reports_reporter_ip_hash_idx" ON "page_reports" USING btree ("reporter_ip_hash");--> statement-breakpoint | ||
| ALTER TABLE "pages" ADD CONSTRAINT "pages_taken_down_by_user_id_users_id_fk" FOREIGN KEY ("taken_down_by_user_id") REFERENCES "auth"."users"("id") ON DELETE set null ON UPDATE no action; |
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.
Uh oh!
There was an error while loading. Please reload this page.