Skip to content

Commit

Permalink
✨ Add a priority score value for ozone subjects (#3495)
Browse files Browse the repository at this point in the history
* ✨ Add a priority score value for ozone subjects

* 🚨 Bring back lock file

* ✅ Update snapshot for pds proxied tests

* ✅ Update takedown appeal snapshot

* ✅ Update takedown appeal snapshot

* ✅ Update repo and record snapshots

* :rotating_lights: Fix lint issue

* ✅ Update moderation events snapshot

* ✅ Update moderation statuses snapshot

* 🧹 Cleanup unnecessary durationInHours field

* ✨ Allow filtering by priority score

* ✨ Add test for priorityScore filter

* 🚨 Fix import order

* ✨ Allow 0 priority score filter

* 📝 Add changeset
  • Loading branch information
foysalit authored Feb 6, 2025
1 parent 526bcf8 commit 709a85b
Show file tree
Hide file tree
Showing 35 changed files with 419 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .changeset/fifty-seals-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@atproto/ozone": patch
"@atproto/api": patch
"@atproto/pds": patch
---

Add a priority score to ozone subjects
27 changes: 25 additions & 2 deletions lexicons/tools/ozone/moderation/defs.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"#modEventTag",
"#accountEvent",
"#identityEvent",
"#recordEvent"
"#recordEvent",
"#modEventPriorityScore"
]
},
"subject": {
Expand Down Expand Up @@ -84,7 +85,8 @@
"#modEventTag",
"#accountEvent",
"#identityEvent",
"#recordEvent"
"#recordEvent",
"#modEventPriorityScore"
]
},
"subject": {
Expand Down Expand Up @@ -143,6 +145,12 @@
"type": "string",
"description": "Sticky comment on the subject."
},
"priorityScore": {
"type": "integer",
"description": "Numeric value representing the level of priority. Higher score means higher priority.",
"minimum": 0,
"maximum": 100
},
"muteUntil": {
"type": "string",
"format": "datetime"
Expand Down Expand Up @@ -381,6 +389,21 @@
}
}
},
"modEventPriorityScore": {
"type": "object",
"description": "Set priority score of the subject. Higher score means higher priority.",
"required": ["score"],
"properties": {
"comment": {
"type": "string"
},
"score": {
"type": "integer",
"minimum": 0,
"maximum": 100
}
}
},
"modEventAcknowledge": {
"type": "object",
"properties": {
Expand Down
3 changes: 2 additions & 1 deletion lexicons/tools/ozone/moderation/emitEvent.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"tools.ozone.moderation.defs#modEventTag",
"tools.ozone.moderation.defs#accountEvent",
"tools.ozone.moderation.defs#identityEvent",
"tools.ozone.moderation.defs#recordEvent"
"tools.ozone.moderation.defs#recordEvent",
"tools.ozone.moderation.defs#modEventPriorityScore"
]
},
"subject": {
Expand Down
9 changes: 8 additions & 1 deletion lexicons/tools/ozone/moderation/queryStatuses.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@
"lastReviewedAt",
"lastReportedAt",
"reportedRecordsCount",
"takendownRecordsCount"
"takendownRecordsCount",
"priorityScore"
]
},
"sortDirection": {
Expand Down Expand Up @@ -175,6 +176,12 @@
"minTakendownRecordsCount": {
"type": "integer",
"description": "If specified, only subjects that belong to an account that has at least this many taken down records will be returned."
},
"minPriorityScore": {
"minimum": 0,
"maximum": 100,
"type": "integer",
"description": "If specified, only subjects that have priority score value above the given value will be returned."
}
}
},
Expand Down
34 changes: 34 additions & 0 deletions packages/api/src/client/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11192,6 +11192,7 @@ export const schemaDict = {
'lex:tools.ozone.moderation.defs#accountEvent',
'lex:tools.ozone.moderation.defs#identityEvent',
'lex:tools.ozone.moderation.defs#recordEvent',
'lex:tools.ozone.moderation.defs#modEventPriorityScore',
],
},
subject: {
Expand Down Expand Up @@ -11259,6 +11260,7 @@ export const schemaDict = {
'lex:tools.ozone.moderation.defs#accountEvent',
'lex:tools.ozone.moderation.defs#identityEvent',
'lex:tools.ozone.moderation.defs#recordEvent',
'lex:tools.ozone.moderation.defs#modEventPriorityScore',
],
},
subject: {
Expand Down Expand Up @@ -11338,6 +11340,13 @@ export const schemaDict = {
type: 'string',
description: 'Sticky comment on the subject.',
},
priorityScore: {
type: 'integer',
description:
'Numeric value representing the level of priority. Higher score means higher priority.',
minimum: 0,
maximum: 100,
},
muteUntil: {
type: 'string',
format: 'datetime',
Expand Down Expand Up @@ -11600,6 +11609,22 @@ export const schemaDict = {
},
},
},
modEventPriorityScore: {
type: 'object',
description:
'Set priority score of the subject. Higher score means higher priority.',
required: ['score'],
properties: {
comment: {
type: 'string',
},
score: {
type: 'integer',
minimum: 0,
maximum: 100,
},
},
},
modEventAcknowledge: {
type: 'object',
properties: {
Expand Down Expand Up @@ -12223,6 +12248,7 @@ export const schemaDict = {
'lex:tools.ozone.moderation.defs#accountEvent',
'lex:tools.ozone.moderation.defs#identityEvent',
'lex:tools.ozone.moderation.defs#recordEvent',
'lex:tools.ozone.moderation.defs#modEventPriorityScore',
],
},
subject: {
Expand Down Expand Up @@ -12719,6 +12745,7 @@ export const schemaDict = {
'lastReportedAt',
'reportedRecordsCount',
'takendownRecordsCount',
'priorityScore',
],
},
sortDirection: {
Expand Down Expand Up @@ -12789,6 +12816,13 @@ export const schemaDict = {
description:
'If specified, only subjects that belong to an account that has at least this many taken down records will be returned.',
},
minPriorityScore: {
minimum: 0,
maximum: 100,
type: 'integer',
description:
'If specified, only subjects that have priority score value above the given value will be returned.',
},
},
},
output: {
Expand Down
28 changes: 28 additions & 0 deletions packages/api/src/client/types/tools/ozone/moderation/defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface ModEventView {
| AccountEvent
| IdentityEvent
| RecordEvent
| ModEventPriorityScore
| { $type: string; [k: string]: unknown }
subject:
| ComAtprotoAdminDefs.RepoRef
Expand Down Expand Up @@ -80,6 +81,7 @@ export interface ModEventViewDetail {
| AccountEvent
| IdentityEvent
| RecordEvent
| ModEventPriorityScore
| { $type: string; [k: string]: unknown }
subject:
| RepoView
Expand Down Expand Up @@ -124,6 +126,8 @@ export interface SubjectStatusView {
reviewState: SubjectReviewState
/** Sticky comment on the subject. */
comment?: string
/** Numeric value representing the level of priority. Higher score means higher priority. */
priorityScore?: number
muteUntil?: string
muteReportingUntil?: string
lastReviewedBy?: string
Expand Down Expand Up @@ -364,6 +368,30 @@ export function validateModEventLabel(v: unknown): ValidationResult {
return lexicons.validate('tools.ozone.moderation.defs#modEventLabel', v)
}

/** Set priority score of the subject. Higher score means higher priority. */
export interface ModEventPriorityScore {
comment?: string
score: number
[k: string]: unknown
}

export function isModEventPriorityScore(
v: unknown,
): v is ModEventPriorityScore {
return (
isObj(v) &&
hasProp(v, '$type') &&
v.$type === 'tools.ozone.moderation.defs#modEventPriorityScore'
)
}

export function validateModEventPriorityScore(v: unknown): ValidationResult {
return lexicons.validate(
'tools.ozone.moderation.defs#modEventPriorityScore',
v,
)
}

export interface ModEventAcknowledge {
comment?: string
/** If true, all other reports on content authored by this account will be resolved (acknowledged). */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface InputSchema {
| ToolsOzoneModerationDefs.AccountEvent
| ToolsOzoneModerationDefs.IdentityEvent
| ToolsOzoneModerationDefs.RecordEvent
| ToolsOzoneModerationDefs.ModEventPriorityScore
| { $type: string; [k: string]: unknown }
subject:
| ComAtprotoAdminDefs.RepoRef
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export interface QueryParams {
| 'lastReportedAt'
| 'reportedRecordsCount'
| 'takendownRecordsCount'
| 'priorityScore'
sortDirection?: 'asc' | 'desc'
/** Get subjects that were taken down */
takendown?: boolean
Expand All @@ -72,6 +73,8 @@ export interface QueryParams {
minReportedRecordsCount?: number
/** If specified, only subjects that belong to an account that has at least this many taken down records will be returned. */
minTakendownRecordsCount?: number
/** If specified, only subjects that have priority score value above the given value will be returned. */
minPriorityScore?: number
}

export type InputSchema = undefined
Expand Down
1 change: 1 addition & 0 deletions packages/ozone/src/api/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ const eventTypes = new Set([
'tools.ozone.moderation.defs#accountEvent',
'tools.ozone.moderation.defs#identityEvent',
'tools.ozone.moderation.defs#recordEvent',
'tools.ozone.moderation.defs#modEventPriorityScore',
])

export const getMemberRole = (role: string) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Kysely } from 'kysely'

export async function up(db: Kysely<unknown>): Promise<void> {
await db.schema
.alterTable('moderation_subject_status')
.addColumn('priorityScore', 'integer', (col) =>
col.notNull().defaultTo('0'),
)
.execute()
await db.schema
.createIndex('moderation_subject_status_priority_score_index')
.on('moderation_subject_status')
.column('priorityScore')
.execute()
}

export async function down(db: Kysely<unknown>): Promise<void> {
await db.schema
.alterTable('moderation_subject_status')
.dropColumn('priorityScore')
.execute()
}
1 change: 1 addition & 0 deletions packages/ozone/src/db/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ export * as _20241008T205730722Z from './20241008T205730722Z-sets'
export * as _20241018T205730722Z from './20241018T205730722Z-setting'
export * as _20241026T205730722Z from './20241026T205730722Z-add-hosting-status-to-subject-status'
export * as _20241220T144630860Z from './20241220T144630860Z-stats-materialized-views'
export * as _20250204T003647759Z from './20250204T003647759Z-add-subject-priority-score'
3 changes: 2 additions & 1 deletion packages/ozone/src/db/schema/moderation_event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface ModerationEvent {
| 'tools.ozone.moderation.defs#accountEvent'
| 'tools.ozone.moderation.defs#identityEvent'
| 'tools.ozone.moderation.defs#recordEvent'
| 'tools.ozone.moderation.defs#modEventPriorityScore'
subjectType:
| 'com.atproto.admin.defs#repoRef'
| 'com.atproto.repo.strongRef'
Expand All @@ -38,7 +39,7 @@ export interface ModerationEvent {
createdBy: string
durationInHours: number | null
expiresAt: string | null
meta: Record<string, string | boolean> | null
meta: Record<string, string | boolean | number> | null
addedTags: string[] | null
removedTags: string[] | null
legacyRefId: number | null
Expand Down
1 change: 1 addition & 0 deletions packages/ozone/src/db/schema/moderation_subject_status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface ModerationSubjectStatus {
appealed: boolean | null
comment: string | null
tags: string[] | null
priorityScore?: number
}

export type PartialDB = {
Expand Down
Loading

0 comments on commit 709a85b

Please sign in to comment.