Skip to content

Commit

Permalink
Add form-allows-ht
Browse files Browse the repository at this point in the history
  • Loading branch information
vaeinoe committed Nov 29, 2023
1 parent e773f6b commit 6dbb599
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
8 changes: 5 additions & 3 deletions src/clj/ataru/email/application_email.clj
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@


(defn preview-submit-email
[lang subject content content-ending signature]
[lang subject content content-ending signature form-allows-ht?]
{:from email-util/from-address
:subject subject
:content content
Expand All @@ -135,7 +135,9 @@
{:label "Liite 3"
:deadline ""}]
:application-url "https://opintopolku.fi/hakemus/01234567890abcdefghijklmn"
:application-url-text (get-in email-link-section-texts [:default (keyword lang)])
:application-url-text (if form-allows-ht?
(get-in email-link-section-texts [:default (keyword lang)])
nil)
:application-oid "1.2.246.562.11.00000000000000000000"
:content (->safe-html content)
:content-ending (->safe-html content-ending)
Expand All @@ -145,7 +147,7 @@
[form-key form-allows-ht?]
(as-> (email-store/get-email-templates form-key) x
(add-blank-templates x form-allows-ht?)
(map #(preview-submit-email (:lang %) (:subject %) (:content %) (:content-ending %) (:signature %)) x)))
(map #(preview-submit-email (:lang %) (:subject %) (:content %) (:content-ending %) (:signature %) form-allows-ht?) x)))

(defn- attachment-with-deadline [_ lang field]
(let [attachment {:label (-> field
Expand Down
8 changes: 4 additions & 4 deletions src/clj/ataru/email/application_email_jobs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
[form-key form-allows-ht?]
(application-email/get-email-templates form-key form-allows-ht?))

(defn preview-submit-emails [previews]
(defn preview-submit-emails [previews form-allows-ht]
(map
#(let [lang (:lang %)
subject (:subject %)
content (:content %)
content-ending (:content-ending %)
signature (:signature %)]
(application-email/preview-submit-email lang subject content content-ending signature)) previews))
(application-email/preview-submit-email lang subject content content-ending signature form-allows-ht)) previews))

(defn start-email-job [job-runner email]
(let [job-id (jdbc/with-db-transaction [connection {:datasource (db/get-datasource :db)}]
Expand Down Expand Up @@ -71,7 +71,7 @@
(start-email-job job-runner email)))))

(defn store-email-templates
[form-key session templates]
[form-key session templates form-allows-ht?]
(let [stored-templates (mapv #(email-store/create-or-update-email-template
form-key
(:lang %)
Expand All @@ -81,4 +81,4 @@
(:content-ending %)
(:signature %))
templates)]
(map #(application-email/preview-submit-email (:lang %) (:subject %) (:content %) (:content_ending %) (:signature %)) stored-templates)))
(map #(application-email/preview-submit-email (:lang %) (:subject %) (:content %) (:content_ending %) (:signature %) form-allows-ht?) stored-templates)))
6 changes: 4 additions & 2 deletions src/clj/ataru/virkailija/virkailija_routes.clj
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,15 @@

(api/POST "/email-template/:form-key/previews" []
:path-params [form-key :- s/Str]
:query-params [{form-allows-ht :- s/Bool false}]
:body [body {:contents [ataru-schema/EmailTemplate]}]
(ok (email/preview-submit-emails (:contents body))))
(ok (email/preview-submit-emails (:contents body) form-allows-ht)))

(api/POST "/email-templates/:form-key" {session :session}
:path-params [form-key :- s/Str]
:query-params [{form-allows-ht :- s/Bool false}]
:body [body {:contents [ataru-schema/EmailTemplate]}]
(ok (email/store-email-templates form-key session (:contents body))))
(ok (email/store-email-templates form-key session (:contents body) form-allows-ht)))

(api/GET "/email-templates/:form-key" []
:path-params [form-key :- s/Str]
Expand Down
8 changes: 5 additions & 3 deletions src/cljs/ataru/virkailija/editor/handlers.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1358,11 +1358,12 @@
:editor/update-email-preview-immediately
(fn [{db :db} [_]]
(let [form-key (get-in db [:editor :selected-form-key])
form-allows-ht? (boolean (get-in db [:editor :forms form-key :properties :allow-hakeminen-tunnistautuneena]))
contents (preview-map-to-list (get-in db [:editor :email-template form-key]))]
{:http {:method :post
:params {:contents contents}
:handler-args {:form-key form-key}
:path (str "/lomake-editori/api/email-template/" form-key "/previews")
:path (str "/lomake-editori/api/email-template/" form-key "/previews?form-allows-ht=" form-allows-ht?)
:handler-or-dispatch :editor/update-email-template-preview}})))

(reg-event-fx
Expand Down Expand Up @@ -1392,11 +1393,12 @@
:editor/save-email-template
(fn [{db :db} [_]]
(let [contents (preview-map-to-list @(subscribe [:editor/email-template]))
form-key (get-in db [:editor :selected-form-key])]
form-key (get-in db [:editor :selected-form-key])
form-allows-ht? (boolean (get-in db [:editor :forms form-key :properties :allow-hakeminen-tunnistautuneena]))]
{:http {:method :post
:params {:contents contents}
:handler-args {:form-key form-key}
:path (str "/lomake-editori/api/email-templates/" form-key)
:path (str "/lomake-editori/api/email-templates/" form-key "?form-allows-ht=" form-allows-ht?)
:handler-or-dispatch :editor/update-saved-email-template-preview}})))

(reg-event-fx
Expand Down

0 comments on commit 6dbb599

Please sign in to comment.