fix deletion of instances with revisions

master
Josha von Gizycki 2 years ago
parent 57412a5544
commit c7b3f4e69a

@ -138,11 +138,10 @@
(comment
(db-rev/revision-queries
{:instance-name "dings"
:instance-uuid "4711"
:properties [{:type "string"
:value "dings-prop"}]})
)
{:instance-name "dings"
:instance-uuid "4711"
:properties [{:type "string"
:value "dings-prop"}]}))
(neo4j/defquery delete
"MATCH (i:instance {uuid: $uuid}),
@ -155,8 +154,13 @@
(i)-[tw:tagged_with]->()
OPTIONAL MATCH
(i)-[l:link]-()
OPTIONAL MATCH
(i)<-[ric:of]-(rev:revision)
OPTIONAL MATCH
(rev_prop:rev_property)-[rpc:of]->(rev)
DELETE pac, pc, cb, ic, p,
l, tw, i")
l, tw, i, ric,
rpc, rev_prop, rev")
(defn delete! [uuid]
(neo4j/exec-query! delete {:uuid uuid}))

@ -39,8 +39,8 @@
instance (forms-inst/form-data->instance form-data
req-attrs)]
(db/create! user-uuid
schema-uuid
instance)
schema-uuid
instance)
(resp/redirect (path :instance-list
(:params req))))
(route-list! schema-uuid req))))
@ -53,7 +53,7 @@
instance (assoc (instance! uuid)
:starred
(db/is-starred! uuid
user-uuid))]
user-uuid))]
(show instance
(domain-schema/accessible-schemas! user-uuid)
req)))
@ -71,7 +71,7 @@
(comment
(forms-inst/with-attributes
(db-attr/find-by-instance!
"def4dacb-979f-4a0d-b1d6-535ac2a3f94b")))
"def4dacb-979f-4a0d-b1d6-535ac2a3f94b")))
(defn route-edit! [uuid req]
(let [attrs (db-attr/find-by-instance! uuid)
@ -79,9 +79,7 @@
(if (form/valid? form-def req)
(let [form-data (form/form-data form-def req)
form-instance (forms-inst/form-data->instance form-data attrs)
instance (assoc form-instance :uuid uuid)
_ (clojure.pprint/pprint instance)]
(clojure.pprint/pprint (files/persist-files! instance))
instance (assoc form-instance :uuid uuid)]
(db/edit! instance (domain/to-revision instance))
(resp/redirect (path :instance-show instance)))
(route-show! uuid req))))
@ -124,12 +122,12 @@
(defn route-mark-starred! [uuid req]
(db/mark-starred! uuid
(-> req :session :uuid))
(-> req :session :uuid))
(resp/redirect (path :instance-show {:uuid uuid})))
(defn route-remove-starred! [uuid req]
(db/remove-starred! uuid
(-> req :session :uuid))
(-> req :session :uuid))
(resp/redirect (path :instance-show {:uuid uuid})))
(defn route-list-starred! [req]
@ -155,11 +153,11 @@
; (clojure.pprint/pprint names)
; (clojure.pprint/pprint instances)
; (clojure.pprint/pprint source-uuid)
#_ (clojure.pprint/pprint
(map (fn [[target-schema target-instances]]
{:link-name (get names target-schema)
:instances target-instances})
instances)))
#_(clojure.pprint/pprint
(map (fn [[target-schema target-instances]]
{:link-name (get names target-schema)
:instances target-instances})
instances)))
(resp/redirect (path :instance-show {:uuid uuid})))
(defn schema-uuid-by-instance [req]
@ -174,12 +172,12 @@
(-> (compojure/routes
(GET (register! :instance-link-selection
"/instance/:uuid/link/:schema-uuid")
[uuid schema-uuid :as req]
(route-link-selection! uuid schema-uuid req))
[uuid schema-uuid :as req]
(route-link-selection! uuid schema-uuid req))
(POST (register! :instance-link-create
"/instance/:uuid/link/:schema-uuid")
[uuid schema-uuid :as req]
(route-create-link! uuid schema-uuid req)))
[uuid schema-uuid :as req]
(route-create-link! uuid schema-uuid req)))
(wrap-routes
(middleware-schema/wrap-allowed-to-write!
#(get-in % [:params :schema-uuid])))
@ -191,32 +189,32 @@
(wrap-routes
(compojure/routes
(GET (register! :instance-edit-form "/instance/:uuid/edit")
[uuid :as req]
(route-edit-form! uuid req))
[uuid :as req]
(route-edit-form! uuid req))
(POST (register! :instance-edit "/instance/:uuid")
[uuid :as req]
(route-edit! uuid req))
[uuid :as req]
(route-edit! uuid req))
(DELETE (register! :instance-delete "/instance/:uuid")
[uuid]
(route-delete! uuid))
[uuid]
(route-delete! uuid))
(DELETE (register! :instance-link-delete
"/instance/:uuid/link/:link-uuid")
[uuid link-uuid]
(route-delete-link! uuid link-uuid))
[uuid link-uuid]
(route-delete-link! uuid link-uuid))
(POST (register! :instance-mark-starred
"/instance/:uuid/starred")
[uuid :as req]
(route-mark-starred! uuid req))
[uuid :as req]
(route-mark-starred! uuid req))
(DELETE (register! :instance-remove-starred
"/instance/:uuid/starred")
[uuid :as req]
(route-remove-starred! uuid req))
[uuid :as req]
(route-remove-starred! uuid req))
(GET (register! :instance-bulk-link-selection "/instance/:uuid/bulk-link")
[uuid :as req]
(route-bulk-link-selection! uuid req))
[uuid :as req]
(route-bulk-link-selection! uuid req))
(POST (register! :instance-bulk-link-create "/instance/:uuid/bulk-link")
[uuid :as req]
(route-create-bulk-link! uuid req)))
[uuid :as req]
(route-create-bulk-link! uuid req)))
(middleware-schema/wrap-allowed-to-write!
schema-uuid-by-instance)))
@ -225,29 +223,29 @@
(wrap-routes
(compojure/routes
(GET (register! :instance-list "/instance/list/:schema-uuid")
[schema-uuid :as req]
(route-list! schema-uuid req)))
[schema-uuid :as req]
(route-list! schema-uuid req)))
(middleware-schema/wrap-allowed-to-read!
schema-uuid-from-params))
(wrap-routes
(compojure/routes
(GET (register! :instance-show "/instance/:uuid")
[uuid :as req]
(route-show! uuid req)))
[uuid :as req]
(route-show! uuid req)))
(middleware-schema/wrap-allowed-to-read!
schema-uuid-by-instance))
(wrap-routes
(compojure/routes
(POST (register! :instance-new "/instance/new") []
route-new!))
route-new!))
(middleware-schema/wrap-allowed-to-write!
schema-uuid-from-params))
linking-routes
writing-routes-with-uuid-in-path
(GET (register! :instance-list-starred "/instance/starred/list")
[:as req]
[:as req]
;; at some point someone will star an instance and then permissions to
;; the schema will be revoked
;; the instances will still be visible but can't be opened anymore
;; because of missing permissions, so they can't be unstared anymore
(route-list-starred! req)))
(route-list-starred! req)))

@ -161,7 +161,15 @@
(str
"MATCH (p:property)
WHERE p.uuid = '" prop-uuid "'
RETURN p.value"))))))
RETURN p.value"))))
(is (= "new-value"
(single-result
(str
"MATCH (rp:rev_property)
-[:of]->(rev:revision)
-[:of]->(i:instance)
WHERE i.uuid = '" (:uuid instance) "'
RETURN rp.value"))))))
(testing "delete first instance"
(inst-routes/route-delete! (:uuid instance))

Loading…
Cancel
Save