Skip to content

Commit

Permalink
modify user endpoint returns same UserProfile as get user (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-cronus authored Jun 13, 2024
1 parent 1af8edf commit 483eb47
Show file tree
Hide file tree
Showing 22 changed files with 98 additions and 132 deletions.
2 changes: 1 addition & 1 deletion auth/email_link/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

type (
UserModifier interface {
ModifyUser(ctx context.Context, usr *users.User, profilePicture *multipart.FileHeader) error
ModifyUser(ctx context.Context, usr *users.User, profilePicture *multipart.FileHeader) (*users.UserProfile, error)
}
Client interface {
IceUserIDClient
Expand Down
6 changes: 3 additions & 3 deletions auth/email_link/email_modify.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (c *client) handleEmailModification(ctx context.Context, els *emailLinkSign
usr := new(users.User)
usr.ID = *els.UserID
usr.Email = newEmail
err := c.userModifier.ModifyUser(users.ConfirmedEmailContext(ctx, newEmail), usr, nil)
_, err := c.userModifier.ModifyUser(users.ConfirmedEmailContext(ctx, newEmail), usr, nil)
if err != nil {
return errors.Wrapf(err, "failed to modify user %v with email modification", els.UserID)
}
Expand Down Expand Up @@ -85,9 +85,9 @@ func (c *client) resetEmailModification(ctx context.Context, userID users.UserID
usr := new(users.User)
usr.ID = userID
usr.Email = oldEmail
_, mErr := c.userModifier.ModifyUser(users.ConfirmedEmailContext(ctx, oldEmail), usr, nil)

return errors.Wrapf(c.userModifier.ModifyUser(users.ConfirmedEmailContext(ctx, oldEmail), usr, nil),
"[rollback] failed to modify user:%v", userID)
return errors.Wrapf(mErr, "[rollback] failed to modify user:%v", userID)
}

func (*client) resetFirebaseEmailModification(ctx context.Context, md *users.JSON, oldEmail string) error {
Expand Down
36 changes: 8 additions & 28 deletions cmd/eskimo-hut/api/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2256,34 +2256,6 @@ const docTemplate = `{
"type": "string",
"example": "did:ethr:0x4B73C58370AEfcEf86A6021afCDe5673511376B2"
},
"kycFaceAvailable": {
"type": "boolean",
"example": true
},
"kycQuizAvailabilityEndedAt": {
"type": "string"
},
"kycQuizAvailabilityStartedAt": {
"type": "string"
},
"kycQuizAvailable": {
"type": "boolean"
},
"kycQuizCompleted": {
"type": "boolean"
},
"kycQuizDisabled": {
"type": "boolean"
},
"kycQuizRemainingAttempts": {
"type": "integer"
},
"kycQuizResetAt": {
"type": "array",
"items": {
"type": "string"
}
},
"kycStepBlocked": {
"allOf": [
{
Expand Down Expand Up @@ -2352,6 +2324,14 @@ const docTemplate = `{
"type": "string"
}
},
"t1ReferralCount": {
"type": "integer",
"example": 100
},
"t2ReferralCount": {
"type": "integer",
"example": 100
},
"updatedAt": {
"type": "string",
"example": "2022-01-03T16:20:52.156534Z"
Expand Down
36 changes: 8 additions & 28 deletions cmd/eskimo-hut/api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2249,34 +2249,6 @@
"type": "string",
"example": "did:ethr:0x4B73C58370AEfcEf86A6021afCDe5673511376B2"
},
"kycFaceAvailable": {
"type": "boolean",
"example": true
},
"kycQuizAvailabilityEndedAt": {
"type": "string"
},
"kycQuizAvailabilityStartedAt": {
"type": "string"
},
"kycQuizAvailable": {
"type": "boolean"
},
"kycQuizCompleted": {
"type": "boolean"
},
"kycQuizDisabled": {
"type": "boolean"
},
"kycQuizRemainingAttempts": {
"type": "integer"
},
"kycQuizResetAt": {
"type": "array",
"items": {
"type": "string"
}
},
"kycStepBlocked": {
"allOf": [
{
Expand Down Expand Up @@ -2345,6 +2317,14 @@
"type": "string"
}
},
"t1ReferralCount": {
"type": "integer",
"example": 100
},
"t2ReferralCount": {
"type": "integer",
"example": 100
},
"updatedAt": {
"type": "string",
"example": "2022-01-03T16:20:52.156534Z"
Expand Down
25 changes: 6 additions & 19 deletions cmd/eskimo-hut/api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,6 @@ definitions:
id:
example: did:ethr:0x4B73C58370AEfcEf86A6021afCDe5673511376B2
type: string
kycFaceAvailable:
example: true
type: boolean
kycQuizAvailabilityEndedAt:
type: string
kycQuizAvailabilityStartedAt:
type: string
kycQuizAvailable:
type: boolean
kycQuizCompleted:
type: boolean
kycQuizDisabled:
type: boolean
kycQuizRemainingAttempts:
type: integer
kycQuizResetAt:
items:
type: string
type: array
kycStepBlocked:
allOf:
- $ref: '#/definitions/users.KYCStep'
Expand Down Expand Up @@ -166,6 +147,12 @@ definitions:
additionalProperties:
type: string
type: object
t1ReferralCount:
example: 100
type: integer
t2ReferralCount:
example: 100
type: integer
updatedAt:
example: "2022-01-03T16:20:52.156534Z"
type: string
Expand Down
2 changes: 1 addition & 1 deletion cmd/eskimo-hut/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func (s *service) ProcessFaceRecognitionResult(

return nil, server.UnprocessableEntity(err, invalidPropertiesErrorCode)
}
if err = s.usersProcessor.ModifyUser(ctx, usr, nil); err != nil {
if _, err = s.usersProcessor.ModifyUser(ctx, usr, nil); err != nil {
err = errors.Wrapf(err, "failed to UpdateFaceRecognitionResult for %#v", usr)
switch {
case errors.Is(err, users.ErrNotFound):
Expand Down
2 changes: 1 addition & 1 deletion cmd/eskimo-hut/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ type (
EmailConfirmed bool `json:"emailConfirmed,omitempty" example:"true"`
}
ModifyUserResponse struct {
*User
*UserProfile
LoginSession string `json:"loginSession,omitempty" example:"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE2ODQzMjQ0NTYsImV4cCI6MTcxNTg2MDQ1NiwiYXVkIjoiIiwic3ViIjoianJvY2tldEBleGFtcGxlLmNvbSIsIm90cCI6IjUxMzRhMzdkLWIyMWEtNGVhNi1hNzk2LTAxOGIwMjMwMmFhMCJ9.q3xa8Gwg2FVCRHLZqkSedH3aK8XBqykaIy85rRU40nM"` //nolint:lll // .
}
User struct {
Expand Down
5 changes: 3 additions & 2 deletions cmd/eskimo-hut/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ func (s *service) ModifyUser( //nolint:gocritic,funlen,revive,cyclop // .
return nil, server.Unexpected(errors.Wrapf(err, "failed to trigger email modification for request:%#v", req.Data))
}
}
err = s.usersProcessor.ModifyUser(users.ContextWithChecksum(ctx, req.Data.Checksum), usr, req.Data.ProfilePicture)
var userProfile *users.UserProfile
userProfile, err = s.usersProcessor.ModifyUser(users.ContextWithChecksum(ctx, req.Data.Checksum), usr, req.Data.ProfilePicture)
if err != nil {
err = errors.Wrapf(err, "failed to modify user for %#v", req.Data)
switch {
Expand All @@ -184,7 +185,7 @@ func (s *service) ModifyUser( //nolint:gocritic,funlen,revive,cyclop // .
}
}

return server.OK(&ModifyUserResponse{User: &User{User: usr, Checksum: usr.Checksum()}, LoginSession: loginSession}), nil
return server.OK(&ModifyUserResponse{UserProfile: &UserProfile{UserProfile: userProfile, Checksum: usr.Checksum()}, LoginSession: loginSession}), nil
}

func validateModifyUser(ctx context.Context, req *server.Request[ModifyUserRequestBody, ModifyUserResponse]) *server.Response[server.ErrorResponse] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func updateDBEmail(usersProcessor users.Processor, usr *record, idx uint64) {
},
},
}
err := usersProcessor.ModifyUser(context.Background(), &updUsr, nil)
_, err := usersProcessor.ModifyUser(context.Background(), &updUsr, nil)
if errors.Is(err, users.ErrDuplicate) { //nolint:revive // Nope.
log.Error(errors.Errorf("duplicate email(belongs to another user): id:%v, email:%v", usr.ID, usr.Email))
} else {
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
)

require (
cloud.google.com/go v0.114.0 // indirect
cloud.google.com/go v0.115.0 // indirect
cloud.google.com/go/auth v0.5.1 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.2 // indirect
cloud.google.com/go/compute/metadata v0.3.0 // indirect
Expand Down Expand Up @@ -96,7 +96,7 @@ require (
github.com/joho/godotenv v1.5.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.8 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
Expand Down Expand Up @@ -162,7 +162,7 @@ require (
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.22.0 // indirect
google.golang.org/api v0.183.0 // indirect
google.golang.org/api v0.184.0 // indirect
google.golang.org/appengine/v2 v2.0.6 // indirect
google.golang.org/genproto v0.0.0-20240610135401-a8a62080eff3 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240610135401-a8a62080eff3 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.114.0 h1:OIPFAdfrFDFO2ve2U7r/H5SwSbBzEdrBdE7xkgwc+kY=
cloud.google.com/go v0.114.0/go.mod h1:ZV9La5YYxctro1HTPug5lXH/GefROyW8PPD4T8n9J8E=
cloud.google.com/go v0.115.0 h1:CnFSK6Xo3lDYRoBKEcAtia6VSC837/ZkJuRduSFnr14=
cloud.google.com/go v0.115.0/go.mod h1:8jIM5vVgoAEoiVxQ/O4BFTfHqulPZgs/ufEzMcFMdWU=
cloud.google.com/go/auth v0.5.1 h1:0QNO7VThG54LUzKiQxv8C6x1YX7lUrzlAa1nVLF8CIw=
cloud.google.com/go/auth v0.5.1/go.mod h1:vbZT8GjzDf3AVqCcQmqeeM32U9HBFc32vVVAbwDsa6s=
cloud.google.com/go/auth/oauth2adapt v0.2.2 h1:+TTV8aXpjeChS9M+aTtN/TjdQnzJvmzKFt//oWu7HX4=
Expand Down Expand Up @@ -244,8 +244,8 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU=
github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS5BM=
github.com/klauspost/cpuid/v2 v2.2.8/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
Expand Down Expand Up @@ -519,8 +519,8 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU=
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90=
google.golang.org/api v0.183.0 h1:PNMeRDwo1pJdgNcFQ9GstuLe/noWKIc89pRWRLMvLwE=
google.golang.org/api v0.183.0/go.mod h1:q43adC5/pHoSZTx5h2mSmdF7NcyfW9JuDyIOJAgS9ZQ=
google.golang.org/api v0.184.0 h1:dmEdk6ZkJNXy1JcDhn/ou0ZUq7n9zropG2/tR4z+RDg=
google.golang.org/api v0.184.0/go.mod h1:CeDTtUEiYENAf8PPG5VZW2yNp2VM3VWbCeTioAZBTBA=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine/v2 v2.0.6 h1:LvPZLGuchSBslPBp+LAhihBeGSiRh1myRoYK4NtuBIw=
Expand Down
2 changes: 1 addition & 1 deletion kyc/face/internal/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ type (
Reset(ctx context.Context, userID string, fetchState bool) error
}
UserRepository interface {
ModifyUser(ctx context.Context, usr *users.User, profilePicture *multipart.FileHeader) error
ModifyUser(ctx context.Context, usr *users.User, profilePicture *multipart.FileHeader) (*users.UserProfile, error)
}
)
3 changes: 2 additions & 1 deletion kyc/face/internal/threedivi/threedivi.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ func (t *threeDivi) CheckAndUpdateStatus(ctx context.Context, userID string) (ha
usr := t.parseApplicant(userID, bafApplicant)
hasFaceKYCResult = (usr.KYCStepPassed != nil && *usr.KYCStepPassed >= users.LivenessDetectionKYCStep) ||
(usr.KYCStepBlocked != nil && *usr.KYCStepBlocked > users.NoneKYCStep)
_, mErr := t.users.ModifyUser(ctx, usr, nil)

return hasFaceKYCResult, errors.Wrapf(t.users.ModifyUser(ctx, usr, nil), "failed to update user with face kyc result")
return hasFaceKYCResult, errors.Wrapf(mErr, "failed to update user with face kyc result")
}

//nolint:funlen,revive // .
Expand Down
2 changes: 1 addition & 1 deletion kyc/quiz/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type (

UserRepository interface {
GetUserByID(ctx context.Context, userID string) (*users.UserProfile, error)
ModifyUser(ctx context.Context, usr *users.User, profilePicture *multipart.FileHeader) error
ModifyUser(ctx context.Context, usr *users.User, profilePicture *multipart.FileHeader) (*users.UserProfile, error)
}
QuizStatus struct { //nolint:revive // Nope cuz we want to be able to embed this
KYCQuizAvailabilityStartedAt *time.Time `json:"kycQuizAvailabilityStartedAt" db:"kyc_quiz_availability_started_at"`
Expand Down
3 changes: 2 additions & 1 deletion kyc/quiz/quiz.go
Original file line number Diff line number Diff line change
Expand Up @@ -941,8 +941,9 @@ func (r *repositoryImpl) modifyUser(ctx context.Context, success, blocked bool,
*usr.KYCStepsLastUpdatedAt = append(*usr.KYCStepsLastUpdatedAt, now)
}
(*usr.KYCStepsLastUpdatedAt)[int(newKYCStep)-1] = now
_, mErr := r.Users.ModifyUser(ctx, usr, nil)

return errors.Wrapf(r.Users.ModifyUser(ctx, usr, nil), "failed to modify user %#v", usr)
return errors.Wrapf(mErr, "failed to modify user %#v", usr)
}

func (r *repositoryImpl) ContinueQuizSession( //nolint:funlen,revive,gocognit //.
Expand Down
2 changes: 1 addition & 1 deletion kyc/social/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type (
}
UserRepository interface {
GetUserByID(ctx context.Context, userID string) (*users.UserProfile, error)
ModifyUser(ctx context.Context, usr *users.User, profilePicture *multipart.FileHeader) error
ModifyUser(ctx context.Context, usr *users.User, profilePicture *multipart.FileHeader) (*users.UserProfile, error)
}
)

Expand Down
4 changes: 2 additions & 2 deletions kyc/social/social.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ func (r *repository) modifyUser(ctx context.Context, success, skip bool, kycStep
usr := new(users.User)
usr.ID = user.ID
usr.KYCStepsLastUpdatedAt = user.KYCStepsLastUpdatedAt

switch {
case success:
usr.KYCStepPassed = &kycStep
Expand All @@ -300,8 +299,9 @@ func (r *repository) modifyUser(ctx context.Context, success, skip bool, kycStep
(*usr.KYCStepsLastUpdatedAt)[int(kycStep)-1] = now
}
}
_, mErr := r.user.ModifyUser(ctx, usr, nil)

return errors.Wrapf(r.user.ModifyUser(ctx, usr, nil), "[skip:%v]failed to modify user %#v", skip, usr)
return errors.Wrapf(mErr, "[skip:%v]failed to modify user %#v", skip, usr)
}

func (r *repository) saveSocialKYCStep(ctx context.Context, now *time.Time, userHandle string, metadata *VerificationMetadata) error {
Expand Down
2 changes: 1 addition & 1 deletion users/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ type (
WriteRepository interface {
CreateUser(ctx context.Context, usr *User, clientIP net.IP) error
DeleteUser(ctx context.Context, userID UserID) error
ModifyUser(ctx context.Context, usr *User, profilePicture *multipart.FileHeader) error
ModifyUser(ctx context.Context, usr *User, profilePicture *multipart.FileHeader) (*UserProfile, error)

TryResetKYCSteps(ctx context.Context, resetClient ResetKycClient, userID string) (*User, error)
}
Expand Down
3 changes: 2 additions & 1 deletion users/ping_user_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func (s *userPingSource) Process(ctx context.Context, msg *messagebroker.Message
usr := new(User)
usr.ID = message.UserID
usr.LastPingCooldownEndedAt = message.LastPingCooldownEndedAt
_, mErr := s.ModifyUser(ctx, usr, nil)

return errors.Wrapf(s.ModifyUser(ctx, usr, nil), "failed to modify user's LastPingCooldownEndedAt for %#v", usr)
return errors.Wrapf(mErr, "failed to modify user's LastPingCooldownEndedAt for %#v", usr)
}
9 changes: 5 additions & 4 deletions users/users_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ func (r *repository) DeleteUser(ctx context.Context, userID UserID) error {
if err != nil {
return errors.Wrapf(err, "failed to get user for userID:%v", userID)
}
if err = r.deleteUser(ctx, gUser); err != nil {
if err = r.deleteUser(ctx, gUser.User); err != nil {
return errors.Wrapf(err, "failed to deleteUser for:%#v", gUser)
}
u := &UserSnapshot{Before: r.sanitizeUser(gUser)}
u := &UserSnapshot{Before: r.sanitizeUser(gUser.User)}
if err = r.sendUserSnapshotMessage(ctx, u); err != nil {
return errors.Wrapf(err, "failed to send deleted user message for %#v", u)
}
Expand Down Expand Up @@ -53,7 +53,7 @@ func (r *repository) deleteUser(ctx context.Context, usr *User) error { //nolint
if err != nil {
return errors.Wrapf(err, "failed to get user for userID:%v", usr.ID)
}
*usr = *gUser
*usr = *gUser.User
sql := `DELETE FROM users WHERE id = $1`
if _, tErr := storage.Exec(ctx, r.db, sql, usr.ID); tErr != nil {
if storage.IsErr(tErr, storage.ErrRelationNotFound) {
Expand Down Expand Up @@ -146,7 +146,8 @@ func (r *repository) updateReferredByForAllT1Referrals(ctx context.Context, user
updatedReferral.ID = res[ix].ID
updatedReferral.ReferredBy = res[ix].NewReferredBy
updatedReferral.RandomReferredBy = &valTrue
errChan <- errors.Wrapf(r.ModifyUser(ctx, updatedReferral, nil),
_, mErr := r.ModifyUser(ctx, updatedReferral, nil)
errChan <- errors.Wrapf(mErr,
"failed to update referred by for userID:%v", res[ix].ID)
}(ii)
}
Expand Down
Loading

0 comments on commit 483eb47

Please sign in to comment.