mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-21 20:38:47 +00:00
fix: features query (#2610)
This commit is contained in:
+125
-47
@@ -7,14 +7,14 @@ import (
|
||||
"time"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/query/projection"
|
||||
)
|
||||
|
||||
type Feature struct {
|
||||
type Features struct {
|
||||
AggregateID string
|
||||
CreationDate time.Time
|
||||
ChangeDate time.Time
|
||||
Sequence uint64
|
||||
IsDefault bool
|
||||
@@ -42,91 +42,113 @@ type Feature struct {
|
||||
}
|
||||
|
||||
var (
|
||||
feautureTable = table{
|
||||
featureTable = table{
|
||||
name: projection.FeatureTable,
|
||||
}
|
||||
FeatureColumnAggregateID = Column{
|
||||
name: projection.FeatureAggregateIDCol,
|
||||
}
|
||||
FeatureColumnCreationDate = Column{
|
||||
name: projection.FeatureCreationDateCol,
|
||||
name: projection.FeatureAggregateIDCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureColumnChangeDate = Column{
|
||||
name: projection.FeatureChangeDateCol,
|
||||
name: projection.FeatureChangeDateCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureColumnSequence = Column{
|
||||
name: projection.FeatureSequenceCol,
|
||||
name: projection.FeatureSequenceCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureColumnIsDefault = Column{
|
||||
name: projection.FeatureIsDefaultCol,
|
||||
name: projection.FeatureIsDefaultCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureTierName = Column{
|
||||
name: projection.FeatureTierNameCol,
|
||||
name: projection.FeatureTierNameCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureTierDescription = Column{
|
||||
name: projection.FeatureTierDescriptionCol,
|
||||
name: projection.FeatureTierDescriptionCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureState = Column{
|
||||
name: projection.FeatureStateCol,
|
||||
name: projection.FeatureStateCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureStateDescription = Column{
|
||||
name: projection.FeatureStateDescriptionCol,
|
||||
name: projection.FeatureStateDescriptionCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureAuditLogRetention = Column{
|
||||
name: projection.FeatureAuditLogRetentionCol,
|
||||
name: projection.FeatureAuditLogRetentionCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureLoginPolicyFactors = Column{
|
||||
name: projection.FeatureLoginPolicyFactorsCol,
|
||||
name: projection.FeatureLoginPolicyFactorsCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureLoginPolicyIDP = Column{
|
||||
name: projection.FeatureLoginPolicyIDPCol,
|
||||
name: projection.FeatureLoginPolicyIDPCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureLoginPolicyPasswordless = Column{
|
||||
name: projection.FeatureLoginPolicyPasswordlessCol,
|
||||
name: projection.FeatureLoginPolicyPasswordlessCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureLoginPolicyRegistration = Column{
|
||||
name: projection.FeatureLoginPolicyRegistrationCol,
|
||||
name: projection.FeatureLoginPolicyRegistrationCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureLoginPolicyUsernameLogin = Column{
|
||||
name: projection.FeatureLoginPolicyUsernameLoginCol,
|
||||
name: projection.FeatureLoginPolicyUsernameLoginCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureLoginPolicyPasswordReset = Column{
|
||||
name: projection.FeatureLoginPolicyPasswordResetCol,
|
||||
name: projection.FeatureLoginPolicyPasswordResetCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeaturePasswordComplexityPolicy = Column{
|
||||
name: projection.FeaturePasswordComplexityPolicyCol,
|
||||
name: projection.FeaturePasswordComplexityPolicyCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureLabelPolicyPrivateLabel = Column{
|
||||
name: projection.FeatureLabelPolicyPrivateLabelCol,
|
||||
name: projection.FeatureLabelPolicyPrivateLabelCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureLabelPolicyWatermark = Column{
|
||||
name: projection.FeatureLabelPolicyWatermarkCol,
|
||||
name: projection.FeatureLabelPolicyWatermarkCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureCustomDomain = Column{
|
||||
name: projection.FeatureCustomDomainCol,
|
||||
name: projection.FeatureCustomDomainCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeaturePrivacyPolicy = Column{
|
||||
name: projection.FeaturePrivacyPolicyCol,
|
||||
name: projection.FeaturePrivacyPolicyCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureMetadataUser = Column{
|
||||
name: projection.FeatureMetadataUserCol,
|
||||
name: projection.FeatureMetadataUserCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureCustomTextMessage = Column{
|
||||
name: projection.FeatureCustomTextMessageCol,
|
||||
name: projection.FeatureCustomTextMessageCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureCustomTextLogin = Column{
|
||||
name: projection.FeatureCustomTextLoginCol,
|
||||
name: projection.FeatureCustomTextLoginCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureLockoutPolicy = Column{
|
||||
name: projection.FeatureLockoutPolicyCol,
|
||||
name: projection.FeatureLockoutPolicyCol,
|
||||
table: featureTable,
|
||||
}
|
||||
FeatureActions = Column{
|
||||
name: projection.FeatureActionsCol,
|
||||
name: projection.FeatureActionsCol,
|
||||
table: featureTable,
|
||||
}
|
||||
)
|
||||
|
||||
func (q *Queries) FeatureByID(ctx context.Context, orgID string) (*Feature, error) {
|
||||
query, scan := prepareFeatureQuery()
|
||||
func (q *Queries) FeaturesByOrgID(ctx context.Context, orgID string) (*Features, error) {
|
||||
query, scan := prepareFeaturesQuery()
|
||||
stmt, args, err := query.Where(
|
||||
sq.Or{
|
||||
sq.Eq{
|
||||
@@ -146,11 +168,11 @@ func (q *Queries) FeatureByID(ctx context.Context, orgID string) (*Feature, erro
|
||||
return scan(row)
|
||||
}
|
||||
|
||||
func (q *Queries) DefaultFeature(ctx context.Context) (*Feature, error) {
|
||||
query, scan := prepareFeatureQuery()
|
||||
func (q *Queries) DefaultFeatures(ctx context.Context) (*Features, error) {
|
||||
query, scan := prepareFeaturesQuery()
|
||||
stmt, args, err := query.Where(sq.Eq{
|
||||
FeatureColumnAggregateID.identifier(): domain.IAMID,
|
||||
}).OrderBy(FeatureColumnIsDefault.identifier()).ToSql()
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "QUERY-1Ndlg", "Errors.Query.SQLStatement")
|
||||
}
|
||||
@@ -159,10 +181,9 @@ func (q *Queries) DefaultFeature(ctx context.Context) (*Feature, error) {
|
||||
return scan(row)
|
||||
}
|
||||
|
||||
func prepareFeatureQuery() (sq.SelectBuilder, func(*sql.Row) (*Feature, error)) {
|
||||
func prepareFeaturesQuery() (sq.SelectBuilder, func(*sql.Row) (*Features, error)) {
|
||||
return sq.Select(
|
||||
FeatureColumnAggregateID.identifier(),
|
||||
FeatureColumnCreationDate.identifier(),
|
||||
FeatureColumnChangeDate.identifier(),
|
||||
FeatureColumnSequence.identifier(),
|
||||
FeatureColumnIsDefault.identifier(),
|
||||
@@ -187,25 +208,26 @@ func prepareFeatureQuery() (sq.SelectBuilder, func(*sql.Row) (*Feature, error))
|
||||
FeatureCustomTextLogin.identifier(),
|
||||
FeatureLockoutPolicy.identifier(),
|
||||
FeatureActions.identifier(),
|
||||
).From(loginPolicyTable.identifier()).PlaceholderFormat(sq.Dollar),
|
||||
func(row *sql.Row) (*Feature, error) {
|
||||
p := new(Feature)
|
||||
).From(featureTable.identifier()).PlaceholderFormat(sq.Dollar),
|
||||
func(row *sql.Row) (*Features, error) {
|
||||
p := new(Features)
|
||||
tierName := sql.NullString{}
|
||||
tierDescription := sql.NullString{}
|
||||
stateDescription := sql.NullString{}
|
||||
err := row.Scan(
|
||||
&p.AggregateID,
|
||||
&p.CreationDate,
|
||||
&p.ChangeDate,
|
||||
&p.Sequence,
|
||||
&p.IsDefault,
|
||||
&p.TierName,
|
||||
&p.TierDescription,
|
||||
&tierName,
|
||||
&tierDescription,
|
||||
&p.State,
|
||||
&p.StateDescription,
|
||||
&stateDescription,
|
||||
&p.AuditLogRetention,
|
||||
&p.LoginPolicyFactors,
|
||||
&p.LoginPolicyIDP,
|
||||
&p.LoginPolicyPasswordless,
|
||||
&p.LoginPolicyRegistration,
|
||||
&p.LoginPolicyRegistration,
|
||||
&p.LoginPolicyUsernameLogin,
|
||||
&p.LoginPolicyPasswordReset,
|
||||
&p.PasswordComplexityPolicy,
|
||||
@@ -221,10 +243,66 @@ func prepareFeatureQuery() (sq.SelectBuilder, func(*sql.Row) (*Feature, error))
|
||||
)
|
||||
if err != nil {
|
||||
if errs.Is(err, sql.ErrNoRows) {
|
||||
return nil, errors.ThrowNotFound(err, "QUERY-M9fse", "Errors.Feature.NotFound")
|
||||
return nil, errors.ThrowNotFound(err, "QUERY-M9fse", "Errors.Features.NotFound")
|
||||
}
|
||||
return nil, errors.ThrowInternal(err, "QUERY-3o9gd", "Errors.Internal")
|
||||
}
|
||||
p.TierName = tierName.String
|
||||
p.TierDescription = tierDescription.String
|
||||
p.StateDescription = stateDescription.String
|
||||
return p, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Features) EnabledFeatureTypes() []string {
|
||||
list := make([]string, 0)
|
||||
if f.LoginPolicyFactors {
|
||||
list = append(list, domain.FeatureLoginPolicyFactors)
|
||||
}
|
||||
if f.LoginPolicyIDP {
|
||||
list = append(list, domain.FeatureLoginPolicyIDP)
|
||||
}
|
||||
if f.LoginPolicyPasswordless {
|
||||
list = append(list, domain.FeatureLoginPolicyPasswordless)
|
||||
}
|
||||
if f.LoginPolicyRegistration {
|
||||
list = append(list, domain.FeatureLoginPolicyRegistration)
|
||||
}
|
||||
if f.LoginPolicyUsernameLogin {
|
||||
list = append(list, domain.FeatureLoginPolicyUsernameLogin)
|
||||
}
|
||||
if f.LoginPolicyPasswordReset {
|
||||
list = append(list, domain.FeatureLoginPolicyPasswordReset)
|
||||
}
|
||||
if f.PasswordComplexityPolicy {
|
||||
list = append(list, domain.FeaturePasswordComplexityPolicy)
|
||||
}
|
||||
if f.LabelPolicyPrivateLabel {
|
||||
list = append(list, domain.FeatureLabelPolicyPrivateLabel)
|
||||
}
|
||||
if f.LabelPolicyWatermark {
|
||||
list = append(list, domain.FeatureLabelPolicyWatermark)
|
||||
}
|
||||
if f.CustomDomain {
|
||||
list = append(list, domain.FeatureCustomDomain)
|
||||
}
|
||||
if f.PrivacyPolicy {
|
||||
list = append(list, domain.FeaturePrivacyPolicy)
|
||||
}
|
||||
if f.MetadataUser {
|
||||
list = append(list, domain.FeatureMetadataUser)
|
||||
}
|
||||
if f.CustomTextMessage {
|
||||
list = append(list, domain.FeatureCustomTextMessage)
|
||||
}
|
||||
if f.CustomTextLogin {
|
||||
list = append(list, domain.FeatureCustomTextLogin)
|
||||
}
|
||||
if f.LockoutPolicy {
|
||||
list = append(list, domain.FeatureLockoutPolicy)
|
||||
}
|
||||
if f.Actions {
|
||||
list = append(list, domain.FeatureActions)
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user