mirror of
https://github.com/penpot/penpot.git
synced 2026-11-08 11:04:44 +00:00
* ✨ Render email templates inside the mail job The web process rendered each email to full subject and HTML body before submitting it, so every queued job carried a huge params payload. The queue now stores only the template id plus the raw template data, and the new :send-templated-mail job renders and sends the email inside the worker. The old :sendmail job stays in place to drain jobs submitted in the previous format; the quota notice and the REPL test mail keep using it. All templated callers (auth, profile, feedback, invitations, comments, Nitrate) submit recipes through eml/send-template. Closes #12445 AI-assisted-by: muse-spark-1.3-contributor * ♻️ Unify templated mail on template id strings The ::eml/template value was a namespaced keyword whose name had to match the registry key, with one live mismatch (user-feedback vs feedback). Callers now pass the registry id string itself, so keys stay ::eml/-namespaced and values stay plain data, and the single templates set rejects unsendable mail both at submit and in the worker. Closes #12445 AI-assisted-by: muse-spark-1.3-contributor * 🐛 Encode templated mail data with the template schema The job params column is plain JSON, so the URIs of an organization (:logo, :avatar-bg-url) were stored as record maps and the template check rejected them in the worker. Invites for organization teams, organization invites and renewal notices failed without a retry. Each registry entry now carries the JSON encoder and decoder of its template schema: send-template encodes the data before submit and the worker decodes it before rendering. The job schema keeps only the mail envelope, as the template schemas own the typed data. Closes #12445 AI-assisted-by: claude-opus-5-5 ---------
65 lines
2.6 KiB
Clojure
65 lines
2.6 KiB
Clojure
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
;;
|
|
;; Copyright (c) KALEIDOS SUBSIDIARY SL
|
|
|
|
(ns backend-tests.rpc-feedback-test
|
|
(:require
|
|
[app.common.schema :as sm]
|
|
[app.config :as cf]
|
|
[app.db :as db]
|
|
[app.email :as eml]
|
|
[app.rpc :as-alias rpc]
|
|
[app.rpc.commands.feedback :as feedback]
|
|
[backend-tests.helpers :as th]
|
|
[clojure.test :as t]))
|
|
|
|
(t/use-fixtures :once th/state-init)
|
|
(t/use-fixtures :each th/database-reset)
|
|
|
|
(t/deftest send-user-feedback-schema-validation
|
|
(let [schema feedback/schema:send-user-feedback]
|
|
|
|
(t/testing "accepts valid feedback with all fields"
|
|
(let [params {:subject "Test subject"
|
|
:content "Test content"
|
|
:type "bug"
|
|
:error-href "https://example.com/error"
|
|
:error-report "Error details here"}]
|
|
(t/is (sm/valid? schema params))))
|
|
|
|
(t/testing "accepts feedback without optional fields"
|
|
(let [params {:subject "Test subject"
|
|
:content "Test content"}]
|
|
(t/is (sm/valid? schema params))))
|
|
|
|
(t/testing "accepts error-report up to 1MiB"
|
|
(let [params {:subject "Test subject"
|
|
:content "Test content"
|
|
:error-report (apply str (repeat 1048576 "x"))}]
|
|
(t/is (sm/valid? schema params))))
|
|
|
|
(t/testing "rejects error-report exceeding 1MiB"
|
|
(let [params {:subject "Test subject"
|
|
:content "Test content"
|
|
:error-report (apply str (repeat 1048577 "x"))}]
|
|
(t/is (not (sm/valid? schema params)))))))
|
|
|
|
(t/deftest send-user-feedback-reaches-send-with-connection
|
|
(with-redefs [cf/flags (conj cf/flags :user-feedback)
|
|
cf/config (assoc cf/config :user-feedback-destination "fb@example.com")]
|
|
(let [profile (th/create-profile* 1 {})
|
|
captured (atom nil)]
|
|
(with-redefs [eml/send-template (fn [cfg params]
|
|
(reset! captured {:cfg cfg :params params})
|
|
nil)]
|
|
(let [{:keys [error]} (th/command! {::th/type :send-user-feedback
|
|
::rpc/profile-id (:id profile)
|
|
:subject "s"
|
|
:content "c"})]
|
|
(t/is (nil? error))))
|
|
(t/testing "send! is reached with a caller connection"
|
|
(t/is (some? (:cfg @captured)))
|
|
(t/is (some? (::db/conn (:cfg @captured))))))))
|