mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-07 07:16:54 +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:
@@ -3,7 +3,6 @@ package eventstore
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -14,7 +13,6 @@ import (
|
||||
"github.com/caos/logging"
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
"golang.org/x/text/language"
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
"github.com/caos/zitadel/internal/config/systemdefaults"
|
||||
@@ -206,134 +204,6 @@ func (repo *OrgRepository) SearchIDPProviders(ctx context.Context, request *iam_
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (repo *OrgRepository) GetDefaultMailTemplate(ctx context.Context) (*iam_model.MailTemplateView, error) {
|
||||
template, err := repo.View.MailTemplateByAggregateID(repo.SystemDefaults.IamID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
template.Default = true
|
||||
return iam_view_model.MailTemplateViewToModel(template), err
|
||||
}
|
||||
|
||||
func (repo *OrgRepository) GetMailTemplate(ctx context.Context) (*iam_model.MailTemplateView, error) {
|
||||
template, err := repo.View.MailTemplateByAggregateID(authz.GetCtxData(ctx).OrgID)
|
||||
if errors.IsNotFound(err) {
|
||||
template, err = repo.View.MailTemplateByAggregateID(repo.SystemDefaults.IamID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
template.Default = true
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return iam_view_model.MailTemplateViewToModel(template), err
|
||||
}
|
||||
|
||||
func (repo *OrgRepository) GetDefaultMessageText(ctx context.Context, textType, lang string) (*domain.CustomMessageText, error) {
|
||||
repo.mutex.Lock()
|
||||
defer repo.mutex.Unlock()
|
||||
var err error
|
||||
contents, ok := repo.NotificationTranslationFileContents[lang]
|
||||
if !ok {
|
||||
contents, err = repo.readTranslationFile(repo.NotificationDir, fmt.Sprintf("/i18n/%s.yaml", lang))
|
||||
if errors.IsNotFound(err) {
|
||||
contents, err = repo.readTranslationFile(repo.NotificationDir, fmt.Sprintf("/i18n/%s.yaml", repo.SystemDefaults.DefaultLanguage.String()))
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
repo.NotificationTranslationFileContents[lang] = contents
|
||||
}
|
||||
notificationTextMap := make(map[string]interface{})
|
||||
if err := yaml.Unmarshal(contents, ¬ificationTextMap); err != nil {
|
||||
return nil, errors.ThrowInternal(err, "TEXT-093sd", "Errors.TranslationFile.ReadError")
|
||||
}
|
||||
texts, err := repo.View.CustomTextsByAggregateIDAndTemplateAndLand(repo.SystemDefaults.IamID, textType, lang)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, text := range texts {
|
||||
messageTextMap, ok := notificationTextMap[textType].(map[string]interface{})
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
messageTextMap[text.Key] = text.Text
|
||||
}
|
||||
jsonbody, err := json.Marshal(notificationTextMap)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "TEXT-02m8f", "Errors.TranslationFile.MergeError")
|
||||
}
|
||||
notificationText := new(domain.MessageTexts)
|
||||
if err := json.Unmarshal(jsonbody, ¬ificationText); err != nil {
|
||||
return nil, errors.ThrowInternal(err, "TEXT-20ops", "Errors.TranslationFile.MergeError")
|
||||
}
|
||||
result := notificationText.GetMessageTextByType(textType)
|
||||
result.Default = true
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (repo *OrgRepository) GetMessageText(ctx context.Context, orgID, textType, lang string) (*domain.CustomMessageText, error) {
|
||||
texts, err := repo.View.CustomTextsByAggregateIDAndTemplateAndLand(orgID, textType, lang)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(texts) == 0 {
|
||||
return repo.GetDefaultMessageText(ctx, textType, lang)
|
||||
}
|
||||
return iam_view_model.CustomTextViewsToMessageDomain(repo.SystemDefaults.IamID, lang, texts), err
|
||||
}
|
||||
|
||||
func (repo *OrgRepository) GetDefaultLoginTexts(ctx context.Context, lang string) (*domain.CustomLoginText, error) {
|
||||
repo.mutex.Lock()
|
||||
defer repo.mutex.Unlock()
|
||||
contents, ok := repo.LoginTranslationFileContents[lang]
|
||||
var err error
|
||||
if !ok {
|
||||
contents, err = repo.readTranslationFile(repo.LoginDir, fmt.Sprintf("/i18n/%s.yaml", lang))
|
||||
if errors.IsNotFound(err) {
|
||||
contents, err = repo.readTranslationFile(repo.LoginDir, fmt.Sprintf("/i18n/%s.yaml", repo.SystemDefaults.DefaultLanguage.String()))
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
repo.LoginTranslationFileContents[lang] = contents
|
||||
}
|
||||
loginTextMap := make(map[string]interface{})
|
||||
if err := yaml.Unmarshal(contents, &loginTextMap); err != nil {
|
||||
return nil, errors.ThrowInternal(err, "TEXT-l0fse", "Errors.TranslationFile.ReadError")
|
||||
}
|
||||
texts, err := repo.View.CustomTextsByAggregateIDAndTemplateAndLand(repo.SystemDefaults.IamID, domain.LoginCustomText, lang)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, text := range texts {
|
||||
keys := strings.Split(text.Key, ".")
|
||||
screenTextMap, ok := loginTextMap[keys[0]].(map[string]interface{})
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
screenTextMap[keys[1]] = text.Text
|
||||
}
|
||||
jsonbody, err := json.Marshal(loginTextMap)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "TEXT-2n8fs", "Errors.TranslationFile.MergeError")
|
||||
}
|
||||
loginText := new(domain.CustomLoginText)
|
||||
if err := json.Unmarshal(jsonbody, &loginText); err != nil {
|
||||
return nil, errors.ThrowInternal(err, "TEXT-2n8fs", "Errors.TranslationFile.MergeError")
|
||||
}
|
||||
return loginText, nil
|
||||
}
|
||||
|
||||
func (repo *OrgRepository) GetLoginTexts(ctx context.Context, orgID, lang string) (*domain.CustomLoginText, error) {
|
||||
texts, err := repo.View.CustomTextsByAggregateIDAndTemplateAndLand(orgID, domain.LoginCustomText, lang)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return iam_view_model.CustomTextViewsToLoginDomain(repo.SystemDefaults.IamID, lang, texts), err
|
||||
}
|
||||
|
||||
func (repo *OrgRepository) getOrgChanges(ctx context.Context, orgID string, lastSequence uint64, limit uint64, sortAscending bool, auditLogRetention time.Duration) (*org_model.OrgChanges, error) {
|
||||
query := org_view.ChangesQuery(orgID, lastSequence, limit, sortAscending, auditLogRetention)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user