naming conventions regarding side effects

neo4j-4
Josha von Gizycki 5 years ago
parent b535880c1d
commit 81a33bb68f

@ -33,7 +33,7 @@
(resp/redirect (path :schema-show {:uuid (get-in req [:params :schema])}))) (resp/redirect (path :schema-show {:uuid (get-in req [:params :schema])})))
(defn wrap-allowed-to-write [] (defn wrap-allowed-to-write []
(schema-middleware/write-permission-middleware (schema-middleware/write-permission-middleware!
#(or (get-in % [:params :schema]) #(or (get-in % [:params :schema])
(get-in % [:route-params :schema]) (get-in % [:route-params :schema])
(-> (get-in % [:route-params :uuid]) (-> (get-in % [:route-params :uuid])

@ -42,7 +42,7 @@
(def standalone-app (def standalone-app
(-> app-routes (-> app-routes
schema-middleware/wrap-user-schemas schema-middleware/wrap-user-schemas!
ring-json/wrap-json-response ring-json/wrap-json-response
(wrap-defaults site-defaults))) (wrap-defaults site-defaults)))
@ -55,7 +55,7 @@
(-> app-routes (-> app-routes
wrap-spec-asserts wrap-spec-asserts
devmode/wrap-devmode devmode/wrap-devmode
schema-middleware/wrap-user-schemas schema-middleware/wrap-user-schemas!
ring-json/wrap-json-response ring-json/wrap-json-response
(wrap-defaults (wrap-defaults
(assoc-in site-defaults (assoc-in site-defaults

@ -2,4 +2,4 @@
(:require [wanijo.infrastructure.view :as view])) (:require [wanijo.infrastructure.view :as view]))
(defn root! [req] (defn root! [req]
(view/layout! :session (:session req))) (view/layout :session (:session req)))

@ -21,7 +21,7 @@
:flash :invalid-credentials)))) :flash :invalid-credentials))))
(defn login! [req] (defn login! [req]
(view/layout! (view/layout
:content :content
[[:h1 "Login"] [[:h1 "Login"]
(hform/form-to (hform/form-to

@ -23,7 +23,7 @@
[:h2.flash__heading--error "Warning"] [:h2.flash__heading--error "Warning"]
content]) content])
(defn layout! (defn layout
[& {:keys [content [& {:keys [content
title title
session session

@ -127,7 +127,7 @@
(GET (register! :instance-list "/instance/list/:schema-uuid") (GET (register! :instance-list "/instance/list/:schema-uuid")
[schema-uuid :as req] [schema-uuid :as req]
(list! schema-uuid req)) (list! schema-uuid req))
(middleware-schema/wrap-allowed-to-read (middleware-schema/wrap-allowed-to-read!
#(get-in % [:params :schema-uuid]))) #(get-in % [:params :schema-uuid])))
(POST (register! :instance-new "/instance/new") [] (POST (register! :instance-new "/instance/new") []
new!) new!)

@ -9,7 +9,7 @@
[formulare.core :as form])) [formulare.core :as form]))
(defn edit [instance form form-data schemas req] (defn edit [instance form form-data schemas req]
(view/layout! (view/layout
:request req :request req
:content :content
[[:h1 [[:h1

@ -8,7 +8,7 @@
[wanijo.infrastructure.time :refer [prettify-dt]])) [wanijo.infrastructure.time :refer [prettify-dt]]))
(defn instances [schema instances new-form req] (defn instances [schema instances new-form req]
(view/layout! (view/layout
:request req :request req
:content :content
[[:h1 "All Instances of schema " [[:h1 "All Instances of schema "

@ -6,7 +6,7 @@
[formulare.core :as form])) [formulare.core :as form]))
(defn link-selection [instance schema form req] (defn link-selection [instance schema form req]
(view/layout! (view/layout
:request req :request req
:content :content
[[:h1 [[:h1

@ -11,7 +11,7 @@
[wanijo.visualisation.viz :as viz])) [wanijo.visualisation.viz :as viz]))
(defn show [instance schemas req] (defn show [instance schemas req]
(view/layout! (view/layout
:request req :request req
:content :content
[[:h1 [[:h1

@ -5,7 +5,7 @@
[wanijo.infrastructure.time :refer [prettify-dt]])) [wanijo.infrastructure.time :refer [prettify-dt]]))
(defn starred [instances req] (defn starred [instances req]
(view/layout! (view/layout
:request req :request req
:content :content
[[:h1 "Starred instances"] [[:h1 "Starred instances"]

@ -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)))))))

@ -86,7 +86,7 @@
(POST (register! :schema-new "/schema/new") [] (POST (register! :schema-new "/schema/new") []
new!) new!)
(comp/wrap-routes read-routes (comp/wrap-routes read-routes
(middleware/wrap-allowed-to-read (middleware/wrap-allowed-to-read!
#(get-in % [:route-params :uuid]))) #(get-in % [:route-params :uuid])))
(comp/wrap-routes write-routes (comp/wrap-routes write-routes
(middleware/wrap-allowed-to-write))) (middleware/wrap-allowed-to-write!)))

@ -14,7 +14,7 @@
(let [session (:session req) (let [session (:session req)
uuid (:uuid session) uuid (:uuid session)
schemas (domain/all-created-by! uuid)] schemas (domain/all-created-by! uuid)]
(view/layout! (view/layout
:request req :request req
:content :content
[[:h1 "All schemas"] [[:h1 "All schemas"]
@ -37,7 +37,7 @@
(hform/submit-button "Create"))]))) (hform/submit-button "Create"))])))
(defn show-schema! [schema attrs assign-form conn-form req] (defn show-schema! [schema attrs assign-form conn-form req]
(view/layout! (view/layout
:request req :request req
:content :content
[[:h1 "Schema " [[:h1 "Schema "

@ -12,7 +12,7 @@
:spec ::domain/ident}}}) :spec ::domain/ident}}})
(defn profile! [req user] (defn profile! [req user]
(view/layout! (view/layout
:session (:session req) :session (:session req)
:content :content
[[:h1 "Hi, " (get-in req [:session :ident])] [[:h1 "Hi, " (get-in req [:session :ident])]

@ -12,7 +12,7 @@
[view :as vis-view]])) [view :as vis-view]]))
(defn all-instances [req] (defn all-instances [req]
(view/layout! (view/layout
:request req :request req
:content :content
[[:h1 "All Instances"] [[:h1 "All Instances"]

@ -6,7 +6,7 @@
[wanijo.infrastructure.view :as view])) [wanijo.infrastructure.view :as view]))
(defn index [instance req] (defn index [instance req]
(view/layout! (view/layout
:request req :request req
:head (list (include-css "/css/vis-network.min.css") :head (list (include-css "/css/vis-network.min.css")
(include-js "/js/vis-network.min.js" (include-js "/js/vis-network.min.js"

Loading…
Cancel
Save