Implement guard on empty full name before NDA is signed

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-03-05 17:07:58 +04:00
parent 6896c1bbb8
commit 97e957f394
19 changed files with 637 additions and 91 deletions

View File

@@ -47,6 +47,15 @@ type (
IdentityID gid.GID `json:"uid"`
Email mail.Addr `json:"email"`
}
ChangeEmailRequest struct {
NewEmail mail.Addr
Password string
}
UpdateIdentityRequest struct {
FullName string `json:"fullName"`
}
)
const (
@@ -57,11 +66,6 @@ func NewAccountService(svc *Service) *AccountService {
return &AccountService{Service: svc}
}
type ChangeEmailRequest struct {
NewEmail mail.Addr
Password string
}
func (req ChangeEmailRequest) Validate() error {
v := validator.New()
@@ -70,6 +74,14 @@ func (req ChangeEmailRequest) Validate() error {
return v.Error()
}
func (req UpdateIdentityRequest) Validate() error {
v := validator.New()
v.Check(req.FullName, "full_name", validator.NotEmpty(), validator.MinLen(2), validator.MaxLen(255))
return v.Error()
}
func (s AccountService) ChangeEmail(ctx context.Context, identityID gid.GID, req *ChangeEmailRequest) error {
if err := req.Validate(); err != nil {
return fmt.Errorf("invalid request: %w", err)
@@ -339,6 +351,42 @@ func (s AccountService) GetIdentity(ctx context.Context, identityID gid.GID) (*c
return identity, nil
}
func (s AccountService) UpdateIdentity(ctx context.Context, identityID gid.GID, req *UpdateIdentityRequest) (*coredata.Identity, error) {
if err := req.Validate(); err != nil {
return nil, fmt.Errorf("invalid request: %w", err)
}
identity := &coredata.Identity{}
err := s.pg.WithTx(
ctx,
func(tx pg.Conn) error {
err := identity.LoadByID(ctx, tx, identityID)
if err != nil {
if err == coredata.ErrResourceNotFound {
return NewIdentityNotFoundError(identityID)
}
return fmt.Errorf("cannot load identity: %w", err)
}
identity.FullName = req.FullName
identity.UpdatedAt = time.Now()
if err := identity.Update(ctx, tx); err != nil {
return fmt.Errorf("cannot update identity: %w", err)
}
return nil
},
)
if err != nil {
return nil, err
}
return identity, nil
}
func (s AccountService) ListPersonalAPIKeys(
ctx context.Context,
identityID gid.GID,

View File

@@ -61,7 +61,6 @@ type (
}
SendMagicLinkRequest struct {
FullName string
Email mail.Addr
URLPath string
OrganizationID gid.GID
@@ -75,7 +74,6 @@ type (
}
MagicLinkData struct {
FullName string `json:"fullName"`
Email mail.Addr `json:"email"`
Continue *string `json:"continue"`
}
@@ -552,7 +550,6 @@ func (s AuthService) SendMagicLink(ctx context.Context, req *SendMagicLinkReques
TokenTypeMagicLink,
s.magicLinkTokenValidity,
MagicLinkData{
FullName: req.FullName,
Email: req.Email,
Continue: req.Continue,
},
@@ -574,9 +571,20 @@ func (s AuthService) SendMagicLink(ctx context.Context, req *SendMagicLinkReques
return fmt.Errorf("cannot insert token: %w", err)
}
fullName := req.FullName
fullName := req.Email.Username()
identity := &coredata.Identity{}
organization := &coredata.Organization{}
if err := identity.LoadByEmail(ctx, tx, req.Email); err == nil {
if identity.FullName != "" {
fullName = identity.FullName
}
} else {
if !errors.Is(err, coredata.ErrResourceNotFound) {
return fmt.Errorf("cannot load identity: %w", err)
}
}
if err := organization.LoadByID(ctx, tx, coredata.NewNoScope(), req.OrganizationID); err != nil {
return fmt.Errorf("cannot load organization: %w", err)
}
@@ -675,10 +683,6 @@ func (s AuthService) OpenSessionWithMagicLink(ctx context.Context, tokenString s
UpdatedAt: now,
}
if identity.FullName == "" {
identity.FullName = payload.Data.FullName
}
if err := identity.Insert(ctx, tx); err != nil {
return fmt.Errorf("cannot create identity: %w", err)
}