integration-tests
Josha von Gizycki 6 years ago
commit 3a8a746bab

@ -9,11 +9,13 @@
(spec/and string? ::neo4j/date-str)) (spec/and string? ::neo4j/date-str))
(spec/def ::assigned-to (spec/def ::assigned-to
(complement empty?)) (spec/or :public empty?
:assigned (spec/coll-of string?)
:single string?))
(neo4j/defquery (neo4j/defquery
all-created-by all-created-by
"MATCH (s:schema)-->(u:user) "MATCH (s:schema)-[:created_by]->(u:user)
WHERE u.uuid = {uuid} WHERE u.uuid = {uuid}
RETURN s RETURN s
ORDER BY s.name") ORDER BY s.name")
@ -130,3 +132,25 @@
(defn find-with-assigned-users! [uuid] (defn find-with-assigned-users! [uuid]
(assoc (find-by-uuid! uuid) (assoc (find-by-uuid! uuid)
:assigned (map :uuid (assigned-users! 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! (view-schema/show-schema!
(domain/find-with-assigned-users! uuid) (domain/find-with-assigned-users! uuid)
(domain-attr/find-by-schema! uuid) (domain-attr/find-by-schema! uuid)
(assoc-in view-schema/access-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!)))
req)) req))
(defn assign! [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))))
;; random change ;; random change

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

Loading…
Cancel
Save