allowed schema connections

integration-tests
Josha von Gizycki 6 years ago
parent 09f12a7bb4
commit 47cae12fa0

@ -9,6 +9,9 @@
(spec/def ::date-str
#(re-matches #"\d{4}\d{2}\d{2}T\d{2}\d{2}\d{2}\.\d{3}Z" %))
(spec/def ::uuid
#(re-matches #"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}" %))
(def conn
(delay (db/connect
"bolt://localhost:7687"

@ -10,7 +10,7 @@
(spec/def ::assigned-to
(spec/or :public empty?
:assigned (spec/coll-of string?)))
:assigned (spec/coll-of ::neo4j/uuid)))
(neo4j/defquery
all-created-by
@ -127,17 +127,31 @@
assigned-users
{:uuid uuid}))
(defn find-with-assigned-users! [uuid]
(let [assigned (reduce #(case (-> %2 :p :type)
"write" (update %1 :write conj (-> %2 :u :uuid))
"read" (update %1 :read conj (-> %2 :u :uuid))
%1)
{:write []
:read []}
(assigned-users! uuid))]
(neo4j/defquery
assigned-schemas
"MATCH (s1:schema)-[p:permission]-(s2:schema)
WHERE s1.uuid = {uuid}
RETURN s2
ORDER BY s2.name")
(defn assigned-schemas! [uuid]
(neo4j/exec-query!
assigned-schemas
{:uuid uuid}))
(defn find-with-assigned-entities! [uuid]
(let [users (reduce #(case (-> %2 :p :type)
"write" (update %1 :write conj (-> %2 :u :uuid))
"read" (update %1 :read conj (-> %2 :u :uuid))
%1)
{:write []
:read []}
(assigned-users! uuid))
schemas (map #(-> % :s2 :uuid) (assigned-schemas! uuid))]
(assoc (find-by-uuid! uuid)
:assigned-read-users (:read assigned)
:assigned-write-users (:write assigned))))
:assigned-read-users (:read users)
:assigned-write-users (:write users)
:assigned-schemas schemas)))
(neo4j/defquery
remove-assignments
@ -162,3 +176,23 @@
{:uuid uuid
:users users
:permtype permission}]))
(neo4j/defquery
remove-schema-assignments
"MATCH (s1:schema)-[p:permission]-(s2:schema)
WHERE s1.uuid = {uuid}
DELETE p")
(neo4j/defquery
create-schema-assignments
"MATCH (s1:schema), (s2:schema)
WHERE s1.uuid = {uuid}
AND s2.uuid IN {schemas}
CREATE (s1)-[:permission]->(s2)")
(defn assign-schemas! [uuid schemas]
(neo4j/exec-queries!
[remove-schema-assignments
{:uuid uuid}]
[create-schema-assignments
{:uuid uuid :schemas schemas}]))

@ -27,12 +27,16 @@
(defn view! [uuid req]
(view-schema/show-schema!
(domain/find-with-assigned-users! uuid)
(domain/find-with-assigned-entities! uuid)
(domain-attr/find-by-schema! uuid)
(assoc-in view-schema/assign-form
[:fields :assigned :options]
(map #(vector (:ident %) (:uuid %))
(domain-user/all!)))
(assoc-in view-schema/schema-connections-form
[:fields :connections :options]
(map #(vector (:name %) (:uuid %))
(domain/all!)))
req))
(defn edit! [req]
@ -43,7 +47,7 @@
(resp/redirect (path :schema-show (:params req))))
(view! uuid req))))
(defn assign! [req]
(defn assign-users! [req]
(let [{:keys [uuid assigned]} (form/form-data view-schema/assign-form req)
permission (get-in req [:params :permission])]
(if (form/valid? view-schema/assign-form req)
@ -52,6 +56,15 @@
(resp/redirect (path :schema-show (:params req))))
(view! uuid req))))
(defn assign-schemas! [req]
(let [form view-schema/schema-connections-form
{:keys [uuid connections]} (form/form-data form req)]
(if (form/valid? form req)
(do
(domain/assign-schemas! uuid connections)
(resp/redirect (path :schema-show (:params req))))
(view! uuid req))))
(defroutes routes
(GET (register! :schema-overview "/schema")
[]
@ -65,9 +78,12 @@
(POST (register! :schema-edit "/schema/edit")
[]
edit!)
(POST (register! :schema-assign "/schema/assign")
(POST (register! :schema-assign-users "/schema/assign/users")
[]
assign-users!)
(POST (register! :schema-assign-schemas "/schema/assign/schemas")
[]
assign!)
assign-schemas!)
(DELETE (register! :schema-delete "/schema/:uuid")
[uuid :as req]
(delete-schema! uuid (:session req))))

@ -39,6 +39,14 @@
:from-req #(if (vector? %) % [%])}
:uuid {:widget :hidden}}})
(def schema-connections-form
{:fields {:connections {:label "Schemas"
:required false
:spec ::domain/assigned-to
:widget :mselect
:from-req #(if (vector? %) % [%])}
:uuid {:widget :hidden}}})
(defn overview! [req]
(let [session (:session req)
uuid (:uuid session)
@ -65,7 +73,7 @@
(form/render-widgets form {} req)
(hform/submit-button "Create"))])))
(defn show-schema! [schema attrs assign-form req]
(defn show-schema! [schema attrs assign-form conn-form req]
(view/layout!
:session (:session req)
:content
@ -77,7 +85,7 @@
(hform/submit-button "Edit"))
[:h2 "Permissions"]
[:h3 "Read permissions"]
(hform/form-to [:post (path :schema-assign)]
(hform/form-to [:post (path :schema-assign-users)]
(form/render-widgets assign-form
(assoc schema :assigned
(:assigned-read-users schema))
@ -85,13 +93,21 @@
(hform/hidden-field "permission" "read")
(hform/submit-button "Assign"))
[:h3 "Write permissions"]
(hform/form-to [:post (path :schema-assign)]
(hform/form-to [:post (path :schema-assign-users)]
(form/render-widgets assign-form
(assoc schema :assigned
(:assigned-write-users schema))
req)
(hform/hidden-field "permission" "write")
(hform/submit-button "Assign"))
[:h3 "Allowed schema connections"]
(hform/form-to [:post (path :schema-assign-schemas)]
(form/render-widgets conn-form
(assoc schema
:connections
(:assigned-schemas schema))
req)
(hform/submit-button "Assign"))
[:h2 "Attributes"]
[:ul.schema-attributes
(for [attr attrs]

Loading…
Cancel
Save