separate read and write permissions

integration-tests
Josha von Gizycki 6 years ago
parent b761806c08
commit 2eb059855c

@ -117,40 +117,75 @@
schema)) schema))
(neo4j/defquery (neo4j/defquery
assigned-users assigned-read-users
"MATCH (s:schema)-[:assigned_to]-(u:user) "MATCH (s:schema)-[:read]-(u:user)
WHERE s.uuid = {uuid} WHERE s.uuid = {uuid}
RETURN u RETURN u
ORDER BY u.ident") ORDER BY u.ident")
(defn assigned-users! [uuid] (defn assigned-read-users! [uuid]
(map :u (map :u
(neo4j/exec-query! (neo4j/exec-query!
assigned-users assigned-read-users
{:uuid uuid})))
(neo4j/defquery
assigned-write-users
"MATCH (s:schema)-[:write]-(u:user)
WHERE s.uuid = {uuid}
RETURN u
ORDER BY u.ident")
(defn assigned-write-users! [uuid]
(map :u
(neo4j/exec-query!
assigned-write-users
{:uuid uuid}))) {:uuid uuid})))
(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-read-users (map :uuid (assigned-read-users! uuid))
:assigned-write-users (map :uuid (assigned-write-users! uuid))))
(neo4j/defquery (neo4j/defquery
remove-assignments remove-read-assignments
"MATCH (s:schema)-[c:assigned_to]-(:user) "MATCH (s:schema)-[c:read]-(:user)
WHERE s.uuid = {uuid} WHERE s.uuid = {uuid}
DELETE c") DELETE c")
(neo4j/defquery (neo4j/defquery
create-assignment create-read-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)-[:assigned_to]->(u)") CREATE (s)<-[:read]-(u)")
(defn assign-users! [uuid users] (neo4j/defquery
(neo4j/exec-query! remove-write-assignments
remove-assignments "MATCH (s:schema)-[c:write]-(:user)
{:uuid uuid}) WHERE s.uuid = {uuid}
(neo4j/exec-query! DELETE c")
create-assignment
{:uuid uuid (neo4j/defquery
:users users})) create-write-assignments
"MATCH (s:schema), (u:user)
WHERE s.uuid = {uuid}
AND u.uuid IN {users}
CREATE (s)<-[:write]-(u)")
(defn assign-users! [uuid users permission]
(if (= permission "write")
(do (neo4j/exec-query!
remove-write-assignments
{:uuid uuid})
(neo4j/exec-query!
create-write-assignments
{:uuid uuid
:users users}))
(do (neo4j/exec-query!
remove-read-assignments
{:uuid uuid})
(neo4j/exec-query!
create-read-assignments
{:uuid uuid
:users users}))))

@ -44,15 +44,11 @@
(view! uuid req)))) (view! uuid req))))
(defn assign! [req] (defn assign! [req]
(let [uuid (get-in req [:params :uuid]) (let [{:keys [uuid assigned]} (form/form-data view-schema/assign-form req)
users (get-in req [:params :assigned])] permission (get-in req [:params :permission])]
(println (:params req))
(if (form/valid? view-schema/assign-form req) (if (form/valid? view-schema/assign-form req)
(do (do
(domain/assign-users! uuid (domain/assign-users! uuid assigned permission)
(if (vector? users)
users
[users]))
(resp/redirect (path :schema-show (:params req)))) (resp/redirect (path :schema-show (:params req))))
(view! uuid req)))) (view! uuid req))))

@ -35,7 +35,8 @@
{:fields {:assigned {:label "Users" {:fields {:assigned {:label "Users"
:required false :required false
:spec ::domain/assigned-to :spec ::domain/assigned-to
:widget :mselect} :widget :mselect
:from-req #(if (vector? %) % [%])}
:uuid {:widget :hidden}}}) :uuid {:widget :hidden}}})
(defn overview! [req] (defn overview! [req]
@ -74,10 +75,6 @@
(hform/form-to [:post (path :schema-edit)] (hform/form-to [:post (path :schema-edit)]
(form/render-widgets form schema req) (form/render-widgets form schema req)
(hform/submit-button "Edit")) (hform/submit-button "Edit"))
[:h3 "Assign to users"]
(hform/form-to [:post (path :schema-assign)]
(form/render-widgets assign-form schema req)
(hform/submit-button "Assign"))
[:h2 "Attributes"] [:h2 "Attributes"]
[:ul.schema-attributes [:ul.schema-attributes
(for [attr attrs] (for [attr attrs]
@ -96,6 +93,23 @@
(form/render-widgets attr-form {} req) (form/render-widgets attr-form {} req)
(hform/hidden-field "schema" (:uuid schema)) (hform/hidden-field "schema" (:uuid schema))
(hform/submit-button "Create")) (hform/submit-button "Create"))
[:h2 "Permissions"]
[:h3 "Read permissions"]
(hform/form-to [:post (path :schema-assign)]
(form/render-widgets assign-form
(assoc schema :assigned
(:assigned-read-users schema))
req)
(hform/hidden-field "permission" "read")
(hform/submit-button "Assign"))
[:h3 "Write permissions"]
(hform/form-to [:post (path :schema-assign)]
(form/render-widgets assign-form
(assoc schema :assigned
(:assigned-write-users schema))
req)
(hform/hidden-field "permission" "write")
(hform/submit-button "Assign"))
[:h2 "Actions"] [:h2 "Actions"]
(hform/form-to {:class "inline"} (hform/form-to {:class "inline"}
[:delete (path :schema-delete schema)] [:delete (path :schema-delete schema)]

Loading…
Cancel
Save