mirror of
https://github.com/penpot/penpot.git
synced 2025-03-20 11:41:47 -05:00
✨ Add backward compatibility fixes for email whitelisting
This commit is contained in:
parent
70c9314f7f
commit
40f39681ad
1 changed files with 26 additions and 18 deletions
|
@ -14,30 +14,38 @@
|
||||||
[clojure.core :as c]
|
[clojure.core :as c]
|
||||||
[clojure.java.io :as io]
|
[clojure.java.io :as io]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
|
[datoteka.fs :as fs]
|
||||||
[integrant.core :as ig]))
|
[integrant.core :as ig]))
|
||||||
|
|
||||||
|
(defn- read-whitelist
|
||||||
|
[path]
|
||||||
|
(when (and path (fs/exists? path))
|
||||||
|
(try
|
||||||
|
(with-open [reader (io/reader path)]
|
||||||
|
(reduce (fn [result line]
|
||||||
|
(if (str/starts-with? line "#")
|
||||||
|
result
|
||||||
|
(conj result (-> line str/trim str/lower))))
|
||||||
|
#{}
|
||||||
|
(line-seq reader)))
|
||||||
|
|
||||||
|
(catch Throwable cause
|
||||||
|
(l/wrn :hint "unexpected exception on reading email whitelist"
|
||||||
|
:cause cause)))))
|
||||||
|
|
||||||
(defmethod ig/init-key ::email/whitelist
|
(defmethod ig/init-key ::email/whitelist
|
||||||
[_ _]
|
[_ _]
|
||||||
(when (c/contains? cf/flags :email-whitelist)
|
(let [whitelist (or (cf/get :registration-domain-whitelist) #{})
|
||||||
(try
|
whitelist (if (c/contains? cf/flags :email-whitelist)
|
||||||
(let [path (cf/get :email-domain-whitelist)
|
(into whitelist (read-whitelist (cf/get :email-domain-whitelist)))
|
||||||
result (with-open [reader (io/reader path)]
|
whitelist)
|
||||||
(reduce (fn [result line]
|
whitelist (not-empty whitelist)]
|
||||||
(if (str/starts-with? line "#")
|
|
||||||
result
|
|
||||||
(conj result (-> line str/trim str/lower))))
|
|
||||||
#{}
|
|
||||||
(line-seq reader)))
|
|
||||||
|
|
||||||
;; backward comapatibility with previous way to set a
|
|
||||||
;; whitelist for email domains
|
|
||||||
result (into result (cf/get :registration-domain-whitelist))]
|
|
||||||
|
|
||||||
(l/inf :hint "initializing email whitelist" :domains (count result))
|
(when whitelist
|
||||||
(not-empty result))
|
(l/inf :hint "initializing email whitelist" :domains (count whitelist)))
|
||||||
(catch Throwable cause
|
|
||||||
(l/wrn :hint "unexpected exception on initializing email whitelist"
|
whitelist))
|
||||||
:cause cause)))))
|
|
||||||
|
|
||||||
(defn contains?
|
(defn contains?
|
||||||
"Check if email is in the whitelist."
|
"Check if email is in the whitelist."
|
||||||
|
|
Loading…
Add table
Reference in a new issue