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])})))
(defn wrap-allowed-to-write []
(schema-middleware/write-permission-middleware
(schema-middleware/write-permission-middleware!
#(or (get-in % [:params :schema])
(get-in % [:route-params :schema])
(-> (get-in % [:route-params :uuid])

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save