Skip to content

Commit

Permalink
✨ Expose emailConfirmedAt field from admin getRepo (#1757)
Browse files Browse the repository at this point in the history
* ✨ Expose emailConfirmedAt field from admin getRepo

* ♻️ Fix typing for repo result

* 🧹 Cleanup unnecessary import

* ✨ Adapt to the new pds based get account info method

* 🧹 Cleanup unused pds util
  • Loading branch information
foysalit authored Nov 7, 2023
1 parent bebc4ba commit 697f5d3
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 18 deletions.
4 changes: 3 additions & 1 deletion lexicons/com/atproto/admin/defs.json
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@
}
},
"invitesDisabled": { "type": "boolean" },
"inviteNote": { "type": "string" }
"inviteNote": { "type": "string" },
"emailConfirmedAt": { "type": "string", "format": "datetime" }
}
},
"accountView": {
Expand All @@ -271,6 +272,7 @@
}
},
"invitesDisabled": { "type": "boolean" },
"emailConfirmedAt": { "type": "string", "format": "datetime" },
"inviteNote": { "type": "string" }
}
},
Expand Down
8 changes: 8 additions & 0 deletions packages/api/src/client/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,10 @@ export const schemaDict = {
inviteNote: {
type: 'string',
},
emailConfirmedAt: {
type: 'string',
format: 'datetime',
},
},
},
accountView: {
Expand Down Expand Up @@ -469,6 +473,10 @@ export const schemaDict = {
invitesDisabled: {
type: 'boolean',
},
emailConfirmedAt: {
type: 'string',
format: 'datetime',
},
inviteNote: {
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 @@ -241,6 +241,7 @@ export interface RepoViewDetail {
invites?: ComAtprotoServerDefs.InviteCode[]
invitesDisabled?: boolean
inviteNote?: string
emailConfirmedAt?: string
[k: string]: unknown
}

Expand All @@ -264,6 +265,7 @@ export interface AccountView {
invitedBy?: ComAtprotoServerDefs.InviteCode
invites?: ComAtprotoServerDefs.InviteCode[]
invitesDisabled?: boolean
emailConfirmedAt?: string
inviteNote?: string
[k: string]: unknown
}
Expand Down
1 change: 1 addition & 0 deletions packages/bsky/src/api/com/atproto/admin/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const addAccountInfoToRepoViewDetail = (
invitesDisabled: accountInfo.invitesDisabled,
inviteNote: accountInfo.inviteNote,
invites: accountInfo.invites,
emailConfirmedAt: accountInfo.emailConfirmedAt,
}
}

Expand Down
8 changes: 8 additions & 0 deletions packages/bsky/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,10 @@ export const schemaDict = {
inviteNote: {
type: 'string',
},
emailConfirmedAt: {
type: 'string',
format: 'datetime',
},
},
},
accountView: {
Expand Down Expand Up @@ -469,6 +473,10 @@ export const schemaDict = {
invitesDisabled: {
type: 'boolean',
},
emailConfirmedAt: {
type: 'string',
format: 'datetime',
},
inviteNote: {
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 @@ -241,6 +241,7 @@ export interface RepoViewDetail {
invites?: ComAtprotoServerDefs.InviteCode[]
invitesDisabled?: boolean
inviteNote?: string
emailConfirmedAt?: string
[k: string]: unknown
}

Expand All @@ -264,6 +265,7 @@ export interface AccountView {
invitedBy?: ComAtprotoServerDefs.InviteCode
invites?: ComAtprotoServerDefs.InviteCode[]
invitesDisabled?: boolean
emailConfirmedAt?: string
inviteNote?: string
[k: string]: unknown
}
Expand Down
33 changes: 33 additions & 0 deletions packages/bsky/tests/admin/get-repo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,39 @@ describe('admin get repo view', () => {
expect(triage).toEqual({ ...admin, email: undefined })
})

it('includes emailConfirmedAt timestamp', async () => {
const { data: beforeEmailVerification } =
await agent.api.com.atproto.admin.getRepo(
{ did: sc.dids.bob },
{ headers: network.pds.adminAuthHeaders() },
)

expect(beforeEmailVerification.emailConfirmedAt).toBeUndefined()
const timestampBeforeVerification = Date.now()
const bobsAccount = sc.accounts[sc.dids.bob]
const verificationToken = await network.pds.ctx.services
.account(network.pds.ctx.db)
.createEmailToken(sc.dids.bob, 'confirm_email')
await agent.api.com.atproto.server.confirmEmail(
{ email: bobsAccount.email, token: verificationToken },
{
encoding: 'application/json',

headers: sc.getHeaders(sc.dids.bob),
},
)
const { data: afterEmailVerification } =
await agent.api.com.atproto.admin.getRepo(
{ did: sc.dids.bob },
{ headers: network.pds.adminAuthHeaders() },
)

expect(afterEmailVerification.emailConfirmedAt).toBeTruthy()
expect(
new Date(afterEmailVerification.emailConfirmedAt as string).getTime(),
).toBeGreaterThan(timestampBeforeVerification)
})

it('fails when repo does not exist.', async () => {
const promise = agent.api.com.atproto.admin.getRepo(
{ did: 'did:plc:doesnotexist' },
Expand Down
17 changes: 0 additions & 17 deletions packages/pds/src/api/com/atproto/admin/util.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import express from 'express'
import {
RepoView,
RepoViewDetail,
} from '../../../../lexicon/types/com/atproto/admin/defs'

// Output designed to passed as second arg to AtpAgent methods.
// The encoding field here is a quirk of the AtpAgent.
Expand All @@ -26,16 +22,3 @@ export function authPassthru(req: express.Request, withEncoding?: boolean) {
}
}
}

// @NOTE mutates.
// merges-in details that the pds knows about the repo.
export function mergeRepoViewPdsDetails<T extends RepoView | RepoViewDetail>(
other: T,
pds: T,
) {
other.email ??= pds.email
other.invites ??= pds.invites
other.invitedBy ??= pds.invitedBy
other.invitesDisabled ??= pds.invitesDisabled
return other
}
8 changes: 8 additions & 0 deletions packages/pds/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,10 @@ export const schemaDict = {
inviteNote: {
type: 'string',
},
emailConfirmedAt: {
type: 'string',
format: 'datetime',
},
},
},
accountView: {
Expand Down Expand Up @@ -469,6 +473,10 @@ export const schemaDict = {
invitesDisabled: {
type: 'boolean',
},
emailConfirmedAt: {
type: 'string',
format: 'datetime',
},
inviteNote: {
type: 'string',
},
Expand Down
2 changes: 2 additions & 0 deletions packages/pds/src/lexicon/types/com/atproto/admin/defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ export interface RepoViewDetail {
invites?: ComAtprotoServerDefs.InviteCode[]
invitesDisabled?: boolean
inviteNote?: string
emailConfirmedAt?: string
[k: string]: unknown
}

Expand All @@ -264,6 +265,7 @@ export interface AccountView {
invitedBy?: ComAtprotoServerDefs.InviteCode
invites?: ComAtprotoServerDefs.InviteCode[]
invitesDisabled?: boolean
emailConfirmedAt?: string
inviteNote?: string
[k: string]: unknown
}
Expand Down
2 changes: 2 additions & 0 deletions packages/pds/src/services/account/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ export class AccountService {
'did_handle.did',
'did_handle.handle',
'user_account.email',
'user_account.emailConfirmedAt',
'user_account.invitesDisabled',
'user_account.inviteNote',
'user_account.createdAt as indexedAt',
Expand All @@ -405,6 +406,7 @@ export class AccountService {
handle: account?.handle ?? INVALID_HANDLE,
invitesDisabled: account.invitesDisabled === 1,
inviteNote: account.inviteNote ?? undefined,
emailConfirmedAt: account.emailConfirmedAt ?? undefined,
invites,
invitedBy: invitedBy[did],
}
Expand Down

0 comments on commit 697f5d3

Please sign in to comment.