parent
b535880c1d
commit
81a33bb68f
@ -1,41 +1,39 @@
|
|||||||
(ns wanijo.schema.middleware
|
(ns wanijo.schema.middleware
|
||||||
(:require [ring.util.response :as resp]
|
(:require [ring.util.response :as resp]
|
||||||
[wanijo.infrastructure.routing :refer [path]]
|
[wanijo.infrastructure.routing :refer [path]]
|
||||||
[wanijo.schema.db :as domain]))
|
[wanijo.schema.db :as db]))
|
||||||
|
|
||||||
(defn wrap-user-schemas [handler]
|
(defn wrap-user-schemas! [handler]
|
||||||
(fn [req]
|
(fn [req]
|
||||||
(if-let [uuid (get-in req [:session :uuid])]
|
(if-let [uuid (get-in req [:session :uuid])]
|
||||||
(handler (assoc-in req
|
(handler (assoc-in req
|
||||||
[:session :schemas]
|
[:session :schemas]
|
||||||
(domain/accessible-schemas! uuid)))
|
(db/accessible-schemas! uuid)))
|
||||||
(handler req))))
|
(handler req))))
|
||||||
|
|
||||||
(defn write-permission-middleware [schema-fn]
|
(defn write-permission-middleware! [schema-fn]
|
||||||
(fn [handler]
|
(fn [handler]
|
||||||
(fn [req]
|
(fn [req]
|
||||||
(let [uuid (schema-fn req)
|
(let [uuid (schema-fn req)]
|
||||||
check-fn domain/has-user-write-permissions?]
|
(if (db/has-user-write-permissions? uuid (-> req :session :uuid))
|
||||||
(if (check-fn uuid (get-in req [:session :uuid]))
|
|
||||||
(handler req)
|
(handler req)
|
||||||
(assoc
|
(assoc
|
||||||
(resp/redirect (path :schema-show {:uuid uuid}))
|
(resp/redirect (path :schema-show {:uuid uuid}))
|
||||||
:flash ["No write permission for schema"]))))))
|
:flash ["No write permission for schema"]))))))
|
||||||
|
|
||||||
(defn wrap-allowed-to-write []
|
(defn wrap-allowed-to-write! []
|
||||||
(write-permission-middleware #(get-in % [:params :uuid])))
|
(write-permission-middleware! #(get-in % [:params :uuid])))
|
||||||
|
|
||||||
(defn wrap-allowed-to-read
|
(defn wrap-allowed-to-read!
|
||||||
([schema-fn]
|
([schema-fn]
|
||||||
(wrap-allowed-to-read schema-fn
|
(wrap-allowed-to-read! schema-fn
|
||||||
(fn [_]
|
(fn [_]
|
||||||
(assoc (resp/redirect (path :schema-overview))
|
(assoc (resp/redirect (path :schema-overview))
|
||||||
:flash ["No read permission for schema"]))))
|
:flash ["No read permission for schema"]))))
|
||||||
([schema-fn not-allowed-fn]
|
([schema-fn not-allowed-fn]
|
||||||
(fn [handler]
|
(fn [handler]
|
||||||
(fn [req]
|
(fn [req]
|
||||||
(let [uuid (schema-fn req)
|
(let [uuid (schema-fn req)]
|
||||||
check-fn domain/has-user-read-permissions?]
|
(if (db/has-user-read-permissions? uuid (-> req :session :uuid))
|
||||||
(if (check-fn uuid (get-in req [:session :uuid]))
|
|
||||||
(handler req)
|
(handler req)
|
||||||
(not-allowed-fn req)))))))
|
(not-allowed-fn req)))))))
|
||||||
|
Loading…
Reference in new issue