feat: cases (reports, rating reviews, removal and deletion requests, appeals) and notifications
Cases are one queue for what someone has to decide, each with a thread (internal notes for those deciding), an assignee and a decision. Reports about a product go to the teams of the catalogs hosting it and to moderators, and only the reporter and moderators know who reported. A creator lowering a rating opens a rating review; a catalog's owner asking to delete it opens a deletion request; a catalog's team can ask for a product's removal everywhere; the person an action affected can appeal it once, decided by another moderator (an admin may decide their own, flagged). Resolving carries the case out: the rating is lowered, the product removed, the catalog deleted. Notifications reach people on the website (a bell with the unread count) and their proxies (realtime): moderators' edits to their products, removals and restores, decisions and replies on their cases, membership decisions. Also: moderators can restore a removed product, and a product's creator and moderators can see it when it's adult without an adult account (getting and wearing it still need one). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
e07a6c6dac
commit
8af4b7b6a9
33 files changed
+5228
-44
No files matched your search
@@ -0,0 +1,46 @@
|
||||
CREATE TABLE "case_note" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"case_id" integer NOT NULL,
|
||||
"by_id" text,
|
||||
"body" text NOT NULL,
|
||||
"internal" boolean DEFAULT false NOT NULL,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "moderation_case" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"kind" text NOT NULL,
|
||||
"status" text DEFAULT 'open' NOT NULL,
|
||||
"tags" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
||||
"opened_by" text,
|
||||
"assignee" text,
|
||||
"reason" text DEFAULT '' NOT NULL,
|
||||
"data" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
||||
"resolution" text DEFAULT '' NOT NULL,
|
||||
"decided_by" text,
|
||||
"decided_at" timestamp with time zone,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "notification" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"user_id" text NOT NULL,
|
||||
"type" text NOT NULL,
|
||||
"tags" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
||||
"data" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"read_at" timestamp with time zone
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "case_note" ADD CONSTRAINT "case_note_case_id_moderation_case_id_fk" FOREIGN KEY ("case_id") REFERENCES "public"."moderation_case"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "case_note" ADD CONSTRAINT "case_note_by_id_user_id_fk" FOREIGN KEY ("by_id") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "moderation_case" ADD CONSTRAINT "moderation_case_opened_by_user_id_fk" FOREIGN KEY ("opened_by") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "moderation_case" ADD CONSTRAINT "moderation_case_assignee_user_id_fk" FOREIGN KEY ("assignee") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "moderation_case" ADD CONSTRAINT "moderation_case_decided_by_user_id_fk" FOREIGN KEY ("decided_by") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "notification" ADD CONSTRAINT "notification_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE INDEX "case_note_case" ON "case_note" USING btree ("case_id","id");--> statement-breakpoint
|
||||
CREATE INDEX "moderation_case_status" ON "moderation_case" USING btree ("status","id");--> statement-breakpoint
|
||||
CREATE INDEX "moderation_case_opened_by" ON "moderation_case" USING btree ("opened_by");--> statement-breakpoint
|
||||
CREATE INDEX "moderation_case_tags" ON "moderation_case" USING gin ("tags");--> statement-breakpoint
|
||||
CREATE INDEX "notification_user" ON "notification" USING btree ("user_id","id");
|
||||
File diff suppressed because it is too large.
Load diff
@@ -85,6 +85,13 @@
|
||||
"when": 1793886718951,
|
||||
"tag": "0011_product_info",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 12,
|
||||
"version": "7",
|
||||
"when": 1793888724185,
|
||||
"tag": "0012_cases",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -598,3 +598,63 @@ export const hubSetting = pgTable("hub_setting", {
|
||||
value: text("value").notNull(),
|
||||
updatedAt: updatedAt(),
|
||||
});
|
||||
|
||||
// A case: something someone has to decide (docs/console.md, "Cases"): a report, a rating review, a removal request,
|
||||
// a catalog's deletion request, or an appeal. ("case" is an SQL keyword, hence the table's name.)
|
||||
export const moderationCase = pgTable(
|
||||
"moderation_case",
|
||||
{
|
||||
id: serial("id").primaryKey(),
|
||||
kind: text("kind").notNull(), // "report", "rating-review", "removal-request", "catalog-deletion", "appeal"
|
||||
status: text("status").notNull().default("open"), // "open", "resolved", "declined"
|
||||
// What it's about ({catalog, product, room, person}), as audit entries are tagged.
|
||||
tags: jsonb("tags").$type<AuditTags>().notNull().default({}),
|
||||
openedBy: text("opened_by").references(() => user.id, { onDelete: "set null" }),
|
||||
assignee: text("assignee").references(() => user.id, { onDelete: "set null" }),
|
||||
reason: text("reason").notNull().default(""), // why it was opened
|
||||
data: jsonb("data").$type<Record<string, unknown>>().notNull().default({}), // per kind (an appeal's audit entry)
|
||||
resolution: text("resolution").notNull().default(""),
|
||||
decidedBy: text("decided_by").references(() => user.id, { onDelete: "set null" }),
|
||||
decidedAt: timestamp("decided_at", { withTimezone: true }),
|
||||
createdAt: createdAt(),
|
||||
updatedAt: updatedAt(),
|
||||
},
|
||||
(t) => [
|
||||
index("moderation_case_status").on(t.status, t.id),
|
||||
index("moderation_case_opened_by").on(t.openedBy),
|
||||
index("moderation_case_tags").using("gin", t.tags),
|
||||
],
|
||||
);
|
||||
|
||||
// A case's thread. Internal notes are only for those deciding it.
|
||||
export const caseNote = pgTable(
|
||||
"case_note",
|
||||
{
|
||||
id: serial("id").primaryKey(),
|
||||
caseId: integer("case_id")
|
||||
.notNull()
|
||||
.references(() => moderationCase.id, { onDelete: "cascade" }),
|
||||
byId: text("by_id").references(() => user.id, { onDelete: "set null" }),
|
||||
body: text("body").notNull(),
|
||||
internal: boolean("internal").notNull().default(false),
|
||||
createdAt: createdAt(),
|
||||
},
|
||||
(t) => [index("case_note_case").on(t.caseId, t.id)],
|
||||
);
|
||||
|
||||
// Something for a person to know: a moderator edited their product, their case was decided, ... (docs/console.md).
|
||||
export const notification = pgTable(
|
||||
"notification",
|
||||
{
|
||||
id: serial("id").primaryKey(),
|
||||
userId: text("user_id")
|
||||
.notNull()
|
||||
.references(() => user.id, { onDelete: "cascade" }),
|
||||
type: text("type").notNull(),
|
||||
tags: jsonb("tags").$type<AuditTags>().notNull().default({}),
|
||||
data: jsonb("data").$type<Record<string, unknown>>().notNull().default({}),
|
||||
createdAt: createdAt(),
|
||||
readAt: timestamp("read_at", { withTimezone: true }),
|
||||
},
|
||||
(t) => [index("notification_user").on(t.userId, t.id)],
|
||||
);
|
||||
Reference in new issue
Block a user