Makes groups possible

This commit is contained in:
2024-02-08 11:41:03 -08:00
parent d5e8545ec8
commit fcefbd5d6d
20 changed files with 364 additions and 276 deletions

View File

@@ -72,7 +72,7 @@
(defn render-index [_]
(response/resource-response "index.html" {:root "public"}))
(def match->handler-lookup
(def match->handler-lookup
(-> {:not-found not-found}
(merge ssr/key->handler)
(merge graphql/match->handler)
@@ -83,13 +83,13 @@
(merge auth/match->handler)
(merge invoices/match->handler)
(merge exports/match->handler)
(merge
(into {}
(map
(merge
(into {}
(map
(fn [k]
[k render-index])
client-routes/all-matches)))))
(fn [k]
[k render-index])
client-routes/all-matches)))))
(def match->handler
(fn [route]
@@ -102,7 +102,7 @@
match->handler))
(defn wrap-guess-route [handler]
(fn [{:keys [uri request-method] :as request} ]
(fn [{:keys [uri request-method] :as request}]
(let [matched-route (:handler
(bidi.bidi/match-route all-routes
uri
@@ -136,21 +136,21 @@
(not= "/api/graphql" (:uri request))
(assoc :query-params (:query-params request)))
(mu/trace ::http-request-trace
{:pairs []
:capture (fn [r] {:status (:status r)})}
(when-not (str/includes? (:uri request) "health-check")
(alog/info ::http-request-starting))
(try
(let [response (handler request)]
response)
(catch Exception e
(alog/error ::request-error
:status 500
:exception e)
(throw e)))))))
{:pairs []
:capture (fn [r] {:status (:status r)})}
(when-not (str/includes? (:uri request) "health-check")
(alog/info ::http-request-starting))
(try
(let [response (handler request)]
response)
(catch Exception e
(alog/error ::request-error
:status 500
:exception e)
(throw e)))))))
(defn wrap-idle-session-timeout
[handler ]
[handler]
(fn [request]
(let [session (:session request {})
end-time (coerce/to-date-time (::idle-timeout session))]
@@ -170,9 +170,9 @@
(assoc response :session (assoc session ::idle-timeout (coerce/to-date end-time)))))))))))
(defn wrap-hx-current-url-params
[handler ]
[handler]
(fn [request]
(let [query-params (some-> (get-in request [:headers "hx-current-url"]) (url/url ) :query)
(let [query-params (some-> (get-in request [:headers "hx-current-url"]) (url/url) :query)
request (assoc request :hx-query-params query-params)]
(handler request))))
@@ -183,30 +183,40 @@
identity (or (-> request :identity)
(-> request :session :identity))
ideal-ids (set (cond
(or (= :all x-clients)
(nil? x-clients))
(->> (dc/q '[:find ?c
:where [?c :client/code]]
(dc/db conn))
(map first))
(or (= :all x-clients)
(nil? x-clients))
(->> (dc/q '[:find ?c
:where [?c :client/code]]
(dc/db conn))
(map first))
(= :mine x-clients)
(map :db/id (:user/clients identity))
(= :mine x-clients)
(map :db/id (:user/clients identity))
(= :group (first x-clients))
(->>
(dc/q '[:find ?c
:in $ ?g
:where [?c :client/groups ?g]]
(dc/db conn)
(str/upper-case (or (second x-clients) "INVALID")))
(map first)
set)
(seq x-clients)
(->> x-clients
(map (fn [c]
(if (string? c)
(try
(Long/parseLong c)
(catch Exception e
nil))
c)))
(filter #(not (nil? %)))
set)))
(seq x-clients)
(->> x-clients
(map (fn [c]
(if (string? c)
(try
(Long/parseLong c)
(catch Exception e
nil))
c)))
(filter #(not (nil? %)))
set)))
limited-clients (some->> (limited-clients identity)
(map :db/id )
(map :db/id)
set)
client-ids (if (= "admin" (:user/role identity))
ideal-ids
@@ -215,8 +225,8 @@
clients (some->> client-ids
seq
(pull-many (dc/db conn)
d-clients/full-read))]
d-clients/full-read))]
(mu/with-context {:clients (take 10 (map :client/code clients))}
(handler (assoc request
:clients clients
@@ -229,8 +239,10 @@
(let [x-clients (edn/read-string (get headers "x-clients"))
x-clients (try (if-let [client-id (and x-clients
(sequential? x-clients)
(first x-clients)
(not= :group (first x-clients))
(first x-clients))]
(do
(do
(assert-can-see-client identity (cond-> client-id
(string? client-id) (Long/parseLong)))
[(if (string? client-id)
@@ -261,16 +273,16 @@
(auth/gunzip gz-clients))
(catch Exception e
(alog/error :cant-gunzip-clients
:error e)
:error e)
request))
request)]
(handler request))))
#_(defn wrap-pprint-session
[handler]
(fn [request]
(clojure.pprint/pprint (:session request))
(handler request)))
[handler]
(fn [request]
(clojure.pprint/pprint (:session request))
(handler request)))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defonce app
@@ -289,13 +301,11 @@
#_(wrap-pprint-session)
(wrap-idle-session-timeout)
(wrap-session {:store (cookie-store
{:key
(byte-array
[42, 52, -31, 105, -126, -33, -118, -69, -82, -59, -15, -69, -38, 103, -102, -1])} )})
{:key
(byte-array
[42, 52, -31, 105, -126, -33, -118, -69, -82, -59, -15, -69, -38, 103, -102, -1])})})
#_(wrap-reload)
(wrap-params)
(mp/wrap-multipart-params)
(wrap-edn-params)
))
(wrap-edn-params)))