Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Advanced e-mail templating support #1859

Merged

Conversation

landerss1
Copy link
Contributor

@landerss1 landerss1 commented Oct 19, 2021

This PR adds more advanced templating functionality to courier messages by

  • Making Sprig functions available to templates
  • Making the identity of the recipient available to templates
  • Implementing support for nested templates in separate files

Related issue(s)

closes #834
closes #925

Checklist

Further Comments

N/A

* Made Sprig functions available to templates
* Made the identity of the recipient available to templates
* Implemented support for nested templates
Copy link
Member

@zepatrik zepatrik left a comment

Choose a reason for hiding this comment

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

Looking pretty good already, thanks a lot 👍
I have some ideas how to improve it further 😉

courier/template/load_template.go Outdated Show resolved Hide resolved
courier/template/load_template.go Outdated Show resolved Hide resolved
courier/template/load_template.go Outdated Show resolved Hide resolved
courier/template/load_template.go Outdated Show resolved Hide resolved
courier/template/load_template_test.go Outdated Show resolved Hide resolved
docs/docs/concepts/email-sms.md Outdated Show resolved Hide resolved
docs/docs/concepts/email-sms.md Outdated Show resolved Hide resolved
x/map_json_test.go Outdated Show resolved Hide resolved
x/map_json_test.go Outdated Show resolved Hide resolved
courier/template/load_template.go Outdated Show resolved Hide resolved
@landerss1
Copy link
Contributor Author

landerss1 commented Oct 19, 2021

@zepatrik I've fixed everything in accordance with your suggestions in a separate commit, plus a few more changes I had to make to get your suggestions to compile and run.

Also, there are some issues with the e2e test, but I don't think that's something I caused:

Error: Timed out waiting for: http-get://127.0.0.1:4455/health, http-get://127.0.0.1:4456/health
    at MergeMapSubscriber.project (/home/circleci/project/node_modules/wait-on/lib/wait-on.js:132:31)
    at MergeMapSubscriber._tryNext (/home/circleci/project/node_modules/rxjs/internal/operators/mergeMap.js:67:27)
    at MergeMapSubscriber._next (/home/circleci/project/node_modules/rxjs/internal/operators/mergeMap.js:57:18)
    at MergeMapSubscriber.Subscriber.next (/home/circleci/project/node_modules/rxjs/internal/Subscriber.js:66:18)
    at AsyncAction.dispatch [as work] (/home/circleci/project/node_modules/rxjs/internal/observable/timer.js:31:16)
    at AsyncAction._execute (/home/circleci/project/node_modules/rxjs/internal/scheduler/AsyncAction.js:71:18)
    at AsyncAction.execute (/home/circleci/project/node_modules/rxjs/internal/scheduler/AsyncAction.js:59:26)
    at AsyncScheduler.flush (/home/circleci/project/node_modules/rxjs/internal/scheduler/AsyncScheduler.js:52:32)
    at listOnTimeout (internal/timers.js:557:17)
    at processTimers (internal/timers.js:500:7)

Copy link
Member

@aeneasr aeneasr left a comment

Choose a reason for hiding this comment

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

Looking great so far! I think we can extract the template interface with Execute into a common type, that would make code readability easier and also avoid duplication :)

courier/template/load_template.go Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Oct 29, 2021

Codecov Report

Merging #1859 (0612543) into master (305bb28) will decrease coverage by 0.05%.
The diff coverage is 67.70%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1859      +/-   ##
==========================================
- Coverage   75.19%   75.13%   -0.06%     
==========================================
  Files         292      292              
  Lines       15180    15241      +61     
==========================================
+ Hits        11414    11451      +37     
- Misses       2953     2965      +12     
- Partials      813      825      +12     
Impacted Files Coverage Δ
selfservice/hook/verification.go 66.66% <0.00%> (ø)
selfservice/strategy/link/sender.go 71.27% <38.88%> (-5.56%) ⬇️
x/map_json.go 80.00% <55.55%> (-7.10%) ⬇️
courier/template/load_template.go 66.66% <71.69%> (+5.12%) ⬆️
courier/template/recovery_invalid.go 100.00% <100.00%> (ø)
courier/template/recovery_valid.go 100.00% <100.00%> (ø)
courier/template/stub.go 100.00% <100.00%> (ø)
courier/template/verification_invalid.go 100.00% <100.00%> (ø)
courier/template/verification_valid.go 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 305bb28...0612543. Read the comment docs.

@aeneasr
Copy link
Member

aeneasr commented Nov 4, 2021

Great job!

@aeneasr aeneasr merged commit 54b97b4 into ory:master Nov 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Have access to username in email templates Add i18n support to mail templates
3 participants