mirror of
https://github.com/zitadel/zitadel.git
synced 2025-11-15 09:05:26 +00:00
feat: e-mail templates (#1158)
* View definition added * Get templates and texts from the database. * Fill in texts in templates * Fill in texts in templates * Client API added * Weekly backup * Weekly backup * Daily backup * Weekly backup * Tests added * Corrections from merge branch * Fixes from pull request review
This commit is contained in:
24
internal/api/grpc/admin/template.go
Normal file
24
internal/api/grpc/admin/template.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/zitadel/pkg/grpc/admin"
|
||||
"github.com/golang/protobuf/ptypes/empty"
|
||||
)
|
||||
|
||||
func (s *Server) GetDefaultMailTemplate(ctx context.Context, _ *empty.Empty) (*admin.DefaultMailTemplateView, error) {
|
||||
result, err := s.iam.GetDefaultMailTemplate(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return templateViewFromModel(result), nil
|
||||
}
|
||||
|
||||
func (s *Server) UpdateDefaultMailTemplate(ctx context.Context, policy *admin.DefaultMailTemplateUpdate) (*admin.DefaultMailTemplate, error) {
|
||||
result, err := s.iam.ChangeDefaultMailTemplate(ctx, templateToModel(policy))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return templateFromModel(result), nil
|
||||
}
|
||||
42
internal/api/grpc/admin/template_converter.go
Normal file
42
internal/api/grpc/admin/template_converter.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"github.com/caos/logging"
|
||||
iam_model "github.com/caos/zitadel/internal/iam/model"
|
||||
"github.com/caos/zitadel/pkg/grpc/admin"
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
)
|
||||
|
||||
func templateToModel(policy *admin.DefaultMailTemplateUpdate) *iam_model.MailTemplate {
|
||||
return &iam_model.MailTemplate{
|
||||
Template: policy.Template,
|
||||
}
|
||||
}
|
||||
|
||||
func templateFromModel(policy *iam_model.MailTemplate) *admin.DefaultMailTemplate {
|
||||
creationDate, err := ptypes.TimestampProto(policy.CreationDate)
|
||||
logging.Log("ADMIN-CAA7T").OnError(err).Debug("date parse failed")
|
||||
|
||||
changeDate, err := ptypes.TimestampProto(policy.ChangeDate)
|
||||
logging.Log("ADMIN-H52Zx").OnError(err).Debug("date parse failed")
|
||||
|
||||
return &admin.DefaultMailTemplate{
|
||||
Template: policy.Template,
|
||||
CreationDate: creationDate,
|
||||
ChangeDate: changeDate,
|
||||
}
|
||||
}
|
||||
|
||||
func templateViewFromModel(policy *iam_model.MailTemplateView) *admin.DefaultMailTemplateView {
|
||||
creationDate, err := ptypes.TimestampProto(policy.CreationDate)
|
||||
logging.Log("ADMIN-yWFs5").OnError(err).Debug("date parse failed")
|
||||
|
||||
changeDate, err := ptypes.TimestampProto(policy.ChangeDate)
|
||||
logging.Log("ADMIN-JRpIO").OnError(err).Debug("date parse failed")
|
||||
|
||||
return &admin.DefaultMailTemplateView{
|
||||
Template: policy.Template,
|
||||
CreationDate: creationDate,
|
||||
ChangeDate: changeDate,
|
||||
}
|
||||
}
|
||||
32
internal/api/grpc/admin/text.go
Normal file
32
internal/api/grpc/admin/text.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/zitadel/pkg/grpc/admin"
|
||||
"github.com/golang/protobuf/ptypes/empty"
|
||||
)
|
||||
|
||||
func (s *Server) GetDefaultMailTexts(ctx context.Context, _ *empty.Empty) (*admin.DefaultMailTextsView, error) {
|
||||
result, err := s.iam.GetDefaultMailTexts(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return textsViewFromModel(result), nil
|
||||
}
|
||||
|
||||
func (s *Server) GetDefaultMailText(ctx context.Context, textType string, language string) (*admin.DefaultMailTextView, error) {
|
||||
result, err := s.iam.GetDefaultMailText(ctx, textType, language)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return textViewFromModel(result), nil
|
||||
}
|
||||
|
||||
func (s *Server) UpdateDefaultMailText(ctx context.Context, text *admin.DefaultMailTextUpdate) (*admin.DefaultMailText, error) {
|
||||
result, err := s.iam.ChangeDefaultMailText(ctx, textToModel(text))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return textFromModel(result), nil
|
||||
}
|
||||
78
internal/api/grpc/admin/text_converter.go
Normal file
78
internal/api/grpc/admin/text_converter.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"github.com/caos/logging"
|
||||
iam_model "github.com/caos/zitadel/internal/iam/model"
|
||||
"github.com/caos/zitadel/pkg/grpc/admin"
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
)
|
||||
|
||||
func textToModel(text *admin.DefaultMailTextUpdate) *iam_model.MailText {
|
||||
return &iam_model.MailText{
|
||||
MailTextType: text.MailTextType,
|
||||
Language: text.Language,
|
||||
Title: text.Title,
|
||||
PreHeader: text.PreHeader,
|
||||
Subject: text.Subject,
|
||||
Greeting: text.Greeting,
|
||||
Text: text.Text,
|
||||
ButtonText: text.ButtonText,
|
||||
}
|
||||
}
|
||||
|
||||
func textFromModel(text *iam_model.MailText) *admin.DefaultMailText {
|
||||
creationDate, err := ptypes.TimestampProto(text.CreationDate)
|
||||
logging.Log("ADMIN-Jlzsj").OnError(err).Debug("date parse failed")
|
||||
|
||||
changeDate, err := ptypes.TimestampProto(text.ChangeDate)
|
||||
logging.Log("ADMIN-mw5b8").OnError(err).Debug("date parse failed")
|
||||
|
||||
return &admin.DefaultMailText{
|
||||
MailTextType: text.MailTextType,
|
||||
Language: text.Language,
|
||||
Title: text.Title,
|
||||
PreHeader: text.PreHeader,
|
||||
Subject: text.Subject,
|
||||
Greeting: text.Greeting,
|
||||
Text: text.Text,
|
||||
ButtonText: text.ButtonText,
|
||||
CreationDate: creationDate,
|
||||
ChangeDate: changeDate,
|
||||
}
|
||||
}
|
||||
|
||||
func textsViewFromModel(textsin *iam_model.MailTextsView) *admin.DefaultMailTextsView {
|
||||
return &admin.DefaultMailTextsView{
|
||||
Texts: textsViewToModel(textsin.Texts),
|
||||
}
|
||||
}
|
||||
|
||||
func textsViewToModel(queries []*iam_model.MailTextView) []*admin.DefaultMailTextView {
|
||||
modelQueries := make([]*admin.DefaultMailTextView, len(queries))
|
||||
for i, query := range queries {
|
||||
modelQueries[i] = textViewFromModel(query)
|
||||
}
|
||||
|
||||
return modelQueries
|
||||
}
|
||||
|
||||
func textViewFromModel(text *iam_model.MailTextView) *admin.DefaultMailTextView {
|
||||
creationDate, err := ptypes.TimestampProto(text.CreationDate)
|
||||
logging.Log("ADMIN-7RyJc").OnError(err).Debug("date parse failed")
|
||||
|
||||
changeDate, err := ptypes.TimestampProto(text.ChangeDate)
|
||||
logging.Log("ADMIN-fTFgY").OnError(err).Debug("date parse failed")
|
||||
|
||||
return &admin.DefaultMailTextView{
|
||||
MailTextType: text.MailTextType,
|
||||
Language: text.Language,
|
||||
Title: text.Title,
|
||||
PreHeader: text.PreHeader,
|
||||
Subject: text.Subject,
|
||||
Greeting: text.Greeting,
|
||||
Text: text.Text,
|
||||
ButtonText: text.ButtonText,
|
||||
CreationDate: creationDate,
|
||||
ChangeDate: changeDate,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user