Implement guard on empty full name before NDA is signed
Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user