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