Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

email.templates: add configurable templates for setPassword, resetPassword#45671

Merged
bobheadxi merged 4 commits into
mainfrom
configurable-email-templates
Dec 15, 2022
Merged

email.templates: add configurable templates for setPassword, resetPassword#45671
bobheadxi merged 4 commits into
mainfrom
configurable-email-templates

Conversation

@bobheadxi

Copy link
Copy Markdown
Member

This allows Cloud and Growth to customize emails sent to customers when creating users and resetting their passwords, which typically means customer side admins. The changes add:

  • a new site configuration field, email.templates, that allows us to add configurable templates for various emails that get sent out
  • site configuration validator for email.templates fields to ensure they are valid
  • configurable email templates for setting passwords (on user creation) and resetting passwords

Closes https://github.com/sourcegraph/customer/issues/1719

Test plan

Add a template:

  "email.templates": {
    "setPassword": {
      "subject": "Welcome to Sourcegraph Cloud!",
      "html": "<p>\nWelcome to Sourcegraph Cloud! An instance has been created for you at {{.Host}}.\n</p>\n<p>To get started, <strong><a href=\"{{.URL}}\">set the password for your account, {{.Username}}</a></strong>.</p>",
      "text": "Welcome to Sourcegraph Cloud! An instance has been created for you at {{.Host}}. To get started, set the password for your account, {{.Username}}: {{.URL}}"
    }
  },

Create a user in the admin UI:

image

Some simple unit tests were also added.

Also note that inline documentation is available about what each template accepts:

image

@cla-bot cla-bot Bot added the cla-signed label Dec 14, 2022
@bobheadxi bobheadxi requested review from a team, danieldides and michaellzc December 14, 2022 19:44
Comment thread internal/txemail/siteconfig.go

@michaellzc michaellzc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

code lgtm

Growth should also review this and see if this meets their need as well

Comment on lines +24 to +37
Somebody (likely you) requested a password reset for the user {{.Username}} on Sourcegraph ({{.Host}}).

To reset the password for {{.Username}} on Sourcegraph, follow this link:

{{.URL}}
`,
HTML: `
<p>
Somebody (likely you) requested a password reset for <strong>{{.Username}}</strong>
on Sourcegraph ({{.Host}}).
</p>

<p><strong><a href="{{.URL}}">Reset password for {{.Username}}</a></strong></p>
`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we add a line in here that says something like:

If you did not request this password reset, please ignore this email and contact your Sourcegraph Cloud support representative.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note that:

  1. This email template existed before and is unchanged
  2. This email template must make sense for self-hosted instances, since this is the default

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Messaging like the above can be added to any custom email.templates we configure in Cloud once this feature is available in a Sourcegraph release (likely 4.4)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sounds good, I like that suggestion that we create a better template specific to Cloud!

@bobheadxi bobheadxi merged commit 568def6 into main Dec 15, 2022
@bobheadxi bobheadxi deleted the configurable-email-templates branch December 15, 2022 16:36
Comment on lines +23 to +30
Text: `
Somebody (likely you) requested a password reset for the user {{.Username}} on Sourcegraph ({{.Host}}).

To reset the password for {{.Username}} on Sourcegraph, follow this link:

{{.URL}}
`,
HTML: `

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In general, the content of both text and HTML versions are the same, is it on purpose that we don't want to automatically degrade HTML to text (i.e. removing all HTML elements)? If not, there is a package that can do that automatically: https://github.com/jaytaylor/html2text

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good idea, I think removing HTML elements is a good default behaviour.

I ended up using a lighter version of the above library that is advertised in the README: https://github.com/sourcegraph/sourcegraph/pull/46085

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants