Skip to content

Commit

Permalink
Allow admins to update handles to reserved handles (bluesky-social#916)
Browse files Browse the repository at this point in the history
* allow admins to update handles to reserved handles

* tidy
  • Loading branch information
dholms authored Apr 27, 2023
1 parent 4b70b80 commit 384e739
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
20 changes: 15 additions & 5 deletions packages/pds/src/api/com/atproto/admin/updateAccountHandle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,35 @@ import { UserAlreadyExistsError } from '../../../../services/account'
export default function (server: Server, ctx: AppContext) {
server.com.atproto.admin.updateAccountHandle({
auth: ctx.adminVerifier,
handler: async ({ input }) => {
handler: async ({ input, req }) => {
const { did } = input.body
let handle: string
try {
handle = ident.normalizeAndEnsureValidHandle(input.body.handle)
} catch (err) {
if (err instanceof ident.InvalidHandleError) {
throw new InvalidRequestError(err.message, 'InvalidHandle')
} else {
throw err
}
}
try {
ident.ensureHandleServiceConstraints(
handle,
ctx.cfg.availableUserDomains,
)
} catch (err) {
if (err instanceof ident.InvalidHandleError) {
throw new InvalidRequestError(err.message, 'InvalidHandle')
} else if (err instanceof ident.UnsupportedDomainError) {
if (err instanceof ident.UnsupportedDomainError) {
throw new InvalidRequestError(
'Unsupported domain',
'UnsupportedDomain',
)
} else if (err instanceof ident.ReservedHandleError) {
throw new InvalidRequestError(err.message, 'HandleNotAvailable')
// we allow this
req.log.info(
{ did, handle: input.body },
'admin setting reserved handle',
)
} else {
throw err
}
Expand Down
19 changes: 19 additions & 0 deletions packages/pds/tests/handles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,25 @@ describe('handles', () => {
expect(profile.data.handle).toBe('bob-alt.test')
})

it('allows admin override of reserved domains', async () => {
await agent.api.com.atproto.admin.updateAccountHandle(
{
did: bob,
handle: 'dril.test',
},
{
headers: { authorization: util.adminAuth() },
encoding: 'application/json',
},
)

const profile = await agent.api.app.bsky.actor.getProfile(
{ actor: bob },
{ headers: sc.getHeaders(bob) },
)
expect(profile.data.handle).toBe('dril.test')
})

it('disallows admin overrules of off-service domains', async () => {
const attempt = agent.api.com.atproto.admin.updateAccountHandle(
{
Expand Down

0 comments on commit 384e739

Please sign in to comment.