0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-10 00:40:30 -05:00

🐛 Fix some internal issues on audit events

This commit is contained in:
Andrey Antukh 2024-02-28 15:53:30 +01:00 committed by Alonso Torres
parent 54511a5ef0
commit 467e4c76a6

View file

@ -121,26 +121,10 @@
(derive :app.main.data.workspace/set-workspace-layout ::generic-action) (derive :app.main.data.workspace/set-workspace-layout ::generic-action)
(derive :app.main.data.workspace/toggle-layout-flag ::generic-action) (derive :app.main.data.workspace/toggle-layout-flag ::generic-action)
(defmulti process-event ptk/type) (defprotocol Event
(defmethod process-event :default [_] nil) (-data [_] "Get event data"))
(defmethod process-event ::event (defn- simplify-props
[event]
(let [data (deref event)
origin (::origin data)]
(when (::name data)
(d/without-nils
{:type (::type data "action")
:name (::name data)
:context (::context data)
:props (-> data
(dissoc ::name)
(dissoc ::type)
(dissoc ::origin)
(dissoc ::context)
(cond-> origin (assoc :origin origin)))}))))
(defn- normalize-props
"Removes complex data types from props." "Removes complex data types from props."
[data] [data]
(into {} (into {}
@ -156,24 +140,65 @@
:else kv)))) :else kv))))
data)) data))
(defmethod process-event ::generic-action
(defmulti process-event-by-type ptk/type)
(defn- process-event-by-proto
[event]
(let [data (d/deep-merge (-data event) (meta event))
type (ptk/type event)
ev-name (name type)
context (-> (::context data)
(assoc :event-origin (::origin data))
(assoc :event-namespace (namespace type))
(assoc :event-symbol ev-name)
(d/without-nils))
props (-> data d/without-qualified simplify-props)]
{:type (::type data "action")
:name (::name data ev-name)
:context context
:props props}))
(defn- process-event
[event]
(if (satisfies? Event event)
(process-event-by-proto event)
(process-event-by-type event)))
(defmethod process-event-by-type :default [_] nil)
(defmethod process-event-by-type ::event
[event]
(let [data (deref event)
context (-> (::context data)
(assoc :event-origin (::origin data))
(d/without-nils))
props (-> data d/without-qualified simplify-props)]
{:type (::type data "action")
:name (::name data "unnamed")
:context context
:props props}))
(defmethod process-event-by-type ::generic-action
[event] [event]
(let [type (ptk/type event) (let [type (ptk/type event)
mdata (meta event)
data (if (satisfies? IDeref event) data (if (satisfies? IDeref event)
(deref event) (deref event)
{})] {})
data (d/deep-merge data (meta event))]
{:type "action" {:type "action"
:name (or (::name mdata) (name type)) :name (or (::name data) (name type))
:props (-> (merge data (::props mdata)) :props (-> (d/without-qualified data)
(normalize-props)) (simplify-props))
:context (d/without-nils :context (d/without-nils
{:event-origin (::origin mdata) {:event-origin (::origin data)
:event-namespace (namespace type) :event-namespace (namespace type)
:event-symbol (name type)})})) :event-symbol (name type)})}))
(defmethod process-event :app.util.router/navigated (defmethod process-event-by-type :app.util.router/navigated
[event] [event]
(let [match (deref event) (let [match (deref event)
route (get-in match [:data :name]) route (get-in match [:data :name])
@ -183,9 +208,9 @@
:project-id (get-in match [:path-params :project-id])}] :project-id (get-in match [:path-params :project-id])}]
{:name "navigate" {:name "navigate"
:type "action" :type "action"
:props (normalize-props props)})) :props (simplify-props props)}))
(defmethod process-event :app.main.data.users/logged-in (defmethod process-event-by-type :app.main.data.users/logged-in
[event] [event]
(let [data (deref event) (let [data (deref event)
mdata (meta data) mdata (meta data)
@ -196,10 +221,11 @@
:is-muted (:is-muted data) :is-muted (:is-muted data)
:default-team-id (str (:default-team-id data)) :default-team-id (str (:default-team-id data))
:default-project-id (str (:default-project-id data))}] :default-project-id (str (:default-project-id data))}]
{:name "signin" {:name "signin"
:type "identify" :type "identify"
:profile-id (:id data) :profile-id (:id data)
:props (normalize-props props)})) :props (simplify-props props)}))
;; --- MAIN LOOP ;; --- MAIN LOOP