Skip to content

Commit

Permalink
Allow filtering moderation queue by language (#2161)
Browse files Browse the repository at this point in the history
* ✨ Store languages on subjects from record data

* ✨ Fetch lang from author feed for repo subject

* ✨ Regenerate lex

* ✨ Add lang to profile subject

* ✨ Move lang to flag

* ✨ Add comment to flag event

* ✅ Update pds test snapshot

* 🐛 Fix broken import

* ✨ Rename flag to tag

* ✅ Update snapshot for event by id

* ✅ Bring back skipped test

* ✨ Move tags to dedicated columns

* ✅ Update test snapshots, use logger

* ✨ Change lang:unknown to lang:und

* ✅ Update test snapshots

* 🧹 Cleanup

* ✨ Add filter params for tags on queryModerationEvents endpoint

* ✨ Add tags property to subject status model

* ✅ Update test code

* ✨ Add filter to get subjects that do not have certain tags
  • Loading branch information
foysalit authored Feb 19, 2024
1 parent 6e6b94b commit d815732
Show file tree
Hide file tree
Showing 52 changed files with 1,031 additions and 69 deletions.
25 changes: 25 additions & 0 deletions lexicons/com/atproto/admin/defs.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@
"suspendUntil": {
"type": "string",
"format": "datetime"
},
"tags": {
"type": "array",
"items": { "type": "string" }
}
}
},
Expand Down Expand Up @@ -587,6 +591,27 @@
}
}
},
"modEventTag": {
"type": "object",
"description": "Add/Remove a tag on a subject",
"required": ["add", "remove"],
"properties": {
"add": {
"type": "array",
"items": { "type": "string" },
"description": "Tags to be added to the subject. If already exists, won't be duplicated."
},
"remove": {
"type": "array",
"items": { "type": "string" },
"description": "Tags to be removed to the subject. Ignores a tag If it doesn't exist, won't be duplicated."
},
"comment": {
"type": "string",
"description": "Additional comment about added/removed tags."
}
}
},
"communicationTemplateView": {
"type": "object",
"required": [
Expand Down
3 changes: 2 additions & 1 deletion lexicons/com/atproto/admin/emitModerationEvent.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"com.atproto.admin.defs#modEventMute",
"com.atproto.admin.defs#modEventReverseTakedown",
"com.atproto.admin.defs#modEventUnmute",
"com.atproto.admin.defs#modEventEmail"
"com.atproto.admin.defs#modEventEmail",
"com.atproto.admin.defs#modEventTag"
]
},
"subject": {
Expand Down
10 changes: 10 additions & 0 deletions lexicons/com/atproto/admin/queryModerationEvents.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@
"items": { "type": "string" },
"description": "If specified, only events where all of these labels were removed are returned"
},
"addedTags": {
"type": "array",
"items": { "type": "string" },
"description": "If specified, only events where all of these tags were added are returned"
},
"removedTags": {
"type": "array",
"items": { "type": "string" },
"description": "If specified, only events where all of these tags were removed are returned"
},
"reportTypes": {
"type": "array",
"items": {
Expand Down
8 changes: 8 additions & 0 deletions lexicons/com/atproto/admin/queryModerationStatuses.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@
"maximum": 100,
"default": 50
},
"tags": {
"type": "array",
"items": { "type": "string" }
},
"excludeTags": {
"type": "array",
"items": { "type": "string" }
},
"cursor": { "type": "string" }
}
},
Expand Down
62 changes: 62 additions & 0 deletions packages/api/src/client/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,12 @@ export const schemaDict = {
type: 'string',
format: 'datetime',
},
tags: {
type: 'array',
items: {
type: 'string',
},
},
},
},
reportViewDetail: {
Expand Down Expand Up @@ -897,6 +903,33 @@ export const schemaDict = {
},
},
},
modEventTag: {
type: 'object',
description: 'Add/Remove a tag on a subject',
required: ['add', 'remove'],
properties: {
add: {
type: 'array',
items: {
type: 'string',
},
description:
"Tags to be added to the subject. If already exists, won't be duplicated.",
},
remove: {
type: 'array',
items: {
type: 'string',
},
description:
"Tags to be removed to the subject. Ignores a tag If it doesn't exist, won't be duplicated.",
},
comment: {
type: 'string',
description: 'Additional comment about added/removed tags.',
},
},
},
communicationTemplateView: {
type: 'object',
required: [
Expand Down Expand Up @@ -1075,6 +1108,7 @@ export const schemaDict = {
'lex:com.atproto.admin.defs#modEventReverseTakedown',
'lex:com.atproto.admin.defs#modEventUnmute',
'lex:com.atproto.admin.defs#modEventEmail',
'lex:com.atproto.admin.defs#modEventTag',
],
},
subject: {
Expand Down Expand Up @@ -1503,6 +1537,22 @@ export const schemaDict = {
description:
'If specified, only events where all of these labels were removed are returned',
},
addedTags: {
type: 'array',
items: {
type: 'string',
},
description:
'If specified, only events where all of these tags were added are returned',
},
removedTags: {
type: 'array',
items: {
type: 'string',
},
description:
'If specified, only events where all of these tags were removed are returned',
},
reportTypes: {
type: 'array',
items: {
Expand Down Expand Up @@ -1620,6 +1670,18 @@ export const schemaDict = {
maximum: 100,
default: 50,
},
tags: {
type: 'array',
items: {
type: 'string',
},
},
excludeTags: {
type: 'array',
items: {
type: 'string',
},
},
cursor: {
type: 'string',
},
Expand Down
24 changes: 24 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 @@ -156,6 +156,7 @@ export interface SubjectStatusView {
/** 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. */
appealed?: boolean
suspendUntil?: string
tags?: string[]
[k: string]: unknown
}

Expand Down Expand Up @@ -720,6 +721,29 @@ export function validateModEventEmail(v: unknown): ValidationResult {
return lexicons.validate('com.atproto.admin.defs#modEventEmail', v)
}

/** Add/Remove a tag on a subject */
export interface ModEventTag {
/** Tags to be added to the subject. If already exists, won't be duplicated. */
add: string[]
/** Tags to be removed to the subject. Ignores a tag If it doesn't exist, won't be duplicated. */
remove: string[]
/** Additional comment about added/removed tags. */
comment?: string
[k: string]: unknown
}

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

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

export interface CommunicationTemplateView {
id: string
/** Name of the template. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface InputSchema {
| ComAtprotoAdminDefs.ModEventReverseTakedown
| ComAtprotoAdminDefs.ModEventUnmute
| ComAtprotoAdminDefs.ModEventEmail
| ComAtprotoAdminDefs.ModEventTag
| { $type: string; [k: string]: unknown }
subject:
| ComAtprotoAdminDefs.RepoRef
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export interface QueryParams {
addedLabels?: string[]
/** If specified, only events where all of these labels were removed are returned */
removedLabels?: string[]
/** If specified, only events where all of these tags were added are returned */
addedTags?: string[]
/** If specified, only events where all of these tags were removed are returned */
removedTags?: string[]
reportTypes?: string[]
cursor?: string
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export interface QueryParams {
/** Get subjects in unresolved appealed status */
appealed?: boolean
limit?: number
tags?: string[]
excludeTags?: string[]
cursor?: string
}

Expand Down
62 changes: 62 additions & 0 deletions packages/bsky/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,12 @@ export const schemaDict = {
type: 'string',
format: 'datetime',
},
tags: {
type: 'array',
items: {
type: 'string',
},
},
},
},
reportViewDetail: {
Expand Down Expand Up @@ -897,6 +903,33 @@ export const schemaDict = {
},
},
},
modEventTag: {
type: 'object',
description: 'Add/Remove a tag on a subject',
required: ['add', 'remove'],
properties: {
add: {
type: 'array',
items: {
type: 'string',
},
description:
"Tags to be added to the subject. If already exists, won't be duplicated.",
},
remove: {
type: 'array',
items: {
type: 'string',
},
description:
"Tags to be removed to the subject. Ignores a tag If it doesn't exist, won't be duplicated.",
},
comment: {
type: 'string',
description: 'Additional comment about added/removed tags.',
},
},
},
communicationTemplateView: {
type: 'object',
required: [
Expand Down Expand Up @@ -1075,6 +1108,7 @@ export const schemaDict = {
'lex:com.atproto.admin.defs#modEventReverseTakedown',
'lex:com.atproto.admin.defs#modEventUnmute',
'lex:com.atproto.admin.defs#modEventEmail',
'lex:com.atproto.admin.defs#modEventTag',
],
},
subject: {
Expand Down Expand Up @@ -1503,6 +1537,22 @@ export const schemaDict = {
description:
'If specified, only events where all of these labels were removed are returned',
},
addedTags: {
type: 'array',
items: {
type: 'string',
},
description:
'If specified, only events where all of these tags were added are returned',
},
removedTags: {
type: 'array',
items: {
type: 'string',
},
description:
'If specified, only events where all of these tags were removed are returned',
},
reportTypes: {
type: 'array',
items: {
Expand Down Expand Up @@ -1620,6 +1670,18 @@ export const schemaDict = {
maximum: 100,
default: 50,
},
tags: {
type: 'array',
items: {
type: 'string',
},
},
excludeTags: {
type: 'array',
items: {
type: 'string',
},
},
cursor: {
type: 'string',
},
Expand Down
24 changes: 24 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 @@ -156,6 +156,7 @@ export interface SubjectStatusView {
/** 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. */
appealed?: boolean
suspendUntil?: string
tags?: string[]
[k: string]: unknown
}

Expand Down Expand Up @@ -720,6 +721,29 @@ export function validateModEventEmail(v: unknown): ValidationResult {
return lexicons.validate('com.atproto.admin.defs#modEventEmail', v)
}

/** Add/Remove a tag on a subject */
export interface ModEventTag {
/** Tags to be added to the subject. If already exists, won't be duplicated. */
add: string[]
/** Tags to be removed to the subject. Ignores a tag If it doesn't exist, won't be duplicated. */
remove: string[]
/** Additional comment about added/removed tags. */
comment?: string
[k: string]: unknown
}

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

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

export interface CommunicationTemplateView {
id: string
/** Name of the template. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface InputSchema {
| ComAtprotoAdminDefs.ModEventReverseTakedown
| ComAtprotoAdminDefs.ModEventUnmute
| ComAtprotoAdminDefs.ModEventEmail
| ComAtprotoAdminDefs.ModEventTag
| { $type: string; [k: string]: unknown }
subject:
| ComAtprotoAdminDefs.RepoRef
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export interface QueryParams {
addedLabels?: string[]
/** If specified, only events where all of these labels were removed are returned */
removedLabels?: string[]
/** If specified, only events where all of these tags were added are returned */
addedTags?: string[]
/** If specified, only events where all of these tags were removed are returned */
removedTags?: string[]
reportTypes?: string[]
cursor?: string
}
Expand Down
Loading

0 comments on commit d815732

Please sign in to comment.