From d3b7de0783230b78edd44010e144f47e0ee4bea5 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Tue, 21 Jul 2020 22:12:02 -0400 Subject: feat(web/panettone): Display who opened issues and when Add a line to the issue show page displaying who opened the issue and when, the latter formatted in dottime. Change-Id: Ie70d7fd9e62ae92f9a479969d4ea21daddccee40 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1345 Reviewed-by: glittershark Tested-by: BuildkiteCI --- web/panettone/src/panettone.lisp | 44 +++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) (limited to 'web/panettone/src') diff --git a/web/panettone/src/panettone.lisp b/web/panettone/src/panettone.lisp index 16ab7cd969d6..b8199034e14b 100644 --- a/web/panettone/src/panettone.lisp +++ b/web/panettone/src/panettone.lisp @@ -14,14 +14,15 @@ (defclass/std issue-comment () ((body :type string) - (author-dn :type string))) + (author-dn :type string) + (created-at :type local-time:timestamp))) (defclass/std issue (cl-prevalence:object-with-id) ((subject body :type string :std "") (author-dn :type string) (comments :std nil :type list :with-prefix) - (created-at :type integer - :std (get-universal-time)))) + (created-at :type local-time:timestamp + :std (local-time:now)))) (defclass/std user () ((cn dn mail displayname :type string))) @@ -55,15 +56,28 @@ (ldap:search *ldap* `(and (= objectClass organizationalPerson) - (= cn ,username)) + (or + (= cn ,username) + (= dn ,username))) ;; TODO(grfn): make this configurable :base "ou=users,dc=tvl,dc=fyi") (ldap:next-search-result *ldap*)) (defun find-user (username) (check-type username (simple-array character (*))) - (ldap-entry->user - (find-user/ldap username))) + (when-let ((ldap-entry (find-user/ldap username))) + (ldap-entry->user ldap-entry))) + +(defun find-user-by-dn (dn) + (ldap:search *ldap* `(= objectClass organizationalPerson) + :base dn + :scope 'ldap:base) + (when-let ((ldap-entry (ldap:next-search-result *ldap*))) + (ldap-entry->user ldap-entry))) + +(comment + (user-by-dn "cn=glittershark,ou=users,dc=tvl,dc=fyi") + ) (defun authenticate-user (user-or-username password) "Checks the given USER-OR-USERNAME has the given PASSWORD, by making a bind @@ -81,6 +95,9 @@ successful, `nil' otherwise" (when (equalp code-sym 'trivial-ldap:success) user)))) +(defun author (object) + (find-user-by-dn (author-dn object))) + ;;; ;;; Persistence ;;; @@ -138,6 +155,7 @@ updated issue" (ensure-directories-exist data-dir) (setq *p-system* (cl-prevalence:make-prevalence-system data-dir)) + (when (null (list-issues *p-system*)) (cl-prevalence:tx-create-id-counter *p-system*))) @@ -208,11 +226,22 @@ updated issue" (:input :type :submit :value "Create Issue")))) +(defun created-by-at (issue) + (format nil "Opened by ~A at ~A" + (when-let ((author (author issue))) + (displayname author)) + (format-dottime (created-at issue)))) + +(comment + (format nil "foo: ~A" "foo") + ) + (defun render/issue (issue) (check-type issue issue) (render (:h1 (who:esc (subject issue))) - (:div (who:esc (body issue))))) + (:p (who:esc (created-by-at issue))) + (:p (who:esc (body issue))))) (defun render/not-found (entity-type) (render @@ -301,6 +330,7 @@ updated issue" (sb-thread:list-all-threads))))) (comment + (setq hunchentoot:*catch-errors-p* nil) (start-panettone :port 6161 :data-dir "/tmp/panettone" :ldap-port 3899) -- cgit 1.4.1