Skip to content

Commit

Permalink
feat: go: migrate /user/deanonymize
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarrosop committed Mar 22, 2024
1 parent 5472bed commit 5573b30
Show file tree
Hide file tree
Showing 21 changed files with 1,412 additions and 145 deletions.
53 changes: 53 additions & 0 deletions go/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,28 @@ paths:
- signup
- email-and-password

/user/deanonymize:
post:
summary: >-
Deanonymize an anonymous user in adding missing email or email+password, depending on the chosen authentication method. Will send a confirmation email if the server is configured to do so
tags:
- anonymous
security:
- BearerAuth: []
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/UserDeanonymizeRequest'
responses:
'200':
description: >-
User deanonymized successfully
content:
application/json:
schema:
$ref: '#/components/schemas/OKResponse'

/user/email/change:
post:
summary: Change user email
Expand Down Expand Up @@ -328,6 +350,7 @@ components:
- role-not-allowed
- signup-disabled
- unverified-user
- user-not-anonymous
- invalid-pat
required:
- status
Expand Down Expand Up @@ -460,6 +483,36 @@ components:
- phoneNumberVerified
- roles

UserDeanonymizeRequest:
type: object
additionalProperties: false
properties:
signInMethod:
description: Which sign-in method to use
type: string
enum:
- email-password
- passwordless
email:
description: A valid email
example: [email protected]
format: email
type: string
password:
description: A password of minimum 3 characters
example: Str0ngPassw#ord-94|%
minLength: 3
type: string
connection:
deprecated: true
description: Deprecated, will be ignored
type: string
options:
$ref: "#/components/schemas/SignUpOptions"
required:
- signInMethod
- email

UserEmailChangeRequest:
type: object
additionalProperties: false
Expand Down
156 changes: 116 additions & 40 deletions go/api/server.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions go/api/types.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 20 additions & 8 deletions go/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,39 @@ type Emailer interface {
) error
}

type DBClient interface { //nolint:interfacebloat
CountSecurityKeysUser(ctx context.Context, userID uuid.UUID) (int64, error)
GetUser(ctx context.Context, id uuid.UUID) (sql.AuthUser, error)
GetUserByEmail(ctx context.Context, email pgtype.Text) (sql.AuthUser, error)
GetUserByRefreshTokenHash(
ctx context.Context, arg sql.GetUserByRefreshTokenHashParams,
) (sql.AuthUser, error)
GetUserRoles(ctx context.Context, userID uuid.UUID) ([]sql.AuthUserRole, error)
type DBClientInsertUser interface {
InsertUser(ctx context.Context, arg sql.InsertUserParams) (sql.InsertUserRow, error)
InsertUserWithRefreshToken(
ctx context.Context, arg sql.InsertUserWithRefreshTokenParams,
) (uuid.UUID, error)
InsertRefreshtoken(ctx context.Context, arg sql.InsertRefreshtokenParams) (uuid.UUID, error)
}

type DBClientUpdateUser interface {
UpdateUserChangeEmail(
ctx context.Context,
arg sql.UpdateUserChangeEmailParams,
) (sql.AuthUser, error)
UpdateUserDeanonymize(ctx context.Context, arg sql.UpdateUserDeanonymizeParams) error
UpdateUserLastSeen(ctx context.Context, id uuid.UUID) (pgtype.Timestamptz, error)
UpdateUserTicket(ctx context.Context, arg sql.UpdateUserTicketParams) (uuid.UUID, error)
}

type DBClient interface {
DBClientInsertUser
DBClientUpdateUser

CountSecurityKeysUser(ctx context.Context, userID uuid.UUID) (int64, error)
DeleteRefreshTokens(ctx context.Context, userID uuid.UUID) error
DeleteUserRoles(ctx context.Context, userID uuid.UUID) error
GetUser(ctx context.Context, id uuid.UUID) (sql.AuthUser, error)
GetUserByEmail(ctx context.Context, email pgtype.Text) (sql.AuthUser, error)
GetUserByRefreshTokenHash(
ctx context.Context, arg sql.GetUserByRefreshTokenHashParams,
) (sql.AuthUser, error)
GetUserRoles(ctx context.Context, userID uuid.UUID) ([]sql.AuthUserRole, error)
}

type Controller struct {
wf *Workflows
config Config
Expand Down
Loading

0 comments on commit 5573b30

Please sign in to comment.