mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 20:57:31 +00:00
fix: org unique check (#5033)
- all verified of domains are checked - domains are checked case insensitive - name is checked case insensitive
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/api/authz"
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
domain_pkg "github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/query/projection"
|
||||
"github.com/zitadel/zitadel/internal/telemetry/tracing"
|
||||
@@ -68,7 +68,7 @@ type Org struct {
|
||||
CreationDate time.Time
|
||||
ChangeDate time.Time
|
||||
ResourceOwner string
|
||||
State domain.OrgState
|
||||
State domain_pkg.OrgState
|
||||
Sequence uint64
|
||||
|
||||
Name string
|
||||
@@ -155,16 +155,20 @@ func (q *Queries) IsOrgUnique(ctx context.Context, name, domain string) (isUniqu
|
||||
stmt, args, err := query.Where(
|
||||
sq.And{
|
||||
sq.Eq{
|
||||
OrgColumnInstanceID.identifier(): authz.GetInstance(ctx).InstanceID(),
|
||||
OrgColumnInstanceID.identifier(): authz.GetInstance(ctx).InstanceID(),
|
||||
OrgDomainIsVerifiedCol.identifier(): true,
|
||||
},
|
||||
sq.Or{
|
||||
sq.Eq{
|
||||
OrgColumnDomain.identifier(): domain,
|
||||
sq.ILike{
|
||||
OrgDomainDomainCol.identifier(): domain,
|
||||
},
|
||||
sq.Eq{
|
||||
sq.ILike{
|
||||
OrgColumnName.identifier(): name,
|
||||
},
|
||||
},
|
||||
sq.NotEq{
|
||||
OrgColumnState.identifier(): domain_pkg.OrgStateRemoved,
|
||||
},
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return false, errors.ThrowInternal(err, "QUERY-Dgbe2", "Errors.Query.SQLStatement")
|
||||
@@ -346,7 +350,9 @@ func prepareOrgWithDomainsQuery() (sq.SelectBuilder, func(*sql.Row) (*Org, error
|
||||
|
||||
func prepareOrgUniqueQuery() (sq.SelectBuilder, func(*sql.Row) (bool, error)) {
|
||||
return sq.Select(uniqueColumn.identifier()).
|
||||
From(orgsTable.identifier()).PlaceholderFormat(sq.Dollar),
|
||||
From(orgsTable.identifier()).
|
||||
LeftJoin(join(OrgDomainOrgIDCol, OrgColumnID)).
|
||||
PlaceholderFormat(sq.Dollar),
|
||||
func(row *sql.Row) (isUnique bool, err error) {
|
||||
err = row.Scan(&isUnique)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user