mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 00:57:33 +00:00
feat: text query (#2735)
* feat: change mail template to new query side * feat: adminapi message text * feat: adminapi message text * feat: adminapi message text * feat: message texts * feat: admin texts * feat: tests * feat: tests * feat: custom login text on adminapi * feat: custom login text * feat: custom login text * feat: message text prepare test * feat: login text texts * feat: custom login text * merge main * fix go.sum Co-authored-by: Livio Amstutz <livio.a@gmail.com>
This commit is contained in:
@@ -991,11 +991,11 @@ func labelPolicyToDomain(p *query.LabelPolicy) *domain.LabelPolicy {
|
||||
}
|
||||
|
||||
func (repo *AuthRequestRepo) getLoginTexts(ctx context.Context, aggregateID string) ([]*domain.CustomText, error) {
|
||||
loginTexts, err := repo.View.CustomTextsByAggregateIDAndTemplate(aggregateID, domain.LoginCustomText)
|
||||
loginTexts, err := repo.Query.CustomTextListByTemplate(ctx, aggregateID, domain.LoginCustomText)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return iam_view_model.CustomTextViewsToDomain(loginTexts), err
|
||||
return query.CustomTextsToDomain(loginTexts), err
|
||||
}
|
||||
|
||||
func (repo *AuthRequestRepo) hasSucceededPage(ctx context.Context, request *domain.AuthRequest, provider applicationProvider) (bool, error) {
|
||||
|
@@ -41,15 +41,15 @@ func (repo *OrgRepository) GetMyPasswordComplexityPolicy(ctx context.Context) (*
|
||||
}
|
||||
|
||||
func (repo *OrgRepository) GetLoginText(ctx context.Context, orgID string) ([]*domain.CustomText, error) {
|
||||
loginTexts, err := repo.View.CustomTextsByAggregateIDAndTemplate(domain.IAMID, domain.LoginCustomText)
|
||||
loginTexts, err := repo.Query.CustomTextListByTemplate(ctx, domain.IAMID, domain.LoginCustomText)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
orgLoginTexts, err := repo.View.CustomTextsByAggregateIDAndTemplate(orgID, domain.LoginCustomText)
|
||||
orgLoginTexts, err := repo.Query.CustomTextListByTemplate(ctx, orgID, domain.LoginCustomText)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return append(iam_view_model.CustomTextViewsToDomain(loginTexts), iam_view_model.CustomTextViewsToDomain(orgLoginTexts)...), nil
|
||||
return append(query.CustomTextsToDomain(loginTexts), query.CustomTextsToDomain(orgLoginTexts)...), nil
|
||||
}
|
||||
|
||||
func (p *OrgRepository) getIAMEvents(ctx context.Context, sequence uint64) ([]*models.Event, error) {
|
||||
|
@@ -1,132 +0,0 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"github.com/caos/logging"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore/v1"
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
"github.com/caos/zitadel/internal/eventstore/v1/query"
|
||||
"github.com/caos/zitadel/internal/eventstore/v1/spooler"
|
||||
iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
||||
iam_model "github.com/caos/zitadel/internal/iam/repository/view/model"
|
||||
"github.com/caos/zitadel/internal/org/repository/eventsourcing/model"
|
||||
)
|
||||
|
||||
type CustomText struct {
|
||||
handler
|
||||
subscription *v1.Subscription
|
||||
}
|
||||
|
||||
func newCustomText(handler handler) *CustomText {
|
||||
h := &CustomText{
|
||||
handler: handler,
|
||||
}
|
||||
|
||||
h.subscribe()
|
||||
|
||||
return h
|
||||
}
|
||||
|
||||
func (m *CustomText) subscribe() {
|
||||
m.subscription = m.es.Subscribe(m.AggregateTypes()...)
|
||||
go func() {
|
||||
for event := range m.subscription.Events {
|
||||
query.ReduceEvent(m, event)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
const (
|
||||
customTextTable = "auth.custom_texts"
|
||||
)
|
||||
|
||||
func (m *CustomText) ViewModel() string {
|
||||
return customTextTable
|
||||
}
|
||||
|
||||
func (m *CustomText) Subscription() *v1.Subscription {
|
||||
return m.subscription
|
||||
}
|
||||
|
||||
func (_ *CustomText) AggregateTypes() []es_models.AggregateType {
|
||||
return []es_models.AggregateType{model.OrgAggregate, iam_es_model.IAMAggregate}
|
||||
}
|
||||
|
||||
func (p *CustomText) CurrentSequence() (uint64, error) {
|
||||
sequence, err := p.view.GetLatestCustomTextSequence()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return sequence.CurrentSequence, nil
|
||||
}
|
||||
|
||||
func (m *CustomText) EventQuery() (*es_models.SearchQuery, error) {
|
||||
sequence, err := m.view.GetLatestCustomTextSequence()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return es_models.NewSearchQuery().
|
||||
AggregateTypeFilter(m.AggregateTypes()...).
|
||||
LatestSequenceFilter(sequence.CurrentSequence), nil
|
||||
}
|
||||
|
||||
func (m *CustomText) Reduce(event *es_models.Event) (err error) {
|
||||
switch event.AggregateType {
|
||||
case model.OrgAggregate, iam_es_model.IAMAggregate:
|
||||
err = m.processCustomText(event)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *CustomText) processCustomText(event *es_models.Event) (err error) {
|
||||
customText := new(iam_model.CustomTextView)
|
||||
switch event.Type {
|
||||
case iam_es_model.CustomTextSet, model.CustomTextSet:
|
||||
text := new(iam_model.CustomTextView)
|
||||
err = text.SetData(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
customText, err = m.view.CustomTextByIDs(event.AggregateID, text.Template, text.Key, text.Language)
|
||||
if err != nil && !caos_errs.IsNotFound(err) {
|
||||
return err
|
||||
}
|
||||
if caos_errs.IsNotFound(err) {
|
||||
err = nil
|
||||
customText = new(iam_model.CustomTextView)
|
||||
customText.Language = text.Language
|
||||
customText.Template = text.Template
|
||||
customText.CreationDate = event.CreationDate
|
||||
}
|
||||
err = customText.AppendEvent(event)
|
||||
case iam_es_model.CustomTextRemoved, model.CustomTextRemoved:
|
||||
text := new(iam_model.CustomTextView)
|
||||
err = text.SetData(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return m.view.DeleteCustomText(event.AggregateID, text.Template, text.Language, text.Key, event)
|
||||
case iam_es_model.CustomTextMessageRemoved, model.CustomTextMessageRemoved:
|
||||
text := new(iam_model.CustomTextView)
|
||||
err = text.SetData(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return m.view.DeleteCustomTextTemplate(event.AggregateID, text.Template, text.Language, event)
|
||||
default:
|
||||
return m.view.ProcessedCustomTextSequence(event)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return m.view.PutCustomText(customText, event)
|
||||
}
|
||||
|
||||
func (m *CustomText) OnError(event *es_models.Event, err error) error {
|
||||
logging.LogWithFields("SPOOL-3m0fs", "id", event.AggregateID).WithError(err).Warn("something went wrong in custom text handler")
|
||||
return spooler.HandleError(event, err, m.view.GetLatestCustomTextFailedEvent, m.view.ProcessedCustomTextFailedEvent, m.view.ProcessedCustomTextSequence, m.errorCountUntilSkip)
|
||||
}
|
||||
|
||||
func (o *CustomText) OnSuccess() error {
|
||||
return spooler.HandleSuccess(o.view.UpdateCustomTextSpoolerRunTimestamp)
|
||||
}
|
@@ -56,7 +56,6 @@ func Register(configs Configs, bulkLimit, errorCount uint64, view *view.View, es
|
||||
handler{view, bulkLimit, configs.cycleDuration("ExternalIDP"), errorCount, es},
|
||||
systemDefaults),
|
||||
newRefreshToken(handler{view, bulkLimit, configs.cycleDuration("RefreshToken"), errorCount, es}),
|
||||
newCustomText(handler{view, bulkLimit, configs.cycleDuration("CustomTexts"), errorCount, es}),
|
||||
newMetadata(handler{view, bulkLimit, configs.cycleDuration("Metadata"), errorCount, es}),
|
||||
newOrgProjectMapping(handler{view, bulkLimit, configs.cycleDuration("OrgProjectMapping"), errorCount, es}),
|
||||
}
|
||||
|
@@ -108,6 +108,7 @@ func Start(conf Config, authZ authz.Config, systemDefaults sd.SystemDefaults, co
|
||||
PrivacyPolicyProvider: queries,
|
||||
LabelPolicyProvider: queries,
|
||||
Command: command,
|
||||
Query: queries,
|
||||
OrgViewProvider: queries,
|
||||
AuthRequests: authReq,
|
||||
View: view,
|
||||
@@ -119,7 +120,6 @@ func Start(conf Config, authZ authz.Config, systemDefaults sd.SystemDefaults, co
|
||||
IDPProviderViewProvider: view,
|
||||
LockoutPolicyViewProvider: queries,
|
||||
LoginPolicyViewProvider: queries,
|
||||
Query: queries,
|
||||
UserGrantProvider: queryView,
|
||||
ProjectProvider: queryView,
|
||||
ApplicationProvider: queries,
|
||||
|
@@ -1,69 +0,0 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
"github.com/caos/zitadel/internal/iam/repository/view"
|
||||
"github.com/caos/zitadel/internal/iam/repository/view/model"
|
||||
global_view "github.com/caos/zitadel/internal/view/repository"
|
||||
)
|
||||
|
||||
const (
|
||||
customTextTable = "auth.custom_texts"
|
||||
)
|
||||
|
||||
func (v *View) CustomTextByIDs(aggregateID, template, lang, key string) (*model.CustomTextView, error) {
|
||||
return view.CustomTextByIDs(v.Db, customTextTable, aggregateID, template, lang, key)
|
||||
}
|
||||
|
||||
func (v *View) CustomTextsByAggregateIDAndTemplateAndLand(aggregateID, template, lang string) ([]*model.CustomTextView, error) {
|
||||
return view.GetCustomTexts(v.Db, customTextTable, aggregateID, template, lang)
|
||||
}
|
||||
|
||||
func (v *View) CustomTextsByAggregateIDAndTemplate(aggregateID, template string) ([]*model.CustomTextView, error) {
|
||||
return view.GetCustomTextsByAggregateIDAndTemplate(v.Db, customTextTable, aggregateID, template)
|
||||
}
|
||||
|
||||
func (v *View) PutCustomText(template *model.CustomTextView, event *models.Event) error {
|
||||
err := view.PutCustomText(v.Db, customTextTable, template)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return v.ProcessedCustomTextSequence(event)
|
||||
}
|
||||
|
||||
func (v *View) DeleteCustomText(aggregateID, textType, lang, key string, event *models.Event) error {
|
||||
err := view.DeleteCustomText(v.Db, customTextTable, aggregateID, textType, lang, key)
|
||||
if err != nil && !errors.IsNotFound(err) {
|
||||
return err
|
||||
}
|
||||
return v.ProcessedCustomTextSequence(event)
|
||||
}
|
||||
|
||||
func (v *View) DeleteCustomTextTemplate(aggregateID, textType, lang string, event *models.Event) error {
|
||||
err := view.DeleteCustomTextTemplate(v.Db, customTextTable, aggregateID, textType, lang)
|
||||
if err != nil && !errors.IsNotFound(err) {
|
||||
return err
|
||||
}
|
||||
return v.ProcessedCustomTextSequence(event)
|
||||
}
|
||||
|
||||
func (v *View) GetLatestCustomTextSequence() (*global_view.CurrentSequence, error) {
|
||||
return v.latestSequence(customTextTable)
|
||||
}
|
||||
|
||||
func (v *View) ProcessedCustomTextSequence(event *models.Event) error {
|
||||
return v.saveCurrentSequence(customTextTable, event)
|
||||
}
|
||||
|
||||
func (v *View) UpdateCustomTextSpoolerRunTimestamp() error {
|
||||
return v.updateSpoolerRunSequence(customTextTable)
|
||||
}
|
||||
|
||||
func (v *View) GetLatestCustomTextFailedEvent(sequence uint64) (*global_view.FailedEvent, error) {
|
||||
return v.latestFailedEvent(customTextTable, sequence)
|
||||
}
|
||||
|
||||
func (v *View) ProcessedCustomTextFailedEvent(failedEvent *global_view.FailedEvent) error {
|
||||
return v.saveFailedEvent(failedEvent)
|
||||
}
|
Reference in New Issue
Block a user