Browse Source

Apply suggestions from code review

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Maksim Nabokikh <max.nabokih@gmail.com>
pull/4643/head
Maksim Nabokikh 1 week ago committed by GitHub
parent
commit
f83cbbd87c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      storage/ent/client/types.go
  2. 7
      storage/ent/client/useridentity.go
  3. 2
      storage/sql/crud.go

4
storage/ent/client/types.go

@ -185,6 +185,10 @@ func toStorageUserIdentity(u *db.UserIdentity) storage.UserIdentity {
// Correctness of json structure is guaranteed on uploading
panic(err)
}
if s.Consents == nil {
// Ensure Consents is non-nil even if JSON was "null".
s.Consents = make(map[string][]string)
}
} else {
// Server code assumes this will be non-nil.
s.Consents = make(map[string][]string)

7
storage/ent/client/useridentity.go

@ -10,6 +10,9 @@ import (
// CreateUserIdentity saves provided user identity into the database.
func (d *Database) CreateUserIdentity(ctx context.Context, identity storage.UserIdentity) error {
if identity.Consents == nil {
identity.Consents = make(map[string]storage.Consent)
}
encodedConsents, err := json.Marshal(identity.Consents)
if err != nil {
return fmt.Errorf("encode consents user identity: %w", err)
@ -78,6 +81,10 @@ func (d *Database) UpdateUserIdentity(ctx context.Context, userID string, connec
return rollback(tx, "update user identity updating: %w", err)
}
if newUserIdentity.Consents == nil {
newUserIdentity.Consents = make(map[string]storage.Consent)
}
encodedConsents, err := json.Marshal(newUserIdentity.Consents)
if err != nil {
return rollback(tx, "encode consents user identity: %w", err)

2
storage/sql/crud.go

@ -911,7 +911,7 @@ func scanUserIdentity(s scanner) (u storage.UserIdentity, err error) {
func (c *conn) DeleteUserIdentity(ctx context.Context, userID, connectorID string) error {
result, err := c.Exec(`delete from user_identity where user_id = $1 AND connector_id = $2`, userID, connectorID)
if err != nil {
return fmt.Errorf("delete user_identity: user_id = %s, connector_id = %s", userID, connectorID)
return fmt.Errorf("delete user_identity: user_id = %s, connector_id = %s: %w", userID, connectorID, err)
}
// For now mandate that the driver implements RowsAffected. If we ever need to support

Loading…
Cancel
Save