mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 18:17:35 +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:
@@ -1,46 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"time"
|
||||
)
|
||||
|
||||
type MailTemplateView struct {
|
||||
AggregateID string
|
||||
Template []byte
|
||||
Default bool
|
||||
|
||||
CreationDate time.Time
|
||||
ChangeDate time.Time
|
||||
Sequence uint64
|
||||
}
|
||||
|
||||
type MailTemplateSearchRequest struct {
|
||||
Offset uint64
|
||||
Limit uint64
|
||||
SortingColumn MailTemplateSearchKey
|
||||
Asc bool
|
||||
Queries []*MailTemplateSearchQuery
|
||||
}
|
||||
|
||||
type MailTemplateSearchKey int32
|
||||
|
||||
const (
|
||||
MailTemplateSearchKeyUnspecified MailTemplateSearchKey = iota
|
||||
MailTemplateSearchKeyAggregateID
|
||||
)
|
||||
|
||||
type MailTemplateSearchQuery struct {
|
||||
Key MailTemplateSearchKey
|
||||
Method domain.SearchMethod
|
||||
Value interface{}
|
||||
}
|
||||
|
||||
type MailTemplateSearchResponse struct {
|
||||
Offset uint64
|
||||
Limit uint64
|
||||
TotalResult uint64
|
||||
Result []*MailTemplateView
|
||||
Sequence uint64
|
||||
Timestamp time.Time
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
iam_model "github.com/caos/zitadel/internal/iam/model"
|
||||
"github.com/caos/zitadel/internal/iam/repository/view/model"
|
||||
"github.com/caos/zitadel/internal/view/repository"
|
||||
"github.com/jinzhu/gorm"
|
||||
)
|
||||
|
||||
func GetMailTemplateByAggregateID(db *gorm.DB, table, aggregateID string) (*model.MailTemplateView, error) {
|
||||
template := new(model.MailTemplateView)
|
||||
aggregateIDQuery := &model.MailTemplateSearchQuery{Key: iam_model.MailTemplateSearchKeyAggregateID, Value: aggregateID, Method: domain.SearchMethodEquals}
|
||||
query := repository.PrepareGetByQuery(table, aggregateIDQuery)
|
||||
err := query(db, template)
|
||||
if caos_errs.IsNotFound(err) {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "VIEW-iPnmU", "Errors.IAM.MailTemplate.NotExisting")
|
||||
}
|
||||
return template, err
|
||||
}
|
||||
|
||||
func PutMailTemplate(db *gorm.DB, table string, template *model.MailTemplateView) error {
|
||||
save := repository.PrepareSave(table)
|
||||
return save(db, template)
|
||||
}
|
||||
|
||||
func DeleteMailTemplate(db *gorm.DB, table, aggregateID string) error {
|
||||
delete := repository.PrepareDeleteByKey(table, model.MailTemplateSearchKey(iam_model.MailTemplateSearchKeyAggregateID), aggregateID)
|
||||
|
||||
return delete(db)
|
||||
}
|
@@ -38,30 +38,6 @@ type CustomTextView struct {
|
||||
Sequence uint64 `json:"-" gorm:"column:sequence"`
|
||||
}
|
||||
|
||||
func CustomTextViewsToDomain(texts []*CustomTextView) []*domain.CustomText {
|
||||
result := make([]*domain.CustomText, len(texts))
|
||||
for i, text := range texts {
|
||||
result[i] = CustomTextViewToDomain(text)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func CustomTextViewToDomain(text *CustomTextView) *domain.CustomText {
|
||||
lang := language.Make(text.Language)
|
||||
return &domain.CustomText{
|
||||
ObjectRoot: models.ObjectRoot{
|
||||
AggregateID: text.AggregateID,
|
||||
Sequence: text.Sequence,
|
||||
CreationDate: text.CreationDate,
|
||||
ChangeDate: text.ChangeDate,
|
||||
},
|
||||
Template: text.Template,
|
||||
Language: lang,
|
||||
Key: text.Key,
|
||||
Text: text.Text,
|
||||
}
|
||||
}
|
||||
|
||||
func (i *CustomTextView) AppendEvent(event *models.Event) (err error) {
|
||||
i.Sequence = event.Sequence
|
||||
switch event.Type {
|
||||
@@ -97,46 +73,6 @@ func (r *CustomTextView) IsMessageTemplate() bool {
|
||||
r.Template == domain.PasswordlessRegistrationMessageType
|
||||
}
|
||||
|
||||
func CustomTextViewsToMessageDomain(aggregateID, lang string, texts []*CustomTextView) *domain.CustomMessageText {
|
||||
langTag := language.Make(lang)
|
||||
result := &domain.CustomMessageText{
|
||||
ObjectRoot: models.ObjectRoot{
|
||||
AggregateID: aggregateID,
|
||||
},
|
||||
Language: langTag,
|
||||
}
|
||||
for _, text := range texts {
|
||||
if text.CreationDate.Before(result.CreationDate) {
|
||||
result.CreationDate = text.CreationDate
|
||||
}
|
||||
if text.ChangeDate.After(result.ChangeDate) {
|
||||
result.ChangeDate = text.ChangeDate
|
||||
}
|
||||
if text.Key == domain.MessageTitle {
|
||||
result.Title = text.Text
|
||||
}
|
||||
if text.Key == domain.MessagePreHeader {
|
||||
result.PreHeader = text.Text
|
||||
}
|
||||
if text.Key == domain.MessageSubject {
|
||||
result.Subject = text.Text
|
||||
}
|
||||
if text.Key == domain.MessageGreeting {
|
||||
result.Greeting = text.Text
|
||||
}
|
||||
if text.Key == domain.MessageText {
|
||||
result.Text = text.Text
|
||||
}
|
||||
if text.Key == domain.MessageButtonText {
|
||||
result.ButtonText = text.Text
|
||||
}
|
||||
if text.Key == domain.MessageFooterText {
|
||||
result.FooterText = text.Text
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func CustomTextViewsToLoginDomain(aggregateID, lang string, texts []*CustomTextView) *domain.CustomLoginText {
|
||||
langTag := language.Make(lang)
|
||||
result := &domain.CustomLoginText{
|
||||
|
@@ -1,80 +0,0 @@
|
||||
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/v1/models"
|
||||
"github.com/caos/zitadel/internal/iam/model"
|
||||
)
|
||||
|
||||
const (
|
||||
MailTemplateKeyAggregateID = "aggregate_id"
|
||||
)
|
||||
|
||||
type MailTemplateView 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:mail_template_state"`
|
||||
|
||||
Template []byte `json:"template" gorm:"column:template"`
|
||||
Default bool `json:"-" gorm:"-"`
|
||||
|
||||
Sequence uint64 `json:"-" gorm:"column:sequence"`
|
||||
}
|
||||
|
||||
func MailTemplateViewFromModel(template *model.MailTemplateView) *MailTemplateView {
|
||||
return &MailTemplateView{
|
||||
AggregateID: template.AggregateID,
|
||||
Sequence: template.Sequence,
|
||||
CreationDate: template.CreationDate,
|
||||
ChangeDate: template.ChangeDate,
|
||||
Template: template.Template,
|
||||
Default: template.Default,
|
||||
}
|
||||
}
|
||||
|
||||
func MailTemplateViewToModel(template *MailTemplateView) *model.MailTemplateView {
|
||||
return &model.MailTemplateView{
|
||||
AggregateID: template.AggregateID,
|
||||
Sequence: template.Sequence,
|
||||
CreationDate: template.CreationDate,
|
||||
ChangeDate: template.ChangeDate,
|
||||
Template: template.Template,
|
||||
Default: template.Default,
|
||||
}
|
||||
}
|
||||
|
||||
func (i *MailTemplateView) AppendEvent(event *models.Event) (err error) {
|
||||
i.Sequence = event.Sequence
|
||||
i.ChangeDate = event.CreationDate
|
||||
switch event.Type {
|
||||
case es_model.MailTemplateAdded, org_es_model.MailTemplateAdded:
|
||||
i.setRootData(event)
|
||||
i.CreationDate = event.CreationDate
|
||||
err = i.SetData(event)
|
||||
case es_model.MailTemplateChanged, org_es_model.MailTemplateChanged:
|
||||
i.ChangeDate = event.CreationDate
|
||||
err = i.SetData(event)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *MailTemplateView) setRootData(event *models.Event) {
|
||||
r.AggregateID = event.AggregateID
|
||||
}
|
||||
|
||||
func (r *MailTemplateView) SetData(event *models.Event) error {
|
||||
if err := json.Unmarshal(event.Data, r); err != nil {
|
||||
logging.Log("MODEL-YDZmZ").WithError(err).Error("could not unmarshal event data")
|
||||
return caos_errs.ThrowInternal(err, "MODEL-sKWwO", "Could not unmarshal data")
|
||||
}
|
||||
return nil
|
||||
}
|
@@ -1,59 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
iam_model "github.com/caos/zitadel/internal/iam/model"
|
||||
"github.com/caos/zitadel/internal/view/repository"
|
||||
)
|
||||
|
||||
type MailTemplateSearchRequest iam_model.MailTemplateSearchRequest
|
||||
type MailTemplateSearchQuery iam_model.MailTemplateSearchQuery
|
||||
type MailTemplateSearchKey iam_model.MailTemplateSearchKey
|
||||
|
||||
func (req MailTemplateSearchRequest) GetLimit() uint64 {
|
||||
return req.Limit
|
||||
}
|
||||
|
||||
func (req MailTemplateSearchRequest) GetOffset() uint64 {
|
||||
return req.Offset
|
||||
}
|
||||
|
||||
func (req MailTemplateSearchRequest) GetSortingColumn() repository.ColumnKey {
|
||||
if req.SortingColumn == iam_model.MailTemplateSearchKeyUnspecified {
|
||||
return nil
|
||||
}
|
||||
return MailTemplateSearchKey(req.SortingColumn)
|
||||
}
|
||||
|
||||
func (req MailTemplateSearchRequest) GetAsc() bool {
|
||||
return req.Asc
|
||||
}
|
||||
|
||||
func (req MailTemplateSearchRequest) GetQueries() []repository.SearchQuery {
|
||||
result := make([]repository.SearchQuery, len(req.Queries))
|
||||
for i, q := range req.Queries {
|
||||
result[i] = MailTemplateSearchQuery{Key: q.Key, Value: q.Value, Method: q.Method}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (req MailTemplateSearchQuery) GetKey() repository.ColumnKey {
|
||||
return MailTemplateSearchKey(req.Key)
|
||||
}
|
||||
|
||||
func (req MailTemplateSearchQuery) GetMethod() domain.SearchMethod {
|
||||
return req.Method
|
||||
}
|
||||
|
||||
func (req MailTemplateSearchQuery) GetValue() interface{} {
|
||||
return req.Value
|
||||
}
|
||||
|
||||
func (key MailTemplateSearchKey) ToColumnName() string {
|
||||
switch iam_model.MailTemplateSearchKey(key) {
|
||||
case iam_model.MailTemplateSearchKeyAggregateID:
|
||||
return MailTemplateKeyAggregateID
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user