User profile page working.
This commit is contained in:
parent
b65223198c
commit
ab568365ef
46 changed files with 873 additions and 698 deletions
|
|
@ -4,6 +4,7 @@
|
|||
[cheshire.core :refer [generate-string parse-string]]
|
||||
[clojure.java.jdbc :as jdbc]
|
||||
[conman.core :as conman]
|
||||
[hugsql.core :as hugsql]
|
||||
[mount.core :refer [defstate]]
|
||||
[youyesyet.config :refer [env]])
|
||||
(:import org.postgresql.util.PGobject
|
||||
|
|
@ -23,6 +24,7 @@
|
|||
:stop (conman/disconnect! *db*))
|
||||
|
||||
(conman/bind-connection *db* "sql/queries.auto.sql" "sql/queries.sql")
|
||||
(hugsql/def-sqlvec-fns "sql/queries.auto.sql")
|
||||
|
||||
(defn to-date [^java.sql.Date sql-date]
|
||||
(-> sql-date (.getTime) (java.util.Date.)))
|
||||
|
|
|
|||
|
|
@ -13,8 +13,9 @@
|
|||
[youyesyet.routes.auto :refer [auto-selmer-routes]]
|
||||
[youyesyet.routes.auto-json :refer [auto-rest-routes]]
|
||||
[youyesyet.routes.issue-experts :refer [issue-expert-routes]]
|
||||
[youyesyet.routes.rest :refer [rest-routes]]
|
||||
[youyesyet.routes.logged-in :refer [logged-in-routes]]
|
||||
[youyesyet.routes.oauth :refer [oauth-routes]]
|
||||
[youyesyet.routes.rest :refer [rest-routes]]
|
||||
[youyesyet.routes.roles :refer [roles-routes]]
|
||||
[youyesyet.routes.services :refer [service-routes]]
|
||||
[youyesyet.env :refer [defaults]]))
|
||||
|
|
@ -70,6 +71,9 @@
|
|||
(-> #'home-routes
|
||||
(wrap-routes middleware/wrap-csrf)
|
||||
(wrap-routes middleware/wrap-formats))
|
||||
(-> #'logged-in-routes
|
||||
(wrap-routes middleware/wrap-csrf)
|
||||
(wrap-routes middleware/wrap-formats))
|
||||
(-> #'roles-routes
|
||||
(wrap-routes middleware/wrap-csrf)
|
||||
(wrap-routes middleware/wrap-formats))
|
||||
|
|
|
|||
|
|
@ -68,18 +68,18 @@
|
|||
;; than me so there's almost certainly a reason it doesn't.
|
||||
[template session & [params]]
|
||||
(let [user (:user session)]
|
||||
(log/debug (str "layout/render: template: '" template "'; user: '" (:username user)))
|
||||
(log/debug (str "layout/render: template: '" template "'; session: '" session "'; params: '" params "'"))
|
||||
(content-type
|
||||
(ok
|
||||
(parser/render-file
|
||||
template
|
||||
(assoc params
|
||||
:page template
|
||||
(merge params
|
||||
{:page template
|
||||
:csrf-token *anti-forgery-token*
|
||||
:user user
|
||||
:user-roles (get-user-roles user)
|
||||
:site-title (:site-title env)
|
||||
:version (System/getProperty "youyesyet.version"))))
|
||||
:version (System/getProperty "youyesyet.version")})))
|
||||
"text/html; charset=utf-8")))
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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 20180715T113636.250Z"
|
||||
"User interface routes for Youyesyet auto-generated by [Application Description Language framework](https://github.com/simon-brooke/adl) at 20180715T195946.069Z"
|
||||
(:require
|
||||
[adl-support.core :as support]
|
||||
[clojure.java.io :as io]
|
||||
|
|
@ -45,18 +45,22 @@
|
|||
#{:locality :address :phone :postcode :longitude :district_id
|
||||
:id :latitude}
|
||||
(keys params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-addresses db/*db* params)
|
||||
:message
|
||||
"Error while searching address records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching address records"]})
|
||||
(support/do-or-log-error
|
||||
(db/list-addresses db/*db* {})
|
||||
:message
|
||||
"Error while fetching address records"
|
||||
:error-return
|
||||
{:warnings ["Error while fetching address records"]}))]
|
||||
(do
|
||||
(log/debug (db/search-strings-addresses-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-addresses db/*db* params)
|
||||
:message
|
||||
"Error while searching address records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching address records"]}))
|
||||
(do
|
||||
(log/debug (db/list-addresses-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/list-addresses db/*db* {})
|
||||
:message
|
||||
"Error while fetching address records"
|
||||
:error-return
|
||||
{:warnings ["Error while fetching address records"]})))]
|
||||
(if (:warnings records) records {:records records}))))))
|
||||
|
||||
(defn
|
||||
|
|
@ -119,18 +123,22 @@
|
|||
#{:access-token-uri :request-token-uri :authorize-uri :id
|
||||
:consumer-secret :consumer-key}
|
||||
(keys params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-authorities db/*db* params)
|
||||
:message
|
||||
"Error while searching authority records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching authority records"]})
|
||||
(support/do-or-log-error
|
||||
(db/list-authorities db/*db* {})
|
||||
:message
|
||||
"Error while fetching authority records"
|
||||
:error-return
|
||||
{:warnings ["Error while fetching authority records"]}))]
|
||||
(do
|
||||
(log/debug (db/search-strings-authorities-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-authorities db/*db* params)
|
||||
:message
|
||||
"Error while searching authority records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching authority records"]}))
|
||||
(do
|
||||
(log/debug (db/list-authorities-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/list-authorities db/*db* {})
|
||||
:message
|
||||
"Error while fetching authority records"
|
||||
:error-return
|
||||
{:warnings ["Error while fetching authority records"]})))]
|
||||
(if (:warnings records) records {:records records}))))))
|
||||
|
||||
(defn
|
||||
|
|
@ -179,18 +187,22 @@
|
|||
#{:email :phone :roles :username :fullname :bio :elector_id
|
||||
:expertise :id :avatar :address_id :authority_id :authorised}
|
||||
(keys params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-canvassers db/*db* params)
|
||||
:message
|
||||
"Error while searching canvasser records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching canvasser records"]})
|
||||
(support/do-or-log-error
|
||||
(db/list-canvassers db/*db* {})
|
||||
:message
|
||||
"Error while fetching canvasser records"
|
||||
:error-return
|
||||
{:warnings ["Error while fetching canvasser records"]}))]
|
||||
(do
|
||||
(log/debug (db/search-strings-canvassers-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-canvassers db/*db* params)
|
||||
:message
|
||||
"Error while searching canvasser records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching canvasser records"]}))
|
||||
(do
|
||||
(log/debug (db/list-canvassers-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/list-canvassers db/*db* {})
|
||||
:message
|
||||
"Error while fetching canvasser records"
|
||||
:error-return
|
||||
{:warnings ["Error while fetching canvasser records"]})))]
|
||||
(if (:warnings records) records {:records records}))))))
|
||||
|
||||
(defn
|
||||
|
|
@ -296,18 +308,22 @@
|
|||
[records
|
||||
(if
|
||||
(some #{:name :id} (keys params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-districts db/*db* params)
|
||||
:message
|
||||
"Error while searching district records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching district records"]})
|
||||
(support/do-or-log-error
|
||||
(db/list-districts db/*db* {})
|
||||
:message
|
||||
"Error while fetching district records"
|
||||
:error-return
|
||||
{:warnings ["Error while fetching district records"]}))]
|
||||
(do
|
||||
(log/debug (db/search-strings-districts-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-districts db/*db* params)
|
||||
:message
|
||||
"Error while searching district records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching district records"]}))
|
||||
(do
|
||||
(log/debug (db/list-districts-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/list-districts db/*db* {})
|
||||
:message
|
||||
"Error while fetching district records"
|
||||
:error-return
|
||||
{:warnings ["Error while fetching district records"]})))]
|
||||
(if (:warnings records) records {:records records}))))))
|
||||
|
||||
(defn
|
||||
|
|
@ -353,18 +369,22 @@
|
|||
[records
|
||||
(if
|
||||
(some #{:id :address_id :sub-address} (keys params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-dwellings db/*db* params)
|
||||
:message
|
||||
"Error while searching dwelling records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching dwelling records"]})
|
||||
(support/do-or-log-error
|
||||
(db/list-dwellings db/*db* {})
|
||||
:message
|
||||
"Error while fetching dwelling records"
|
||||
:error-return
|
||||
{:warnings ["Error while fetching dwelling records"]}))]
|
||||
(do
|
||||
(log/debug (db/search-strings-dwellings-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-dwellings db/*db* params)
|
||||
:message
|
||||
"Error while searching dwelling records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching dwelling records"]}))
|
||||
(do
|
||||
(log/debug (db/list-dwellings-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/list-dwellings db/*db* {})
|
||||
:message
|
||||
"Error while fetching dwelling records"
|
||||
:error-return
|
||||
{:warnings ["Error while fetching dwelling records"]})))]
|
||||
(if (:warnings records) records {:records records}))))))
|
||||
|
||||
(defn
|
||||
|
|
@ -426,18 +446,22 @@
|
|||
(some
|
||||
#{:email :phone :name :dwelling_id :id :gender}
|
||||
(keys params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-electors db/*db* params)
|
||||
:message
|
||||
"Error while searching elector records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching elector records"]})
|
||||
(support/do-or-log-error
|
||||
(db/list-electors db/*db* {})
|
||||
:message
|
||||
"Error while fetching elector records"
|
||||
:error-return
|
||||
{:warnings ["Error while fetching elector records"]}))]
|
||||
(do
|
||||
(log/debug (db/search-strings-electors-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-electors db/*db* params)
|
||||
:message
|
||||
"Error while searching elector records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching elector records"]}))
|
||||
(do
|
||||
(log/debug (db/list-electors-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/list-electors db/*db* {})
|
||||
:message
|
||||
"Error while fetching elector records"
|
||||
:error-return
|
||||
{:warnings ["Error while fetching elector records"]})))]
|
||||
(if (:warnings records) records {:records records}))))))
|
||||
|
||||
(defn
|
||||
|
|
@ -548,18 +572,22 @@
|
|||
(some
|
||||
#{:date :name :time :teams :cancelled :decription :id}
|
||||
(keys params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-events db/*db* params)
|
||||
:message
|
||||
"Error while searching event records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching event records"]})
|
||||
(support/do-or-log-error
|
||||
(db/list-events db/*db* {})
|
||||
:message
|
||||
"Error while fetching event records"
|
||||
:error-return
|
||||
{:warnings ["Error while fetching event records"]}))]
|
||||
(do
|
||||
(log/debug (db/search-strings-events-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-events db/*db* params)
|
||||
:message
|
||||
"Error while searching event records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching event records"]}))
|
||||
(do
|
||||
(log/debug (db/list-events-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/list-events db/*db* {})
|
||||
:message
|
||||
"Error while fetching event records"
|
||||
:error-return
|
||||
{:warnings ["Error while fetching event records"]})))]
|
||||
(if (:warnings records) records {:records records}))))))
|
||||
|
||||
(defn
|
||||
|
|
@ -583,18 +611,23 @@
|
|||
(some
|
||||
#{:closed :date :id :notes :request_id :actor}
|
||||
(keys params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-followupactions db/*db* params)
|
||||
:message
|
||||
"Error while searching followupaction records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching followupaction records"]})
|
||||
(support/do-or-log-error
|
||||
(db/list-followupactions db/*db* {})
|
||||
:message
|
||||
"Error while fetching followupaction records"
|
||||
:error-return
|
||||
{:warnings ["Error while fetching followupaction records"]}))]
|
||||
(do
|
||||
(log/debug (db/search-strings-followupactions-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-followupactions db/*db* params)
|
||||
:message
|
||||
"Error while searching followupaction records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching followupaction records"]}))
|
||||
(do
|
||||
(log/debug (db/list-followupactions-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/list-followupactions db/*db* {})
|
||||
:message
|
||||
"Error while fetching followupaction records"
|
||||
:error-return
|
||||
{:warnings
|
||||
["Error while fetching followupaction records"]})))]
|
||||
(if (:warnings records) records {:records records}))))))
|
||||
|
||||
(defn
|
||||
|
|
@ -669,18 +702,23 @@
|
|||
[records
|
||||
(if
|
||||
(some #{:id} (keys params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-followupmethods db/*db* params)
|
||||
:message
|
||||
"Error while searching followupmethod records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching followupmethod records"]})
|
||||
(support/do-or-log-error
|
||||
(db/list-followupmethods db/*db* {})
|
||||
:message
|
||||
"Error while fetching followupmethod records"
|
||||
:error-return
|
||||
{:warnings ["Error while fetching followupmethod records"]}))]
|
||||
(do
|
||||
(log/debug (db/search-strings-followupmethods-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-followupmethods db/*db* params)
|
||||
:message
|
||||
"Error while searching followupmethod records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching followupmethod records"]}))
|
||||
(do
|
||||
(log/debug (db/list-followupmethods-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/list-followupmethods db/*db* {})
|
||||
:message
|
||||
"Error while fetching followupmethod records"
|
||||
:error-return
|
||||
{:warnings
|
||||
["Error while fetching followupmethod records"]})))]
|
||||
(if (:warnings records) records {:records records}))))))
|
||||
|
||||
(defn
|
||||
|
|
@ -730,18 +768,24 @@
|
|||
(some
|
||||
#{:issue_id :visit_id :elector_id :id :method_id}
|
||||
(keys params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-followuprequests db/*db* params)
|
||||
:message
|
||||
"Error while searching followuprequest records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching followuprequest records"]})
|
||||
(support/do-or-log-error
|
||||
(db/list-followuprequests db/*db* {})
|
||||
:message
|
||||
"Error while fetching followuprequest records"
|
||||
:error-return
|
||||
{:warnings ["Error while fetching followuprequest records"]}))]
|
||||
(do
|
||||
(log/debug (db/search-strings-followuprequests-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-followuprequests db/*db* params)
|
||||
:message
|
||||
"Error while searching followuprequest records"
|
||||
:error-return
|
||||
{:warnings
|
||||
["Error while searching followuprequest records"]}))
|
||||
(do
|
||||
(log/debug (db/list-followuprequests-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/list-followuprequests db/*db* {})
|
||||
:message
|
||||
"Error while fetching followuprequest records"
|
||||
:error-return
|
||||
{:warnings
|
||||
["Error while fetching followuprequest records"]})))]
|
||||
(if (:warnings records) records {:records records}))))))
|
||||
|
||||
(defn
|
||||
|
|
@ -843,18 +887,22 @@
|
|||
[records
|
||||
(if
|
||||
(some #{:id} (keys params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-genders db/*db* params)
|
||||
:message
|
||||
"Error while searching gender records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching gender records"]})
|
||||
(support/do-or-log-error
|
||||
(db/list-genders db/*db* {})
|
||||
:message
|
||||
"Error while fetching gender records"
|
||||
:error-return
|
||||
{:warnings ["Error while fetching gender records"]}))]
|
||||
(do
|
||||
(log/debug (db/search-strings-genders-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-genders db/*db* params)
|
||||
:message
|
||||
"Error while searching gender records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching gender records"]}))
|
||||
(do
|
||||
(log/debug (db/list-genders-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/list-genders db/*db* {})
|
||||
:message
|
||||
"Error while fetching gender records"
|
||||
:error-return
|
||||
{:warnings ["Error while fetching gender records"]})))]
|
||||
(if (:warnings records) records {:records records}))))))
|
||||
|
||||
(defn
|
||||
|
|
@ -902,18 +950,22 @@
|
|||
(some
|
||||
#{:locality :option_id :visit_id :elector_id :id}
|
||||
(keys params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-intentions db/*db* params)
|
||||
:message
|
||||
"Error while searching intention records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching intention records"]})
|
||||
(support/do-or-log-error
|
||||
(db/list-intentions db/*db* {})
|
||||
:message
|
||||
"Error while fetching intention records"
|
||||
:error-return
|
||||
{:warnings ["Error while fetching intention records"]}))]
|
||||
(do
|
||||
(log/debug (db/search-strings-intentions-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-intentions db/*db* params)
|
||||
:message
|
||||
"Error while searching intention records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching intention records"]}))
|
||||
(do
|
||||
(log/debug (db/list-intentions-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/list-intentions db/*db* {})
|
||||
:message
|
||||
"Error while fetching intention records"
|
||||
:error-return
|
||||
{:warnings ["Error while fetching intention records"]})))]
|
||||
(if (:warnings records) records {:records records}))))))
|
||||
|
||||
(defn
|
||||
|
|
@ -999,18 +1051,22 @@
|
|||
[records
|
||||
(if
|
||||
(some #{:experts :brief :id :current :url} (keys params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-issues db/*db* params)
|
||||
:message
|
||||
"Error while searching issue records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching issue records"]})
|
||||
(support/do-or-log-error
|
||||
(db/list-issues db/*db* {})
|
||||
:message
|
||||
"Error while fetching issue records"
|
||||
:error-return
|
||||
{:warnings ["Error while fetching issue records"]}))]
|
||||
(do
|
||||
(log/debug (db/search-strings-issues-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-issues db/*db* params)
|
||||
:message
|
||||
"Error while searching issue records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching issue records"]}))
|
||||
(do
|
||||
(log/debug (db/list-issues-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/list-issues db/*db* {})
|
||||
:message
|
||||
"Error while fetching issue records"
|
||||
:error-return
|
||||
{:warnings ["Error while fetching issue records"]})))]
|
||||
(if (:warnings records) records {:records records}))))))
|
||||
|
||||
(defn
|
||||
|
|
@ -1067,18 +1123,22 @@
|
|||
[records
|
||||
(if
|
||||
(some #{:id} (keys params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-options db/*db* params)
|
||||
:message
|
||||
"Error while searching option records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching option records"]})
|
||||
(support/do-or-log-error
|
||||
(db/list-options db/*db* {})
|
||||
:message
|
||||
"Error while fetching option records"
|
||||
:error-return
|
||||
{:warnings ["Error while fetching option records"]}))]
|
||||
(do
|
||||
(log/debug (db/search-strings-options-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-options db/*db* params)
|
||||
:message
|
||||
"Error while searching option records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching option records"]}))
|
||||
(do
|
||||
(log/debug (db/list-options-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/list-options db/*db* {})
|
||||
:message
|
||||
"Error while fetching option records"
|
||||
:error-return
|
||||
{:warnings ["Error while fetching option records"]})))]
|
||||
(if (:warnings records) records {:records records}))))))
|
||||
|
||||
(defn
|
||||
|
|
@ -1124,18 +1184,22 @@
|
|||
[records
|
||||
(if
|
||||
(some #{:name :id :members} (keys params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-roles db/*db* params)
|
||||
:message
|
||||
"Error while searching role records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching role records"]})
|
||||
(support/do-or-log-error
|
||||
(db/list-roles db/*db* {})
|
||||
:message
|
||||
"Error while fetching role records"
|
||||
:error-return
|
||||
{:warnings ["Error while fetching role records"]}))]
|
||||
(do
|
||||
(log/debug (db/search-strings-roles-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-roles db/*db* params)
|
||||
:message
|
||||
"Error while searching role records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching role records"]}))
|
||||
(do
|
||||
(log/debug (db/list-roles-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/list-roles db/*db* {})
|
||||
:message
|
||||
"Error while fetching role records"
|
||||
:error-return
|
||||
{:warnings ["Error while fetching role records"]})))]
|
||||
(if (:warnings records) records {:records records}))))))
|
||||
|
||||
(defn
|
||||
|
|
@ -1194,18 +1258,22 @@
|
|||
#{:name :organisers :longitude :district_id :id :latitude
|
||||
:members}
|
||||
(keys params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-teams db/*db* params)
|
||||
:message
|
||||
"Error while searching team records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching team records"]})
|
||||
(support/do-or-log-error
|
||||
(db/list-teams db/*db* {})
|
||||
:message
|
||||
"Error while fetching team records"
|
||||
:error-return
|
||||
{:warnings ["Error while fetching team records"]}))]
|
||||
(do
|
||||
(log/debug (db/search-strings-teams-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-teams db/*db* params)
|
||||
:message
|
||||
"Error while searching team records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching team records"]}))
|
||||
(do
|
||||
(log/debug (db/list-teams-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/list-teams db/*db* {})
|
||||
:message
|
||||
"Error while fetching team records"
|
||||
:error-return
|
||||
{:warnings ["Error while fetching team records"]})))]
|
||||
(if (:warnings records) records {:records records}))))))
|
||||
|
||||
(defn
|
||||
|
|
@ -1284,18 +1352,22 @@
|
|||
[records
|
||||
(if
|
||||
(some #{:canvasser_id :date :id :address_id} (keys params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-visits db/*db* params)
|
||||
:message
|
||||
"Error while searching visit records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching visit records"]})
|
||||
(support/do-or-log-error
|
||||
(db/list-visits db/*db* {})
|
||||
:message
|
||||
"Error while fetching visit records"
|
||||
:error-return
|
||||
{:warnings ["Error while fetching visit records"]}))]
|
||||
(do
|
||||
(log/debug (db/search-strings-visits-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/search-strings-visits db/*db* params)
|
||||
:message
|
||||
"Error while searching visit records"
|
||||
:error-return
|
||||
{:warnings ["Error while searching visit records"]}))
|
||||
(do
|
||||
(log/debug (db/list-visits-sqlvec params))
|
||||
(support/do-or-log-error
|
||||
(db/list-visits db/*db* {})
|
||||
:message
|
||||
"Error while fetching visit records"
|
||||
:error-return
|
||||
{:warnings ["Error while fetching visit records"]})))]
|
||||
(if (:warnings records) records {:records records}))))))
|
||||
|
||||
(defn
|
||||
|
|
|
|||
|
|
@ -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 20180715T113634.964Z"
|
||||
"JSON routes for youyesyet auto-generated by [Application Description Language framework](https://github.com/simon-brooke/adl) at 20180715T195944.782Z"
|
||||
(:require
|
||||
[adl-support.core :as support]
|
||||
[clojure.core.memoize :as memo]
|
||||
|
|
|
|||
|
|
@ -48,11 +48,6 @@
|
|||
(if (.exists motd) (slurp motd) "")))
|
||||
|
||||
|
||||
(defn app-page [request]
|
||||
(layout/render "app.html" {:title "Canvasser app"
|
||||
:user (:user (:session request))}))
|
||||
|
||||
|
||||
(defn about-page []
|
||||
(layout/render "about.html" {} {:title
|
||||
(str "About " (:site-title env))
|
||||
|
|
@ -126,11 +121,6 @@
|
|||
: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))
|
||||
|
|
@ -139,10 +129,7 @@
|
|||
(POST "/call-me" request (call-me-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?"}))
|
||||
;; TODO: this should move somewhere else but I'm not sure where yet
|
||||
(GET "/app" [request] (route/restricted (app-page request))))
|
||||
{:title "Have you signed up as a canvasser yet?"})))
|
||||
|
|
|
|||
127
src/clj/youyesyet/routes/logged_in.clj
Normal file
127
src/clj/youyesyet/routes/logged_in.clj
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
(ns ^{:doc "Routes/pages available to authenticated users."
|
||||
:author "Simon Brooke"} youyesyet.routes.logged-in
|
||||
(:require [adl-support.core :as support]
|
||||
[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]]
|
||||
[youyesyet.db.core :as db]
|
||||
[youyesyet.layout :as layout]
|
||||
[youyesyet.oauth :as oauth]
|
||||
[compojure.core :refer [defroutes GET POST]]
|
||||
))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;;;
|
||||
;;;; youyesyet.routes.logged-in: routes and pages for authenticated users.
|
||||
;;;;
|
||||
;;;; This program is free software; you can redistribute it and/or
|
||||
;;;; modify it under the terms of the GNU General Public License
|
||||
;;;; as published by the Free Software Foundation; either version 2
|
||||
;;;; of the License, or (at your option) any later version.
|
||||
;;;;
|
||||
;;;; This program is distributed in the hope that it will be useful,
|
||||
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
;;;; GNU General Public License for more details.
|
||||
;;;;
|
||||
;;;; You should have received a copy of the GNU General Public License
|
||||
;;;; along with this program; if not, write to the Free Software
|
||||
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||
;;;; USA.
|
||||
;;;;
|
||||
;;;; Copyright (C) 2016 Simon Brooke for Radical Independence Campaign
|
||||
;;;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
|
||||
(defn app-page [request]
|
||||
(layout/render "app.html"
|
||||
(:session request)
|
||||
{:title "Canvasser app"}))
|
||||
|
||||
|
||||
(defn profile-page [request]
|
||||
"Show the canvassers form for the current user, only."
|
||||
(let [record (-> request :session :user)]
|
||||
(layout/render
|
||||
"auto/form-canvassers-Canvasser.html"
|
||||
(:session request)
|
||||
{:title (str "Profile for " (-> request :session :user :fullname))
|
||||
:record record
|
||||
:elector_id
|
||||
(flatten
|
||||
(remove
|
||||
nil?
|
||||
(list
|
||||
(support/do-or-log-error
|
||||
(db/get-elector db/*db* {:id (:elector_id record)})
|
||||
:message
|
||||
"Error while fetching elector record {:id (:elector_id record)}")
|
||||
(support/do-or-log-error
|
||||
(db/list-electors db/*db*)
|
||||
:message
|
||||
"Error while fetching elector list")))),
|
||||
:address_id
|
||||
(flatten
|
||||
(remove
|
||||
nil?
|
||||
(list
|
||||
(support/do-or-log-error
|
||||
(db/get-address db/*db* {:id (:address_id record)})
|
||||
:message
|
||||
"Error while fetching address record {:id (:address_id record)}")
|
||||
(support/do-or-log-error
|
||||
(db/list-addresses db/*db*)
|
||||
:message
|
||||
"Error while fetching address list")))),
|
||||
:authority_id
|
||||
(flatten
|
||||
(remove
|
||||
nil?
|
||||
(list
|
||||
(support/do-or-log-error
|
||||
(db/get-authority db/*db* {:id (:authority_id record)})
|
||||
:message
|
||||
"Error while fetching authority record {:id (:authority_id record)}")
|
||||
(support/do-or-log-error
|
||||
(db/list-authorities db/*db*)
|
||||
:message
|
||||
"Error while fetching authority list")))),
|
||||
:roles
|
||||
(flatten
|
||||
(remove
|
||||
nil?
|
||||
(list
|
||||
nil
|
||||
(support/do-or-log-error
|
||||
(db/list-roles db/*db*)
|
||||
:message
|
||||
"Error while fetching role list")))),
|
||||
:expertise
|
||||
(flatten
|
||||
(remove
|
||||
nil?
|
||||
(list
|
||||
nil
|
||||
(support/do-or-log-error
|
||||
(db/list-issues db/*db*)
|
||||
:message
|
||||
"Error while fetching issue list"))))})))
|
||||
|
||||
|
||||
(defn handle-logout
|
||||
[request]
|
||||
(dissoc (response/found "home") :user :roles))
|
||||
|
||||
|
||||
(defroutes logged-in-routes
|
||||
(GET "/logout" request (handle-logout request))
|
||||
(GET "/profile" request (route/restricted (profile-page request)))
|
||||
(GET "/app" [request] (route/restricted (app-page request)))
|
||||
)
|
||||
|
|
@ -55,7 +55,7 @@
|
|||
|
||||
(defn canvassers-page
|
||||
[request]
|
||||
(layout/render "roles/canvasser.html" request {}))
|
||||
(layout/render "roles/canvasser.html" (:session request) {}))
|
||||
|
||||
|
||||
(defn team-organisers-page
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue