fix(panettone): handle missing DNs when looking up displaynames

* Fix find-user-by-dn raising an error condition if the search returns
  no results, return nil instead.
* Adopt strategy of defaulting to “someone” as displayname if lookup
  fails for all usage of displaynames in panettone.

I've tested this change for issues and comments created by missing
users. Adjusting the displayname seems to fix all 500 being created
by missing users both logged out and logged in.

Change-Id: I0a84eb0631c4a49f1664bed6d03afa60dce6eb47
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2448
Tested-by: BuildkiteCI
Reviewed-by: glittershark <grfn@gws.fyi>
This commit is contained in:
sterni 2021-01-29 12:22:40 +01:00
parent 001ee91169
commit 0176a9e300
2 changed files with 21 additions and 13 deletions

View file

@ -79,12 +79,18 @@ and a retry"
(defun find-user-by-dn (dn) (defun find-user-by-dn (dn)
(with-ldap () (with-ldap ()
(progn (let ((have-results
(handler-case
(ldap:search *ldap* `(= objectClass organizationalPerson) (ldap:search *ldap* `(= objectClass organizationalPerson)
:base dn :base dn
:scope 'ldap:base) :scope 'ldap:base)
; catch ldap-errors generated by trivial-ldap:parse-ldap-message
; since this is thrown on conditions which we don't want this
; function to fail like when there are no search results
(trivial-ldap:ldap-error (e) nil))))
(when have-results
(when-let ((ldap-entry (ldap:next-search-result *ldap*))) (when-let ((ldap-entry (ldap:next-search-result *ldap*)))
(ldap-entry->user ldap-entry))))) (ldap-entry->user ldap-entry))))))
(comment (comment
(find-user-by-dn "cn=glittershark,ou=users,dc=tvl,dc=fyi") (find-user-by-dn "cn=glittershark,ou=users,dc=tvl,dc=fyi")

View file

@ -90,6 +90,10 @@
(defun author (object) (defun author (object)
(find-user-by-dn (author-dn object))) (find-user-by-dn (author-dn object)))
(defun displayname-if-known (user)
(or (when user (displayname user))
"unknown"))
(defmacro render ((&key (defmacro render ((&key
(footer t) (footer t)
(header t)) (header t))
@ -171,11 +175,8 @@
(:span :class "created-by-at" (:span :class "created-by-at"
"Opened by " "Opened by "
(:span :class "username" (:span :class "username"
(who:esc (who:esc (displayname-if-known
(or (author issue))))
(when-let ((author (author issue)))
(displayname author))
"someone")))
" at " " at "
(:span :class "timestamp" (:span :class "timestamp"
(who:esc (who:esc
@ -293,7 +294,8 @@
(:p (:p
:class "comment-info" :class "comment-info"
(:span :class "username" (:span :class "username"
(who:esc (displayname (author comment))) (who:esc
(displayname-if-known (author comment)))
" at " " at "
(:a :href (concatenate 'string "#" fragment) (:a :href (concatenate 'string "#" fragment)
(who:esc (format-dottime (created-at comment)))))))))) (who:esc (format-dottime (created-at comment))))))))))
@ -304,7 +306,7 @@
(:li (:li
:class "event" :class "event"
:id :id
(who:esc (displayname user)) (who:esc (displayname-if-known user))
(if (string= (field event) "STATUS") (if (string= (field event) "STATUS")
(who:htm (who:htm
(who:esc (who:esc