fix(governance): ask for the public URL during owner setup (#2076)
This commit is contained in:
11 files changed
+147
-147
No files matched your search
@@ -6,7 +6,6 @@ import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -75,7 +74,7 @@ func writeAccount(ctx context.Context, tx pgx.Tx, r identity.AccountRegistration
|
||||
now := time.Now().UTC()
|
||||
value.CreatedAt, value.UpdatedAt = now, now
|
||||
if bootstrap {
|
||||
if err := setupAccountOrganisation(ctx, tx, r, orgID, now); err != nil {
|
||||
if _, err := tx.Exec(ctx, `INSERT INTO authentication_settings (public_url) VALUES ($1)`, r.PublicURL); err != nil {
|
||||
return identity.Identity{}, err
|
||||
}
|
||||
}
|
||||
@@ -229,7 +228,8 @@ func accountRegistrationScope(ctx context.Context, r *identity.AccountRegistrati
|
||||
role := org.Role(r.Role)
|
||||
orgID := org.OrgFromContext(ctx)
|
||||
if bootstrap {
|
||||
if err := validateAccountSetup(r); err != nil {
|
||||
r.PublicURL = strings.TrimRight(strings.TrimSpace(r.PublicURL), "/")
|
||||
if err := (identity.AuthenticationSettings{PublicURL: r.PublicURL}).Validate(); err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
return org.RoleOwner, org.DefaultOrgID, nil
|
||||
@@ -257,30 +257,3 @@ func recordFailedAccountLogin(ctx context.Context, tx pgx.Tx, id string, attempt
|
||||
}
|
||||
return identity.ErrCredentialRejected
|
||||
}
|
||||
|
||||
func setupAccountOrganisation(ctx context.Context, tx pgx.Tx, r identity.AccountRegistration, orgID org.OrgID, now time.Time) error {
|
||||
_, err := tx.Exec(ctx, `UPDATE orgs SET name=$1, updated_at=$2 WHERE id=$3`, r.OrganisationName, now, string(orgID))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := tx.Exec(ctx, `UPDATE workspaces SET name=$1,updated_at=$2 WHERE org_id=$3 AND id=$4`, r.WorkspaceName, now, string(orgID), string(org.DefaultWorkspaceID)); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := tx.Exec(ctx, `INSERT INTO authentication_settings (public_url) VALUES ($1)`, r.PublicURL); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateAccountSetup(r *identity.AccountRegistration) error {
|
||||
r.OrganisationName = strings.TrimSpace(r.OrganisationName)
|
||||
r.WorkspaceName = strings.TrimSpace(r.WorkspaceName)
|
||||
r.PublicURL = strings.TrimRight(r.PublicURL, "/")
|
||||
if r.WorkspaceName == "" || len(r.WorkspaceName) > 200 {
|
||||
return identity.ErrInvalid
|
||||
}
|
||||
if r.OrganisationName == "" || len(r.OrganisationName) > 200 {
|
||||
return fmt.Errorf("%w: organisation name is required", identity.ErrInvalid)
|
||||
}
|
||||
return (identity.AuthenticationSettings{PublicURL: r.PublicURL}).Validate()
|
||||
}
|
||||
Reference in new issue
Block a user