Tactical commit; much progress but not ready for release.
This commit is contained in:
parent
fc2bd86cff
commit
0026218993
61 changed files with 2920 additions and 1031 deletions
|
|
@ -11,7 +11,7 @@
|
|||
clojure.lang.IPersistentMap
|
||||
clojure.lang.IPersistentVector
|
||||
[java.sql
|
||||
BatchUpdateException
|
||||
;; BatchUpdateException
|
||||
Date
|
||||
Timestamp
|
||||
PreparedStatement]))
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@
|
|||
[youyesyet.routes.auto-json :refer [auto-rest-routes]]
|
||||
[youyesyet.routes.auto :refer [auto-selmer-routes]]
|
||||
[youyesyet.routes.rest :refer [rest-routes]]
|
||||
[youyesyet.routes.roles :refer [roles-routes]]
|
||||
[youyesyet.routes.services :refer [service-routes]]
|
||||
[youyesyet.env :refer [defaults]]))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
|
@ -61,11 +63,15 @@
|
|||
(shutdown-agents)
|
||||
(log/info "youyesyet has shut down!"))
|
||||
|
||||
|
||||
(def app-routes
|
||||
(routes
|
||||
(-> #'home-routes
|
||||
(wrap-routes middleware/wrap-csrf)
|
||||
(wrap-routes middleware/wrap-formats))
|
||||
(-> #'roles-routes
|
||||
(wrap-routes middleware/wrap-csrf)
|
||||
(wrap-routes middleware/wrap-formats))
|
||||
(-> #'auto-rest-routes
|
||||
(wrap-routes middleware/wrap-csrf)
|
||||
(wrap-routes middleware/wrap-formats))
|
||||
|
|
@ -76,12 +82,15 @@
|
|||
(wrap-routes middleware/wrap-formats))
|
||||
(-> #'rest-routes
|
||||
(wrap-routes middleware/wrap-formats))
|
||||
(-> #'service-routes
|
||||
(wrap-routes middleware/wrap-formats)) ;; TODO: and authentication, but let's not sweat the small stuff.
|
||||
'oauth-routes
|
||||
(route/resources "/")
|
||||
(route/not-found
|
||||
(:body
|
||||
(error-page {:status 404
|
||||
:title "page not found"})))))
|
||||
:title "Page not found"
|
||||
:message "The page you requested has not yet been implemented"})))))
|
||||
|
||||
|
||||
(def app (middleware/wrap-base #'app-routes))
|
||||
|
|
|
|||
|
|
@ -90,4 +90,4 @@
|
|||
[error-details]
|
||||
{:status (:status error-details)
|
||||
:headers {"Content-Type" "text/html; charset=utf-8"}
|
||||
:body (parser/render-file "error.html" error-details)})
|
||||
:body (render "error.html" {} error-details)})
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
(ns
|
||||
youyesyet.routes.auto
|
||||
"User interface routes for Youyesyet auto-generated by [Application Description Language framework](https://github.com/simon-brooke/adl) at 20180705T101418.070Z"
|
||||
"User interface routes for Youyesyet auto-generated by [Application Description Language framework](https://github.com/simon-brooke/adl) at 20180707T080949.557Z"
|
||||
(:require
|
||||
[adl-support.core :as support]
|
||||
[clojure.java.io :as io]
|
||||
|
|
@ -63,8 +63,8 @@
|
|||
(do (db/create-address! db/*db* p) {:message "Saved record"}))
|
||||
(catch
|
||||
java.lang.Exception
|
||||
any__2078__auto__
|
||||
{:error (.getMessage any__2078__auto__)})))
|
||||
any__2085__auto__
|
||||
{:error (.getMessage any__2085__auto__)})))
|
||||
{:record
|
||||
(if
|
||||
(empty? (remove nil? (vals p)))
|
||||
|
|
@ -114,8 +114,8 @@
|
|||
{:message "Saved record"}))
|
||||
(catch
|
||||
java.lang.Exception
|
||||
any__2078__auto__
|
||||
{:error (.getMessage any__2078__auto__)})))
|
||||
any__2085__auto__
|
||||
{:error (.getMessage any__2085__auto__)})))
|
||||
{:record
|
||||
(if
|
||||
(empty? (remove nil? (vals p)))
|
||||
|
|
@ -165,8 +165,8 @@
|
|||
{:message "Saved record"}))
|
||||
(catch
|
||||
java.lang.Exception
|
||||
any__2078__auto__
|
||||
{:error (.getMessage any__2078__auto__)})))
|
||||
any__2085__auto__
|
||||
{:error (.getMessage any__2085__auto__)})))
|
||||
{:record
|
||||
(if
|
||||
(empty? (remove nil? (vals p)))
|
||||
|
|
@ -220,8 +220,8 @@
|
|||
{:message "Saved record"}))
|
||||
(catch
|
||||
java.lang.Exception
|
||||
any__2078__auto__
|
||||
{:error (.getMessage any__2078__auto__)})))
|
||||
any__2085__auto__
|
||||
{:error (.getMessage any__2085__auto__)})))
|
||||
{:record
|
||||
(if
|
||||
(empty? (remove nil? (vals p)))
|
||||
|
|
@ -271,8 +271,8 @@
|
|||
{:message "Saved record"}))
|
||||
(catch
|
||||
java.lang.Exception
|
||||
any__2078__auto__
|
||||
{:error (.getMessage any__2078__auto__)})))
|
||||
any__2085__auto__
|
||||
{:error (.getMessage any__2085__auto__)})))
|
||||
{:record
|
||||
(if
|
||||
(empty? (remove nil? (vals p)))
|
||||
|
|
@ -320,8 +320,8 @@
|
|||
(do (db/create-elector! db/*db* p) {:message "Saved record"}))
|
||||
(catch
|
||||
java.lang.Exception
|
||||
any__2078__auto__
|
||||
{:error (.getMessage any__2078__auto__)})))
|
||||
any__2085__auto__
|
||||
{:error (.getMessage any__2085__auto__)})))
|
||||
{:record
|
||||
(if
|
||||
(empty? (remove nil? (vals p)))
|
||||
|
|
@ -331,6 +331,53 @@
|
|||
{:dwellings (db/list-dwellings db/*db*)}
|
||||
{:genders (db/list-genders db/*db*)}))))))
|
||||
|
||||
(defn
|
||||
form-events-Events
|
||||
[r]
|
||||
(let
|
||||
[p (support/massage-params (:params r) (:form-params r) #{"id"})]
|
||||
(l/render
|
||||
(support/resolve-template "form-events-Events.html")
|
||||
(:session r)
|
||||
(merge
|
||||
{:title "Events", :params p}
|
||||
(reduce
|
||||
merge
|
||||
(merge
|
||||
(cond
|
||||
(:save-button p)
|
||||
(try
|
||||
(if
|
||||
(some #{"id"} (map name (keys p)))
|
||||
(do (db/update-event! db/*db* p) {:message "Updated record"})
|
||||
(do (db/create-event! db/*db* p) {:message "Saved record"}))
|
||||
(catch
|
||||
java.lang.Exception
|
||||
any__2085__auto__
|
||||
{:error (.getMessage any__2085__auto__)})))
|
||||
{:record
|
||||
(if
|
||||
(empty? (remove nil? (vals p)))
|
||||
[]
|
||||
(db/get-event db/*db* p))})
|
||||
(list {:teams (db/list-teams db/*db*)}))))))
|
||||
|
||||
(defn
|
||||
list-events-Events
|
||||
[r]
|
||||
(let
|
||||
[p (support/massage-params (:params r) (:form-params r) #{"id"})]
|
||||
(l/render
|
||||
(support/resolve-template "list-events-Events.html")
|
||||
(:session r)
|
||||
(merge
|
||||
{:title "Events", :params p}
|
||||
{:records
|
||||
(if
|
||||
(not (empty? (remove nil? (vals p))))
|
||||
(db/search-strings-events db/*db* p)
|
||||
(db/list-events db/*db* {}))}))))
|
||||
|
||||
(defn
|
||||
list-followupactions-Followupactions
|
||||
[r]
|
||||
|
|
@ -375,8 +422,8 @@
|
|||
{:message "Saved record"}))
|
||||
(catch
|
||||
java.lang.Exception
|
||||
any__2078__auto__
|
||||
{:error (.getMessage any__2078__auto__)})))
|
||||
any__2085__auto__
|
||||
{:error (.getMessage any__2085__auto__)})))
|
||||
{:record
|
||||
(if
|
||||
(empty? (remove nil? (vals p)))
|
||||
|
|
@ -430,8 +477,8 @@
|
|||
{:message "Saved record"}))
|
||||
(catch
|
||||
java.lang.Exception
|
||||
any__2078__auto__
|
||||
{:error (.getMessage any__2078__auto__)})))
|
||||
any__2085__auto__
|
||||
{:error (.getMessage any__2085__auto__)})))
|
||||
{:record
|
||||
(if
|
||||
(empty? (remove nil? (vals p)))
|
||||
|
|
@ -483,8 +530,8 @@
|
|||
{:message "Saved record"}))
|
||||
(catch
|
||||
java.lang.Exception
|
||||
any__2078__auto__
|
||||
{:error (.getMessage any__2078__auto__)})))
|
||||
any__2085__auto__
|
||||
{:error (.getMessage any__2085__auto__)})))
|
||||
{:record
|
||||
(if
|
||||
(empty? (remove nil? (vals p)))
|
||||
|
|
@ -534,8 +581,8 @@
|
|||
(do (db/create-gender! db/*db* p) {:message "Saved record"}))
|
||||
(catch
|
||||
java.lang.Exception
|
||||
any__2078__auto__
|
||||
{:error (.getMessage any__2078__auto__)})))
|
||||
any__2085__auto__
|
||||
{:error (.getMessage any__2085__auto__)})))
|
||||
{:record
|
||||
(if
|
||||
(empty? (remove nil? (vals p)))
|
||||
|
|
@ -547,7 +594,7 @@
|
|||
list-intentions-Intentions
|
||||
[r]
|
||||
(let
|
||||
[p (support/massage-params (:params r) (:form-params r) #{"Id"})]
|
||||
[p (support/massage-params (:params r) (:form-params r) #{"id"})]
|
||||
(l/render
|
||||
(support/resolve-template "list-intentions-Intentions.html")
|
||||
(:session r)
|
||||
|
|
@ -563,7 +610,7 @@
|
|||
form-intentions-Intention
|
||||
[r]
|
||||
(let
|
||||
[p (support/massage-params (:params r) (:form-params r) #{"Id"})]
|
||||
[p (support/massage-params (:params r) (:form-params r) #{"id"})]
|
||||
(l/render
|
||||
(support/resolve-template "form-intentions-Intention.html")
|
||||
(:session r)
|
||||
|
|
@ -576,7 +623,7 @@
|
|||
(:save-button p)
|
||||
(try
|
||||
(if
|
||||
(some #{"Id"} (map name (keys p)))
|
||||
(some #{"id"} (map name (keys p)))
|
||||
(do
|
||||
(db/update-intention! db/*db* p)
|
||||
{:message "Updated record"})
|
||||
|
|
@ -585,8 +632,8 @@
|
|||
{:message "Saved record"}))
|
||||
(catch
|
||||
java.lang.Exception
|
||||
any__2078__auto__
|
||||
{:error (.getMessage any__2078__auto__)})))
|
||||
any__2085__auto__
|
||||
{:error (.getMessage any__2085__auto__)})))
|
||||
{:record
|
||||
(if
|
||||
(empty? (remove nil? (vals p)))
|
||||
|
|
@ -635,8 +682,8 @@
|
|||
(do (db/create-issue! db/*db* p) {:message "Saved record"}))
|
||||
(catch
|
||||
java.lang.Exception
|
||||
any__2078__auto__
|
||||
{:error (.getMessage any__2078__auto__)})))
|
||||
any__2085__auto__
|
||||
{:error (.getMessage any__2085__auto__)})))
|
||||
{:record
|
||||
(if
|
||||
(empty? (remove nil? (vals p)))
|
||||
|
|
@ -682,8 +729,8 @@
|
|||
(do (db/create-option! db/*db* p) {:message "Saved record"}))
|
||||
(catch
|
||||
java.lang.Exception
|
||||
any__2078__auto__
|
||||
{:error (.getMessage any__2078__auto__)})))
|
||||
any__2085__auto__
|
||||
{:error (.getMessage any__2085__auto__)})))
|
||||
{:record
|
||||
(if
|
||||
(empty? (remove nil? (vals p)))
|
||||
|
|
@ -729,8 +776,8 @@
|
|||
(do (db/create-role! db/*db* p) {:message "Saved record"}))
|
||||
(catch
|
||||
java.lang.Exception
|
||||
any__2078__auto__
|
||||
{:error (.getMessage any__2078__auto__)})))
|
||||
any__2085__auto__
|
||||
{:error (.getMessage any__2085__auto__)})))
|
||||
{:record
|
||||
(if
|
||||
(empty? (remove nil? (vals p)))
|
||||
|
|
@ -776,8 +823,8 @@
|
|||
(do (db/create-team! db/*db* p) {:message "Saved record"}))
|
||||
(catch
|
||||
java.lang.Exception
|
||||
any__2078__auto__
|
||||
{:error (.getMessage any__2078__auto__)})))
|
||||
any__2085__auto__
|
||||
{:error (.getMessage any__2085__auto__)})))
|
||||
{:record
|
||||
(if
|
||||
(empty? (remove nil? (vals p)))
|
||||
|
|
@ -826,8 +873,8 @@
|
|||
(do (db/create-visit! db/*db* p) {:message "Saved record"}))
|
||||
(catch
|
||||
java.lang.Exception
|
||||
any__2078__auto__
|
||||
{:error (.getMessage any__2078__auto__)})))
|
||||
any__2085__auto__
|
||||
{:error (.getMessage any__2085__auto__)})))
|
||||
{:record
|
||||
(if
|
||||
(empty? (remove nil? (vals p)))
|
||||
|
|
@ -924,6 +971,16 @@
|
|||
request
|
||||
(route/restricted
|
||||
(apply (resolve-handler "form-electors-Elector") (list request))))
|
||||
(GET
|
||||
"/form-events-Events"
|
||||
request
|
||||
(route/restricted
|
||||
(apply (resolve-handler "form-events-Events") (list request))))
|
||||
(POST
|
||||
"/form-events-Events"
|
||||
request
|
||||
(route/restricted
|
||||
(apply (resolve-handler "form-events-Events") (list request))))
|
||||
(GET
|
||||
"/form-followupactions-Followupaction"
|
||||
request
|
||||
|
|
@ -1120,6 +1177,16 @@
|
|||
request
|
||||
(route/restricted
|
||||
(apply (resolve-handler "list-electors-Electors") (list request))))
|
||||
(GET
|
||||
"/list-events-Events"
|
||||
request
|
||||
(route/restricted
|
||||
(apply (resolve-handler "list-events-Events") (list request))))
|
||||
(POST
|
||||
"/list-events-Events"
|
||||
request
|
||||
(route/restricted
|
||||
(apply (resolve-handler "list-events-Events") (list request))))
|
||||
(GET
|
||||
"/list-followupactions-Followupactions"
|
||||
request
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
(ns
|
||||
youyesyet.routes.auto-json
|
||||
"JSON routes for youyesyet auto-generated by [Application Description Language framework](https://github.com/simon-brooke/adl) at 20180705T101417.082Z"
|
||||
"JSON routes for youyesyet auto-generated by [Application Description Language framework](https://github.com/simon-brooke/adl) at 20180707T080948.404Z"
|
||||
(:require
|
||||
[adl-support.core :as support]
|
||||
[clojure.core.memoize :as memo]
|
||||
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
(defn
|
||||
create-canvasser!
|
||||
"Auto-generated method to insert one record to the `canvassers` table. Expects the following key(s) to be present in `params`: `(:username :fullname :elector_id :address_id :phone :email :authority_id :authorised)`. Returns a map containing the keys `#{\"id\"}` identifying the record created."
|
||||
"Auto-generated method to insert one record to the `canvassers` table. Expects the following key(s) to be present in `params`: `(:username :fullname :avatar :bio :elector_id :address_id :phone :email :authority_id :authorised)`. Returns a map containing the keys `#{\"id\"}` identifying the record created."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
|
|
@ -79,6 +79,17 @@
|
|||
(support/massage-params params form-params #{"id"}))]
|
||||
(response/ok result)))
|
||||
|
||||
(defn
|
||||
create-event!
|
||||
"Auto-generated method to insert one record to the `events` table. Expects the following key(s) to be present in `params`: `(:name :date :time :decription :cancelled)`. Returns a map containing the keys `#{\"id\"}` identifying the record created."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/create-event!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
(response/ok result)))
|
||||
|
||||
(defn
|
||||
create-followupaction!
|
||||
"Auto-generated method to insert one record to the `followupactions` table. Expects the following key(s) to be present in `params`: `(:request_id :actor :date :notes :closed)`. Returns a map containing the keys `#{\"id\"}` identifying the record created."
|
||||
|
|
@ -125,13 +136,13 @@
|
|||
|
||||
(defn
|
||||
create-intention!
|
||||
"Auto-generated method to insert one record to the `intentions` table. Expects the following key(s) to be present in `params`: `(:visit_id :elector_id :option_id :locality)`. Returns a map containing the keys `#{\"Id\"}` identifying the record created."
|
||||
"Auto-generated method to insert one record to the `intentions` table. Expects the following key(s) to be present in `params`: `(:visit_id :elector_id :option_id :locality)`. Returns a map containing the keys `#{\"id\"}` identifying the record created."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/create-intention!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"Id"}))]
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
(response/ok result)))
|
||||
|
||||
(defn
|
||||
|
|
@ -193,176 +204,153 @@
|
|||
delete-address!
|
||||
"Auto-generated method to delete one record from the `addresses` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/delete-address!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
((db/delete-address!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defn
|
||||
delete-authority!
|
||||
"Auto-generated method to delete one record from the `authorities` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/delete-authority!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
((db/delete-authority!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defn
|
||||
delete-canvasser!
|
||||
"Auto-generated method to delete one record from the `canvassers` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/delete-canvasser!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
((db/delete-canvasser!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defn
|
||||
delete-district!
|
||||
"Auto-generated method to delete one record from the `districts` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/delete-district!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
((db/delete-district!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defn
|
||||
delete-dwelling!
|
||||
"Auto-generated method to delete one record from the `dwellings` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/delete-dwelling!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
((db/delete-dwelling!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defn
|
||||
delete-elector!
|
||||
"Auto-generated method to delete one record from the `electors` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/delete-elector!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
((db/delete-elector!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defn
|
||||
delete-event!
|
||||
"Auto-generated method to delete one record from the `events` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`."
|
||||
[{:keys [params form-params]}]
|
||||
((db/delete-event!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defn
|
||||
delete-followupaction!
|
||||
"Auto-generated method to delete one record from the `followupactions` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/delete-followupaction!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
((db/delete-followupaction!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defn
|
||||
delete-followupmethod!
|
||||
"Auto-generated method to delete one record from the `followupmethods` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/delete-followupmethod!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
((db/delete-followupmethod!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defn
|
||||
delete-followuprequest!
|
||||
"Auto-generated method to delete one record from the `followuprequests` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/delete-followuprequest!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
((db/delete-followuprequest!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defn
|
||||
delete-gender!
|
||||
"Auto-generated method to delete one record from the `genders` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/delete-gender!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
((db/delete-gender!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defn
|
||||
delete-intention!
|
||||
"Auto-generated method to delete one record from the `intentions` table. Expects the following key(s) to be present in `params`: `#{\"Id\"}`."
|
||||
"Auto-generated method to delete one record from the `intentions` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/delete-intention!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"Id"}))]
|
||||
((db/delete-intention!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defn
|
||||
delete-issue!
|
||||
"Auto-generated method to delete one record from the `issues` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/delete-issue!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
((db/delete-issue!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defn
|
||||
delete-option!
|
||||
"Auto-generated method to delete one record from the `options` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/delete-option!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
((db/delete-option!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defn
|
||||
delete-role!
|
||||
"Auto-generated method to delete one record from the `roles` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/delete-role!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
((db/delete-role!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defn
|
||||
delete-team!
|
||||
"Auto-generated method to delete one record from the `teams` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/delete-team!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
((db/delete-team!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defn
|
||||
delete-visit!
|
||||
"Auto-generated method to delete one record from the `visits` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/delete-visit!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
((db/delete-visit!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(def
|
||||
|
|
@ -463,6 +451,17 @@
|
|||
:ttl/threshold
|
||||
100000000))
|
||||
|
||||
(defn
|
||||
get-event
|
||||
"Auto-generated method to select one record from the `events` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`. Returns a map containing the following keys: `clojure.lang.LazySeq@3ac90901`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/get-event
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
(response/ok result)))
|
||||
|
||||
(defn
|
||||
get-followupaction
|
||||
"Auto-generated method to select one record from the `followupactions` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`. Returns a map containing the following keys: `clojure.lang.LazySeq@6b32af0e`."
|
||||
|
|
@ -525,7 +524,7 @@
|
|||
[result
|
||||
(db/get-intention
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"Id"}))]
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
(response/ok result)))
|
||||
:ttl/threshold
|
||||
100000))
|
||||
|
|
@ -738,6 +737,22 @@
|
|||
[{:keys [params]}]
|
||||
(do (db/list-electors-by-gender params)))
|
||||
|
||||
(defn
|
||||
list-events
|
||||
"Auto-generated method to select all records from the `events` table. If the keys `(:limit :offset)` are present in the request then they will be used to page through the data. Returns a sequence of maps each containing the following keys: `(:name :teams :date :time :decription :cancelled :id)`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/list-events
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
(response/ok result)))
|
||||
|
||||
(defn
|
||||
list-events-by-team
|
||||
[{:keys [params]}]
|
||||
(do (db/list-events-by-team params)))
|
||||
|
||||
(defn
|
||||
list-followupactions
|
||||
"Auto-generated method to select all records from the `followupactions` table. If the keys `(:limit :offset)` are present in the request then they will be used to page through the data. Returns a sequence of maps each containing the following keys: `(:request_id :actor :date :notes :closed :id)`."
|
||||
|
|
@ -830,7 +845,7 @@
|
|||
[result
|
||||
(db/list-intentions
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"Id"}))]
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
(response/ok result)))
|
||||
:ttl/threshold
|
||||
100000))
|
||||
|
|
@ -1029,6 +1044,17 @@
|
|||
:ttl/threshold
|
||||
100000000))
|
||||
|
||||
(defn
|
||||
search-strings-events
|
||||
"Auto-generated method to select all records from the `events` table with any text field matching the value of the key `:pattern` which should be in the request. If the keys `(:limit :offset)` are present in the request then they will be used to page through the data. Returns a sequence of maps each containing the following keys: `(:name :teams :date :time :decription :cancelled :id)`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/search-strings-events
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
(response/ok result)))
|
||||
|
||||
(defn
|
||||
search-strings-followupactions
|
||||
"Auto-generated method to select all records from the `followupactions` table with any text field matching the value of the key `:pattern` which should be in the request. If the keys `(:limit :offset)` are present in the request then they will be used to page through the data. Returns a sequence of maps each containing the following keys: `(:request_id :actor :date :notes :closed :id)`."
|
||||
|
|
@ -1091,7 +1117,7 @@
|
|||
[result
|
||||
(db/search-strings-intentions
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"Id"}))]
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
(response/ok result)))
|
||||
:ttl/threshold
|
||||
100000))
|
||||
|
|
@ -1170,176 +1196,153 @@
|
|||
update-address!
|
||||
"Auto-generated method to update one record in the `addresses` table. Expects the following key(s) to be present in `params`: `(:address :district_id :id :latitude :locality :longitude :phone :postcode)`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/update-address!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
((db/update-address!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defn
|
||||
update-authority!
|
||||
"Auto-generated method to update one record in the `authorities` table. Expects the following key(s) to be present in `params`: `(:access-token-uri :authorize-uri :consumer-key :consumer-secret :id :request-token-uri)`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/update-authority!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
((db/update-authority!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defn
|
||||
update-canvasser!
|
||||
"Auto-generated method to update one record in the `canvassers` table. Expects the following key(s) to be present in `params`: `(:address_id :authorised :authority_id :elector_id :email :fullname :id :phone :username)`."
|
||||
"Auto-generated method to update one record in the `canvassers` table. Expects the following key(s) to be present in `params`: `(:address_id :authorised :authority_id :avatar :bio :elector_id :email :fullname :id :phone :username)`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/update-canvasser!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
((db/update-canvasser!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defn
|
||||
update-district!
|
||||
"Auto-generated method to update one record in the `districts` table. Expects the following key(s) to be present in `params`: `(:id :name)`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/update-district!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
((db/update-district!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defn
|
||||
update-dwelling!
|
||||
"Auto-generated method to update one record in the `dwellings` table. Expects the following key(s) to be present in `params`: `(:address_id :id :sub-address)`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/update-dwelling!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
((db/update-dwelling!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defn
|
||||
update-elector!
|
||||
"Auto-generated method to update one record in the `electors` table. Expects the following key(s) to be present in `params`: `(:dwelling_id :email :gender :id :name :phone)`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/update-elector!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
((db/update-elector!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defn
|
||||
update-event!
|
||||
"Auto-generated method to update one record in the `events` table. Expects the following key(s) to be present in `params`: `(:cancelled :date :decription :id :name :time)`."
|
||||
[{:keys [params form-params]}]
|
||||
((db/update-event!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defn
|
||||
update-followupaction!
|
||||
"Auto-generated method to update one record in the `followupactions` table. Expects the following key(s) to be present in `params`: `(:actor :closed :date :id :notes :request_id)`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/update-followupaction!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
((db/update-followupaction!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defn
|
||||
update-followupmethod!
|
||||
"Auto-generated method to update one record in the `followupmethods` table. Expects the following key(s) to be present in `params`: `(:id)`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/update-followupmethod!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
((db/update-followupmethod!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defn
|
||||
update-followuprequest!
|
||||
"Auto-generated method to update one record in the `followuprequests` table. Expects the following key(s) to be present in `params`: `(:elector_id :id :issue_id :method_id :visit_id)`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/update-followuprequest!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
((db/update-followuprequest!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defn
|
||||
update-gender!
|
||||
"Auto-generated method to update one record in the `genders` table. Expects the following key(s) to be present in `params`: `(:id)`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/update-gender!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
((db/update-gender!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defn
|
||||
update-intention!
|
||||
"Auto-generated method to update one record in the `intentions` table. Expects the following key(s) to be present in `params`: `(:Id :elector_id :locality :option_id :visit_id)`."
|
||||
"Auto-generated method to update one record in the `intentions` table. Expects the following key(s) to be present in `params`: `(:elector_id :id :locality :option_id :visit_id)`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/update-intention!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"Id"}))]
|
||||
((db/update-intention!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defn
|
||||
update-issue!
|
||||
"Auto-generated method to update one record in the `issues` table. Expects the following key(s) to be present in `params`: `(:brief :current :id :url)`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/update-issue!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
((db/update-issue!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defn
|
||||
update-option!
|
||||
"Auto-generated method to update one record in the `options` table. Expects the following key(s) to be present in `params`: `(:id)`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/update-option!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
((db/update-option!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defn
|
||||
update-role!
|
||||
"Auto-generated method to update one record in the `roles` table. Expects the following key(s) to be present in `params`: `(:id :name)`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/update-role!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
((db/update-role!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defn
|
||||
update-team!
|
||||
"Auto-generated method to update one record in the `teams` table. Expects the following key(s) to be present in `params`: `(:district_id :id :latitude :longitude :name)`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/update-team!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
((db/update-team!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defn
|
||||
update-visit!
|
||||
"Auto-generated method to update one record in the `visits` table. Expects the following key(s) to be present in `params`: `(:address_id :canvasser_id :date :id)`."
|
||||
[{:keys [params form-params]}]
|
||||
(let
|
||||
[result
|
||||
(db/update-visit!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))]
|
||||
((db/update-visit!
|
||||
db/*db*
|
||||
(support/massage-params params form-params #{"id"}))
|
||||
(response/found "/")))
|
||||
|
||||
(defroutes
|
||||
|
|
@ -1368,6 +1371,10 @@
|
|||
"/json/auto/create-elector"
|
||||
request
|
||||
(route/restricted (create-elector! request)))
|
||||
(POST
|
||||
"/json/auto/create-event"
|
||||
request
|
||||
(route/restricted (create-event! request)))
|
||||
(POST
|
||||
"/json/auto/create-followupaction"
|
||||
request
|
||||
|
|
@ -1432,6 +1439,10 @@
|
|||
"/json/auto/delete-elector"
|
||||
request
|
||||
(route/restricted (delete-elector! request)))
|
||||
(POST
|
||||
"/json/auto/delete-event"
|
||||
request
|
||||
(route/restricted (delete-event! request)))
|
||||
(POST
|
||||
"/json/auto/delete-followupaction"
|
||||
request
|
||||
|
|
@ -1500,6 +1511,10 @@
|
|||
"/json/auto/get-elector"
|
||||
request
|
||||
(route/restricted (get-elector request)))
|
||||
(GET
|
||||
"/json/auto/get-event"
|
||||
request
|
||||
(route/restricted (get-event request)))
|
||||
(GET
|
||||
"/json/auto/get-followupaction"
|
||||
request
|
||||
|
|
@ -1600,6 +1615,14 @@
|
|||
"/json/auto/list-electors-by-gender"
|
||||
request
|
||||
(route/restricted (list-electors-by-gender request)))
|
||||
(GET
|
||||
"/json/auto/list-events"
|
||||
request
|
||||
(route/restricted (list-events request)))
|
||||
(GET
|
||||
"/json/auto/list-events-by-team"
|
||||
request
|
||||
(route/restricted (list-events-by-team request)))
|
||||
(GET
|
||||
"/json/auto/list-followupactions"
|
||||
request
|
||||
|
|
@ -1720,6 +1743,10 @@
|
|||
"/json/auto/search-strings-electors"
|
||||
request
|
||||
(route/restricted (search-strings-electors request)))
|
||||
(GET
|
||||
"/json/auto/search-strings-events"
|
||||
request
|
||||
(route/restricted (search-strings-events request)))
|
||||
(GET
|
||||
"/json/auto/search-strings-followupactions"
|
||||
request
|
||||
|
|
@ -1784,6 +1811,10 @@
|
|||
"/json/auto/update-elector"
|
||||
request
|
||||
(route/restricted (update-elector! request)))
|
||||
(POST
|
||||
"/json/auto/update-event"
|
||||
request
|
||||
(route/restricted (update-event! request)))
|
||||
(POST
|
||||
"/json/auto/update-followupaction"
|
||||
request
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
(ns ^{:doc "Routes/pages available to unauthenticated users."
|
||||
:author "Simon Brooke"} youyesyet.routes.home
|
||||
(:require [clojure.java.io :as io]
|
||||
(:require [adl-support.utils :refer [safe-name]]
|
||||
[clojure.java.io :as io]
|
||||
[clojure.string :as s]
|
||||
[clojure.tools.logging :as log]
|
||||
[clojure.walk :refer [keywordize-keys]]
|
||||
[markdown.core :refer [md-to-html-string]]
|
||||
[noir.util.route :as route]
|
||||
[ring.util.http-response :as response]
|
||||
[youyesyet.config :refer [env]]
|
||||
|
|
@ -36,6 +38,16 @@
|
|||
;;;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
|
||||
(defn motd
|
||||
[]
|
||||
"Message of the day data is currently being loaded from a file in resources.
|
||||
That probably isn't the final solution, but I don't currently have a final
|
||||
solution"
|
||||
(let [motd (io/as-file (io/resource (env :motd)))]
|
||||
(if (.exists motd) (slurp motd) "")))
|
||||
|
||||
|
||||
(defn app-page [request]
|
||||
(layout/render "app.html" {:title "Canvasser app"
|
||||
:user (:user (:session request))}))
|
||||
|
|
@ -43,7 +55,9 @@
|
|||
|
||||
(defn about-page []
|
||||
(layout/render "about.html" {} {:title
|
||||
(str "About " (:site-title env))}))
|
||||
(str "About " (:site-title env))
|
||||
|
||||
:motd (md-to-html-string (motd))}))
|
||||
|
||||
|
||||
(defn call-me-page [request]
|
||||
|
|
@ -58,23 +72,9 @@
|
|||
:concerns (db-core/list-issues db-core/*db* {})})))
|
||||
|
||||
|
||||
(defn roles-page [request]
|
||||
(let
|
||||
[session (:session request)
|
||||
user (:user session)
|
||||
roles (if user (db-core/list-roles-by-canvasser db-core/*db* {:id (:id user)}))]
|
||||
(cond
|
||||
roles (layout/render "roles.html"
|
||||
(:session request)
|
||||
{:title (str "Welcome " (:fullname user) ", what do you want to do?")
|
||||
:user user
|
||||
:roles roles})
|
||||
(empty? roles)(response/found "/app")
|
||||
true (assoc (response/found "/login") :session (dissoc session :user)))))
|
||||
|
||||
|
||||
(defn home-page []
|
||||
(layout/render "home.html" {} {:title "You yes yet?"}))
|
||||
(layout/render "home.html" {} {:title "You yes yet?"
|
||||
:motd (md-to-html-string (motd))}))
|
||||
|
||||
|
||||
(defn login-page
|
||||
|
|
@ -126,17 +126,23 @@
|
|||
:authorities (db-core/list-authorities db-core/*db*)}))))
|
||||
|
||||
|
||||
(defn handle-logout
|
||||
[request]
|
||||
(dissoc (response/found "home") :user :roles))
|
||||
|
||||
|
||||
(defroutes home-routes
|
||||
(GET "/" [] (home-page))
|
||||
(GET "/home" [] (home-page))
|
||||
(GET "/about" [] (about-page))
|
||||
(GET "/roles" request (route/restricted (roles-page request)))
|
||||
(GET "/canvassers" [request] (route/restricted (app-page request)))
|
||||
(GET "/call-me" [] (call-me-page nil))
|
||||
(POST "/call-me" request (call-me-page request))
|
||||
(GET "/auth" request (login-page request))
|
||||
(POST "/auth" request (login-page request))
|
||||
(GET "/login" request (login-page request))
|
||||
(POST "/login" request (login-page request))
|
||||
(GET "/logout" request (handle-logout request))
|
||||
(GET "/notyet" [] (layout/render "notyet.html" {}
|
||||
{:title "Can we persuade you?"}))
|
||||
(GET "/supporter" [] (layout/render "supporter.html" {}
|
||||
{:title "Have you signed up as a canvasser yet?"})))
|
||||
{:title "Have you signed up as a canvasser yet?"}))
|
||||
;; TODO: this should move somewhere else but I'm not sure where yet
|
||||
(GET "/app" [request] (route/restricted (app-page request))))
|
||||
|
|
|
|||
71
src/clj/youyesyet/routes/roles.clj
Normal file
71
src/clj/youyesyet/routes/roles.clj
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
(ns ^{:doc "Routes/pages available to authenticated users in specific roles."
|
||||
:author "Simon Brooke"} youyesyet.routes.roles
|
||||
(:require [adl-support.utils :refer [safe-name]]
|
||||
[clojure.tools.logging :as log]
|
||||
[clojure.walk :refer [keywordize-keys]]
|
||||
[compojure.core :refer [defroutes GET POST]]
|
||||
[noir.util.route :as route]
|
||||
[ring.util.http-response :as response]
|
||||
[youyesyet.config :refer [env]]
|
||||
[youyesyet.db.core :as db-core]
|
||||
[youyesyet.layout :as layout]
|
||||
[youyesyet.oauth :as oauth]
|
||||
[youyesyet.routes.auto :as auto]))
|
||||
|
||||
|
||||
(defn roles-page [request]
|
||||
"Render the routing page for the roles the currently logged in user is member of."
|
||||
(let
|
||||
[session (:session request)
|
||||
user (:user session)
|
||||
roles (if
|
||||
user
|
||||
(db-core/list-roles-by-canvasser db-core/*db* {:id (:id user)}))]
|
||||
(log/info (str "Roles routing page; user is " user "; roles are " roles))
|
||||
(cond
|
||||
roles (layout/render "roles.html"
|
||||
(:session request)
|
||||
{:title (str "Welcome " (:fullname user) ", what do you want to do?")
|
||||
:user user
|
||||
:roles (map #(assoc % :link (safe-name (:name %) :sql)) roles)})
|
||||
(empty? roles)(response/found "/app")
|
||||
true (assoc (response/found "/login") :session (dissoc session :user)))))
|
||||
|
||||
|
||||
(defn admins-page
|
||||
[request]
|
||||
(response/found "/admin"))
|
||||
|
||||
|
||||
(defn analysts-page
|
||||
"My expectation is that analysts will do a lot of their work through QGIS or
|
||||
some other geographical information system; so there isn't a need to put
|
||||
anything sophisticated here."
|
||||
[request]
|
||||
(response/found "/admin"))
|
||||
|
||||
|
||||
(defn canvassers-page
|
||||
[request]
|
||||
(layout/render "roles/canvasser.html" request {}))
|
||||
|
||||
|
||||
(defn issue-experts-page
|
||||
[request]
|
||||
(layout/render "roles/issue-experts.html" request {}))
|
||||
|
||||
|
||||
(defn team-organisers-page
|
||||
[request]
|
||||
(layout/render "roles/team-orgenisers.html" request {}))
|
||||
|
||||
|
||||
(defroutes roles-routes
|
||||
(GET "/roles/admins" [request] (route/restricted (admins-page request)))
|
||||
(GET "/roles/analysts" [request] (route/restricted (analysts-page request)))
|
||||
(GET "/roles/canvassers" [request] (route/restricted (canvassers-page request)))
|
||||
(GET "/roles/issue_editors" [request] (route/restricted (auto/list-issues-Issues request)))
|
||||
(GET "/roles/issue_experts" [request] (route/restricted (issue-experts-page request)))
|
||||
(GET "/roles/team_organisers" [request] (route/restricted (auto/list-teams-Teams request)))
|
||||
(GET "/roles" request (route/restricted (roles-page request))))
|
||||
|
||||
|
|
@ -3,21 +3,26 @@
|
|||
(ns ^{:doc "REST API."
|
||||
:author "Simon Brooke"} youyesyet.routes.services
|
||||
(:require [clj-http.client :as client]
|
||||
[ring.util.http-response :refer :all]
|
||||
[compojure.api.sweet :refer :all]
|
||||
[schema.core :as s]))
|
||||
[ring.util.http-response :refer :all]
|
||||
[schema.core :as s]
|
||||
[youyesyet.db.core :as db]))
|
||||
|
||||
(defapi service-routes
|
||||
{:swagger {:ui "/swagger-ui"
|
||||
:spec "/swagger.json"
|
||||
:coercion :schema
|
||||
:data {:info {:version "1.0.0"
|
||||
:title "Sample API"
|
||||
:description "Sample Services"}}}}
|
||||
|
||||
(context "/api" []
|
||||
:tags ["thingie"]
|
||||
|
||||
(GET "/electors/:address-id" []
|
||||
;; (GET "/electors-by-dwelling/:dwelling-id" []
|
||||
;; :return map
|
||||
;; :query-params [dwelling-id :- s/Int]
|
||||
;; :summary ""
|
||||
;; (db/list-electors-by-dwelling db/*db* {:id dwelling-id}))
|
||||
|
||||
(GET "/plus" []
|
||||
:return Long
|
||||
|
|
@ -47,4 +52,4 @@
|
|||
:return Long
|
||||
:header-params [x :- Long, y :- Long]
|
||||
:summary "x^y with header-parameters"
|
||||
(ok (long (Math/pow x y)))))))
|
||||
(ok (long (Math/pow x y))))))
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
(ns^{:doc "Custom Selmer tags."
|
||||
:author "Simon Brooke"}
|
||||
youyesyet.tags
|
||||
(:require [selmer.parser :as parser]
|
||||
[selmer.filters :as filters]
|
||||
[selmer.util :refer :all]))
|
||||
|
||||
|
||||
(defn if-writable-handler [params tag-content render rdr]
|
||||
"If the current element is writable by the current user, emit the content of
|
||||
the if clause; else emit the content of the else clause."
|
||||
(let [{if-tags :ifwritable else-tags :else} (tag-content rdr :ifwritable :else :endifwritable)]
|
||||
params))
|
||||
|
||||
|
||||
(defn if-readable-handler [params tag-content render rdr]
|
||||
"If the current element is readable by the current user, emit the content of
|
||||
the if clause; else emit the content of the else clause."
|
||||
(let [{if-tags :ifreadable else-tags :else} (tag-content rdr :ifwritable :else :endifwritable)]
|
||||
params))
|
||||
|
|
@ -39,7 +39,7 @@
|
|||
[:div
|
||||
[:h1 "You Yes Yet?"]
|
||||
[:div.container {:id "main-container"}
|
||||
[:h2 "Pre-alpha/proof of concept"]
|
||||
[:h2 "Alpha test code"]
|
||||
[:p.motd {:dangerouslySetInnerHTML
|
||||
{:__html (md->html motd)}}]
|
||||
[:p
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue