Skip to content

Add debug API endpoint for mail template rendering#830

Open
Varsius wants to merge 1 commit intomasterfrom
render-mail-template-endpoint
Open

Add debug API endpoint for mail template rendering#830
Varsius wants to merge 1 commit intomasterfrom
render-mail-template-endpoint

Conversation

@Varsius
Copy link
Contributor

@Varsius Varsius commented Feb 5, 2026

Checklist:

  • I updated the documentation to describe the semantical or interface changes I introduced.

@Varsius Varsius requested a review from a team as a code owner February 5, 2026 15:02
@Varsius Varsius force-pushed the render-mail-template-endpoint branch from 9f10ae5 to 30e7863 Compare February 5, 2026 15:06

Renders the mail template of the respective type using dummy values and
verifies that the generated content is valid HTML.
Requires the `?template_type` query parameter. No newline at end of file
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Requires the `?template_type` query parameter.
Requires the `template_type` query parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The ? was added to be consistent with the existing admin endpoints documentation

case "transferred_commitments":
template = mailConfig.Templates.ConfirmedCommitments
default:
http.Error(w, "invalid template type", http.StatusBadRequest)
Copy link
Member

Choose a reason for hiding this comment

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

Should we list available templates here? The user needs admin anyhow, so we don't leak anything, right?

@Varsius Varsius force-pushed the render-mail-template-endpoint branch 2 times, most recently from 5975026 to f9975ec Compare February 6, 2026 17:55
wagnerd3
wagnerd3 previously approved these changes Feb 9, 2026
Copy link
Contributor

@wagnerd3 wagnerd3 left a comment

Choose a reason for hiding this comment

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

I think this current state would be sufficient for me right now.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds an admin-only debug endpoint to render configured mail templates using dummy data, primarily to help validate mail template rendering during development/testing.

Changes:

  • Add GET /admin/mail/render endpoint that renders a chosen template type using dummy commitment data.
  • Extend test setup with WithMailTemplates and add an API test covering auth and parameter validation.
  • Vendor golang.org/x/net/html (and update go.mod/go.sum/vendor/modules.txt) to parse the rendered output.

Reviewed changes

Copilot reviewed 6 out of 23 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
internal/api/mail.go Implements the new mail template render endpoint and HTML parse check.
internal/api/core.go Registers the new route in the v1 API router.
internal/api/mail_test.go Adds tests for permissions and request parameter validation.
internal/test/setup.go Adds WithMailTemplates option to inject dummy mail templates for tests.
docs/users/api-spec-resources.md Documents the new endpoint and its query parameter.
go.mod Adds direct dependency on golang.org/x/net.
go.sum Updates checksums for updated golang.org/x/* dependencies.
vendor/modules.txt Reflects newly vendored golang.org/x/net and updated golang.org/x/sys.
vendor/golang.org/x/net/html/token.go Vendored HTML tokenizer implementation.
vendor/golang.org/x/net/html/render.go Vendored HTML renderer implementation.
vendor/golang.org/x/net/html/parse.go Vendored HTML parser implementation.
vendor/golang.org/x/net/html/node.go Vendored DOM node model implementation.
vendor/golang.org/x/net/html/iter.go Vendored iterator helpers for node traversal (go build tag).
vendor/golang.org/x/net/html/foreign.go Vendored foreign content parsing helpers (SVG/MathML).
vendor/golang.org/x/net/html/escape.go Vendored HTML escaping/unescaping helpers.
vendor/golang.org/x/net/html/doctype.go Vendored doctype parsing logic.
vendor/golang.org/x/net/html/doc.go Vendored package documentation.
vendor/golang.org/x/net/html/const.go Vendored parsing constants/helpers.
vendor/golang.org/x/net/html/atom/table.go Vendored generated atom table for tags/attrs.
vendor/golang.org/x/net/html/atom/atom.go Vendored atom lookup implementation.
vendor/golang.org/x/net/LICENSE Vendored license for golang.org/x/net.
vendor/golang.org/x/net/PATENTS Vendored patents grant for golang.org/x/net.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@VoigtS VoigtS left a comment

Choose a reason for hiding this comment

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

I left a couple of notes.

@Varsius Varsius force-pushed the render-mail-template-endpoint branch from cebced3 to 123d050 Compare February 11, 2026 17:09
@Varsius
Copy link
Contributor Author

Varsius commented Feb 11, 2026

The tests are failing since with the test cases added in this PR, the total amount of tests exceeds the concurrency limit of postgres connections in our testing setup. Increasing the amount of max_connections = 100 in postgressql.conf should do the trick, this likely needs to be changed in g-m-m.

SuperSandro2000 added a commit to sapcc/go-bits that referenced this pull request Feb 12, 2026
@SuperSandro2000
Copy link
Member

It's in go-bits 😅 fix at sapcc/go-bits#292

SuperSandro2000 added a commit to sapcc/go-bits that referenced this pull request Feb 12, 2026
@Varsius Varsius force-pushed the render-mail-template-endpoint branch from 123d050 to 387c935 Compare February 16, 2026 16:16
@github-actions
Copy link

Merging this branch will increase overall coverage

Impacted Packages Coverage Δ 🤖
github.com/sapcc/limes/internal/api 78.40% (+0.24%) 👍

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/sapcc/limes/internal/api/core.go 80.00% (+0.15%) 810 (+6) 648 (+6) 162 👍
github.com/sapcc/limes/internal/api/mail.go 87.23% (+87.23%) 282 (+282) 246 (+246) 36 (+36) 🌟

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/sapcc/limes/internal/api/mail_test.go

@Varsius Varsius requested a review from VoigtS February 16, 2026 19:54
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.

4 participants