mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 03:24:26 +00:00
42384763d1
* Label Policy added * save * chore: update docs action * Save * Save * Get colors from DB * Variables inserted * Get images from global directory. * Add tests * Add tests * Corrections from mergerequest * Corrections from mergerequest * Test corrected. * Added colors to all notifications. * Added colors to Corrected text and formatting.all notifications. * Spelling error corrected. * fix: tests * Merge Branch corrected. * Step6 added * Corrections from mergerequest * fix: generate management * Formatted texts. * fix: migrations Co-authored-by: Florian Forster <florian@caos.ch> Co-authored-by: adlerhurst <silvan.reusser@gmail.com> Co-authored-by: Fabiennne <fabienne.gerschwiler@gmail.com>
83 lines
2.5 KiB
Go
83 lines
2.5 KiB
Go
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
|
|
org_es_model "github.com/caos/zitadel/internal/org/repository/eventsourcing/model"
|
|
|
|
es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
|
|
|
"github.com/caos/logging"
|
|
caos_errs "github.com/caos/zitadel/internal/errors"
|
|
"github.com/caos/zitadel/internal/eventstore/models"
|
|
"github.com/caos/zitadel/internal/iam/model"
|
|
)
|
|
|
|
const (
|
|
LabelPolicyKeyAggregateID = "aggregate_id"
|
|
)
|
|
|
|
type LabelPolicyView struct {
|
|
AggregateID string `json:"-" gorm:"column:aggregate_id;primary_key"`
|
|
CreationDate time.Time `json:"-" gorm:"column:creation_date"`
|
|
ChangeDate time.Time `json:"-" gorm:"column:change_date"`
|
|
State int32 `json:"-" gorm:"column:label_policy_state"`
|
|
|
|
PrimaryColor string `json:"primaryColor" gorm:"column:primary_color"`
|
|
SecondaryColor string `json:"secondaryColor" gorm:"column:secondary_color"`
|
|
Default bool `json:"-" gorm:"-"`
|
|
|
|
Sequence uint64 `json:"-" gorm:"column:sequence"`
|
|
}
|
|
|
|
func LabelPolicyViewFromModel(policy *model.LabelPolicyView) *LabelPolicyView {
|
|
return &LabelPolicyView{
|
|
AggregateID: policy.AggregateID,
|
|
Sequence: policy.Sequence,
|
|
CreationDate: policy.CreationDate,
|
|
ChangeDate: policy.ChangeDate,
|
|
PrimaryColor: policy.PrimaryColor,
|
|
SecondaryColor: policy.SecondaryColor,
|
|
Default: policy.Default,
|
|
}
|
|
}
|
|
|
|
func LabelPolicyViewToModel(policy *LabelPolicyView) *model.LabelPolicyView {
|
|
return &model.LabelPolicyView{
|
|
AggregateID: policy.AggregateID,
|
|
Sequence: policy.Sequence,
|
|
CreationDate: policy.CreationDate,
|
|
ChangeDate: policy.ChangeDate,
|
|
PrimaryColor: policy.PrimaryColor,
|
|
SecondaryColor: policy.SecondaryColor,
|
|
Default: policy.Default,
|
|
}
|
|
}
|
|
|
|
func (i *LabelPolicyView) AppendEvent(event *models.Event) (err error) {
|
|
i.Sequence = event.Sequence
|
|
i.ChangeDate = event.CreationDate
|
|
switch event.Type {
|
|
case es_model.LabelPolicyAdded, org_es_model.LabelPolicyAdded:
|
|
i.setRootData(event)
|
|
i.CreationDate = event.CreationDate
|
|
err = i.SetData(event)
|
|
case es_model.LabelPolicyChanged, org_es_model.LabelPolicyChanged:
|
|
err = i.SetData(event)
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (r *LabelPolicyView) setRootData(event *models.Event) {
|
|
r.AggregateID = event.AggregateID
|
|
}
|
|
|
|
func (r *LabelPolicyView) SetData(event *models.Event) error {
|
|
if err := json.Unmarshal(event.Data, r); err != nil {
|
|
logging.Log("MODEL-Flp9C").WithError(err).Error("could not unmarshal event data")
|
|
return caos_errs.ThrowInternal(err, "MODEL-Hs8uf", "Could not unmarshal data")
|
|
}
|
|
return nil
|
|
}
|