|
|
@ -1,5 +1,5 @@
|
|
|
|
(ns wanijo.schema.routes
|
|
|
|
(ns wanijo.schema.routes
|
|
|
|
(:require [compojure.core :refer [defroutes GET POST DELETE]]
|
|
|
|
(:require [compojure.core :refer [defroutes GET POST DELETE] :as comp]
|
|
|
|
[ring.util.response :as resp]
|
|
|
|
[ring.util.response :as resp]
|
|
|
|
[formulare.core :as form]
|
|
|
|
[formulare.core :as form]
|
|
|
|
[wanijo.framework.view :as view]
|
|
|
|
[wanijo.framework.view :as view]
|
|
|
@ -19,11 +19,8 @@
|
|
|
|
(view-schema/overview! req)))
|
|
|
|
(view-schema/overview! req)))
|
|
|
|
|
|
|
|
|
|
|
|
(defn delete-schema! [uuid session]
|
|
|
|
(defn delete-schema! [uuid session]
|
|
|
|
(if (domain/can-user-modify? uuid (:uuid session))
|
|
|
|
(domain/delete! uuid)
|
|
|
|
(do
|
|
|
|
(resp/redirect (path :schema-overview)))
|
|
|
|
(domain/delete! uuid)
|
|
|
|
|
|
|
|
(resp/redirect (path :schema-overview)))
|
|
|
|
|
|
|
|
{:status 403}))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defn view! [uuid req]
|
|
|
|
(defn view! [uuid req]
|
|
|
|
(view-schema/show-schema!
|
|
|
|
(view-schema/show-schema!
|
|
|
@ -65,7 +62,18 @@
|
|
|
|
(resp/redirect (path :schema-show (:params req))))
|
|
|
|
(resp/redirect (path :schema-show (:params req))))
|
|
|
|
(view! uuid req))))
|
|
|
|
(view! uuid req))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defn wrap-allowed-to-write [handler]
|
|
|
|
|
|
|
|
(fn [req]
|
|
|
|
|
|
|
|
(let [uuid (get-in req [:params :uuid])
|
|
|
|
|
|
|
|
user (get-in req [:session :uuid])]
|
|
|
|
|
|
|
|
(if (domain/has-user-write-permissions? uuid user)
|
|
|
|
|
|
|
|
(handler req)
|
|
|
|
|
|
|
|
(assoc
|
|
|
|
|
|
|
|
(resp/redirect (path :schema-show (:params req)))
|
|
|
|
|
|
|
|
:flash ["No write permission for schema"])))))
|
|
|
|
|
|
|
|
|
|
|
|
(defroutes routes
|
|
|
|
(defroutes routes
|
|
|
|
|
|
|
|
(GET "/403" [] {:status 403 :body "NE"})
|
|
|
|
(GET (register! :schema-overview "/schema")
|
|
|
|
(GET (register! :schema-overview "/schema")
|
|
|
|
[]
|
|
|
|
[]
|
|
|
|
view-schema/overview!)
|
|
|
|
view-schema/overview!)
|
|
|
@ -75,15 +83,14 @@
|
|
|
|
(POST (register! :schema-new "/schema/new")
|
|
|
|
(POST (register! :schema-new "/schema/new")
|
|
|
|
[]
|
|
|
|
[]
|
|
|
|
new!)
|
|
|
|
new!)
|
|
|
|
(POST (register! :schema-edit "/schema/edit")
|
|
|
|
(wrap-allowed-to-write
|
|
|
|
[]
|
|
|
|
(comp/routes
|
|
|
|
edit!)
|
|
|
|
(POST (register! :schema-edit "/schema/edit") []
|
|
|
|
(POST (register! :schema-assign-users "/schema/assign/users")
|
|
|
|
edit!)
|
|
|
|
[]
|
|
|
|
(POST (register! :schema-assign-users "/schema/assign/users") []
|
|
|
|
assign-users!)
|
|
|
|
assign-users!)
|
|
|
|
(POST (register! :schema-assign-schemas "/schema/assign/schemas")
|
|
|
|
(POST (register! :schema-assign-schemas "/schema/assign/schemas") []
|
|
|
|
[]
|
|
|
|
assign-schemas!)
|
|
|
|
assign-schemas!)
|
|
|
|
(DELETE (register! :schema-delete "/schema/:uuid")
|
|
|
|
(DELETE (register! :schema-delete "/schema/:uuid")
|
|
|
|
[uuid :as req]
|
|
|
|
[uuid :as req]
|
|
|
|
(delete-schema! uuid (:session req))))))
|
|
|
|
(delete-schema! uuid (:session req))))
|
|
|
|
|
|
|
|