2020-07-22 00:59:25 +02:00
|
|
|
(in-package :panettone)
|
|
|
|
(declaim (optimize (safety 3)))
|
|
|
|
|
2020-07-31 05:05:19 +02:00
|
|
|
(defvar *cheddar-url* "http://localhost:4238")
|
|
|
|
|
|
|
|
(defgeneric render-markdown (markdown)
|
|
|
|
(:documentation
|
|
|
|
"Render the argument, or the elements of the argument, as markdown, and return
|
|
|
|
the same structure"))
|
|
|
|
|
|
|
|
(defmethod render-markdown ((markdown string))
|
|
|
|
(cdr
|
|
|
|
(assoc :markdown
|
|
|
|
(cl-json:decode-json
|
|
|
|
(drakma:http-request
|
|
|
|
(concatenate 'string
|
|
|
|
*cheddar-url*
|
|
|
|
"/markdown")
|
|
|
|
:accept "application/json"
|
|
|
|
:method :post
|
|
|
|
:content-type "application/json"
|
|
|
|
:external-format-out :utf-8
|
|
|
|
:external-format-in :utf-8
|
|
|
|
:content (json:encode-json-to-string
|
|
|
|
`((markdown . ,markdown)))
|
|
|
|
:want-stream t)))))
|
|
|
|
|
|
|
|
(defmethod render-markdown ((markdown hash-table))
|
|
|
|
(alist-hash-table
|
|
|
|
(cl-json:decode-json
|
|
|
|
(drakma:http-request
|
|
|
|
(concatenate 'string
|
|
|
|
*cheddar-url*
|
|
|
|
"/markdown")
|
|
|
|
:accept "application/json"
|
|
|
|
:method :post
|
|
|
|
:content-type "application/json"
|
|
|
|
:external-format-out :utf-8
|
|
|
|
:external-format-in :utf-8
|
|
|
|
:content (json:encode-json-to-string markdown)
|
|
|
|
:want-stream t))))
|
|
|
|
|
|
|
|
(defun markdownify-comment-bodies (comments)
|
|
|
|
"Convert the bodies of the given list of comments to markdown in-place using
|
|
|
|
Cheddar, and return nothing"
|
|
|
|
(let ((in (make-hash-table))
|
|
|
|
(comment-table (make-hash-table)))
|
|
|
|
(dolist (comment comments)
|
2020-08-01 04:32:42 +02:00
|
|
|
(when (typep comment 'model:issue-comment)
|
|
|
|
(setf (gethash (id comment) in) (body comment))
|
|
|
|
(setf (gethash (id comment) comment-table) comment)))
|
2020-07-31 05:05:19 +02:00
|
|
|
(let ((res (render-markdown in)))
|
|
|
|
(iter (for (comment-id markdown-body) in-hashtable res)
|
|
|
|
(let ((comment-id (parse-integer (symbol-name comment-id))))
|
|
|
|
(setf (slot-value (gethash comment-id comment-table)
|
|
|
|
'model:body)
|
|
|
|
markdown-body)))))
|
|
|
|
(values))
|
|
|
|
|
2020-07-22 00:59:25 +02:00
|
|
|
;;;
|
|
|
|
;;; Views
|
|
|
|
;;;
|
|
|
|
|
|
|
|
(defvar *title* "Panettone")
|
|
|
|
|
2020-07-24 23:49:52 +02:00
|
|
|
(setf (who:html-mode) :html5)
|
2020-07-22 00:59:25 +02:00
|
|
|
|
2020-08-29 00:10:27 +02:00
|
|
|
(defun render/nav ()
|
2020-07-24 02:53:36 +02:00
|
|
|
(who:with-html-output (*standard-output*)
|
2020-08-29 00:10:27 +02:00
|
|
|
(:nav
|
|
|
|
(if (find (car (split "\\?" (hunchentoot:request-uri*) :limit 2))
|
|
|
|
(list "/" "/issues/closed")
|
|
|
|
:test #'string=)
|
|
|
|
(who:htm (:span :class "placeholder"))
|
|
|
|
(who:htm (:a :href "/" "All Issues")))
|
|
|
|
(if *user*
|
|
|
|
(who:htm
|
|
|
|
(:form :class "form-link log-out"
|
|
|
|
:method "post"
|
|
|
|
:action "/logout"
|
|
|
|
(:input :type "submit" :value "Log Out")))
|
|
|
|
(who:htm
|
|
|
|
(:a :href
|
|
|
|
(format nil
|
|
|
|
"/login?original-uri=~A"
|
|
|
|
(drakma:url-encode (hunchentoot:request-uri*)
|
|
|
|
:utf-8))
|
|
|
|
"Log In"))))))
|
2020-07-24 02:53:36 +02:00
|
|
|
|
2020-07-28 06:31:55 +02:00
|
|
|
(defun author (object)
|
|
|
|
(find-user-by-dn (author-dn object)))
|
|
|
|
|
2020-08-29 00:10:27 +02:00
|
|
|
(defmacro render ((&key
|
|
|
|
(footer t)
|
|
|
|
(header t))
|
|
|
|
&body body)
|
2020-07-22 00:59:25 +02:00
|
|
|
`(who:with-html-output-to-string (*standard-output* nil :prologue t)
|
2020-07-24 23:49:52 +02:00
|
|
|
(:html
|
|
|
|
:lang "en"
|
|
|
|
(:head
|
|
|
|
(:title (who:esc *title*))
|
2020-07-24 03:07:49 +02:00
|
|
|
(:link :rel "stylesheet" :type "text/css" :href "/main.css")
|
|
|
|
(:meta :name "viewport"
|
|
|
|
:content "width=device-width,initial-scale=1"))
|
2020-07-24 23:49:52 +02:00
|
|
|
(:body
|
|
|
|
(:div
|
|
|
|
:class "content"
|
2020-08-29 00:10:27 +02:00
|
|
|
(when ,header
|
|
|
|
(who:htm
|
|
|
|
(render/nav)))
|
2020-07-24 23:49:52 +02:00
|
|
|
,@body
|
|
|
|
(when ,footer
|
2020-08-29 00:10:27 +02:00
|
|
|
(who:htm
|
|
|
|
(:footer
|
|
|
|
(render/nav)))))))))
|
2020-07-22 00:59:25 +02:00
|
|
|
|
2020-08-01 18:10:27 +02:00
|
|
|
(defun form-button (&key
|
|
|
|
class
|
|
|
|
input-class
|
|
|
|
href
|
|
|
|
label
|
|
|
|
(method "post"))
|
|
|
|
(who:with-html-output (*standard-output*)
|
|
|
|
(:form :class class
|
|
|
|
:method method
|
|
|
|
:action href
|
|
|
|
(:input :type "submit"
|
|
|
|
:class input-class
|
|
|
|
:value label))))
|
|
|
|
|
2020-07-24 00:50:13 +02:00
|
|
|
(defun render/alert (message)
|
|
|
|
"Render an alert box for MESSAGE, if non-null"
|
|
|
|
(check-type message (or null string))
|
|
|
|
(who:with-html-output (*standard-output*)
|
|
|
|
(when message
|
|
|
|
(who:htm (:div :class "alert" (who:esc message))))))
|
|
|
|
|
2020-07-24 01:59:15 +02:00
|
|
|
(defun render/login (&key message (original-uri "/"))
|
2020-08-29 00:10:27 +02:00
|
|
|
(render (:footer nil :header nil)
|
2020-07-23 00:16:58 +02:00
|
|
|
(:div
|
|
|
|
:class "login-form"
|
|
|
|
(:header
|
|
|
|
(:h1 "Login"))
|
|
|
|
(:main
|
|
|
|
:class "login-form"
|
2020-07-24 00:50:13 +02:00
|
|
|
(render/alert message)
|
2020-07-23 00:16:58 +02:00
|
|
|
(:form
|
|
|
|
:method :post :action "/login"
|
2020-07-24 01:59:15 +02:00
|
|
|
(:input :type "hidden" :name "original-uri"
|
|
|
|
:value original-uri)
|
2020-07-23 00:16:58 +02:00
|
|
|
(:div
|
|
|
|
(:label :for "username"
|
|
|
|
"Username")
|
|
|
|
(:input :type "text"
|
|
|
|
:name "username"
|
|
|
|
:id "username"
|
|
|
|
:placeholder "username"))
|
|
|
|
(:div
|
|
|
|
(:label :for "password"
|
|
|
|
"Password")
|
|
|
|
(:input :type "password"
|
|
|
|
:name "password"
|
|
|
|
:id "password"
|
|
|
|
:placeholder "password"))
|
|
|
|
(:input :type "submit"
|
|
|
|
:value "Submit"))))))
|
|
|
|
|
|
|
|
(defun created-by-at (issue)
|
2020-07-26 21:33:27 +02:00
|
|
|
(check-type issue model:issue)
|
2020-07-23 00:16:58 +02:00
|
|
|
(who:with-html-output (*standard-output*)
|
|
|
|
(:span :class "created-by-at"
|
|
|
|
"Opened by "
|
|
|
|
(:span :class "username"
|
|
|
|
(who:esc
|
|
|
|
(or
|
|
|
|
(when-let ((author (author issue)))
|
|
|
|
(displayname author))
|
|
|
|
"someone")))
|
|
|
|
" at "
|
|
|
|
(:span :class "timestamp"
|
|
|
|
(who:esc
|
|
|
|
(format-dottime (created-at issue)))))))
|
2020-07-22 00:59:25 +02:00
|
|
|
|
2020-07-23 05:11:10 +02:00
|
|
|
(defun render/issue-list (&key issues)
|
|
|
|
(who:with-html-output (*standard-output*)
|
|
|
|
(:ol
|
|
|
|
:class "issue-list"
|
|
|
|
(dolist (issue issues)
|
2020-07-26 21:33:27 +02:00
|
|
|
(let ((issue-id (model:id issue)))
|
2020-07-23 05:11:10 +02:00
|
|
|
(who:htm
|
|
|
|
(:li
|
|
|
|
(:a :href (format nil "/issues/~A" issue-id)
|
|
|
|
(:p
|
|
|
|
(:span :class "issue-subject"
|
|
|
|
(who:esc (subject issue))))
|
|
|
|
(:span :class "issue-number"
|
|
|
|
(who:esc (format nil "#~A" issue-id)))
|
|
|
|
" - "
|
|
|
|
(created-by-at issue)
|
|
|
|
(let ((num-comments (length (issue-comments issue))))
|
|
|
|
(unless (zerop num-comments)
|
|
|
|
(who:htm
|
|
|
|
(:span :class "comment-count"
|
|
|
|
" - "
|
|
|
|
(who:esc
|
|
|
|
(format nil "~A comment~:p" num-comments))))))))))))))
|
|
|
|
|
2020-07-22 00:59:25 +02:00
|
|
|
(defun render/index (&key issues)
|
2020-07-24 02:53:36 +02:00
|
|
|
(render ()
|
2020-07-23 00:16:58 +02:00
|
|
|
(:header
|
|
|
|
(:h1 "Issues")
|
2020-07-24 02:59:48 +02:00
|
|
|
(when *user*
|
|
|
|
(who:htm
|
|
|
|
(:a
|
|
|
|
:class "new-issue"
|
|
|
|
:href "/issues/new" "New Issue"))))
|
2020-07-23 00:16:58 +02:00
|
|
|
(:main
|
2020-07-23 05:11:10 +02:00
|
|
|
(:div
|
|
|
|
:class "issue-links"
|
|
|
|
(:a :href "/issues/closed" "View closed issues"))
|
|
|
|
(render/issue-list :issues issues))))
|
|
|
|
|
|
|
|
(defun render/closed-issues (&key issues)
|
2020-07-24 02:53:36 +02:00
|
|
|
(render ()
|
2020-07-23 05:11:10 +02:00
|
|
|
(:header
|
|
|
|
(:h1 "Closed issues"))
|
|
|
|
(:main
|
|
|
|
(:div
|
|
|
|
:class "issue-links"
|
|
|
|
(:a :href "/" "View open isues"))
|
|
|
|
(render/issue-list :issues issues))))
|
2020-07-22 00:59:25 +02:00
|
|
|
|
2020-08-01 18:10:27 +02:00
|
|
|
(defun render/issue-form (&optional issue message)
|
2020-08-03 15:27:43 +02:00
|
|
|
(let ((editing (and issue (id issue))))
|
|
|
|
(render ()
|
|
|
|
(:header
|
|
|
|
(:h1
|
|
|
|
(who:esc
|
|
|
|
(if editing "Edit Issue" "New Issue"))))
|
|
|
|
(:main
|
|
|
|
(render/alert message)
|
|
|
|
(:form :method "post"
|
|
|
|
:action (if editing
|
|
|
|
(format nil "/issues/~A"
|
|
|
|
(id issue))
|
|
|
|
"/issues")
|
|
|
|
:class "issue-form"
|
|
|
|
(:div
|
|
|
|
(:input :type "text"
|
|
|
|
:id "subject"
|
|
|
|
:name "subject"
|
|
|
|
:placeholder "Subject"
|
|
|
|
:value (when editing
|
|
|
|
(subject issue))))
|
2020-07-23 00:16:58 +02:00
|
|
|
|
2020-08-03 15:27:43 +02:00
|
|
|
(:div
|
|
|
|
(:textarea :name "body"
|
|
|
|
:placeholder "Description"
|
|
|
|
:rows 10
|
|
|
|
(who:esc
|
|
|
|
(when editing
|
|
|
|
(body issue)))))
|
2020-07-23 00:16:58 +02:00
|
|
|
|
2020-08-03 15:27:43 +02:00
|
|
|
(:input :type "submit"
|
|
|
|
:value
|
|
|
|
(if editing
|
|
|
|
"Save Issue"
|
|
|
|
"Create Issue")))))))
|
2020-07-22 04:12:02 +02:00
|
|
|
|
2020-07-23 03:43:30 +02:00
|
|
|
(defun render/new-comment (issue-id)
|
|
|
|
(who:with-html-output (*standard-output*)
|
|
|
|
(:form
|
|
|
|
:class "new-comment"
|
|
|
|
:method "post"
|
|
|
|
:action (format nil "/issues/~A/comments" issue-id)
|
|
|
|
(:div
|
|
|
|
(:textarea :name "body"
|
|
|
|
:placeholder "Leave a comment"
|
|
|
|
:rows 5))
|
|
|
|
(:input :type "submit"
|
|
|
|
:value "Comment"))))
|
2020-07-22 04:12:02 +02:00
|
|
|
|
2020-07-29 00:29:30 +02:00
|
|
|
(defgeneric render/issue-history-item (item))
|
|
|
|
|
|
|
|
(defmethod render/issue-history-item ((comment model:issue-comment))
|
2020-08-02 04:54:58 +02:00
|
|
|
(let ((fragment (format nil "comment-~A" (id comment))))
|
|
|
|
(who:with-html-output (*standard-output*)
|
|
|
|
(:li
|
|
|
|
:class "comment"
|
|
|
|
:id fragment
|
|
|
|
(:p (who:str (body comment)))
|
|
|
|
(:p
|
|
|
|
:class "comment-info"
|
|
|
|
(:span :class "username"
|
|
|
|
(who:esc (displayname (author comment)))
|
|
|
|
" at "
|
|
|
|
(:a :href (concatenate 'string "#" fragment)
|
|
|
|
(who:esc (format-dottime (created-at comment))))))))))
|
2020-07-29 00:29:30 +02:00
|
|
|
|
|
|
|
(defmethod render/issue-history-item ((event model:issue-event))
|
2020-08-01 18:10:27 +02:00
|
|
|
(let ((user (find-user-by-dn (acting-user-dn event))))
|
2020-07-29 00:29:30 +02:00
|
|
|
(who:with-html-output (*standard-output*)
|
2020-08-01 18:10:27 +02:00
|
|
|
(:li
|
|
|
|
:class "event"
|
2020-08-02 04:54:58 +02:00
|
|
|
:id
|
2020-08-01 18:10:27 +02:00
|
|
|
(who:esc (displayname user))
|
|
|
|
(if (string= (field event) "STATUS")
|
|
|
|
(who:htm
|
|
|
|
(who:esc
|
|
|
|
(switch ((new-value event) :test #'string=)
|
|
|
|
("OPEN" " reopened ")
|
|
|
|
("CLOSED" " closed ")))
|
|
|
|
" this issue ")
|
|
|
|
(who:htm
|
|
|
|
" changed the "
|
|
|
|
(who:esc (string-downcase (field event)))
|
|
|
|
" of this issue from \""
|
|
|
|
(who:esc (previous-value event))
|
|
|
|
"\" to \""
|
|
|
|
(who:esc (new-value event))
|
|
|
|
"\""))
|
|
|
|
" at "
|
|
|
|
(who:esc (format-dottime (created-at event)))))))
|
2020-07-29 00:29:30 +02:00
|
|
|
|
2020-07-22 00:59:25 +02:00
|
|
|
(defun render/issue (issue)
|
2020-07-26 21:33:27 +02:00
|
|
|
(check-type issue model:issue)
|
|
|
|
(let ((issue-id (id issue))
|
2020-07-23 05:11:10 +02:00
|
|
|
(issue-status (status issue)))
|
2020-07-24 02:53:36 +02:00
|
|
|
(render ()
|
2020-07-23 05:11:10 +02:00
|
|
|
(:header
|
|
|
|
(:h1 (who:esc (subject issue)))
|
|
|
|
(:div :class "issue-number"
|
|
|
|
(who:esc (format nil "#~A" issue-id))))
|
|
|
|
(:main
|
|
|
|
(:div
|
|
|
|
:class "issue-info"
|
|
|
|
(created-by-at issue)
|
|
|
|
|
2020-07-24 02:59:48 +02:00
|
|
|
(when *user*
|
|
|
|
(who:htm
|
2020-08-01 18:10:27 +02:00
|
|
|
(when (string= (author-dn issue)
|
|
|
|
(dn *user*))
|
|
|
|
(who:htm
|
|
|
|
(:a :class "edit-issue"
|
|
|
|
:href (format nil "/issues/~A/edit"
|
|
|
|
issue-id)
|
|
|
|
"Edit")))
|
|
|
|
(form-button
|
|
|
|
:class "set-issue-status"
|
|
|
|
:href (format nil "/issues/~A/~A"
|
|
|
|
issue-id
|
|
|
|
(case issue-status
|
|
|
|
(:open "close")
|
|
|
|
(:closed "open")))
|
|
|
|
:input-class (case issue-status
|
|
|
|
(:open "close-issue")
|
|
|
|
(:closed "open-issue"))
|
|
|
|
:label (case issue-status
|
|
|
|
(:open "Close")
|
|
|
|
(:closed "Reopen"))))))
|
2020-07-31 05:05:19 +02:00
|
|
|
(:p (who:str (render-markdown (body issue))))
|
2020-07-29 00:29:30 +02:00
|
|
|
(let* ((comments (issue-comments issue))
|
|
|
|
(events (issue-events issue))
|
|
|
|
(history (merge 'list
|
|
|
|
comments
|
|
|
|
events
|
|
|
|
#'local-time:timestamp<
|
|
|
|
:key #'created-at)))
|
2020-07-31 05:05:19 +02:00
|
|
|
(markdownify-comment-bodies comments)
|
2020-07-23 05:11:10 +02:00
|
|
|
(who:htm
|
2020-07-29 00:29:30 +02:00
|
|
|
(:ol
|
|
|
|
:class "issue-history"
|
|
|
|
(dolist (item history)
|
|
|
|
(render/issue-history-item item))
|
2020-07-24 02:59:48 +02:00
|
|
|
(when *user*
|
2020-07-26 21:33:27 +02:00
|
|
|
(render/new-comment (id issue))))))))))
|
2020-07-22 00:59:25 +02:00
|
|
|
|
|
|
|
(defun render/not-found (entity-type)
|
2020-07-24 02:53:36 +02:00
|
|
|
(render ()
|
2020-08-09 20:36:11 +02:00
|
|
|
(:h1 (who:esc entity-type) "Not Found")))
|
2020-07-22 00:59:25 +02:00
|
|
|
|
|
|
|
;;;
|
|
|
|
;;; HTTP handlers
|
|
|
|
;;;
|
|
|
|
|
2020-07-24 02:59:48 +02:00
|
|
|
(defun @auth-optional (next)
|
|
|
|
(let ((*user* (hunchentoot:session-value 'user)))
|
|
|
|
(funcall next)))
|
|
|
|
|
2020-07-22 00:59:25 +02:00
|
|
|
(defun @auth (next)
|
|
|
|
(if-let ((*user* (hunchentoot:session-value 'user)))
|
|
|
|
(funcall next)
|
2020-07-24 01:59:15 +02:00
|
|
|
(hunchentoot:redirect
|
|
|
|
(format nil "/login?original-uri=~A"
|
|
|
|
(drakma:url-encode
|
|
|
|
(hunchentoot:request-uri*)
|
|
|
|
:utf-8)))))
|
|
|
|
|
2020-07-26 21:33:27 +02:00
|
|
|
(defun @txn (next)
|
|
|
|
(pomo:with-transaction ()
|
|
|
|
(catch
|
|
|
|
;; 'hunchentoot:handler-done is unexported, but is used by functions
|
|
|
|
;; like hunchentoot:redirect to nonlocally abort the request handler -
|
|
|
|
;; this doesn't mean an error occurred, so we need to catch it here to
|
|
|
|
;; make the transaction still get committed
|
|
|
|
(intern "HANDLER-DONE" "HUNCHENTOOT")
|
|
|
|
(funcall next))))
|
|
|
|
|
|
|
|
(defun @handle-issue-not-found (next)
|
|
|
|
(handler-case (funcall next)
|
2020-07-28 06:31:55 +02:00
|
|
|
(model:issue-not-found (err)
|
2020-07-26 21:33:27 +02:00
|
|
|
(render/not-found
|
|
|
|
(format nil "Issue #~A" (model:id err))))))
|
|
|
|
|
2020-07-24 01:59:15 +02:00
|
|
|
(defroute login-form ("/login" :method :get)
|
|
|
|
(original-uri)
|
2020-07-22 00:59:25 +02:00
|
|
|
(if (hunchentoot:session-value 'user)
|
2020-07-24 01:59:15 +02:00
|
|
|
(hunchentoot:redirect (or original-uri "/"))
|
|
|
|
(render/login :original-uri original-uri)))
|
2020-07-22 00:59:25 +02:00
|
|
|
|
|
|
|
(defroute submit-login ("/login" :method :post)
|
2020-07-24 01:59:15 +02:00
|
|
|
(&post original-uri username password)
|
2020-07-22 00:59:25 +02:00
|
|
|
(if-let ((user (authenticate-user username password)))
|
|
|
|
(progn
|
|
|
|
(setf (hunchentoot:session-value 'user) user)
|
2020-07-24 01:59:15 +02:00
|
|
|
(hunchentoot:redirect (or original-uri "/")))
|
2020-07-29 00:39:54 +02:00
|
|
|
(render/login :message "Invalid credentials"
|
|
|
|
:original-uri original-uri)))
|
2020-07-22 00:59:25 +02:00
|
|
|
|
2020-07-24 02:53:36 +02:00
|
|
|
(defroute logout ("/logout" :method :post) ()
|
|
|
|
(hunchentoot:delete-session-value 'user)
|
|
|
|
(hunchentoot:redirect "/"))
|
|
|
|
|
2020-07-24 02:59:48 +02:00
|
|
|
(defroute index ("/" :decorators (@auth-optional)) ()
|
2020-07-26 21:33:27 +02:00
|
|
|
(let ((issues (model:list-issues :status :open)))
|
2020-07-22 00:59:25 +02:00
|
|
|
(render/index :issues issues)))
|
|
|
|
|
2020-07-24 02:59:48 +02:00
|
|
|
(defroute handle-closed-issues
|
|
|
|
("/issues/closed" :decorators (@auth-optional)) ()
|
2020-07-26 21:33:27 +02:00
|
|
|
(let ((issues (model:list-issues :status :closed)))
|
2020-07-23 05:11:10 +02:00
|
|
|
(render/closed-issues :issues issues)))
|
|
|
|
|
2020-07-22 00:59:25 +02:00
|
|
|
(defroute new-issue ("/issues/new" :decorators (@auth)) ()
|
2020-08-01 18:10:27 +02:00
|
|
|
(render/issue-form))
|
2020-07-22 00:59:25 +02:00
|
|
|
|
|
|
|
(defroute handle-create-issue
|
2020-07-26 21:33:27 +02:00
|
|
|
("/issues" :method :post :decorators (@auth @txn))
|
2020-07-22 00:59:25 +02:00
|
|
|
(&post subject body)
|
2020-07-24 00:50:13 +02:00
|
|
|
(if (string= subject "")
|
2020-08-01 18:10:27 +02:00
|
|
|
(render/issue-form
|
|
|
|
(make-instance 'model:issue :subject subject :body body)
|
|
|
|
"Subject is required")
|
2020-11-08 19:38:19 +01:00
|
|
|
(let ((issue
|
|
|
|
(model:create-issue :subject subject
|
|
|
|
:body body
|
|
|
|
:author-dn (dn *user*))))
|
|
|
|
(send-irc-notification (format nil "b/~A: \"~A\" opened by ~A - https://b.tvl.fyi/issues/~A"
|
|
|
|
(issue-id issue) subject (dn *user*)
|
|
|
|
(issue-id issue))
|
|
|
|
:channel (uiop:getenvp "ISSUECHANNEL"))
|
2020-07-24 00:50:13 +02:00
|
|
|
(hunchentoot:redirect "/"))))
|
2020-07-22 00:59:25 +02:00
|
|
|
|
2020-07-26 21:33:27 +02:00
|
|
|
(defroute show-issue
|
2020-07-28 03:27:32 +02:00
|
|
|
("/issues/:id" :decorators (@auth-optional @handle-issue-not-found))
|
2020-07-22 00:59:25 +02:00
|
|
|
(&path (id 'integer))
|
2020-08-09 20:36:11 +02:00
|
|
|
(let* ((issue (model:get-issue id))
|
|
|
|
(*title* (format nil "~A | Panettone"
|
|
|
|
(subject issue))))
|
|
|
|
(render/issue issue)))
|
2020-07-22 00:59:25 +02:00
|
|
|
|
2020-08-01 18:10:27 +02:00
|
|
|
(defroute edit-issue
|
|
|
|
("/issues/:id/edit" :decorators (@auth @handle-issue-not-found))
|
|
|
|
(&path (id 'integer))
|
|
|
|
(let* ((issue (model:get-issue id))
|
|
|
|
(*title* "Edit Issue | Panettone"))
|
|
|
|
(render/issue-form issue)))
|
|
|
|
|
|
|
|
(defroute update-issue
|
|
|
|
("/issues/:id" :decorators (@auth @handle-issue-not-found @txn)
|
|
|
|
;; NOTE: this should be a put, but we're all HTML forms
|
|
|
|
;; right now and those don't support PUT
|
|
|
|
:method :post)
|
|
|
|
(&path (id 'integer) &post subject body)
|
|
|
|
(let ((issue (model:get-issue id)))
|
|
|
|
;; only the original author can edit an issue
|
|
|
|
(if (string-equal (author-dn issue)
|
|
|
|
(dn *user*))
|
|
|
|
(progn
|
|
|
|
(model:update-issue issue
|
|
|
|
'model:subject subject
|
|
|
|
'model:body body)
|
|
|
|
(hunchentoot:redirect (format nil "/issues/~A" id)))
|
|
|
|
(render/not-found "Issue"))))
|
|
|
|
|
2020-07-23 03:43:30 +02:00
|
|
|
(defroute handle-create-comment
|
2020-07-26 21:33:27 +02:00
|
|
|
("/issues/:id/comments"
|
|
|
|
:decorators (@auth @handle-issue-not-found @txn)
|
|
|
|
:method :post)
|
2020-07-23 03:43:30 +02:00
|
|
|
(&path (id 'integer) &post body)
|
2020-07-24 00:56:25 +02:00
|
|
|
(flet ((redirect-to-issue ()
|
|
|
|
(hunchentoot:redirect (format nil "/issues/~A" id))))
|
2020-07-26 21:33:27 +02:00
|
|
|
(cond
|
|
|
|
((string= body "")
|
|
|
|
(redirect-to-issue))
|
|
|
|
(:else
|
|
|
|
(model:create-issue-comment
|
|
|
|
:issue-id id
|
|
|
|
:body body
|
|
|
|
:author-dn (dn *user*))
|
|
|
|
(redirect-to-issue)))))
|
2020-07-23 03:43:30 +02:00
|
|
|
|
2020-07-23 05:11:10 +02:00
|
|
|
(defroute close-issue
|
2020-07-26 21:33:27 +02:00
|
|
|
("/issues/:id/close" :decorators (@auth @handle-issue-not-found @txn)
|
2020-07-23 05:11:10 +02:00
|
|
|
:method :post)
|
|
|
|
(&path (id 'integer))
|
2020-07-26 21:33:27 +02:00
|
|
|
(model:set-issue-status id :closed)
|
2020-07-23 05:11:10 +02:00
|
|
|
(hunchentoot:redirect (format nil "/issues/~A" id)))
|
|
|
|
|
|
|
|
(defroute open-issue
|
|
|
|
("/issues/:id/open" :decorators (@auth)
|
2020-08-01 18:10:27 +02:00
|
|
|
:method :post)
|
2020-07-23 05:11:10 +02:00
|
|
|
(&path (id 'integer))
|
2020-07-26 21:33:27 +02:00
|
|
|
(model:set-issue-status id :open)
|
2020-07-23 05:11:10 +02:00
|
|
|
(hunchentoot:redirect (format nil "/issues/~A" id)))
|
|
|
|
|
2020-07-23 00:16:58 +02:00
|
|
|
(defroute styles ("/main.css") ()
|
|
|
|
(setf (hunchentoot:content-type*) "text/css")
|
|
|
|
(apply #'lass:compile-and-write panettone.css:styles))
|
|
|
|
|
2020-07-22 00:59:25 +02:00
|
|
|
(defvar *acceptor* nil
|
|
|
|
"Hunchentoot acceptor for Panettone's web server.")
|
|
|
|
|
2020-07-26 21:33:27 +02:00
|
|
|
(defun migrate-db ()
|
2020-07-28 06:09:36 +02:00
|
|
|
"Migrate the database to the latest version of the schema"
|
|
|
|
(model:ddl/init))
|
2020-07-26 21:33:27 +02:00
|
|
|
|
2020-07-28 06:09:36 +02:00
|
|
|
(defun start-panettone (&key port
|
2020-07-22 01:36:21 +02:00
|
|
|
(ldap-host "localhost")
|
2020-07-26 21:33:27 +02:00
|
|
|
(ldap-port 389)
|
2020-08-28 23:42:00 +02:00
|
|
|
postgres-params
|
|
|
|
session-secret)
|
2020-07-22 01:36:21 +02:00
|
|
|
(connect-ldap :host ldap-host
|
|
|
|
:port ldap-port)
|
2020-07-26 21:33:27 +02:00
|
|
|
|
|
|
|
(apply #'model:connect-postgres postgres-params)
|
|
|
|
(migrate-db)
|
2020-07-22 00:59:25 +02:00
|
|
|
|
2020-08-28 23:42:00 +02:00
|
|
|
(when session-secret
|
|
|
|
(setq hunchentoot:*session-secret* session-secret))
|
|
|
|
|
2020-08-28 23:44:21 +02:00
|
|
|
(setq hunchentoot:*session-max-time* (* 60 60 24 90))
|
|
|
|
|
2020-07-22 00:59:25 +02:00
|
|
|
(setq *acceptor*
|
|
|
|
(make-instance 'easy-routes:routes-acceptor :port port))
|
|
|
|
(hunchentoot:start *acceptor*))
|
|
|
|
|
|
|
|
(defun main ()
|
2020-07-22 01:36:21 +02:00
|
|
|
(let ((port (integer-env "PANETTONE_PORT" :default 6161))
|
2020-07-31 05:05:19 +02:00
|
|
|
(ldap-port (integer-env "LDAP_PORT" :default 389))
|
2020-08-28 23:42:00 +02:00
|
|
|
(cheddar-url (uiop:getenvp "CHEDDAR_URL"))
|
|
|
|
(session-secret (uiop:getenvp "SESSION_SECRET")))
|
2020-07-31 05:05:19 +02:00
|
|
|
(when cheddar-url (setq *cheddar-url* cheddar-url))
|
2020-07-26 23:42:39 +02:00
|
|
|
(setq hunchentoot:*show-lisp-backtraces-p* nil)
|
|
|
|
(setq hunchentoot:*log-lisp-backtraces-p* nil)
|
2020-08-28 23:42:00 +02:00
|
|
|
|
2020-07-22 00:59:25 +02:00
|
|
|
(start-panettone :port port
|
2020-08-28 23:42:00 +02:00
|
|
|
:ldap-port ldap-port
|
|
|
|
:session-secret session-secret)
|
|
|
|
|
2020-07-22 00:59:25 +02:00
|
|
|
(sb-thread:join-thread
|
|
|
|
(find-if (lambda (th)
|
|
|
|
(string= (sb-thread:thread-name th)
|
|
|
|
(format nil "hunchentoot-listener-*:~A" port)))
|
|
|
|
(sb-thread:list-all-threads)))))
|
|
|
|
|
|
|
|
(comment
|
2020-07-22 04:12:02 +02:00
|
|
|
(setq hunchentoot:*catch-errors-p* nil)
|
2020-08-29 00:49:29 +02:00
|
|
|
;; to setup an ssh tunnel to ldap+cheddar for development:
|
|
|
|
;; ssh -NL 3899:localhost:389 -L 4238:localhost:4238 whitby.tvl.fyi
|
2020-07-22 00:59:25 +02:00
|
|
|
(start-panettone :port 6161
|
2020-08-28 23:42:00 +02:00
|
|
|
:ldap-port 3899
|
|
|
|
:session-secret "session-secret")
|
2020-07-22 00:59:25 +02:00
|
|
|
)
|