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)
(with-ldap ()
(progn
(ldap:search *ldap* `(= objectClass organizationalPerson)
:base dn
:scope 'ldap:base)
(when-let ((ldap-entry (ldap:next-search-result *ldap*)))
(ldap-entry->user ldap-entry)))))
(let ((have-results
(handler-case
(ldap:search *ldap* `(= objectClass organizationalPerson)
:base dn
: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*)))
(ldap-entry->user ldap-entry))))))
(comment
(find-user-by-dn "cn=glittershark,ou=users,dc=tvl,dc=fyi")

View file

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