mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 11:34: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>
68 lines
2.1 KiB
Go
68 lines
2.1 KiB
Go
package handler
|
|
|
|
import (
|
|
"github.com/caos/logging"
|
|
iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
|
|
|
"github.com/caos/zitadel/internal/eventstore/models"
|
|
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
|
"github.com/caos/zitadel/internal/eventstore/spooler"
|
|
iam_model "github.com/caos/zitadel/internal/iam/repository/view/model"
|
|
"github.com/caos/zitadel/internal/org/repository/eventsourcing/model"
|
|
)
|
|
|
|
type LabelPolicy struct {
|
|
handler
|
|
}
|
|
|
|
const (
|
|
labelPolicyTable = "management.label_policies"
|
|
)
|
|
|
|
func (m *LabelPolicy) ViewModel() string {
|
|
return labelPolicyTable
|
|
}
|
|
|
|
func (m *LabelPolicy) EventQuery() (*models.SearchQuery, error) {
|
|
sequence, err := m.view.GetLatestLabelPolicySequence()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return es_models.NewSearchQuery().
|
|
AggregateTypeFilter(model.OrgAggregate, iam_es_model.IAMAggregate).
|
|
LatestSequenceFilter(sequence.CurrentSequence), nil
|
|
}
|
|
|
|
func (m *LabelPolicy) Reduce(event *models.Event) (err error) {
|
|
switch event.AggregateType {
|
|
case model.OrgAggregate, iam_es_model.IAMAggregate:
|
|
err = m.processLabelPolicy(event)
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (m *LabelPolicy) processLabelPolicy(event *models.Event) (err error) {
|
|
policy := new(iam_model.LabelPolicyView)
|
|
switch event.Type {
|
|
case iam_es_model.LabelPolicyAdded, model.LabelPolicyAdded:
|
|
err = policy.AppendEvent(event)
|
|
case iam_es_model.LabelPolicyChanged, model.LabelPolicyChanged:
|
|
policy, err = m.view.LabelPolicyByAggregateID(event.AggregateID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = policy.AppendEvent(event)
|
|
default:
|
|
return m.view.ProcessedLabelPolicySequence(event.Sequence)
|
|
}
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return m.view.PutLabelPolicy(policy, policy.Sequence)
|
|
}
|
|
|
|
func (m *LabelPolicy) OnError(event *models.Event, err error) error {
|
|
logging.LogWithFields("SPOOL-4Djo9", "id", event.AggregateID).WithError(err).Warn("something went wrong in label policy handler")
|
|
return spooler.HandleError(event, err, m.view.GetLatestLabelPolicyFailedEvent, m.view.ProcessedLabelPolicyFailedEvent, m.view.ProcessedLabelPolicySequence, m.errorCountUntilSkip)
|
|
}
|