Skip to content
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

✨ Add date range and comment filter to queryModerationEvents endpoint #2124

Merged
merged 9 commits into from
Feb 6, 2024
Merged
5 changes: 5 additions & 0 deletions .changeset/sharp-ducks-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@atproto/api': patch
---

Allow filtering for comment, label, report type and date range on queryModerationEvents endpoint.
4 changes: 3 additions & 1 deletion lexicons/com/atproto/admin/defs.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"#modEventAcknowledge",
"#modEventEscalate",
"#modEventMute",
"#modEventEmail"
"#modEventEmail",
"#modEventResolveAppeal"
]
},
"subject": {
Expand Down Expand Up @@ -70,6 +71,7 @@
"#modEventAcknowledge",
"#modEventEscalate",
"#modEventMute",
"#modEventEmail",
"#modEventResolveAppeal"
]
},
Expand Down
34 changes: 34 additions & 0 deletions lexicons/com/atproto/admin/queryModerationEvents.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@
"enum": ["asc", "desc"],
"description": "Sort direction for the events. Defaults to descending order of created at timestamp."
},
"createdAfter": {
"type": "string",
"format": "datetime",
"description": "Retrieve events created after a given timestamp"
},
"createdBefore": {
"type": "string",
"format": "datetime",
"description": "Retrieve events created before a given timestamp"
},
"subject": { "type": "string", "format": "uri" },
"includeAllUserRecords": {
"type": "boolean",
Expand All @@ -35,6 +45,30 @@
"maximum": 100,
"default": 50
},
"hasComment": {
"type": "boolean",
"description": "If true, only events with comments are returned"
},
"comment": {
"type": "string",
"description": "If specified, only events with comments containing the keyword are returned"
},
"addedLabels": {
"type": "array",
"items": { "type": "string" },
"description": "If specified, only events where all of these labels were added are returned"
},
"removedLabels": {
"type": "array",
"items": { "type": "string" },
"description": "If specified, only events where all of these labels were removed are returned"
},
"reportTypes": {
"type": "array",
"items": {
"type": "string"
}
},
"cursor": { "type": "string" }
}
},
Expand Down
43 changes: 43 additions & 0 deletions packages/api/src/client/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const schemaDict = {
'lex:com.atproto.admin.defs#modEventEscalate',
'lex:com.atproto.admin.defs#modEventMute',
'lex:com.atproto.admin.defs#modEventEmail',
'lex:com.atproto.admin.defs#modEventResolveAppeal',
],
},
subject: {
Expand Down Expand Up @@ -147,6 +148,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#modEventEmail',
'lex:com.atproto.admin.defs#modEventResolveAppeal',
],
},
Expand Down Expand Up @@ -1450,6 +1452,16 @@ export const schemaDict = {
description:
'Sort direction for the events. Defaults to descending order of created at timestamp.',
},
createdAfter: {
type: 'string',
format: 'datetime',
description: 'Retrieve events created after a given timestamp',
},
createdBefore: {
type: 'string',
format: 'datetime',
description: 'Retrieve events created before a given timestamp',
},
subject: {
type: 'string',
format: 'uri',
Expand All @@ -1466,6 +1478,37 @@ export const schemaDict = {
maximum: 100,
default: 50,
},
hasComment: {
type: 'boolean',
description: 'If true, only events with comments are returned',
},
comment: {
type: 'string',
description:
'If specified, only events with comments containing the keyword are returned',
},
addedLabels: {
type: 'array',
items: {
type: 'string',
},
description:
'If specified, only events where all of these labels were added are returned',
},
removedLabels: {
type: 'array',
items: {
type: 'string',
},
description:
'If specified, only events where all of these labels were removed are returned',
},
reportTypes: {
type: 'array',
items: {
type: 'string',
},
},
cursor: {
type: 'string',
},
Expand Down
2 changes: 2 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 @@ -40,6 +40,7 @@ export interface ModEventView {
| ModEventEscalate
| ModEventMute
| ModEventEmail
| ModEventResolveAppeal
| { $type: string; [k: string]: unknown }
subject:
| RepoRef
Expand Down Expand Up @@ -76,6 +77,7 @@ export interface ModEventViewDetail {
| ModEventAcknowledge
| ModEventEscalate
| ModEventMute
| ModEventEmail
| ModEventResolveAppeal
| { $type: string; [k: string]: unknown }
subject:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,23 @@ export interface QueryParams {
createdBy?: string
/** Sort direction for the events. Defaults to descending order of created at timestamp. */
sortDirection?: 'asc' | 'desc'
/** Retrieve events created after a given timestamp */
createdAfter?: string
/** Retrieve events created before a given timestamp */
createdBefore?: string
subject?: string
/** If true, events on all record types (posts, lists, profile etc.) owned by the did are returned */
includeAllUserRecords?: boolean
limit?: number
/** If true, only events with comments are returned */
hasComment?: boolean
/** If specified, only events with comments containing the keyword are returned */
comment?: string
/** If specified, only events where all of these labels were added are returned */
addedLabels?: string[]
/** If specified, only events where all of these labels were removed are returned */
removedLabels?: string[]
reportTypes?: string[]
cursor?: string
}

Expand Down
43 changes: 43 additions & 0 deletions packages/bsky/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const schemaDict = {
'lex:com.atproto.admin.defs#modEventEscalate',
'lex:com.atproto.admin.defs#modEventMute',
'lex:com.atproto.admin.defs#modEventEmail',
'lex:com.atproto.admin.defs#modEventResolveAppeal',
],
},
subject: {
Expand Down Expand Up @@ -147,6 +148,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#modEventEmail',
'lex:com.atproto.admin.defs#modEventResolveAppeal',
],
},
Expand Down Expand Up @@ -1450,6 +1452,16 @@ export const schemaDict = {
description:
'Sort direction for the events. Defaults to descending order of created at timestamp.',
},
createdAfter: {
type: 'string',
format: 'datetime',
description: 'Retrieve events created after a given timestamp',
},
createdBefore: {
type: 'string',
format: 'datetime',
description: 'Retrieve events created before a given timestamp',
},
subject: {
type: 'string',
format: 'uri',
Expand All @@ -1466,6 +1478,37 @@ export const schemaDict = {
maximum: 100,
default: 50,
},
hasComment: {
type: 'boolean',
description: 'If true, only events with comments are returned',
},
comment: {
type: 'string',
description:
'If specified, only events with comments containing the keyword are returned',
},
addedLabels: {
type: 'array',
items: {
type: 'string',
},
description:
'If specified, only events where all of these labels were added are returned',
},
removedLabels: {
type: 'array',
items: {
type: 'string',
},
description:
'If specified, only events where all of these labels were removed are returned',
},
reportTypes: {
type: 'array',
items: {
type: 'string',
},
},
cursor: {
type: 'string',
},
Expand Down
2 changes: 2 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 @@ -40,6 +40,7 @@ export interface ModEventView {
| ModEventEscalate
| ModEventMute
| ModEventEmail
| ModEventResolveAppeal
| { $type: string; [k: string]: unknown }
subject:
| RepoRef
Expand Down Expand Up @@ -76,6 +77,7 @@ export interface ModEventViewDetail {
| ModEventAcknowledge
| ModEventEscalate
| ModEventMute
| ModEventEmail
| ModEventResolveAppeal
| { $type: string; [k: string]: unknown }
subject:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,23 @@ export interface QueryParams {
createdBy?: string
/** Sort direction for the events. Defaults to descending order of created at timestamp. */
sortDirection: 'asc' | 'desc'
/** Retrieve events created after a given timestamp */
createdAfter?: string
/** Retrieve events created before a given timestamp */
createdBefore?: string
subject?: string
/** If true, events on all record types (posts, lists, profile etc.) owned by the did are returned */
includeAllUserRecords: boolean
limit: number
/** If true, only events with comments are returned */
hasComment?: boolean
/** If specified, only events with comments containing the keyword are returned */
comment?: string
/** If specified, only events where all of these labels were added are returned */
addedLabels?: string[]
/** If specified, only events where all of these labels were removed are returned */
removedLabels?: string[]
reportTypes?: string[]
cursor?: string
}

Expand Down
2 changes: 2 additions & 0 deletions packages/bsky/tests/auto-moderator/labeler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ describe('labeler', () => {
subject: uri.toString(),
limit: 10,
types: [],
addedLabels: [],
removedLabels: [],
})
expect(events.length).toBe(1)
expect(events[0]).toMatchObject({
Expand Down
14 changes: 14 additions & 0 deletions packages/ozone/src/api/admin/queryModerationEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ export default function (server: Server, ctx: AppContext) {
sortDirection = 'desc',
types,
includeAllUserRecords = false,
hasComment,
comment,
createdBy,
createdAfter,
createdBefore,
addedLabels = [],
removedLabels = [],
reportTypes,
} = params
const db = ctx.db
const modService = ctx.modService(db)
Expand All @@ -25,6 +32,13 @@ export default function (server: Server, ctx: AppContext) {
cursor,
sortDirection,
includeAllUserRecords,
hasComment,
comment,
createdAfter,
createdBefore,
addedLabels,
removedLabels,
reportTypes,
})
return {
encoding: 'application/json',
Expand Down
1 change: 1 addition & 0 deletions packages/ozone/src/api/moderation/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ const eventTypes = new Set([
'com.atproto.admin.defs#modEventUnmute',
'com.atproto.admin.defs#modEventReverseTakedown',
'com.atproto.admin.defs#modEventEmail',
'com.atproto.admin.defs#modEventResolveAppeal',
])
Loading
Loading