0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-24 15:39:50 -05:00

🐛 Fix incorrect props cleaning on auditlog

This commit is contained in:
Andrey Antukh 2023-02-07 18:38:54 +01:00
parent ea470068bb
commit 8161d3ae09
3 changed files with 25 additions and 31 deletions

View file

@ -77,28 +77,20 @@
(merge (:props profile)) (merge (:props profile))
(d/without-nils))) (d/without-nils)))
(defn clean-props (def reserved-props
[{:keys [profile-id] :as event}] #{:session-id
(let [invalid-keys #{:session-id :password
:password :old-password
:old-password :token})
:token}
xform (comp
(remove (fn [kv]
(qualified-keyword? (first kv))))
(remove (fn [kv]
(contains? invalid-keys (first kv))))
(remove (fn [[k v]]
(and (= k :profile-id)
(= v profile-id))))
(filter (fn [[_ v]]
(or (string? v)
(keyword? v)
(uuid? v)
(boolean? v)
(number? v)))))]
(update event :props #(into {} xform %)))) (defn clean-props
[props]
(into {}
(comp
(d/without-nils)
(d/without-qualified)
(remove #(contains? reserved-props (key %))))
props))
;; --- SPECS ;; --- SPECS

View file

@ -219,8 +219,7 @@
(merge (::audit/props resultm)) (merge (::audit/props resultm))
(dissoc :profile-id) (dissoc :profile-id)
(dissoc :type))) (dissoc :type)))
(d/without-qualified) (audit/clean-props))
(d/without-nils))
event {:type (or (::audit/type resultm) event {:type (or (::audit/type resultm)
(::type cfg)) (::type cfg))

View file

@ -216,19 +216,22 @@
([coll value] ([coll value]
(sequence (replace-by-id value) coll))) (sequence (replace-by-id value) coll)))
(defn without-nils
"Given a map, return a map removing key-value
pairs when value is `nil`."
[data]
(into {} (remove (comp nil? second)) data))
(defn vec-without-nils (defn vec-without-nils
[coll] [coll]
(into [] (remove nil?) coll)) (into [] (remove nil?) coll))
(defn without-nils
"Given a map, return a map removing key-value
pairs when value is `nil`."
([] (remove (comp nil? val)))
([data]
(into {} (without-nils) data)))
(defn without-qualified (defn without-qualified
[data] ([]
(into {} (remove (comp qualified-keyword? first)) data)) (remove (comp qualified-keyword? key)))
([data]
(into {} (without-qualified) data)))
(defn without-keys (defn without-keys
"Return a map without the keys provided "Return a map without the keys provided