Skip to content

Commit

Permalink
Remove namespace on template translations as it's not needed by engin…
Browse files Browse the repository at this point in the history
…e and can be added by mailroom when queueing
  • Loading branch information
rowanseymour committed Jul 3, 2024
1 parent 2459f40 commit 225a83b
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 30 deletions.
9 changes: 2 additions & 7 deletions assets/static/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,14 @@ func (t *Template) Translations() []assets.TemplateTranslation {
type TemplateTranslation struct {
Channel_ *assets.ChannelReference `json:"channel" validate:"required"`
Locale_ i18n.Locale `json:"locale" validate:"required"`
Namespace_ string `json:"namespace"`
Components_ []*TemplateComponent `json:"components"`
Variables_ []*TemplateVariable `json:"variables"`
}

// NewTemplateTranslation creates a new template translation
func NewTemplateTranslation(channel *assets.ChannelReference, locale i18n.Locale, namespace string, components []*TemplateComponent, variables []*TemplateVariable) *TemplateTranslation {
func NewTemplateTranslation(channel *assets.ChannelReference, locale i18n.Locale, components []*TemplateComponent, variables []*TemplateVariable) *TemplateTranslation {
return &TemplateTranslation{
Channel_: channel,
Namespace_: namespace,
Locale_: locale,
Components_: components,
Variables_: variables,
Expand All @@ -74,10 +72,7 @@ func (t *TemplateTranslation) Variables() []assets.TemplateVariable {
return vs
}

// Namespace returns the namespace for this template
func (t *TemplateTranslation) Namespace() string { return t.Namespace_ }

// Language returns the locale this translation is in
// Locale returns the locale this translation is in
func (t *TemplateTranslation) Locale() i18n.Locale { return t.Locale_ }

// Channel returns the channel this template translation is for
Expand Down
4 changes: 1 addition & 3 deletions assets/static/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ func TestTemplate(t *testing.T) {
assert.Equal(t, "", c1.Display())
assert.Equal(t, map[string]int{"1": 0}, c1.Variables())

translation := static.NewTemplateTranslation(channel, i18n.Locale("eng-US"), "0162a7f4_dfe4_4c96_be07_854d5dba3b2b", []*static.TemplateComponent{c1, c2}, []*static.TemplateVariable{v1, v2})
translation := static.NewTemplateTranslation(channel, i18n.Locale("eng-US"), []*static.TemplateComponent{c1, c2}, []*static.TemplateVariable{v1, v2})
assert.Equal(t, channel, translation.Channel())
assert.Equal(t, i18n.Locale("eng-US"), translation.Locale())
assert.Equal(t, "0162a7f4_dfe4_4c96_be07_854d5dba3b2b", translation.Namespace())
assert.Equal(t, []assets.TemplateComponent{
(assets.TemplateComponent)(c1),
(assets.TemplateComponent)(c2),
Expand All @@ -51,5 +50,4 @@ func TestTemplate(t *testing.T) {

assert.Equal(t, copy.Name(), template.Name())
assert.Equal(t, copy.UUID(), template.UUID())
assert.Equal(t, copy.Translations()[0].Namespace(), template.Translations()[0].Namespace())
}
1 change: 0 additions & 1 deletion assets/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ type TemplateComponent interface {
// TemplateTranslation represents a single translation for a specific template and channel
type TemplateTranslation interface {
Locale() i18n.Locale
Namespace() string
Channel() *ChannelReference
Components() []TemplateComponent
Variables() []TemplateVariable
Expand Down
2 changes: 1 addition & 1 deletion flows/actions/send_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (a *SendMsgAction) getTemplateMsg(run flows.Run, urn urns.URN, channelRef *
// the message we return is an approximate preview of what the channel will send using the template
preview := translation.Preview(variables)
locale := translation.Locale()
templating := flows.NewMsgTemplating(a.Template, translation.Namespace(), components, variables)
templating := flows.NewMsgTemplating(a.Template, components, variables)

return flows.NewMsgOut(urn, channelRef, preview.Text, preview.Attachments, preview.QuickReplies, templating, flows.NilMsgTopic, locale, unsendableReason)
}
10 changes: 2 additions & 8 deletions flows/actions/testdata/send_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,6 @@
"uuid": "5722e1fd-fe32-4e74-ac78-3cf41a6adb7e",
"name": "affirmation"
},
"namespace": "",
"components": [
{
"name": "body",
Expand Down Expand Up @@ -535,7 +534,6 @@
"uuid": "5722e1fd-fe32-4e74-ac78-3cf41a6adb7e",
"name": "affirmation"
},
"namespace": "",
"components": [
{
"name": "body",
Expand Down Expand Up @@ -615,8 +613,7 @@
"template": {
"uuid": "2edc8dfd-aef0-41cf-a900-8a71bdb00900",
"name": "wakeup"
},
"namespace": ""
}
},
"locale": "eng"
}
Expand Down Expand Up @@ -679,8 +676,7 @@
"template": {
"uuid": "2edc8dfd-aef0-41cf-a900-8a71bdb00900",
"name": "wakeup"
},
"namespace": ""
}
},
"locale": "eng"
}
Expand Down Expand Up @@ -840,7 +836,6 @@
"uuid": "ce00c80e-991a-4c03-b373-3273c23ee042",
"name": "gender_update"
},
"namespace": "",
"components": [
{
"name": "body",
Expand Down Expand Up @@ -952,7 +947,6 @@
"uuid": "be68beff-1a5b-424b-815e-023cc53c1ddc",
"name": "cat_fact"
},
"namespace": "",
"components": [
{
"name": "header",
Expand Down
5 changes: 2 additions & 3 deletions flows/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,13 @@ type TemplatingComponent struct {
// MsgTemplating represents any substituted message template that should be applied when sending this message
type MsgTemplating struct {
Template *assets.TemplateReference `json:"template"`
Namespace string `json:"namespace"`
Components []*TemplatingComponent `json:"components,omitempty"`
Variables []*TemplatingVariable `json:"variables,omitempty"`
}

// NewMsgTemplating creates and returns a new msg template
func NewMsgTemplating(template *assets.TemplateReference, namespace string, components []*TemplatingComponent, variables []*TemplatingVariable) *MsgTemplating {
return &MsgTemplating{Template: template, Namespace: namespace, Components: components, Variables: variables}
func NewMsgTemplating(template *assets.TemplateReference, components []*TemplatingComponent, variables []*TemplatingVariable) *MsgTemplating {
return &MsgTemplating{Template: template, Components: components, Variables: variables}
}

// MsgContent is message content in a particular language
Expand Down
3 changes: 0 additions & 3 deletions flows/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,11 @@ func TestMsgTemplating(t *testing.T) {

msgTemplating := flows.NewMsgTemplating(
templateRef,
"0162a7f4_dfe4_4c96_be07_854d5dba3b2b",
[]*flows.TemplatingComponent{{Type: "body/text", Name: "body", Variables: map[string]int{"1": 0, "2": 1}}},
[]*flows.TemplatingVariable{{Type: "text", Value: "Ryan Lewis"}, {Type: "text", Value: "boy"}},
)

assert.Equal(t, templateRef, msgTemplating.Template)
assert.Equal(t, "0162a7f4_dfe4_4c96_be07_854d5dba3b2b", msgTemplating.Namespace)
assert.Equal(t, []*flows.TemplatingComponent{{Type: "body/text", Name: "body", Variables: map[string]int{"1": 0, "2": 1}}}, msgTemplating.Components)
assert.Equal(t, []*flows.TemplatingVariable{{Type: "text", Value: "Ryan Lewis"}, {Type: "text", Value: "boy"}}, msgTemplating.Variables)

Expand All @@ -237,7 +235,6 @@ func TestMsgTemplating(t *testing.T) {
"name":"Affirmation",
"uuid":"61602f3e-f603-4c70-8a8f-c477505bf4bf"
},
"namespace":"0162a7f4_dfe4_4c96_be07_854d5dba3b2b",
"components":[
{
"name": "body",
Expand Down
8 changes: 4 additions & 4 deletions flows/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ func TestFindTranslation(t *testing.T) {
channel1Ref := assets.NewChannelReference(channel1.UUID(), channel1.Name())
channel2Ref := assets.NewChannelReference(channel2.UUID(), channel2.Name())

tt1 := static.NewTemplateTranslation(channel1Ref, i18n.Locale("eng"), "", []*static.TemplateComponent{}, []*static.TemplateVariable{})
tt2 := static.NewTemplateTranslation(channel1Ref, i18n.Locale("spa-EC"), "", []*static.TemplateComponent{}, []*static.TemplateVariable{})
tt3 := static.NewTemplateTranslation(channel1Ref, i18n.Locale("spa-ES"), "", []*static.TemplateComponent{}, []*static.TemplateVariable{})
tt4 := static.NewTemplateTranslation(channel2Ref, i18n.Locale("kin"), "", []*static.TemplateComponent{}, []*static.TemplateVariable{})
tt1 := static.NewTemplateTranslation(channel1Ref, i18n.Locale("eng"), []*static.TemplateComponent{}, []*static.TemplateVariable{})
tt2 := static.NewTemplateTranslation(channel1Ref, i18n.Locale("spa-EC"), []*static.TemplateComponent{}, []*static.TemplateVariable{})
tt3 := static.NewTemplateTranslation(channel1Ref, i18n.Locale("spa-ES"), []*static.TemplateComponent{}, []*static.TemplateVariable{})
tt4 := static.NewTemplateTranslation(channel2Ref, i18n.Locale("kin"), []*static.TemplateComponent{}, []*static.TemplateVariable{})

template := flows.NewTemplate(static.NewTemplate("c520cbda-e118-440f-aaf6-c0485088384f", "greeting", []*static.TemplateTranslation{tt1, tt2, tt3, tt4}))
tas := flows.NewTemplateAssets([]assets.Template{template})
Expand Down

0 comments on commit 225a83b

Please sign in to comment.