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