some logic into schema/domain

neo4j-4
Josha von Gizycki 5 years ago
parent cc30b94d24
commit b1d7c31a83

@ -1,18 +1,6 @@
(ns wanijo.schema.db (ns wanijo.schema.db
(:require [clojure.spec.alpha :as spec] (:require [wanijo.infrastructure.neo4j :as neo4j]
[wanijo.specs :as specs] [wanijo.schema.domain :as domain]))
[wanijo.infrastructure.neo4j :as neo4j]))
(spec/def ::name
(spec/and ::specs/name (complement empty?)))
(spec/def ::assigned-to
(spec/or :public empty?
:assigned (spec/coll-of ::neo4j/uuid)
:assigned-single ::neo4j/uuid))
(spec/def ::schema
(spec/keys ::req-un [::name
::specs/created-at
::neo4j/uuid]))
(neo4j/defquery all-created-by (neo4j/defquery all-created-by
"MATCH (s:schema)-[:created_by]->(u:user) "MATCH (s:schema)-[:created_by]->(u:user)
@ -45,10 +33,10 @@
(->> (->>
(neo4j/exec-query! (neo4j/exec-query!
create-new create-new
{:u_uuid user-uuid {:u_uuid user-uuid}
:name schema-name :name schema-name
:s_uuid (neo4j/uuid) :s_uuid (neo4j/uuid)
:created_at (neo4j/now-str)}) :created_at (neo4j/now-str))
first first
:uuid)) :uuid))
@ -86,13 +74,12 @@
-[: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 [perms (first
(neo4j/exec-query! schema-permissions
{:schema_uuid schema-uuid {:schema_uuid schema-uuid
:user_uuid user-uuid :user_uuid user-uuid
:type perm-type})) :type perm-type}))]
public? (:is_public permissions) (domain/has-user-permission? perms)))
user? (:user_has_permission permissions)]
(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]

@ -0,0 +1,20 @@
(ns wanijo.schema.domain
(:require [clojure.spec.alpha :as spec]
[wanijo.specs :as specs]
[wanijo.infrastructure.neo4j :as neo4j]))
(spec/def ::name
(spec/and ::specs/name (complement empty?)))
(spec/def ::assigned-to
(spec/or :public empty?
:assigned (spec/coll-of ::neo4j/uuid)
:assigned-single ::neo4j/uuid))
(spec/def ::schema
(spec/keys ::req-un [::name
::specs/created-at
::neo4j/uuid]))
(defn has-user-permission?
[{public? :is_public
user-permission :user_has_permission}]
(or public? user-permission))
Loading…
Cancel
Save