about summary refs log tree commit diff
path: root/web/panettone/src
diff options
context:
space:
mode:
authorsterni <sternenseemann@systemli.org>2021-01-29T11·22+0100
committersterni <sternenseemann@systemli.org>2021-01-29T17·38+0000
commit0176a9e300062ae2edf2f0ba2e365a8c2c4dbc99 (patch)
treed8a5627058cacefa58948fcfeb8acf51c8977e6f /web/panettone/src
parent001ee91169c4e25bd3696fc3c69e5151f5547a7f (diff)
fix(panettone): handle missing DNs when looking up displaynames r/2152
* 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>
Diffstat (limited to 'web/panettone/src')
-rw-r--r--web/panettone/src/authentication.lisp18
-rw-r--r--web/panettone/src/panettone.lisp16
2 files changed, 21 insertions, 13 deletions
diff --git a/web/panettone/src/authentication.lisp b/web/panettone/src/authentication.lisp
index 20510257539f..50befbc7a168 100644
--- a/web/panettone/src/authentication.lisp
+++ b/web/panettone/src/authentication.lisp
@@ -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")
diff --git a/web/panettone/src/panettone.lisp b/web/panettone/src/panettone.lisp
index e090f11acfac..6e43312327ea 100644
--- a/web/panettone/src/panettone.lisp
+++ b/web/panettone/src/panettone.lisp
@@ -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