Skip to content

Commit

Permalink
✨ Allow filtering ozone team list by role and status (#3554)
Browse files Browse the repository at this point in the history
* ✨ Allow filtering ozone team list by role and status

* fix style

* changeset

---------

Co-authored-by: Matthieu Sieben <[email protected]>
  • Loading branch information
foysalit and matthieusieben authored Feb 19, 2025
1 parent 7b93618 commit 7449f86
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 366 deletions.
5 changes: 5 additions & 0 deletions .changeset/lucky-comics-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/ozone": patch
---

Allow filtering Ozone members based on role and status
17 changes: 15 additions & 2 deletions lexicons/tools/ozone/team/listMembers.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,24 @@
"parameters": {
"type": "params",
"properties": {
"disabled": {
"type": "boolean"
},
"roles": {
"type": "array",
"items": {
"type": "string"
}
},
"limit": {
"type": "integer",
"minimum": 1,
"maximum": 100,
"default": 50
},
"cursor": { "type": "string" }
"cursor": {
"type": "string"
}
}
},
"output": {
Expand All @@ -23,7 +34,9 @@
"type": "object",
"required": ["members"],
"properties": {
"cursor": { "type": "string" },
"cursor": {
"type": "string"
},
"members": {
"type": "array",
"items": {
Expand Down
9 changes: 9 additions & 0 deletions packages/api/src/client/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13953,6 +13953,15 @@ export const schemaDict = {
parameters: {
type: 'params',
properties: {
disabled: {
type: 'boolean',
},
roles: {
type: 'array',
items: {
type: 'string',
},
},
limit: {
type: 'integer',
minimum: 1,
Expand Down
2 changes: 2 additions & 0 deletions packages/api/src/client/types/tools/ozone/team/listMembers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const is$typed = _is$typed,
const id = 'tools.ozone.team.listMembers'

export interface QueryParams {
disabled?: boolean
roles?: string[]
limit?: number
cursor?: string
}
Expand Down
9 changes: 9 additions & 0 deletions packages/ozone/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13953,6 +13953,15 @@ export const schemaDict = {
parameters: {
type: 'params',
properties: {
disabled: {
type: 'boolean',
},
roles: {
type: 'array',
items: {
type: 'string',
},
},
limit: {
type: 'integer',
minimum: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const is$typed = _is$typed,
const id = 'tools.ozone.team.listMembers'

export interface QueryParams {
disabled?: boolean
roles?: string[]
limit: number
cursor?: string
}
Expand Down
20 changes: 20 additions & 0 deletions packages/ozone/src/team/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,34 @@ export class TeamService {
async list({
cursor,
limit = 25,
roles,
disabled,
}: {
cursor?: string
limit?: number
disabled?: boolean
roles?: string[]
}): Promise<{ members: Selectable<Member>[]; cursor?: string }> {
let builder = this.db.db.selectFrom('member').selectAll()
if (cursor) {
builder = builder.where('createdAt', '>', new Date(cursor))
}
if (roles !== undefined) {
const knownRoles = roles.filter(
(r) =>
r === 'tools.ozone.team.defs#roleAdmin' ||
r === 'tools.ozone.team.defs#roleModerator' ||
r === 'tools.ozone.team.defs#roleTriage',
)

// Optimization: no need to query to know that no values will be returned
if (!knownRoles.length) return { members: [] }

builder = builder.where('role', 'in', knownRoles)
}
if (disabled !== undefined) {
builder = builder.where('disabled', disabled ? 'is' : 'is not', true)
}
const members = await builder
.limit(limit)
.orderBy('createdAt', 'asc')
Expand Down
Loading

0 comments on commit 7449f86

Please sign in to comment.