mirror of
https://github.com/journeyman-cc/smeagol.git
synced 2026-04-12 18:05:06 +00:00
Tidy-up and robustness; no major functional change.
This commit is contained in:
parent
9f3c16a348
commit
2f6f9286a3
10 changed files with 147 additions and 98 deletions
|
|
@ -8,9 +8,7 @@
|
|||
[com.cemerick/url "0.1.1"]
|
||||
[com.fzakaria/slf4j-timbre "0.3.7"]
|
||||
[com.taoensso/encore "2.92.0"]
|
||||
[com.cemerick/url "0.1.1"]
|
||||
[com.taoensso/timbre "4.10.0"]
|
||||
[com.fzakaria/slf4j-timbre "0.3.7"]
|
||||
[com.taoensso/tower "3.0.2" :exclusions [com.taoensso/encore]]
|
||||
[crypto-password "0.2.0"]
|
||||
[environ "1.1.0"]
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
{:admin {:admin true, :email "info@weft.scot", :password "admin"}, :jenny {:email "jenny@auchencairn.org", :admin false, :password "$s0$f0801$1uniQfftB37G5e5GklJANQ==$kQ0+/YcCuaz2x5iYjwhNlDlnWX/exE/8pSC+R4C0WvQ="}}
|
||||
{:admin {:admin true, :email "info@weft.scot", :password "admin"}}
|
||||
|
|
|
|||
|
|
@ -265,6 +265,14 @@ th {
|
|||
padding: 0 2em 0 0;
|
||||
}
|
||||
|
||||
.sanity-cause .sanity-stacktrace {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.sanity-cause:hover .sanity-stacktrace {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.vega-bindings, .vega-actions {
|
||||
font-size: 66%;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@
|
|||
(def password-file-path
|
||||
(or
|
||||
(env :smeagol-passwd)
|
||||
(str (clojure.java.io/resource "passwd"))))
|
||||
(str (io/resource-path) "../passwd")))
|
||||
|
||||
|
||||
(defn- get-users
|
||||
|
|
@ -112,7 +112,7 @@
|
|||
(timbre/info (str "Successfully changed password for user " username))
|
||||
true))
|
||||
(catch Exception any
|
||||
(timbre/error
|
||||
(timbre/error any
|
||||
(format "Changing password failed for user %s failed: %s (%s)"
|
||||
username (.getName (.getClass any)) (.getMessage any)))
|
||||
false))))
|
||||
|
|
@ -162,7 +162,7 @@
|
|||
(timbre/info "Successfully added user " username)
|
||||
true)
|
||||
(catch Exception any
|
||||
(timbre/error
|
||||
(timbre/error any
|
||||
(format "Adding user %s failed: %s (%s)"
|
||||
username (.getName (.getClass any)) (.getMessage any)))
|
||||
false)))))
|
||||
|
|
@ -179,7 +179,7 @@
|
|||
(timbre/info (str "Successfully deleted user " username))
|
||||
true)
|
||||
(catch Exception any
|
||||
(timbre/error
|
||||
(timbre/error any
|
||||
(format "Deleting user %s failed: %s (%s)"
|
||||
username (.getName (.getClass any)) (.getMessage any)))
|
||||
false))))
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@
|
|||
;;;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
|
||||
(def config-file-path
|
||||
"The relative path to the config file."
|
||||
(or
|
||||
|
|
@ -50,5 +49,5 @@
|
|||
(try
|
||||
(read-string (slurp config-file-path))
|
||||
(catch Exception any
|
||||
(timbre/error "Could not load configuration" any)
|
||||
(timbre/error any "Could not load configuration")
|
||||
{})))
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@
|
|||
(timbre/info "\n-=[ smeagol started successfully"
|
||||
(when (env :dev) "using the development profile") "]=-")
|
||||
(catch Exception any
|
||||
(timbre/error "Failure during startup" any)
|
||||
(timbre/error any "Failure during startup")
|
||||
(destroy))))
|
||||
|
||||
;; timeout sessions after 30 minutes
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@
|
|||
:details details
|
||||
:users (auth/list-users)})))
|
||||
(catch Exception any
|
||||
(timbre/error (.getMessage any))
|
||||
(timbre/error any)
|
||||
(layout/render "edit-user.html"
|
||||
(merge (util/standard-params request)
|
||||
{:title (str (:edit-title-prefix (util/get-messages request)) " " (:target params))
|
||||
|
|
|
|||
|
|
@ -45,13 +45,6 @@
|
|||
;;;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
|
||||
(defn get-git-repo
|
||||
"Get the git repository for my content, creating it if necessary"
|
||||
[]
|
||||
(hist/load-or-init-repo util/content-dir))
|
||||
|
||||
|
||||
(defn process-source
|
||||
"Process `source-text` and save it to the specified `file-path`, committing it
|
||||
to Git and finally redirecting to wiki-page."
|
||||
|
|
@ -61,7 +54,7 @@
|
|||
file-name (str page suffix)
|
||||
file-path (cjio/file util/content-dir file-name)
|
||||
exists? (.exists (cjio/as-file file-path))
|
||||
git-repo (get-git-repo)
|
||||
git-repo (hist/load-or-init-repo util/content-dir)
|
||||
user (session/get :user)
|
||||
email (auth/get-email user)
|
||||
summary (format "%s: %s" user (or (:summary params) "no summary"))]
|
||||
|
|
@ -157,7 +150,7 @@
|
|||
[request]
|
||||
(let [params (keywordize-keys (:params request))
|
||||
data-path (str (io/resource-path) "/content/uploads/")
|
||||
git-repo (get-git-repo)
|
||||
git-repo (hist/load-or-init-repo util/content-dir)
|
||||
upload (:upload params)
|
||||
uploaded (if upload (ul/store-upload params data-path))
|
||||
user (session/get :user)
|
||||
|
|
|
|||
|
|
@ -252,13 +252,28 @@
|
|||
(as-hiccup [this dictionary] "")
|
||||
|
||||
clojure.lang.Keyword
|
||||
(as-hiccup [this dictionary] (str (or (this dictionary)(string/replace (name this) "-" " ")) " "))
|
||||
(as-hiccup [this dictionary]
|
||||
(str
|
||||
(or
|
||||
(this dictionary)
|
||||
(string/replace (name this) "-" " "))
|
||||
" "))
|
||||
|
||||
clojure.lang.PersistentList
|
||||
(as-hiccup [this dictionary] (apply vector (cons :div (map #(as-hiccup % dictionary) this))))
|
||||
(as-hiccup [this dictionary]
|
||||
(apply
|
||||
vector
|
||||
(cons
|
||||
:div
|
||||
(map #(as-hiccup % dictionary) this))))
|
||||
|
||||
clojure.lang.PersistentVector
|
||||
(as-hiccup [this dictionary] (apply vector (cons :div (map #(as-hiccup % dictionary) this))))
|
||||
(as-hiccup [this dictionary]
|
||||
(apply
|
||||
vector
|
||||
(cons
|
||||
:div
|
||||
(map #(as-hiccup % dictionary) this))))
|
||||
|
||||
clojure.lang.PersistentArrayMap
|
||||
(as-hiccup [this dictionary]
|
||||
|
|
@ -302,7 +317,7 @@
|
|||
(fn [x]
|
||||
[:div
|
||||
{:class "sanity-cause"}
|
||||
(.getMessage x)
|
||||
[:h2 (.getMessage x)]
|
||||
[:div {:class "sanity-stacktrace"}
|
||||
(apply
|
||||
vector
|
||||
|
|
@ -317,34 +332,43 @@
|
|||
(as-hiccup [this dictionary] (str this " ")))
|
||||
|
||||
|
||||
(defn sanity-check-report
|
||||
[problems]
|
||||
(defn get-locale-messages
|
||||
"Get messages for the server-side locale."
|
||||
[]
|
||||
(let [locale (Locale/getDefault)
|
||||
locale-specifier (str (.getLanguage locale) "-" (.getCountry locale))
|
||||
messages (try
|
||||
locale-specifier (str (.getLanguage locale) "-" (.getCountry locale))]
|
||||
(try
|
||||
(i18n/get-messages locale-specifier "i18n" "en-GB")
|
||||
(catch Exception any {}))]
|
||||
(html
|
||||
[:html
|
||||
(catch Exception any {}))))
|
||||
|
||||
|
||||
;; Prepackaged hiccup sub-units
|
||||
(defn as-hiccup-head
|
||||
[messages]
|
||||
[:head
|
||||
[:title (as-hiccup :smeagol-not-initialised messages)]
|
||||
[:link {:href "/content/stylesheet.css" :rel "stylesheet"}]]
|
||||
[:body
|
||||
[:link {:href "/content/stylesheet.css" :rel "stylesheet"}]])
|
||||
|
||||
|
||||
(defn as-hiccup-header
|
||||
[messages]
|
||||
[:header
|
||||
[:div {:id "nav"} " "]
|
||||
[:h1 (as-hiccup :smeagol-not-initialised messages)]
|
||||
[:p " "]]
|
||||
[:div {:id "error" :class "error"}
|
||||
[:div {:class "error"}
|
||||
(as-hiccup [(count (keys problems)) :problems-found] messages)]]
|
||||
[:div {:id "main-container" :class "sanity-check-report"}
|
||||
[:p (as-hiccup :smeagol-misconfiguration messages)]
|
||||
(as-hiccup problems messages)
|
||||
[:p " "]])
|
||||
|
||||
|
||||
(defn as-hiccup-see-doc
|
||||
[messages]
|
||||
[:p (as-hiccup :see-documentation messages)
|
||||
[:a
|
||||
{:href
|
||||
"https://github.com/journeyman-cc/smeagol/blob/master/resources/public/content/Deploying%20Smeagol.md"}
|
||||
(as-hiccup :here messages)]]]
|
||||
"https://github.com/journeyman-cc/smeagol/wiki/Deploying-Smeagol"}
|
||||
(as-hiccup :here messages)] "."])
|
||||
|
||||
|
||||
(defn as-hiccup-footer
|
||||
[messages]
|
||||
[:footer
|
||||
[:div {:id "credits"}
|
||||
[:div
|
||||
|
|
@ -355,7 +379,26 @@
|
|||
:alt "The Web Engineering Factory & Toolworks"
|
||||
:src "http://www.weft.scot/images/weft.logo.64.png"}]
|
||||
" Developed by "
|
||||
[:a {:href "http://www.weft.scot/"}"WEFT"]]]]]])))
|
||||
[:a {:href "http://www.weft.scot/"}"WEFT"]]]])
|
||||
|
||||
|
||||
(defn sanity-check-report
|
||||
"Convert this `problem` report into a nicely formatted HTML page"
|
||||
[problems]
|
||||
(let [messages (get-locale-messages)]
|
||||
(html
|
||||
[:html
|
||||
(as-hiccup-head messages)
|
||||
[:body
|
||||
(as-hiccup-header messages)
|
||||
[:div {:id "error"}
|
||||
[:p {:class "error"}
|
||||
(rest (as-hiccup [(count (keys problems)) :problems-found] messages))]]
|
||||
[:div {:id "main-container" :class "sanity-check-report"}
|
||||
[:p (as-hiccup :smeagol-misconfiguration messages)]
|
||||
(as-hiccup problems messages)
|
||||
(as-hiccup-see-doc messages)]
|
||||
(as-hiccup-footer messages)]])))
|
||||
|
||||
|
||||
(defn- raw-sanity-check-installation
|
||||
|
|
@ -383,26 +426,26 @@
|
|||
If no argument is passed, run the sanity check and if it fails return page contents;
|
||||
if `error` is passed, just return page content describing the error."
|
||||
([error]
|
||||
(let [messages (get-locale-messages)]
|
||||
(html
|
||||
[:html
|
||||
[:head
|
||||
[:title "Smeagol is not initialised correctly"]
|
||||
[:link {:href "/content/stylesheet.css" :rel "stylesheet"}]]
|
||||
(as-hiccup-head messages)
|
||||
[:body
|
||||
[:header
|
||||
[:h1 "Smeagol is not initialised correctly"]]
|
||||
(as-hiccup-header messages)
|
||||
[:div {:id "error"}
|
||||
[:p {:class "error"} (.getMessage error)]]
|
||||
[:p "There was a problem launching Smeagol probably because of misconfiguration:"]
|
||||
(apply
|
||||
vector
|
||||
(cons :ol
|
||||
(map #(vector :li (.getMessage %))
|
||||
(get-causes error))))
|
||||
[:p :see-documentation
|
||||
[:a {:href "https://github.com/journeyman-cc/smeagol/blob/develop/resources/public/content/Deploying%20Smeagol.md"} "here"]]]]))
|
||||
[:div {:id "main-container" :class "sanity-check-report"}
|
||||
[:p (as-hiccup :smeagol-misconfiguration messages)]
|
||||
(as-hiccup error messages)
|
||||
(as-hiccup-see-doc messages)]
|
||||
(as-hiccup-footer messages)]])))
|
||||
([]
|
||||
(try
|
||||
(sanity-check-installation)
|
||||
(catch Exception any (show-sanity-check-error any)))))
|
||||
(catch Exception any
|
||||
(timbre/error any "Failure during sanity check")
|
||||
(show-sanity-check-error any)))))
|
||||
|
||||
(show-sanity-check-error (Exception. "That's insane!"))
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@
|
|||
[scot.weft.i18n.core :as i18n]
|
||||
[smeagol.authenticate :as auth]
|
||||
[smeagol.configuration :refer [config]]
|
||||
[smeagol.formatting :refer [md->html]]))
|
||||
[smeagol.formatting :refer [md->html]]
|
||||
[taoensso.timbre :as timbre]))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;;;
|
||||
|
|
@ -55,12 +56,19 @@
|
|||
"Return the most acceptable messages collection we have given the
|
||||
`Accept-Language` header in this `request`."
|
||||
[request]
|
||||
(let [specifier ((:headers request) "accept-language")
|
||||
messages (try
|
||||
(i18n/get-messages specifier "i18n" "en-GB")
|
||||
(catch Exception any
|
||||
(timbre/error
|
||||
any
|
||||
(str
|
||||
"Failed to parse accept-language header "
|
||||
specifier))
|
||||
{}))]
|
||||
(merge
|
||||
(i18n/get-messages
|
||||
((:headers request) "accept-language")
|
||||
"i18n"
|
||||
"en-GB")
|
||||
config))
|
||||
messages
|
||||
config)))
|
||||
|
||||
|
||||
(def get-messages (memoize raw-get-messages))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue