Skip to content

Commit

Permalink
✨ Move to appealed boolean state column
Browse files Browse the repository at this point in the history
  • Loading branch information
foysalit committed Dec 21, 2023
1 parent cb29500 commit 3dfc2e8
Show file tree
Hide file tree
Showing 21 changed files with 260 additions and 97 deletions.
30 changes: 18 additions & 12 deletions lexicons/com/atproto/admin/defs.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
"#modEventLabel",
"#modEventAcknowledge",
"#modEventEscalate",
"#modEventMute"
"#modEventMute",
"#modEventResolveAppeal"
]
},
"subject": {
Expand Down Expand Up @@ -167,14 +168,18 @@
"type": "string",
"format": "datetime"
},
"appealedAt": {
"lastAppealedAt": {
"type": "string",
"format": "datetime",
"description": "Timestamp referencing when the owner of the subject appealed a moderation action"
},
"takendown": {
"type": "boolean"
},
"appealed": {
"type": "boolean",
"description": "True Indicates that the a previously taken moderator action was appealed against, by the author of the content. False indicates last appeal was resolved by moderators."
},
"suspendUntil": {
"type": "string",
"format": "datetime"
Expand Down Expand Up @@ -437,12 +442,7 @@
},
"subjectReviewState": {
"type": "string",
"knownValues": [
"#reviewOpen",
"#reviewEscalated",
"#reviewClosed",
"#reviewAppealed"
]
"knownValues": ["#reviewOpen", "#reviewEscalated", "#reviewClosed"]
},
"reviewOpen": {
"type": "token",
Expand All @@ -456,10 +456,6 @@
"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 All @@ -483,6 +479,16 @@
}
}
},
"modEventResolveAppeal": {
"type": "object",
"description": "Resolve appeal on a subject",
"properties": {
"comment": {
"type": "string",
"description": "Describe resolution."
}
}
},
"modEventComment": {
"type": "object",
"description": "Add a comment to a subject",
Expand Down
4 changes: 4 additions & 0 deletions lexicons/com/atproto/admin/queryModerationStatuses.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
"type": "boolean",
"description": "Get subjects that were taken down"
},
"appealed": {
"type": "boolean",
"description": "Get subjects in unresolved appealed status"
},
"limit": {
"type": "integer",
"minimum": 1,
Expand Down
1 change: 0 additions & 1 deletion packages/api/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ 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 Down
28 changes: 21 additions & 7 deletions packages/api/src/client/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export const schemaDict = {
'lex:com.atproto.admin.defs#modEventAcknowledge',
'lex:com.atproto.admin.defs#modEventEscalate',
'lex:com.atproto.admin.defs#modEventMute',
'lex:com.atproto.admin.defs#modEventResolveAppeal',
],
},
subject: {
Expand Down Expand Up @@ -237,7 +238,7 @@ export const schemaDict = {
type: 'string',
format: 'datetime',
},
appealedAt: {
lastAppealedAt: {
type: 'string',
format: 'datetime',
description:
Expand All @@ -246,6 +247,11 @@ export const schemaDict = {
takendown: {
type: 'boolean',
},
appealed: {
type: 'boolean',
description:
'True Indicates that the a previously taken moderator action was appealed against, by the author of the content. False indicates last appeal was resolved by moderators. Null indicates no prior appeal on the subject.',
},
suspendUntil: {
type: 'string',
format: 'datetime',
Expand Down Expand Up @@ -682,7 +688,6 @@ 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 @@ -700,11 +705,6 @@ 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 All @@ -729,6 +729,16 @@ export const schemaDict = {
},
},
},
modEventResolveAppeal: {
type: 'object',
description: 'Resolve appeal on a subject',
properties: {
comment: {
type: 'string',
description: 'Describe resolution.',
},
},
},
modEventComment: {
type: 'object',
description: 'Add a comment to a subject',
Expand Down Expand Up @@ -1369,6 +1379,10 @@ export const schemaDict = {
type: 'boolean',
description: 'Get subjects that were taken down',
},
appealed: {
type: 'boolean',
description: 'Get subjects in unresolved appealed status',
},
limit: {
type: 'integer',
minimum: 1,
Expand Down
29 changes: 25 additions & 4 deletions packages/api/src/client/types/com/atproto/admin/defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export interface ModEventViewDetail {
| ModEventAcknowledge
| ModEventEscalate
| ModEventMute
| ModEventResolveAppeal
| { $type: string; [k: string]: unknown }
subject:
| RepoView
Expand Down Expand Up @@ -148,8 +149,10 @@ export interface SubjectStatusView {
lastReviewedAt?: string
lastReportedAt?: string
/** Timestamp referencing when the owner of the subject appealed a moderation action */
appealedAt?: string
lastAppealedAt?: string
takendown?: boolean
/** True Indicates that the a previously taken moderator action was appealed against, by the author of the content. False indicates last appeal was resolved by moderators. Null indicates no prior appeal on the subject. */
appealed?: boolean
suspendUntil?: string
[k: string]: unknown
}
Expand Down Expand Up @@ -490,7 +493,6 @@ 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 @@ -499,8 +501,6 @@ 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 Expand Up @@ -543,6 +543,27 @@ export function validateModEventReverseTakedown(v: unknown): ValidationResult {
return lexicons.validate('com.atproto.admin.defs#modEventReverseTakedown', v)
}

/** Resolve appeal on a subject */
export interface ModEventResolveAppeal {
/** Describe resolution. */
comment?: string
[k: string]: unknown
}

export function isModEventResolveAppeal(
v: unknown,
): v is ModEventResolveAppeal {
return (
isObj(v) &&
hasProp(v, '$type') &&
v.$type === 'com.atproto.admin.defs#modEventResolveAppeal'
)
}

export function validateModEventResolveAppeal(v: unknown): ValidationResult {
return lexicons.validate('com.atproto.admin.defs#modEventResolveAppeal', v)
}

/** Add a comment to a subject */
export interface ModEventComment {
comment: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export interface QueryParams {
sortDirection?: 'asc' | 'desc'
/** Get subjects that were taken down */
takendown?: boolean
/** Get subjects in unresolved appealed status */
appealed?: boolean
limit?: number
cursor?: string
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default function (server: Server, ctx: AppContext) {
const {
subject,
takendown,
appealed,
reviewState,
reviewedAfter,
reviewedBefore,
Expand All @@ -28,6 +29,7 @@ export default function (server: Server, ctx: AppContext) {
reviewState: getReviewState(reviewState),
subject,
takendown,
appealed,
reviewedAfter,
reviewedBefore,
reportedAfter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ import { Kysely } from 'kysely'
export async function up(db: Kysely<unknown>): Promise<void> {
await db.schema
.alterTable('moderation_subject_status')
.addColumn('appealedAt', 'varchar')
.addColumn('lastAppealedAt', 'varchar')
.execute()
await db.schema
.alterTable('moderation_subject_status')
.addColumn('appealed', 'boolean')
.execute()
}

export async function down(db: Kysely<unknown>): Promise<void> {
await db.schema
.alterTable('moderation_subject_status')
.dropColumn('appealedAt')
.dropColumn('lastAppealedAt')
.execute()
await db.schema
.alterTable('moderation_subject_status')
.dropColumn('appealed')
.execute()
}
11 changes: 4 additions & 7 deletions packages/bsky/src/db/tables/moderation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
REVIEWCLOSED,
REVIEWOPEN,
REVIEWESCALATED,
REVIEWAPPEALED,
} from '../../lexicon/types/com/atproto/admin/defs'

export const eventTableName = 'moderation_event'
Expand All @@ -21,6 +20,7 @@ export interface ModerationEvent {
| 'com.atproto.admin.defs#modEventMute'
| 'com.atproto.admin.defs#modEventReverseTakedown'
| 'com.atproto.admin.defs#modEventEmail'
| 'com.atproto.admin.defs#modEventResolveAppeal'
subjectType: 'com.atproto.admin.defs#repoRef' | 'com.atproto.repo.strongRef'
subjectDid: string
subjectUri: string | null
Expand All @@ -42,20 +42,17 @@ export interface ModerationSubjectStatus {
recordPath: string
recordCid: string | null
blobCids: string[] | null
reviewState:
| typeof REVIEWCLOSED
| typeof REVIEWOPEN
| typeof REVIEWESCALATED
| typeof REVIEWAPPEALED
reviewState: typeof REVIEWCLOSED | typeof REVIEWOPEN | typeof REVIEWESCALATED
createdAt: string
updatedAt: string
lastReviewedBy: string | null
lastReviewedAt: string | null
lastReportedAt: string | null
appealedAt: string | null
lastAppealedAt: string | null
muteUntil: string | null
suspendUntil: string | null
takendown: boolean
appealed: boolean | null
comment: string | null
}

Expand Down
3 changes: 2 additions & 1 deletion packages/bsky/src/lexicon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ 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 Down Expand Up @@ -1599,11 +1598,13 @@ 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
Loading

0 comments on commit 3dfc2e8

Please sign in to comment.