Skip to content

Commit

Permalink
✨ Allow appealing a moderator decision through special report type
Browse files Browse the repository at this point in the history
  • Loading branch information
foysalit committed Dec 14, 2023
1 parent 8d4a87c commit f052224
Show file tree
Hide file tree
Showing 20 changed files with 371 additions and 8 deletions.
16 changes: 15 additions & 1 deletion lexicons/com/atproto/admin/defs.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@
"type": "string",
"format": "datetime"
},
"appealedAt": {
"type": "string",
"format": "datetime",
"description": "Timestamp referencing when the owner of the subject appealed a moderation action"
},
"takendown": {
"type": "boolean"
},
Expand Down Expand Up @@ -432,7 +437,12 @@
},
"subjectReviewState": {
"type": "string",
"knownValues": ["#reviewOpen", "#reviewEscalated", "#reviewClosed"]
"knownValues": [
"#reviewOpen",
"#reviewEscalated",
"#reviewClosed",
"#reviewAppealed"
]
},
"reviewOpen": {
"type": "token",
Expand All @@ -446,6 +456,10 @@
"type": "token",
"description": "Moderator review status of a subject: Closed. Indicates that the subject was already reviewed and resolved by a moderator"
},
"reviewAppealed": {
"type": "token",
"description": "Moderator review status of a subject: Appealed. Indicates that the a previously taken moderator action was appealed agains, by the author of the content"
},
"modEventTakedown": {
"type": "object",
"description": "Take down a subject permanently or temporarily",
Expand Down
7 changes: 6 additions & 1 deletion lexicons/com/atproto/moderation/defs.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"com.atproto.moderation.defs#reasonMisleading",
"com.atproto.moderation.defs#reasonSexual",
"com.atproto.moderation.defs#reasonRude",
"com.atproto.moderation.defs#reasonOther"
"com.atproto.moderation.defs#reasonOther",
"com.atproto.moderation.defs#reasonAppeal"
]
},
"reasonSpam": {
Expand All @@ -36,6 +37,10 @@
"reasonOther": {
"type": "token",
"description": "Other: reports not falling under another report category"
},
"reasonAppeal": {
"type": "token",
"description": "Appeal: appeal a previously taken moderation action"
}
}
}
2 changes: 2 additions & 0 deletions packages/api/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ export const COM_ATPROTO_ADMIN = {
DefsReviewOpen: 'com.atproto.admin.defs#reviewOpen',
DefsReviewEscalated: 'com.atproto.admin.defs#reviewEscalated',
DefsReviewClosed: 'com.atproto.admin.defs#reviewClosed',
DefsReviewAppealed: 'com.atproto.admin.defs#reviewAppealed',
}
export const COM_ATPROTO_MODERATION = {
DefsReasonSpam: 'com.atproto.moderation.defs#reasonSpam',
Expand All @@ -297,6 +298,7 @@ export const COM_ATPROTO_MODERATION = {
DefsReasonSexual: 'com.atproto.moderation.defs#reasonSexual',
DefsReasonRude: 'com.atproto.moderation.defs#reasonRude',
DefsReasonOther: 'com.atproto.moderation.defs#reasonOther',
DefsReasonAppeal: 'com.atproto.moderation.defs#reasonAppeal',
}
export const APP_BSKY_GRAPH = {
DefsModlist: 'app.bsky.graph.defs#modlist',
Expand Down
17 changes: 17 additions & 0 deletions packages/api/src/client/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ export const schemaDict = {
type: 'string',
format: 'datetime',
},
appealedAt: {
type: 'string',
format: 'datetime',
description:
'Timestamp referencing when the owner of the subject appealed a moderation action',
},
takendown: {
type: 'boolean',
},
Expand Down Expand Up @@ -676,6 +682,7 @@ export const schemaDict = {
'lex:com.atproto.admin.defs#reviewOpen',
'lex:com.atproto.admin.defs#reviewEscalated',
'lex:com.atproto.admin.defs#reviewClosed',
'lex:com.atproto.admin.defs#reviewAppealed',
],
},
reviewOpen: {
Expand All @@ -693,6 +700,11 @@ export const schemaDict = {
description:
'Moderator review status of a subject: Closed. Indicates that the subject was already reviewed and resolved by a moderator',
},
reviewAppealed: {
type: 'token',
description:
'Moderator review status of a subject: Appealed. Indicates that the a previously taken moderator action was appealed agains, by the author of the content',
},
modEventTakedown: {
type: 'object',
description: 'Take down a subject permanently or temporarily',
Expand Down Expand Up @@ -1937,6 +1949,7 @@ export const schemaDict = {
'com.atproto.moderation.defs#reasonSexual',
'com.atproto.moderation.defs#reasonRude',
'com.atproto.moderation.defs#reasonOther',
'com.atproto.moderation.defs#reasonAppeal',
],
},
reasonSpam: {
Expand Down Expand Up @@ -1964,6 +1977,10 @@ export const schemaDict = {
type: 'token',
description: 'Other: reports not falling under another report category',
},
reasonAppeal: {
type: 'token',
description: 'Appeal: appeal a previously taken moderation action',
},
},
},
ComAtprotoRepoApplyWrites: {
Expand Down
5 changes: 5 additions & 0 deletions packages/api/src/client/types/com/atproto/admin/defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ export interface SubjectStatusView {
lastReviewedBy?: string
lastReviewedAt?: string
lastReportedAt?: string
/** Timestamp referencing when the owner of the subject appealed a moderation action */
appealedAt?: string
takendown?: boolean
suspendUntil?: string
[k: string]: unknown
Expand Down Expand Up @@ -488,6 +490,7 @@ export type SubjectReviewState =
| 'lex:com.atproto.admin.defs#reviewOpen'
| 'lex:com.atproto.admin.defs#reviewEscalated'
| 'lex:com.atproto.admin.defs#reviewClosed'
| 'lex:com.atproto.admin.defs#reviewAppealed'
| (string & {})

/** Moderator review status of a subject: Open. Indicates that the subject needs to be reviewed by a moderator */
Expand All @@ -496,6 +499,8 @@ export const REVIEWOPEN = 'com.atproto.admin.defs#reviewOpen'
export const REVIEWESCALATED = 'com.atproto.admin.defs#reviewEscalated'
/** Moderator review status of a subject: Closed. Indicates that the subject was already reviewed and resolved by a moderator */
export const REVIEWCLOSED = 'com.atproto.admin.defs#reviewClosed'
/** Moderator review status of a subject: Appealed. Indicates that the a previously taken moderator action was appealed agains, by the author of the content */
export const REVIEWAPPEALED = 'com.atproto.admin.defs#reviewAppealed'

/** Take down a subject permanently or temporarily */
export interface ModEventTakedown {
Expand Down
3 changes: 3 additions & 0 deletions packages/api/src/client/types/com/atproto/moderation/defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type ReasonType =
| 'com.atproto.moderation.defs#reasonSexual'
| 'com.atproto.moderation.defs#reasonRude'
| 'com.atproto.moderation.defs#reasonOther'
| 'com.atproto.moderation.defs#reasonAppeal'
| (string & {})

/** Spam: frequent unwanted promotion, replies, mentions */
Expand All @@ -27,3 +28,5 @@ export const REASONSEXUAL = 'com.atproto.moderation.defs#reasonSexual'
export const REASONRUDE = 'com.atproto.moderation.defs#reasonRude'
/** Other: reports not falling under another report category */
export const REASONOTHER = 'com.atproto.moderation.defs#reasonOther'
/** Appeal: appeal a previously taken moderation action */
export const REASONAPPEAL = 'com.atproto.moderation.defs#reasonAppeal'
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Kysely } from 'kysely'

export async function up(db: Kysely<unknown>): Promise<void> {
await db.schema
.alterTable('moderation_subject_status')
.addColumn('appealedAt', 'varchar')
.execute()
}

export async function down(db: Kysely<unknown>): Promise<void> {
await db.schema
.alterTable('moderation_subject_status')
.dropColumn('appealedAt')
.execute()
}
1 change: 1 addition & 0 deletions packages/bsky/src/db/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ export * as _20230920T213858047Z from './20230920T213858047Z-add-tags-to-post'
export * as _20230929T192920807Z from './20230929T192920807Z-record-cursor-indexes'
export * as _20231003T202833377Z from './20231003T202833377Z-create-moderation-subject-status'
export * as _20231205T000257238Z from './20231205T000257238Z-remove-did-cache'
export * as _20231213T181744386Z from './20231213T181744386Z-moderation-subject-appeal'
8 changes: 7 additions & 1 deletion packages/bsky/src/db/tables/moderation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
REVIEWCLOSED,
REVIEWOPEN,
REVIEWESCALATED,
REVIEWAPPEALED,
} from '../../lexicon/types/com/atproto/admin/defs'

export const eventTableName = 'moderation_event'
Expand Down Expand Up @@ -41,12 +42,17 @@ export interface ModerationSubjectStatus {
recordPath: string
recordCid: string | null
blobCids: string[] | null
reviewState: typeof REVIEWCLOSED | typeof REVIEWOPEN | typeof REVIEWESCALATED
reviewState:
| typeof REVIEWCLOSED
| typeof REVIEWOPEN
| typeof REVIEWESCALATED
| typeof REVIEWAPPEALED
createdAt: string
updatedAt: string
lastReviewedBy: string | null
lastReviewedAt: string | null
lastReportedAt: string | null
appealedAt: string | null
muteUntil: string | null
suspendUntil: string | null
takendown: boolean
Expand Down
4 changes: 2 additions & 2 deletions packages/bsky/src/lexicon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export const COM_ATPROTO_ADMIN = {
DefsReviewOpen: 'com.atproto.admin.defs#reviewOpen',
DefsReviewEscalated: 'com.atproto.admin.defs#reviewEscalated',
DefsReviewClosed: 'com.atproto.admin.defs#reviewClosed',
DefsReviewAppealed: 'com.atproto.admin.defs#reviewAppealed',
}
export const COM_ATPROTO_MODERATION = {
DefsReasonSpam: 'com.atproto.moderation.defs#reasonSpam',
Expand All @@ -135,6 +136,7 @@ export const COM_ATPROTO_MODERATION = {
DefsReasonSexual: 'com.atproto.moderation.defs#reasonSexual',
DefsReasonRude: 'com.atproto.moderation.defs#reasonRude',
DefsReasonOther: 'com.atproto.moderation.defs#reasonOther',
DefsReasonAppeal: 'com.atproto.moderation.defs#reasonAppeal',
}
export const APP_BSKY_GRAPH = {
DefsModlist: 'app.bsky.graph.defs#modlist',
Expand Down Expand Up @@ -1597,13 +1599,11 @@ type RouteRateLimitOpts<T> = {
calcKey?: (ctx: T) => string
calcPoints?: (ctx: T) => number
}
type HandlerOpts = { blobLimit?: number }
type HandlerRateLimitOpts<T> = SharedRateLimitOpts<T> | RouteRateLimitOpts<T>
type ConfigOf<Auth, Handler, ReqCtx> =
| Handler
| {
auth?: Auth
opts?: HandlerOpts
rateLimit?: HandlerRateLimitOpts<ReqCtx> | HandlerRateLimitOpts<ReqCtx>[]
handler: Handler
}
Expand Down
17 changes: 17 additions & 0 deletions packages/bsky/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ export const schemaDict = {
type: 'string',
format: 'datetime',
},
appealedAt: {
type: 'string',
format: 'datetime',
description:
'Timestamp referencing when the owner of the subject appealed a moderation action',
},
takendown: {
type: 'boolean',
},
Expand Down Expand Up @@ -676,6 +682,7 @@ export const schemaDict = {
'lex:com.atproto.admin.defs#reviewOpen',
'lex:com.atproto.admin.defs#reviewEscalated',
'lex:com.atproto.admin.defs#reviewClosed',
'lex:com.atproto.admin.defs#reviewAppealed',
],
},
reviewOpen: {
Expand All @@ -693,6 +700,11 @@ export const schemaDict = {
description:
'Moderator review status of a subject: Closed. Indicates that the subject was already reviewed and resolved by a moderator',
},
reviewAppealed: {
type: 'token',
description:
'Moderator review status of a subject: Appealed. Indicates that the a previously taken moderator action was appealed agains, by the author of the content',
},
modEventTakedown: {
type: 'object',
description: 'Take down a subject permanently or temporarily',
Expand Down Expand Up @@ -1937,6 +1949,7 @@ export const schemaDict = {
'com.atproto.moderation.defs#reasonSexual',
'com.atproto.moderation.defs#reasonRude',
'com.atproto.moderation.defs#reasonOther',
'com.atproto.moderation.defs#reasonAppeal',
],
},
reasonSpam: {
Expand Down Expand Up @@ -1964,6 +1977,10 @@ export const schemaDict = {
type: 'token',
description: 'Other: reports not falling under another report category',
},
reasonAppeal: {
type: 'token',
description: 'Appeal: appeal a previously taken moderation action',
},
},
},
ComAtprotoRepoApplyWrites: {
Expand Down
5 changes: 5 additions & 0 deletions packages/bsky/src/lexicon/types/com/atproto/admin/defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ export interface SubjectStatusView {
lastReviewedBy?: string
lastReviewedAt?: string
lastReportedAt?: string
/** Timestamp referencing when the owner of the subject appealed a moderation action */
appealedAt?: string
takendown?: boolean
suspendUntil?: string
[k: string]: unknown
Expand Down Expand Up @@ -488,6 +490,7 @@ export type SubjectReviewState =
| 'lex:com.atproto.admin.defs#reviewOpen'
| 'lex:com.atproto.admin.defs#reviewEscalated'
| 'lex:com.atproto.admin.defs#reviewClosed'
| 'lex:com.atproto.admin.defs#reviewAppealed'
| (string & {})

/** Moderator review status of a subject: Open. Indicates that the subject needs to be reviewed by a moderator */
Expand All @@ -496,6 +499,8 @@ export const REVIEWOPEN = 'com.atproto.admin.defs#reviewOpen'
export const REVIEWESCALATED = 'com.atproto.admin.defs#reviewEscalated'
/** Moderator review status of a subject: Closed. Indicates that the subject was already reviewed and resolved by a moderator */
export const REVIEWCLOSED = 'com.atproto.admin.defs#reviewClosed'
/** Moderator review status of a subject: Appealed. Indicates that the a previously taken moderator action was appealed agains, by the author of the content */
export const REVIEWAPPEALED = 'com.atproto.admin.defs#reviewAppealed'

/** Take down a subject permanently or temporarily */
export interface ModEventTakedown {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type ReasonType =
| 'com.atproto.moderation.defs#reasonSexual'
| 'com.atproto.moderation.defs#reasonRude'
| 'com.atproto.moderation.defs#reasonOther'
| 'com.atproto.moderation.defs#reasonAppeal'
| (string & {})

/** Spam: frequent unwanted promotion, replies, mentions */
Expand All @@ -27,3 +28,5 @@ export const REASONSEXUAL = 'com.atproto.moderation.defs#reasonSexual'
export const REASONRUDE = 'com.atproto.moderation.defs#reasonRude'
/** Other: reports not falling under another report category */
export const REASONOTHER = 'com.atproto.moderation.defs#reasonOther'
/** Appeal: appeal a previously taken moderation action */
export const REASONAPPEAL = 'com.atproto.moderation.defs#reasonAppeal'
Loading

0 comments on commit f052224

Please sign in to comment.