allowed schema connections

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

@ -9,6 +9,9 @@
(spec/def ::date-str (spec/def ::date-str
#(re-matches #"\d{4}\d{2}\d{2}T\d{2}\d{2}\d{2}\.\d{3}Z" %)) #(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 (def conn
(delay (db/connect (delay (db/connect
"bolt://localhost:7687" "bolt://localhost:7687"

@ -10,7 +10,7 @@
(spec/def ::assigned-to (spec/def ::assigned-to
(spec/or :public empty? (spec/or :public empty?
:assigned (spec/coll-of string?))) :assigned (spec/coll-of ::neo4j/uuid)))
(neo4j/defquery (neo4j/defquery
all-created-by all-created-by
@ -127,17 +127,31 @@
assigned-users assigned-users
{:uuid uuid})) {:uuid uuid}))
(defn find-with-assigned-users! [uuid] (neo4j/defquery
(let [assigned (reduce #(case (-> %2 :p :type) 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)) "write" (update %1 :write conj (-> %2 :u :uuid))
"read" (update %1 :read conj (-> %2 :u :uuid)) "read" (update %1 :read conj (-> %2 :u :uuid))
%1) %1)
{:write [] {:write []
:read []} :read []}
(assigned-users! uuid))] (assigned-users! uuid))
schemas (map #(-> % :s2 :uuid) (assigned-schemas! uuid))]
(assoc (find-by-uuid! uuid) (assoc (find-by-uuid! uuid)
:assigned-read-users (:read assigned) :assigned-read-users (:read users)
:assigned-write-users (:write assigned)))) :assigned-write-users (:write users)
:assigned-schemas schemas)))
(neo4j/defquery (neo4j/defquery
remove-assignments remove-assignments
@ -162,3 +176,23 @@
{:uuid uuid {:uuid uuid
:users users :users users
:permtype permission}])) :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] (defn view! [uuid req]
(view-schema/show-schema! (view-schema/show-schema!
(domain/find-with-assigned-users! uuid) (domain/find-with-assigned-entities! uuid)
(domain-attr/find-by-schema! uuid) (domain-attr/find-by-schema! uuid)
(assoc-in view-schema/assign-form (assoc-in view-schema/assign-form
[:fields :assigned :options] [:fields :assigned :options]
(map #(vector (:ident %) (:uuid %)) (map #(vector (:ident %) (:uuid %))
(domain-user/all!))) (domain-user/all!)))
(assoc-in view-schema/schema-connections-form
[:fields :connections :options]
(map #(vector (:name %) (:uuid %))
(domain/all!)))
req)) req))
(defn edit! [req] (defn edit! [req]
@ -43,7 +47,7 @@
(resp/redirect (path :schema-show (:params req)))) (resp/redirect (path :schema-show (:params req))))
(view! uuid req)))) (view! uuid req))))
(defn assign! [req] (defn assign-users! [req]
(let [{:keys [uuid assigned]} (form/form-data view-schema/assign-form req) (let [{:keys [uuid assigned]} (form/form-data view-schema/assign-form req)
permission (get-in req [:params :permission])] permission (get-in req [:params :permission])]
(if (form/valid? view-schema/assign-form req) (if (form/valid? view-schema/assign-form req)
@ -52,6 +56,15 @@
(resp/redirect (path :schema-show (:params req)))) (resp/redirect (path :schema-show (:params req))))
(view! uuid 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 (defroutes routes
(GET (register! :schema-overview "/schema") (GET (register! :schema-overview "/schema")
[] []
@ -65,9 +78,12 @@
(POST (register! :schema-edit "/schema/edit") (POST (register! :schema-edit "/schema/edit")
[] []
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") (DELETE (register! :schema-delete "/schema/:uuid")
[uuid :as req] [uuid :as req]
(delete-schema! uuid (:session req)))) (delete-schema! uuid (:session req))))

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

Loading…
Cancel
Save