Makes logging unified
This commit is contained in:
@@ -8,9 +8,9 @@
|
||||
[iol-ion.query :refer [entid]]
|
||||
[clojure.walk :as walk]
|
||||
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
|
||||
[clojure.tools.logging :as log]
|
||||
[com.brunobonacci.mulog :as mu]
|
||||
[clojure.set :as set]))
|
||||
[clojure.set :as set]
|
||||
[auto-ap.logging :as alog]))
|
||||
|
||||
|
||||
(defn snake->kebab [s]
|
||||
@@ -56,7 +56,7 @@
|
||||
|
||||
(defn assert-admin [id]
|
||||
(when-not (= "admin" (:user/role id))
|
||||
(log/warn "user " id " not an admin!")
|
||||
(alog/warn ::unauthorized :user id :role "admin")
|
||||
(throw-unauthorized)))
|
||||
|
||||
(defn assert-present
|
||||
@@ -74,19 +74,19 @@
|
||||
|
||||
(defn assert-power-user [id]
|
||||
(when-not (#{"power-user" "admin"} (:user/role id))
|
||||
(log/warn "user " id " not an power-user!")
|
||||
(alog/warn ::unauthorized :user id :role "power-user")
|
||||
(throw-unauthorized)))
|
||||
|
||||
(defn can-see-client? [identity client]
|
||||
(when (not client)
|
||||
(log/warn "WARNING - permission checking for null client"))
|
||||
(alog/error ::checking-for-null-client :id identity))
|
||||
(or (= "admin" (:user/role identity))
|
||||
((set (map :db/id (:user/clients identity))) (:db/id client))
|
||||
((set (map :db/id (:user/clients identity))) client)))
|
||||
|
||||
(defn assert-can-see-client [identity client]
|
||||
(when-not (can-see-client? identity client)
|
||||
(log/warn "IDENTITY " identity " can not see company " client)
|
||||
(alog/warn ::unauthorized :id identity :client client)
|
||||
(throw-unauthorized)))
|
||||
|
||||
(defn limited-clients [id]
|
||||
@@ -149,10 +149,12 @@
|
||||
|
||||
(defn trace-query [key f]
|
||||
(fn trace [a b c]
|
||||
(mu/with-context {:query key
|
||||
:mutation (boolean (= "mutation"
|
||||
(namespace key)))
|
||||
:user (:id a)}
|
||||
(mu/with-context (merge
|
||||
(:log-context a {})
|
||||
{:query key
|
||||
:mutation (boolean (= "mutation"
|
||||
(namespace key)))
|
||||
:user (:id a)})
|
||||
(mu/trace (keyword "graphql" (name key))
|
||||
[]
|
||||
(f a b c)))))
|
||||
|
||||
Reference in New Issue
Block a user