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 team member handle and displayName #3587

Merged
merged 7 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/proud-steaks-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@atproto/dev-env": patch
"@atproto/ozone": patch
"@atproto/api": patch
"@atproto/pds": patch
---

Add searchable handle and displayName to ozone team members
3 changes: 3 additions & 0 deletions lexicons/tools/ozone/team/listMembers.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"parameters": {
"type": "params",
"properties": {
"q": {
"type": "string"
},
"disabled": {
"type": "boolean"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/api/src/client/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14365,6 +14365,9 @@ export const schemaDict = {
parameters: {
type: 'params',
properties: {
q: {
type: 'string',
},
disabled: {
type: 'boolean',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const is$typed = _is$typed,
const id = 'tools.ozone.team.listMembers'

export interface QueryParams {
q?: string
disabled?: boolean
roles?: string[]
limit?: number
Expand Down
6 changes: 6 additions & 0 deletions packages/dev-env/src/ozone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ export class TestOzone {
await this.ctx.teamService(this.ctx.db).create({
did,
disabled: false,
handle: null,
displayName: null,
lastUpdatedBy: this.ctx.cfg.service.did,
role: 'tools.ozone.team.defs#roleAdmin',
})
Expand All @@ -127,6 +129,8 @@ export class TestOzone {
await this.ctx.teamService(this.ctx.db).create({
did,
disabled: false,
handle: null,
displayName: null,
lastUpdatedBy: this.ctx.cfg.service.did,
role: 'tools.ozone.team.defs#roleModerator',
})
Expand All @@ -137,6 +141,8 @@ export class TestOzone {
await this.ctx.teamService(this.ctx.db).create({
did,
disabled: false,
handle: null,
displayName: null,
lastUpdatedBy: this.ctx.cfg.service.did,
role: 'tools.ozone.team.defs#roleTriage',
})
Expand Down
7 changes: 6 additions & 1 deletion packages/ozone/src/api/team/addMember.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,19 @@ export default function (server: Server, ctx: AppContext) {
)
}

const profiles = await teamService.getProfiles([did])
const profile = profiles.get(did)

const member = await teamService.create({
did,
handle: profile?.handle || null,
displayName: profile?.displayName || null,
disabled: false,
role: getMemberRole(role),
lastUpdatedBy:
access.type === 'admin_token' ? 'admin_token' : access.iss,
})
const memberView = await teamService.view([member], ctx)
const memberView = await teamService.view([member])
return memberView[0]
})

Expand Down
2 changes: 1 addition & 1 deletion packages/ozone/src/api/team/listMembers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function (server: Server, ctx: AppContext) {
encoding: 'application/json',
body: {
cursor,
members: await teamService.view(members, ctx),
members: await teamService.view(members),
},
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/ozone/src/api/team/updateMember.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function (server: Server, ctx: AppContext) {
lastUpdatedBy:
access.type === 'admin_token' ? 'admin_token' : access.iss,
})
const memberView = await teamService.view([updated], ctx)
const memberView = await teamService.view([updated])
return memberView[0]
})

Expand Down
2 changes: 2 additions & 0 deletions packages/ozone/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const envToCfg = (env: OzoneEnvironment): OzoneConfig => {
poolMaxUses: env.dbPoolMaxUses,
poolIdleTimeoutMs: env.dbPoolIdleTimeoutMs,
materializedViewRefreshIntervalMs: env.dbMaterializedViewRefreshIntervalMs,
teamProfileRefreshIntervalMs: env.dbTeamProfileRefreshIntervalMs,
}

assert(env.appviewUrl, 'appviewUrl is required')
Expand Down Expand Up @@ -124,6 +125,7 @@ export type DatabaseConfig = {
poolMaxUses?: number
poolIdleTimeoutMs?: number
materializedViewRefreshIntervalMs?: number
teamProfileRefreshIntervalMs?: number
}

export type AppviewConfig = {
Expand Down
4 changes: 4 additions & 0 deletions packages/ozone/src/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export const readEnv = (): OzoneEnvironment => {
dbMaterializedViewRefreshIntervalMs: envInt(
'OZONE_DB_MATERIALIZED_VIEW_REFRESH_INTERVAL_MS',
),
dbTeamProfileRefreshIntervalMs: envInt(
'OZONE_DB_TEAM_PROFILE_REFRESH_INTERVAL_MS',
),
didPlcUrl: envStr('OZONE_DID_PLC_URL'),
didCacheStaleTTL: envInt('OZONE_DID_CACHE_STALE_TTL'),
didCacheMaxTTL: envInt('OZONE_DID_CACHE_MAX_TTL'),
Expand Down Expand Up @@ -57,6 +60,7 @@ export type OzoneEnvironment = {
dbPoolMaxUses?: number
dbPoolIdleTimeoutMs?: number
dbMaterializedViewRefreshIntervalMs?: number
dbTeamProfileRefreshIntervalMs?: number
didPlcUrl?: string
didCacheStaleTTL?: number
didCacheMaxTTL?: number
Expand Down
6 changes: 5 additions & 1 deletion packages/ozone/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ export class AppContext {
)

const communicationTemplateService = CommunicationTemplateService.creator()
const teamService = TeamService.creator()
const teamService = TeamService.creator(
appviewAgent,
cfg.appview.did,
createAuthHeaders,
)
const setService = SetService.creator()
const settingService = SettingService.creator()

Expand Down
21 changes: 21 additions & 0 deletions packages/ozone/src/daemon/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import { BackgroundQueue } from '../background'
import { OzoneConfig, OzoneSecrets } from '../config'
import { Database } from '../db'
import { ModerationService } from '../mod-service'
import { TeamService } from '../team'
import { getSigningKeyId } from '../util'
import { EventPusher } from './event-pusher'
import { EventReverser } from './event-reverser'
import { MaterializedViewRefresher } from './materialized-view-refresher'
import { TeamProfileSynchronizer } from './team-profile-synchronizer'

export type DaemonContextOptions = {
db: Database
Expand All @@ -20,6 +22,7 @@ export type DaemonContextOptions = {
eventPusher: EventPusher
eventReverser: EventReverser
materializedViewRefresher: MaterializedViewRefresher
teamProfileSynchronizer: TeamProfileSynchronizer
}

export class DaemonContext {
Expand Down Expand Up @@ -67,6 +70,16 @@ export class DaemonContext {
appviewAgent,
createAuthHeaders,
)
const teamService = TeamService.creator(
appviewAgent,
cfg.appview.did,
createAuthHeaders,
)
const teamProfileSynchronizer = new TeamProfileSynchronizer(
backgroundQueue,
teamService(db),
cfg.db.teamProfileRefreshIntervalMs,
)

const eventReverser = new EventReverser(db, modService)

Expand All @@ -83,6 +96,7 @@ export class DaemonContext {
eventPusher,
eventReverser,
materializedViewRefresher,
teamProfileSynchronizer,
...(overrides ?? {}),
})
}
Expand Down Expand Up @@ -111,16 +125,22 @@ export class DaemonContext {
return this.opts.materializedViewRefresher
}

get teamProfileSynchronizer(): TeamProfileSynchronizer {
return this.opts.teamProfileSynchronizer
}

async start() {
this.eventPusher.start()
this.eventReverser.start()
this.materializedViewRefresher.start()
this.teamProfileSynchronizer.start()
}

async processAll() {
// Sequential because the materialized view values depend on the events.
await this.eventPusher.processAll()
await this.materializedViewRefresher.run()
await this.teamProfileSynchronizer.run()
}

async destroy() {
Expand All @@ -129,6 +149,7 @@ export class DaemonContext {
this.eventReverser.destroy(),
this.eventPusher.destroy(),
this.materializedViewRefresher.destroy(),
this.teamProfileSynchronizer.destroy(),
])
} finally {
await this.backgroundQueue.destroy()
Expand Down
15 changes: 15 additions & 0 deletions packages/ozone/src/daemon/team-profile-synchronizer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { HOUR } from '@atproto/common'
import { BackgroundQueue, PeriodicBackgroundTask } from '../background'
import { TeamService } from '../team'

export class TeamProfileSynchronizer extends PeriodicBackgroundTask {
constructor(
backgroundQueue: BackgroundQueue,
teamService: TeamService,
interval = 24 * HOUR,
) {
super(backgroundQueue, interval, async () => {
await teamService.syncMemberProfiles()
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Kysely } from 'kysely'

export async function up(db: Kysely<unknown>): Promise<void> {
await db.schema.alterTable('member').addColumn('handle', 'text').execute()
await db.schema
.alterTable('member')
.addColumn('displayName', 'text')
.execute()
}

export async function down(db: Kysely<unknown>): Promise<void> {
await db.schema.alterTable('member').dropColumn('handle').execute()
await db.schema.alterTable('member').dropColumn('displayName').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 @@ -21,3 +21,4 @@ export * as _20241220T144630860Z from './20241220T144630860Z-stats-materialized-
export * as _20250204T003647759Z from './20250204T003647759Z-add-subject-priority-score'
export * as _20250211T003647759Z from './20250211T003647759Z-add-reporter-stats-index'
export * as _20250211T132135150Z from './20250211T132135150Z-moderation-event-message-partial-idx'
export * as _20250221T132135150Z from './20250221T132135150Z-member-details'
2 changes: 2 additions & 0 deletions packages/ozone/src/db/schema/member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export interface Member {
| 'tools.ozone.team.defs#roleTriage'
| 'tools.ozone.team.defs#roleModerator'
disabled: Generated<boolean>
handle: string | null
displayName: string | null
createdAt: Date
updatedAt: Date
lastUpdatedBy: string
Expand Down
3 changes: 3 additions & 0 deletions packages/ozone/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14365,6 +14365,9 @@ export const schemaDict = {
parameters: {
type: 'params',
properties: {
q: {
type: 'string',
},
disabled: {
type: 'boolean',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const is$typed = _is$typed,
const id = 'tools.ozone.team.listMembers'

export interface QueryParams {
q?: string
disabled?: boolean
roles?: string[]
limit: number
Expand Down
Loading