Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Add Multi-SMS template columns to realm db #1325

Merged
merged 13 commits into from
Dec 14, 2020

Conversation

whaught
Copy link
Contributor

@whaught whaught commented Dec 11, 2020

Issue #1320

Proposed Changes

  • Add fields for alternate SMS templates + labels
    • (original field will be 'default')
  • Add validation for all templates
  • Add a unit test for Realm validation
Enable postgres hstore. Add fields to realm to store multiple SMS templates and add validation for them.

@googlebot googlebot added the cla: yes Auto: added by CLA bot when all committers have signed a CLA. label Dec 11, 2020
pkg/database/migrations.go Outdated Show resolved Hide resolved
pkg/database/migrations.go Outdated Show resolved Hide resolved
// Check that we have exactly one of [code] or [longcode] as template substitutions.
if c, lc := strings.Contains(r.SMSTextTemplate, SMSCode), strings.Contains(r.SMSTextTemplate, SMSLongCode); !(c || lc) || (c && lc) {
r.AddError("SMSTextTemplate", fmt.Sprintf("must contain exactly one of %q or %q", SMSCode, SMSLongCode))
r.validateSMSTemplate(r.SMSTextTemplate)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This API is a bit weird since it doesn't return anything. I don't have a better solution though.

pkg/database/realm.go Outdated Show resolved Hide resolved
pkg/database/realm.go Show resolved Hide resolved
pkg/database/realm.go Outdated Show resolved Hide resolved
func (r *Realm) validateSMSTemplate(t string) {
if r.EnableENExpress {
if !strings.Contains(t, SMSENExpressLink) {
r.AddError("SMSTextTemplate", fmt.Sprintf("must contain %q", SMSENExpressLink))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these errors aren't going to be right, since they are for SMSTextTemplate

validation is going to be tricky...

this is where I think breaking these out into a separate table so you had a stable ID that could be part of a form field ID would be valuable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should Take the field name as another param to this function. We could also prefix the error with the label name for alt templates.

That being said, we'll mark these as required in the HTML, so the only way someone gets to these errors is if they do some significant mucking about. I think it's probably fine to keep this as-is and create a follow-up issue to make it betterer in the future. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can also include the label in the error message - I'm worried about a user not being able to tell where the error is
and therefore not be able to fix it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine w/ doing the follow up when the UI is added.

Copy link
Member

@sethvargo sethvargo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/hold

pkg/database/migrations.go Show resolved Hide resolved
func (r *Realm) validateSMSTemplate(t string) {
if r.EnableENExpress {
if !strings.Contains(t, SMSENExpressLink) {
r.AddError("SMSTextTemplate", fmt.Sprintf("must contain %q", SMSENExpressLink))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should Take the field name as another param to this function. We could also prefix the error with the label name for alt templates.

That being said, we'll mark these as required in the HTML, so the only way someone gets to these errors is if they do some significant mucking about. I think it's probably fine to keep this as-is and create a follow-up issue to make it betterer in the future. WDYT?

@google-oss-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sethvargo, whaught

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Contributor

@mikehelmick mikehelmick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@whaught
Copy link
Contributor Author

whaught commented Dec 14, 2020

/unhold

I hear you on errors - I was intending to solve that in the follow up with more complete UX

@google-oss-robot google-oss-robot merged commit 6c18437 into google:main Dec 14, 2020
@whaught whaught deleted the multi-template branch December 14, 2020 23:29
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes Auto: added by CLA bot when all committers have signed a CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants