forked from bluesky-social/atproto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add admin.updateAccountEamil (bluesky-social#812)
* -add admin capability to update account email * pr feedback
- Loading branch information
Showing
11 changed files
with
237 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"lexicon": 1, | ||
"id": "com.atproto.admin.updateAccountEmail", | ||
"defs": { | ||
"main": { | ||
"type": "procedure", | ||
"description": "Administrative action to update an account's email", | ||
"input": { | ||
"encoding": "application/json", | ||
"schema": { | ||
"type": "object", | ||
"required": ["account", "email"], | ||
"properties": { | ||
"account": { | ||
"type": "string", | ||
"format": "at-identifier", | ||
"description": "The handle or DID of the repo." | ||
}, | ||
"email": {"type": "string"} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
packages/api/src/client/types/com/atproto/admin/updateAccountEmail.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* GENERATED CODE - DO NOT MODIFY | ||
*/ | ||
import { Headers, XRPCError } from '@atproto/xrpc' | ||
import { ValidationResult, BlobRef } from '@atproto/lexicon' | ||
import { isObj, hasProp } from '../../../../util' | ||
import { lexicons } from '../../../../lexicons' | ||
import { CID } from 'multiformats/cid' | ||
|
||
export interface QueryParams {} | ||
|
||
export interface InputSchema { | ||
/** The handle or DID of the repo. */ | ||
account: string | ||
email: string | ||
[k: string]: unknown | ||
} | ||
|
||
export interface CallOptions { | ||
headers?: Headers | ||
qp?: QueryParams | ||
encoding: 'application/json' | ||
} | ||
|
||
export interface Response { | ||
success: boolean | ||
headers: Headers | ||
} | ||
|
||
export function toKnownErr(e: any) { | ||
if (e instanceof XRPCError) { | ||
} | ||
return e | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/pds/src/api/com/atproto/admin/updateAccountEmail.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { InvalidRequestError } from '@atproto/xrpc-server' | ||
import { Server } from '../../../../lexicon' | ||
import AppContext from '../../../../context' | ||
|
||
export default function (server: Server, ctx: AppContext) { | ||
server.com.atproto.admin.updateAccountEmail({ | ||
auth: ctx.adminVerifier, | ||
handler: async ({ input }) => { | ||
await ctx.db.transaction(async (dbTxn) => { | ||
const accntService = ctx.services.account(dbTxn) | ||
const account = await accntService.getAccount(input.body.account) | ||
if (!account) { | ||
throw new InvalidRequestError( | ||
`Account does not exist: ${input.body.account}`, | ||
) | ||
} | ||
await accntService.updateEmail(account.did, input.body.email) | ||
}) | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/pds/src/lexicon/types/com/atproto/admin/updateAccountEmail.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* GENERATED CODE - DO NOT MODIFY | ||
*/ | ||
import express from 'express' | ||
import { ValidationResult, BlobRef } from '@atproto/lexicon' | ||
import { lexicons } from '../../../../lexicons' | ||
import { isObj, hasProp } from '../../../../util' | ||
import { CID } from 'multiformats/cid' | ||
import { HandlerAuth } from '@atproto/xrpc-server' | ||
|
||
export interface QueryParams {} | ||
|
||
export interface InputSchema { | ||
/** The handle or DID of the repo. */ | ||
account: string | ||
email: string | ||
[k: string]: unknown | ||
} | ||
|
||
export interface HandlerInput { | ||
encoding: 'application/json' | ||
body: InputSchema | ||
} | ||
|
||
export interface HandlerError { | ||
status: number | ||
message?: string | ||
} | ||
|
||
export type HandlerOutput = HandlerError | void | ||
export type Handler<HA extends HandlerAuth = never> = (ctx: { | ||
auth: HA | ||
params: QueryParams | ||
input: HandlerInput | ||
req: express.Request | ||
res: express.Response | ||
}) => Promise<HandlerOutput> | HandlerOutput |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,6 +168,36 @@ describe('account', () => { | |
]) | ||
}) | ||
|
||
it('allows administrative email updates', async () => { | ||
await agent.api.com.atproto.admin.updateAccountEmail( | ||
{ | ||
account: handle, | ||
email: '[email protected]', | ||
}, | ||
{ | ||
encoding: 'application/json', | ||
headers: { authorization: util.adminAuth() }, | ||
}, | ||
) | ||
|
||
const accnt = await ctx.services.account(ctx.db).getAccount(handle) | ||
expect(accnt?.email).toBe('[email protected]') | ||
|
||
await agent.api.com.atproto.admin.updateAccountEmail( | ||
{ | ||
account: did, | ||
email, | ||
}, | ||
{ | ||
encoding: 'application/json', | ||
headers: { authorization: util.adminAuth() }, | ||
}, | ||
) | ||
|
||
const accnt2 = await ctx.services.account(ctx.db).getAccount(handle) | ||
expect(accnt2?.email).toBe(email) | ||
}) | ||
|
||
it('disallows duplicate email addresses and handles', async () => { | ||
const inviteCode = await createInviteCode(agent, 2) | ||
const email = '[email protected]' | ||
|