time shit and deleting shit and such

integration-tests
Josha von Gizycki 6 years ago
parent 7b4f3aeba5
commit 39c1b06ff5

@ -8,7 +8,8 @@
[gorillalabs/neo4j-clj "1.1.0"] [gorillalabs/neo4j-clj "1.1.0"]
[hiccup "1.0.5"] [hiccup "1.0.5"]
[buddy/buddy-hashers "1.3.0" [buddy/buddy-hashers "1.3.0"
:exclusions [commons-codec]]] :exclusions [commons-codec]]
[clj-time "0.14.4"]]
:plugins [[lein-ring "0.9.7"]] :plugins [[lein-ring "0.9.7"]]
:ring {:handler wanijo.handler/app} :ring {:handler wanijo.handler/app}
:profiles {:dev {:dependencies :profiles {:dev {:dependencies

@ -0,0 +1,17 @@
(ns wanijo.attribute.domain
(:require [clojure.spec.alpha :as spec]
[wanijo.framework.neo4j :as neo4j]))
(neo4j/defquery
findy-by-schema
"MATCH (a:attribute)-->(s:schema)
WHERE s.uuid = {uuid}
RETURN a
ORDER BY a.name")
(defn find-by-schema! [schema-uuid]
(->>
(neo4j/exec-query!
findy-by-schema
{:uuid schema-uuid})
(map :a)))

@ -19,7 +19,7 @@
(-> (redirect "/login") (-> (redirect "/login")
(assoc :flash :invalid-credentials))))) (assoc :flash :invalid-credentials)))))
(defn login [req] (defn login! [req]
(view/layout! (view/layout!
:content :content
[[:h1 "Kama ken"] [[:h1 "Kama ken"]
@ -37,7 +37,7 @@
(anti-forgery-field))])) (anti-forgery-field))]))
(defroutes routes (defroutes routes
(GET "/login" [] login) (GET "/login" [] login!)
(POST "/login-check" [] login-check!) (POST "/login-check" [] login-check!)
(GET "/logout" [] (-> (redirect "/login") (GET "/logout" [] (-> (redirect "/login")
(assoc :session nil)))) (assoc :session nil))))

@ -1,6 +1,8 @@
(ns wanijo.framework.neo4j (ns wanijo.framework.neo4j
(:require [neo4j-clj.core :as db] (:require [neo4j-clj.core :as db]
[wanijo.framework.devmode :as devmode]) [wanijo.framework.devmode :as devmode]
[clj-time.format :as time-format]
[clj-time.local :as time-local])
(:import (java.util UUID))) (:import (java.util UUID)))
(def conn (def conn
@ -23,10 +25,15 @@
(filter #(> (count %) 0)) (filter #(> (count %) 0))
(clojure.string/join \newline))) (clojure.string/join \newline)))
(defn exec-query [qry params] (defn exec-query! [qry params]
(with-open [session (db/get-session @conn)] (with-open [session (db/get-session @conn)]
(devmode/send-to-bar (devmode/send-to-bar
(str (butiful-query qry) (str (butiful-query qry)
"<br>---Params---<br>" "<br>---Params---<br>"
params)) params))
(qry session params))) (qry session params)))
(defn now-str []
(time-format/unparse
(time-format/formatters :basic-date-time)
(time-local/local-now)))

@ -11,7 +11,7 @@
SET n.uuid = {uuid}") SET n.uuid = {uuid}")
(defn create-user! [ident pw] (defn create-user! [ident pw]
(neo4j/exec-query (neo4j/exec-query!
create-user create-user
{:ident ident {:ident ident
:pw (hashers/derive pw) :pw (hashers/derive pw)

@ -0,0 +1,2 @@
(ns wanijo.framework.time
(:require [clj-time.core :as t]))

@ -36,7 +36,7 @@
(when authed? (when authed?
[:section.header-content [:section.header-content
(btnlink "/schema" "Jaki ijo" "header-content__link") (btnlink "/schema" "Jaki ijo" "header-content__link")
(btnlink "/logout" "Lape" "header-content__link")])] (btnlink "/logout" "Lape!" "header-content__link")])]
[:nav (when authed? "nav")] [:nav (when authed? "nav")]
(vec (concat [:main] content)) (vec (concat [:main] content))
[:aside (when authed? "aside")] [:aside (when authed? "aside")]

@ -6,10 +6,8 @@
(spec/and string? not-empty)) (spec/and string? not-empty))
(spec/def ::created-at (spec/def ::created-at
(spec/or :int (spec/and int? (spec/and string?
#(> % 20000101000000)) #(re-matches #"\d{4}\d{2}\d{2}T\d{2}\d{2}\d{2}\.\d{3}Z" %)))
:str (spec/and string?
#(re-matches #"\d{4}\d{2}\d{2}\d{2}\d{2}\d{2}" %))))
(neo4j/defquery (neo4j/defquery
all-created-by all-created-by
@ -19,10 +17,11 @@
ORDER BY s.name") ORDER BY s.name")
(defn all-created-by! [user-uuid] (defn all-created-by! [user-uuid]
(map :s (->>
(neo4j/exec-query (neo4j/exec-query!
all-created-by all-created-by
{:uuid user-uuid}))) {:uuid user-uuid})
(map :s)))
(neo4j/defquery (neo4j/defquery
create-new create-new
@ -31,28 +30,63 @@
CREATE (s:schema)-[:created_by]->(u) CREATE (s:schema)-[:created_by]->(u)
SET s.name = {name} SET s.name = {name}
SET s.uuid = {s_uuid} SET s.uuid = {s_uuid}
SET s.created_at = {created_at}
RETURN s") RETURN s")
(defn create-new! [name user-uuid] (defn create-new! [name user-uuid]
(->> (->>
(neo4j/exec-query (neo4j/exec-query!
create-new create-new
{:u_uuid user-uuid {:u_uuid user-uuid
:name name :name name
:s_uuid (neo4j/uuid)}) :s_uuid (neo4j/uuid)
:created_at (neo4j/now-str)})
first first
:uuid)) :uuid))
(neo4j/defquery (neo4j/defquery
find-by-id! find-by-uuid
"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!
find-by-id! find-by-uuid
{:uuid uuid}) {:uuid uuid})
first first
:s)) :s))
(neo4j/defquery
schema-creator
"MATCH (s:schema)-->(u:user)
WHERE s.uuid = {uuid}
RETURN u.uuid as uuid")
(defn find-schema-creator! [uuid]
(->>
(neo4j/exec-query!
schema-creator
{:uuid uuid})
first
:uuid))
(defn can-user-modify? [schema-uuid user-uuid]
(let [creator (find-schema-creator! schema-uuid)]
(= creator user-uuid)))
(neo4j/defquery
delete
"MATCH (s:schema)
WHERE s.uuid = {uuid}
OPTIONAL MATCH (s)--(a:attribute)
DELETE a
WITH s
MATCH (s)-[c]-()
DELETE c, s")
(defn delete! [uuid]
(neo4j/exec-query!
delete
{:uuid uuid}))

@ -1,10 +1,11 @@
(ns wanijo.schema.routes (ns wanijo.schema.routes
(:require [compojure.core :refer [defroutes GET POST]] (:require [compojure.core :refer [defroutes GET POST DELETE]]
[ring.util.response :as resp] [ring.util.response :as resp]
[wanijo.framework.view :as view] [wanijo.framework.view :as view]
[wanijo.framework.form :as form] [wanijo.framework.form :as form]
[wanijo.schema.domain :as domain] [wanijo.schema.domain :as domain]
[wanijo.schema.view :as view-schema])) [wanijo.schema.view :as view-schema]
[wanijo.attribute.domain :as attr-domain]))
(defn new! [req] (defn new! [req]
(if (form/valid? view-schema/new-form req) (if (form/valid? view-schema/new-form req)
@ -16,12 +17,20 @@
(view-schema/overview! req))) (view-schema/overview! req)))
(defn show-schema! [uuid session] (defn show-schema! [uuid session]
(println uuid session)
(view-schema/show-schema! (view-schema/show-schema!
(domain/find-by-uuid! uuid) (domain/find-by-uuid! uuid)
(attr-domain/find-by-schema! uuid)
session)) session))
(defn delete-schema! [uuid session]
(if (domain/can-user-modify? uuid (:uuid session))
(do
(domain/delete! uuid)
(resp/redirect "/schema"))
{:status 403}))
(defroutes routes (defroutes routes
(GET "/schema" [] view-schema/overview!) (GET "/schema" [] view-schema/overview!)
(GET "/schema/:uuid" [uuid :as req] (show-schema! uuid (:session req))) (GET "/schema/:uuid" [uuid :as req] (show-schema! uuid (:session req)))
(POST "/schema/new" [] new!)) (POST "/schema/new" [] new!)
(DELETE "/schema/:uuid/delete" [uuid :as req] (delete-schema! uuid (:session req))))

@ -8,7 +8,7 @@
(def new-form (def new-form
{:fields {:schema-name {:label "Nimi" {:fields {:schema-name {:label "Nimi"
:required true :required true
:spec :wanijo.domain.schema/name}}}) :spec ::domain/name}}})
(defn overview! [req] (defn overview! [req]
(let [session (:session req) (let [session (:session req)
@ -37,8 +37,19 @@
(hform/submit-button "Pali") (hform/submit-button "Pali")
(anti-forgery-field))]))) (anti-forgery-field))])))
(defn show-schema! [schema session] (defn show-schema! [schema attrs session]
(view/layout! (view/layout!
:session session :session session
:content :content
[[:h1 "Jaki ijo " (:name schema)]])) [[:h1 "Jaki ijo " (:name schema)]
(hform/form-to
[:post "/schema/edit"])
[:h2 "Lili wan e jaki ijo"]
[:ul
(for [attr attrs]
[:li (:name attr)])]
[:h2 "Mute pali"]
(hform/form-to
[:delete (str "/schema/" (:uuid schema) "/delete")]
(anti-forgery-field)
(hform/submit-button "Pakala!"))]))

@ -9,7 +9,7 @@
(defn find! [ident] (defn find! [ident]
(->> (->>
(neo4j/exec-query (neo4j/exec-query!
find-user find-user
{:ident ident}) {:ident ident})
first first

Loading…
Cancel
Save