fix form spec

integration-tests
Josha von Gizycki 5 years ago
parent 874af1eecf
commit b64045a34e

@ -1,5 +1,6 @@
(ns wanijo.schema.domain (ns wanijo.schema.domain
(:require [clojure.spec.alpha :as spec] (:require [clojure.spec.alpha :as spec]
[wanijo.specs :as specs]
[wanijo.framework.neo4j :as neo4j])) [wanijo.framework.neo4j :as neo4j]))
(spec/def ::name (spec/def ::name
@ -8,8 +9,8 @@
(spec/and string? ::neo4j/date-str)) (spec/and string? ::neo4j/date-str))
(spec/def ::assigned-to (spec/def ::assigned-to
(spec/or :public empty? (spec/or :public empty?
:assigned-single ::neo4j/uuid :assigned (spec/coll-of ::neo4j/uuid)
:assigned (spec/coll-of ::neo4j/uuid))) :assigned-single ::neo4j/uuid))
(spec/def ::schema (spec/def ::schema
(spec/keys ::req-un [::name (spec/keys ::req-un [::name
::created-at ::created-at
@ -20,7 +21,6 @@
WHERE u.uuid = {uuid} WHERE u.uuid = {uuid}
RETURN s RETURN s
ORDER BY s.name") ORDER BY s.name")
(defn all-created-by! [user-uuid] (defn all-created-by! [user-uuid]
(map :s (map :s
(neo4j/exec-query! (neo4j/exec-query!
@ -31,7 +31,6 @@
"MATCH (s:schema) "MATCH (s:schema)
RETURN s RETURN s
ORDER BY s.name") ORDER BY s.name")
(defn all! [] (defn all! []
(map :s (map :s
(neo4j/exec-query! all {}))) (neo4j/exec-query! all {})))
@ -44,7 +43,6 @@
SET s.uuid = {s_uuid} SET s.uuid = {s_uuid}
SET s.created_at = {created_at} SET s.created_at = {created_at}
RETURN s") RETURN s")
(defn create-new! [schema-name user-uuid] (defn create-new! [schema-name user-uuid]
(->> (->>
(neo4j/exec-query! (neo4j/exec-query!
@ -60,7 +58,6 @@
"MATCH (s:schema) "MATCH (s:schema)
WHERE s.uuid = {uuid} WHERE s.uuid = {uuid}
RETURN s") RETURN s")
(defn find-by-uuid! [uuid] (defn find-by-uuid! [uuid]
(->> (->>
(neo4j/exec-query! (neo4j/exec-query!
@ -73,7 +70,6 @@
"MATCH (s:schema)-->(u:user) "MATCH (s:schema)-->(u:user)
WHERE s.uuid = {uuid} WHERE s.uuid = {uuid}
RETURN u.uuid as uuid") RETURN u.uuid as uuid")
(defn find-schema-creator! [uuid] (defn find-schema-creator! [uuid]
(->> (->>
(neo4j/exec-query! (neo4j/exec-query!
@ -91,7 +87,6 @@
NOT EXISTS((:user) NOT EXISTS((:user)
-[:permission {type:{type}}]- -[:permission {type:{type}}]-
(s)) AS is_public") (s)) AS is_public")
(defn has-user-permission? [perm-type schema-uuid user-uuid] (defn has-user-permission? [perm-type schema-uuid user-uuid]
(let [permissions (first (neo4j/exec-query! schema-permissions (let [permissions (first (neo4j/exec-query! schema-permissions
{:schema_uuid schema-uuid {:schema_uuid schema-uuid
@ -100,10 +95,8 @@
public? (:is_public permissions) public? (:is_public permissions)
user? (:user_has_permission permissions)] user? (:user_has_permission permissions)]
(or public? user?))) (or public? user?)))
(defn has-user-write-permissions? [schema-uuid user-uuid] (defn has-user-write-permissions? [schema-uuid user-uuid]
(has-user-permission? "write" schema-uuid user-uuid)) (has-user-permission? "write" schema-uuid user-uuid))
(defn has-user-read-permissions? [schema-uuid user-uuid] (defn has-user-read-permissions? [schema-uuid user-uuid]
(has-user-permission? "read" schema-uuid user-uuid)) (has-user-permission? "read" schema-uuid user-uuid))
@ -114,7 +107,6 @@
OR NOT EXISTS((:user)-[:permission {type:'read'}]->(s)) OR NOT EXISTS((:user)-[:permission {type:'read'}]->(s))
RETURN s RETURN s
ORDER BY s.name") ORDER BY s.name")
(defn accessible-schemas! [user-uuid] (defn accessible-schemas! [user-uuid]
(map :s (map :s
(neo4j/exec-query! accessible-schemas (neo4j/exec-query! accessible-schemas
@ -128,7 +120,6 @@
WITH s WITH s
MATCH (s)-[c]-() MATCH (s)-[c]-()
DELETE c, s") DELETE c, s")
(defn delete! [uuid] (defn delete! [uuid]
(neo4j/exec-query! (neo4j/exec-query!
delete delete
@ -138,7 +129,6 @@
"MATCH (s:schema) "MATCH (s:schema)
WHERE s.uuid = {uuid} WHERE s.uuid = {uuid}
SET s.name = {name}") SET s.name = {name}")
(defn edit! [schema] (defn edit! [schema]
(neo4j/exec-query! (neo4j/exec-query!
edit edit
@ -149,7 +139,6 @@
WHERE s.uuid = {uuid} WHERE s.uuid = {uuid}
RETURN u, p RETURN u, p
ORDER BY u.ident") ORDER BY u.ident")
(defn assigned-users! [uuid] (defn assigned-users! [uuid]
(neo4j/exec-query! (neo4j/exec-query!
assigned-users assigned-users
@ -160,7 +149,6 @@
WHERE s1.uuid = {uuid} WHERE s1.uuid = {uuid}
RETURN s2 RETURN s2
ORDER BY s2.name") ORDER BY s2.name")
(defn assigned-schemas! [uuid] (defn assigned-schemas! [uuid]
(neo4j/exec-query! (neo4j/exec-query!
assigned-schemas assigned-schemas
@ -185,13 +173,11 @@
WHERE s.uuid = {uuid} WHERE s.uuid = {uuid}
AND c.type = {permtype} AND c.type = {permtype}
DELETE c") DELETE c")
(neo4j/defquery create-assignments (neo4j/defquery create-assignments
"MATCH (s:schema), (u:user) "MATCH (s:schema), (u:user)
WHERE s.uuid = {uuid} WHERE s.uuid = {uuid}
AND u.uuid IN {users} AND u.uuid IN {users}
CREATE (s)<-[:permission{type:{permtype}}]-(u)") CREATE (s)<-[:permission{type:{permtype}}]-(u)")
(defn assign-users! [uuid users permission] (defn assign-users! [uuid users permission]
(neo4j/exec-queries! (neo4j/exec-queries!
[remove-assignments [remove-assignments
@ -206,13 +192,11 @@
"MATCH (s1:schema)-[p:permission]-(s2:schema) "MATCH (s1:schema)-[p:permission]-(s2:schema)
WHERE s1.uuid = {uuid} WHERE s1.uuid = {uuid}
DELETE p") DELETE p")
(neo4j/defquery create-schema-assignments (neo4j/defquery create-schema-assignments
"MATCH (s1:schema), (s2:schema) "MATCH (s1:schema), (s2:schema)
WHERE s1.uuid = {uuid} WHERE s1.uuid = {uuid}
AND s2.uuid IN {schemas} AND s2.uuid IN {schemas}
CREATE (s1)-[:permission]->(s2)") CREATE (s1)-[:permission]->(s2)")
(defn assign-schemas! [uuid schemas] (defn assign-schemas! [uuid schemas]
(neo4j/exec-queries! (neo4j/exec-queries!
[remove-schema-assignments [remove-schema-assignments
@ -223,7 +207,6 @@
(neo4j/defquery find-by-instance (neo4j/defquery find-by-instance
"MATCH (i:instance {uuid:{uuid}})-[:of]->(s:schema) "MATCH (i:instance {uuid:{uuid}})-[:of]->(s:schema)
RETURN s") RETURN s")
(defn find-by-instance! [uuid] (defn find-by-instance! [uuid]
(-> find-by-instance (-> find-by-instance
(neo4j/exec-query! {:uuid uuid}) (neo4j/exec-query! {:uuid uuid})

Loading…
Cancel
Save