mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 11:47:34 +00:00
chore: move the go code into a subfolder
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
es_models "github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
||||
iam_model "github.com/zitadel/zitadel/internal/iam/model"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
type DomainPolicy struct {
|
||||
es_models.ObjectRoot
|
||||
|
||||
State int32 `json:"-"`
|
||||
UserLoginMustBeDomain bool `json:"userLoginMustBeDomain"`
|
||||
}
|
||||
|
||||
func DomainPolicyToModel(policy *DomainPolicy) *iam_model.DomainPolicy {
|
||||
return &iam_model.DomainPolicy{
|
||||
ObjectRoot: policy.ObjectRoot,
|
||||
State: iam_model.PolicyState(policy.State),
|
||||
UserLoginMustBeDomain: policy.UserLoginMustBeDomain,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *DomainPolicy) SetData(event eventstore.Event) error {
|
||||
err := event.Unmarshal(p)
|
||||
if err != nil {
|
||||
return zerrors.ThrowInternal(err, "EVENT-7JS9d", "unable to unmarshal data")
|
||||
}
|
||||
return nil
|
||||
}
|
193
apps/api/internal/iam/repository/view/model/label_policy.go
Normal file
193
apps/api/internal/iam/repository/view/model/label_policy.go
Normal file
@@ -0,0 +1,193 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/zitadel/logging"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
const (
|
||||
LabelPolicyKeyAggregateID = "aggregate_id"
|
||||
LabelPolicyKeyState = "label_policy_state"
|
||||
LabelPolicyKeyInstanceID = "instance_id"
|
||||
LabelPolicyKeyOwnerRemoved = "owner_removed"
|
||||
)
|
||||
|
||||
type LabelPolicyView struct {
|
||||
AggregateID string `json:"-" gorm:"column:aggregate_id;primary_key"`
|
||||
State int32 `json:"-" gorm:"column:label_policy_state;primary_key"`
|
||||
CreationDate time.Time `json:"-" gorm:"column:creation_date"`
|
||||
ChangeDate time.Time `json:"-" gorm:"column:change_date"`
|
||||
|
||||
PrimaryColor string `json:"primaryColor" gorm:"column:primary_color"`
|
||||
BackgroundColor string `json:"backgroundColor" gorm:"column:background_color"`
|
||||
WarnColor string `json:"warnColor" gorm:"column:warn_color"`
|
||||
FontColor string `json:"fontColor" gorm:"column:font_color"`
|
||||
PrimaryColorDark string `json:"primaryColorDark" gorm:"column:primary_color_dark"`
|
||||
BackgroundColorDark string `json:"backgroundColorDark" gorm:"column:background_color_dark"`
|
||||
WarnColorDark string `json:"warnColorDark" gorm:"column:warn_color_dark"`
|
||||
FontColorDark string `json:"fontColorDark" gorm:"column:font_color_dark"`
|
||||
LogoURL string `json:"-" gorm:"column:logo_url"`
|
||||
IconURL string `json:"-" gorm:"column:icon_url"`
|
||||
LogoDarkURL string `json:"-" gorm:"column:logo_dark_url"`
|
||||
IconDarkURL string `json:"-" gorm:"column:icon_dark_url"`
|
||||
FontURL string `json:"-" gorm:"column:font_url"`
|
||||
HideLoginNameSuffix bool `json:"hideLoginNameSuffix" gorm:"column:hide_login_name_suffix"`
|
||||
ErrorMsgPopup bool `json:"errorMsgPopup" gorm:"column:err_msg_popup"`
|
||||
DisableWatermark bool `json:"disableWatermark" gorm:"column:disable_watermark"`
|
||||
Default bool `json:"-" gorm:"-"`
|
||||
|
||||
Sequence uint64 `json:"-" gorm:"column:sequence"`
|
||||
InstanceID string `json:"instanceID" gorm:"column:instance_id;primary_key"`
|
||||
}
|
||||
|
||||
type AssetView struct {
|
||||
AssetURL string `json:"storeKey"`
|
||||
}
|
||||
|
||||
func (p *LabelPolicyView) ToDomain() *domain.LabelPolicy {
|
||||
return &domain.LabelPolicy{
|
||||
ObjectRoot: models.ObjectRoot{
|
||||
AggregateID: p.AggregateID,
|
||||
CreationDate: p.CreationDate,
|
||||
ChangeDate: p.ChangeDate,
|
||||
Sequence: p.Sequence,
|
||||
},
|
||||
Default: p.Default,
|
||||
PrimaryColor: p.PrimaryColor,
|
||||
BackgroundColor: p.BackgroundColor,
|
||||
WarnColor: p.WarnColor,
|
||||
FontColor: p.FontColor,
|
||||
LogoURL: p.LogoURL,
|
||||
IconURL: p.IconURL,
|
||||
|
||||
PrimaryColorDark: p.PrimaryColorDark,
|
||||
BackgroundColorDark: p.BackgroundColorDark,
|
||||
WarnColorDark: p.WarnColorDark,
|
||||
FontColorDark: p.FontColorDark,
|
||||
LogoDarkURL: p.LogoDarkURL,
|
||||
IconDarkURL: p.IconDarkURL,
|
||||
Font: p.FontURL,
|
||||
|
||||
HideLoginNameSuffix: p.HideLoginNameSuffix,
|
||||
ErrorMsgPopup: p.ErrorMsgPopup,
|
||||
DisableWatermark: p.DisableWatermark,
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LabelPolicyView) AppendEvent(event eventstore.Event) (err error) {
|
||||
asset := &AssetView{}
|
||||
i.Sequence = event.Sequence()
|
||||
i.ChangeDate = event.CreatedAt()
|
||||
switch event.Type() {
|
||||
case instance.LabelPolicyAddedEventType,
|
||||
org.LabelPolicyAddedEventType:
|
||||
i.setRootData(event)
|
||||
i.CreationDate = event.CreatedAt()
|
||||
i.State = int32(domain.LabelPolicyStatePreview)
|
||||
err = i.SetData(event)
|
||||
case instance.LabelPolicyChangedEventType,
|
||||
org.LabelPolicyChangedEventType:
|
||||
err = i.SetData(event)
|
||||
i.State = int32(domain.LabelPolicyStatePreview)
|
||||
case instance.LabelPolicyLogoAddedEventType,
|
||||
org.LabelPolicyLogoAddedEventType:
|
||||
err = asset.SetData(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
i.LogoURL = asset.AssetURL
|
||||
i.State = int32(domain.LabelPolicyStatePreview)
|
||||
case instance.LabelPolicyLogoRemovedEventType,
|
||||
org.LabelPolicyLogoRemovedEventType:
|
||||
i.LogoURL = ""
|
||||
i.State = int32(domain.LabelPolicyStatePreview)
|
||||
case instance.LabelPolicyIconAddedEventType,
|
||||
org.LabelPolicyIconAddedEventType:
|
||||
err = asset.SetData(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
i.IconURL = asset.AssetURL
|
||||
i.State = int32(domain.LabelPolicyStatePreview)
|
||||
case instance.LabelPolicyIconRemovedEventType,
|
||||
org.LabelPolicyIconRemovedEventType:
|
||||
i.IconURL = ""
|
||||
case instance.LabelPolicyLogoDarkAddedEventType,
|
||||
org.LabelPolicyLogoDarkAddedEventType:
|
||||
err = asset.SetData(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
i.LogoDarkURL = asset.AssetURL
|
||||
i.State = int32(domain.LabelPolicyStatePreview)
|
||||
case instance.LabelPolicyLogoDarkRemovedEventType,
|
||||
org.LabelPolicyLogoDarkRemovedEventType:
|
||||
i.LogoDarkURL = ""
|
||||
i.State = int32(domain.LabelPolicyStatePreview)
|
||||
case instance.LabelPolicyIconDarkAddedEventType,
|
||||
org.LabelPolicyIconDarkAddedEventType:
|
||||
err = asset.SetData(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
i.IconDarkURL = asset.AssetURL
|
||||
i.State = int32(domain.LabelPolicyStatePreview)
|
||||
case instance.LabelPolicyIconDarkRemovedEventType,
|
||||
org.LabelPolicyIconDarkRemovedEventType:
|
||||
i.IconDarkURL = ""
|
||||
i.State = int32(domain.LabelPolicyStatePreview)
|
||||
case instance.LabelPolicyFontAddedEventType,
|
||||
org.LabelPolicyFontAddedEventType:
|
||||
err = asset.SetData(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
i.FontURL = asset.AssetURL
|
||||
i.State = int32(domain.LabelPolicyStatePreview)
|
||||
case instance.LabelPolicyFontRemovedEventType,
|
||||
org.LabelPolicyFontRemovedEventType:
|
||||
i.FontURL = ""
|
||||
i.State = int32(domain.LabelPolicyStatePreview)
|
||||
case instance.LabelPolicyActivatedEventType,
|
||||
org.LabelPolicyActivatedEventType:
|
||||
i.State = int32(domain.LabelPolicyStateActive)
|
||||
case instance.LabelPolicyAssetsRemovedEventType,
|
||||
org.LabelPolicyAssetsRemovedEventType:
|
||||
i.LogoURL = ""
|
||||
i.IconURL = ""
|
||||
i.LogoDarkURL = ""
|
||||
i.IconDarkURL = ""
|
||||
i.FontURL = ""
|
||||
i.State = int32(domain.LabelPolicyStatePreview)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *LabelPolicyView) setRootData(event eventstore.Event) {
|
||||
r.AggregateID = event.Aggregate().ID
|
||||
r.InstanceID = event.Aggregate().InstanceID
|
||||
}
|
||||
|
||||
func (r *LabelPolicyView) SetData(event eventstore.Event) error {
|
||||
if err := event.Unmarshal(r); err != nil {
|
||||
logging.Log("MODEL-Flp9C").WithError(err).Error("could not unmarshal event data")
|
||||
return zerrors.ThrowInternal(err, "MODEL-Hs8uf", "Could not unmarshal data")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *AssetView) SetData(event eventstore.Event) error {
|
||||
if err := event.Unmarshal(r); err != nil {
|
||||
logging.Log("MODEL-Ms8f2").WithError(err).Error("could not unmarshal event data")
|
||||
return zerrors.ThrowInternal(err, "MODEL-Hs8uf", "Could not unmarshal data")
|
||||
}
|
||||
return nil
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
iam_model "github.com/zitadel/zitadel/internal/iam/model"
|
||||
"github.com/zitadel/zitadel/internal/view/repository"
|
||||
)
|
||||
|
||||
type LabelPolicySearchQuery iam_model.LabelPolicySearchQuery
|
||||
type LabelPolicySearchKey iam_model.LabelPolicySearchKey
|
||||
|
||||
func (req LabelPolicySearchQuery) GetKey() repository.ColumnKey {
|
||||
return LabelPolicySearchKey(req.Key)
|
||||
}
|
||||
|
||||
func (req LabelPolicySearchQuery) GetMethod() domain.SearchMethod {
|
||||
return req.Method
|
||||
}
|
||||
|
||||
func (req LabelPolicySearchQuery) GetValue() interface{} {
|
||||
return req.Value
|
||||
}
|
||||
|
||||
func (key LabelPolicySearchKey) ToColumnName() string {
|
||||
switch iam_model.LabelPolicySearchKey(key) {
|
||||
case iam_model.LabelPolicySearchKeyAggregateID:
|
||||
return LabelPolicyKeyAggregateID
|
||||
case iam_model.LabelPolicySearchKeyState:
|
||||
return LabelPolicyKeyState
|
||||
case iam_model.LabelPolicySearchKeyInstanceID:
|
||||
return LabelPolicyKeyInstanceID
|
||||
case iam_model.LabelPolicySearchKeyOwnerRemoved:
|
||||
return LabelPolicyKeyOwnerRemoved
|
||||
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/zitadel/zitadel/internal/iam/model"
|
||||
"github.com/zitadel/zitadel/internal/query"
|
||||
)
|
||||
|
||||
func PasswordComplexityViewToModel(policy *query.PasswordComplexityPolicy) *model.PasswordComplexityPolicyView {
|
||||
return &model.PasswordComplexityPolicyView{
|
||||
AggregateID: policy.ID,
|
||||
Sequence: policy.Sequence,
|
||||
CreationDate: policy.CreationDate,
|
||||
ChangeDate: policy.ChangeDate,
|
||||
MinLength: policy.MinLength,
|
||||
HasLowercase: policy.HasLowercase,
|
||||
HasUppercase: policy.HasUppercase,
|
||||
HasSymbol: policy.HasSymbol,
|
||||
HasNumber: policy.HasNumber,
|
||||
Default: policy.IsDefault,
|
||||
}
|
||||
}
|
45
apps/api/internal/iam/repository/view/styling.go
Normal file
45
apps/api/internal/iam/repository/view/styling.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
"github.com/jinzhu/gorm"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
iam_model "github.com/zitadel/zitadel/internal/iam/model"
|
||||
"github.com/zitadel/zitadel/internal/iam/repository/view/model"
|
||||
"github.com/zitadel/zitadel/internal/view/repository"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
func GetStylingByAggregateIDAndState(db *gorm.DB, table, aggregateID, instanceID string, state int32) (*model.LabelPolicyView, error) {
|
||||
policy := new(model.LabelPolicyView)
|
||||
aggregateIDQuery := &model.LabelPolicySearchQuery{Key: iam_model.LabelPolicySearchKeyAggregateID, Value: aggregateID, Method: domain.SearchMethodEquals}
|
||||
stateQuery := &model.LabelPolicySearchQuery{Key: iam_model.LabelPolicySearchKeyState, Value: state, Method: domain.SearchMethodEquals}
|
||||
instanceIDQuery := &model.LabelPolicySearchQuery{Key: iam_model.LabelPolicySearchKeyInstanceID, Value: instanceID, Method: domain.SearchMethodEquals}
|
||||
ownerRemovedQuery := &model.LabelPolicySearchQuery{Key: iam_model.LabelPolicySearchKeyOwnerRemoved, Value: false, Method: domain.SearchMethodEquals}
|
||||
query := repository.PrepareGetByQuery(table, aggregateIDQuery, stateQuery, instanceIDQuery, ownerRemovedQuery)
|
||||
err := query(db, policy)
|
||||
if zerrors.IsNotFound(err) {
|
||||
return nil, zerrors.ThrowNotFound(nil, "VIEW-68G11", "Errors.IAM.LabelPolicy.NotExisting")
|
||||
}
|
||||
return policy, err
|
||||
}
|
||||
|
||||
func PutStyling(db *gorm.DB, table string, policy *model.LabelPolicyView) error {
|
||||
save := repository.PrepareSave(table)
|
||||
return save(db, policy)
|
||||
}
|
||||
|
||||
func UpdateOrgOwnerRemovedStyling(db *gorm.DB, table, instanceID, aggID string) error {
|
||||
update := repository.PrepareUpdateByKeys(table,
|
||||
model.LabelPolicySearchKey(iam_model.LabelPolicySearchKeyOwnerRemoved),
|
||||
true,
|
||||
repository.Key{Key: model.LabelPolicySearchKey(iam_model.LabelPolicySearchKeyInstanceID), Value: instanceID},
|
||||
repository.Key{Key: model.LabelPolicySearchKey(iam_model.LabelPolicySearchKeyAggregateID), Value: aggID},
|
||||
)
|
||||
return update(db)
|
||||
}
|
||||
|
||||
func DeleteInstanceStyling(db *gorm.DB, table, instanceID string) error {
|
||||
delete := repository.PrepareDeleteByKey(table, model.LabelPolicySearchKey(iam_model.LabelPolicySearchKeyInstanceID), instanceID)
|
||||
return delete(db)
|
||||
}
|
Reference in New Issue
Block a user