assigning users

integration-tests
Josha von Gizycki 6 years ago
parent 417a4f28d3
commit eee34e70f6

@ -9,11 +9,13 @@
(spec/and string? ::neo4j/date-str))
(spec/def ::assigned-to
(complement empty?))
(spec/or :public empty?
:assigned (spec/coll-of string?)
:single string?))
(neo4j/defquery
all-created-by
"MATCH (s:schema)-->(u:user)
"MATCH (s:schema)-[:created_by]->(u:user)
WHERE u.uuid = {uuid}
RETURN s
ORDER BY s.name")
@ -130,3 +132,25 @@
(defn find-with-assigned-users! [uuid]
(assoc (find-by-uuid! uuid)
:assigned (map :uuid (assigned-users! uuid))))
(neo4j/defquery
remove-assignments
"MATCH (s:schema)-[c:assigned_to]-(:user)
WHERE s.uuid = {uuid}
DELETE c")
(neo4j/defquery
create-assignment
"MATCH (s:schema), (u:user)
WHERE s.uuid = {uuid}
AND u.uuid IN {users}
CREATE (s)-[:assigned_to]->(u)")
(defn assign-users! [uuid users]
(neo4j/exec-query!
remove-assignments
{:uuid uuid})
(neo4j/exec-query!
create-assignment
{:uuid uuid
:users users}))

@ -40,14 +40,24 @@
(view-schema/show-schema!
(domain/find-with-assigned-users! uuid)
(domain-attr/find-by-schema! uuid)
(assoc-in view-schema/access-form
(assoc-in view-schema/assign-form
[:fields :assigned :options]
(map #(vector (:ident %) (:uuid %))
(domain-user/all!)))
req))
(defn assign! [req]
(println (:params req)))
(let [uuid (get-in req [:params :uuid])
users (get-in req [:params :assigned])]
(println (:params req))
(if (form/valid? view-schema/assign-form req)
(do
(domain/assign-users! uuid
(if (vector? users)
users
[users]))
(resp/redirect (path :schema-show (:params req))))
(view! uuid req))))
(defroutes routes
(GET (register! :schema-overview "/schema")

@ -29,10 +29,10 @@
:spec ::attr-domain/required
:widget :checkbox}}})
(def access-form
(def assign-form
{:fields {:assigned {:label "Users"
:required false
:spec :a
:spec ::domain/assigned-to
:widget :mselect}}})
(defn overview! [req]
@ -61,7 +61,7 @@
(form/render-widgets form {} req)
(hform/submit-button "Create"))])))
(defn show-schema! [schema attrs access-form req]
(defn show-schema! [schema attrs assign-form req]
(view/layout!
:session (:session req)
:content
@ -74,7 +74,7 @@
(hform/submit-button "Edit"))
[:h3 "Assign to users"]
(hform/form-to [:post (path :schema-assign)]
(form/render-widgets access-form schema req)
(form/render-widgets assign-form schema req)
(hform/hidden-field "uuid" (:uuid schema))
(hform/submit-button "Assign"))
[:h2 "Attributes"]

Loading…
Cancel
Save