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.
Account deletion (bluesky-social#488)
* wip * fleshing out repo storage * fleshing out sql storage * cleaning things up * fix up tests * dumb bug - commit log reversed * rm staging in favor of commiting diffs to blockstore * clean up benches * fixing up sql storage * some caching for sql repo store * pr feedback * migration * wip * migraiton test * unclear param * sql repo storage tests * rm unused code * fix up some diff code * pr feedback * enum for action types * missed some * wip * ripping out auth lib * more auth cleanup * another lurker * wip better sync primitives * wip * improving diffs & sync * tests working! * actually implemented checkout lol * simplify interface & improve error handling * writing sql storage code * fixing up tests * testing & bugfixes * checkouts return records instead of cids * one last refactor lol * missed one * handle other cid codecs on incoming car verification * tests + tricky bugs * unneeded blockstore method * trim mst on del instead of save * cleanup comment * dont resolve did for every commit * use "commit" instead of "root" * getRoot -> getHead * pr feedback * very silly bug fix * improve sync output * reorging + sync of particular records * serve & verify proofs. also rename some ipld methods * fix up sync issue in mst * find reachable records form carfile * getRecord xrpc method * pr feedback * better migration test * check migraiton result * fixing up a couple things for pg * explicit migrateTo * async exceptions * ipld car mimetype + remove updateRepo * Update module publish scripts (bluesky-social#478) * Update pds package publishing scripts * Update auth package publishing scripts * Update crypto package publishing scripts * Update did-resolver package publishing scripts * Update handle package publishing scripts * Update xrpc-server package publishing scripts * Update common package publishing scripts * Update plc package publishing scripts * Update uri package publishing scripts * Update repo package publishing scripts * Sort "suggested follows" by number of posts (bluesky-social#477) * return suggestions by post count * pr feedback * fix up PG pagination issue * partiion commit-history & commit-blocks by user did * some lexicons reworking routes request deletion flows delete actor rows migration for user-partitioned-cids move creator to be on ipld_block migration tests * delete records & repos * delete blobs * hook it up in route * pettier ignore email templates * testing & bugfixes * testing blobs & bugfixes * pr feedback * make deletion test more robust * change out handle for did on account deletion * small cleanup --------- Co-authored-by: Paul Frazee <[email protected]>
- Loading branch information
Showing
55 changed files
with
1,594 additions
and
182 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
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,10 @@ | ||
{ | ||
"lexicon": 1, | ||
"id": "com.atproto.account.requestDelete", | ||
"defs": { | ||
"main": { | ||
"type": "procedure", | ||
"description": "Initiate a user account deletion via 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
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
27 changes: 27 additions & 0 deletions
27
packages/api/src/client/types/com/atproto/account/requestDelete.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,27 @@ | ||
/** | ||
* GENERATED CODE - DO NOT MODIFY | ||
*/ | ||
import { Headers, XRPCError } from '@atproto/xrpc' | ||
import { ValidationResult } from '@atproto/lexicon' | ||
import { isObj, hasProp } from '../../../../util' | ||
import { lexicons } from '../../../../lexicons' | ||
|
||
export interface QueryParams {} | ||
|
||
export type InputSchema = undefined | ||
|
||
export interface CallOptions { | ||
headers?: Headers | ||
qp?: QueryParams | ||
} | ||
|
||
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
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
src/lexicon/**/* | ||
src/lexicon/**/* | ||
src/mailer/templates/**/* |
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
4 changes: 2 additions & 2 deletions
4
packages/pds/src/api/com/atproto/invites.ts → ...i/com/atproto/account/createInviteCode.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
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,78 @@ | ||
import { AuthRequiredError } from '@atproto/xrpc-server' | ||
import { Server } from '../../../../lexicon' | ||
import AppContext from '../../../../context' | ||
import Database from '../../../../db' | ||
|
||
export default function (server: Server, ctx: AppContext) { | ||
server.com.atproto.account.delete(async ({ input }) => { | ||
const { did, password, token } = input.body | ||
const validPass = await ctx.services | ||
.actor(ctx.db) | ||
.verifyUserDidPassword(did, password) | ||
if (!validPass) { | ||
throw new AuthRequiredError('Invalid did or password') | ||
} | ||
|
||
const tokenInfo = await ctx.db.db | ||
.selectFrom('did_handle') | ||
.innerJoin('delete_account_token as token', 'token.did', 'did_handle.did') | ||
.where('did_handle.did', '=', did) | ||
.where('token.token', '=', token) | ||
.select([ | ||
'token.token as token', | ||
'token.requestedAt as requestedAt', | ||
'token.did as did', | ||
]) | ||
.executeTakeFirst() | ||
|
||
if (!tokenInfo) { | ||
return createInvalidTokenError() | ||
} | ||
|
||
const now = new Date() | ||
const requestedAt = new Date(tokenInfo.requestedAt) | ||
const expiresAt = new Date(requestedAt.getTime() + 15 * minsToMs) | ||
if (now > expiresAt) { | ||
await removeDeleteToken(ctx.db, tokenInfo.did) | ||
return createExpiredTokenError() | ||
} | ||
|
||
await ctx.db.transaction(async (dbTxn) => { | ||
await removeDeleteToken(dbTxn, did) | ||
await ctx.services.record(dbTxn).deleteForUser(did) | ||
await ctx.services.repo(dbTxn).deleteRepo(did) | ||
await ctx.services.actor(dbTxn).deleteUser(did) | ||
}) | ||
}) | ||
} | ||
|
||
type ErrorResponse = { | ||
status: number | ||
error: string | ||
message: string | ||
} | ||
|
||
const minsToMs = 60 * 1000 | ||
|
||
const createInvalidTokenError = (): ErrorResponse & { | ||
error: 'InvalidToken' | ||
} => ({ | ||
status: 400, | ||
error: 'InvalidToken', | ||
message: 'Token is invalid', | ||
}) | ||
|
||
const createExpiredTokenError = (): ErrorResponse & { | ||
error: 'ExpiredToken' | ||
} => ({ | ||
status: 400, | ||
error: 'ExpiredToken', | ||
message: 'The password reset token has expired', | ||
}) | ||
|
||
const removeDeleteToken = async (db: Database, did: string) => { | ||
await db.db | ||
.deleteFrom('delete_account_token') | ||
.where('delete_account_token.did', '=', did) | ||
.execute() | ||
} |
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,9 @@ | ||
import { InvalidRequestError } from '@atproto/xrpc-server' | ||
import { Server } from '../../../../lexicon' | ||
import AppContext from '../../../../context' | ||
|
||
export default function (server: Server, _ctx: AppContext) { | ||
server.com.atproto.account.get(() => { | ||
throw new InvalidRequestError('Not implemented') | ||
}) | ||
} |
Oops, something went wrong.