diff --git a/webapp/avatar.py b/webapp/avatar.py index 240ad78..f3b7a96 100644 --- a/webapp/avatar.py +++ b/webapp/avatar.py @@ -99,7 +99,7 @@ def default_avatar(uid: str) -> Image: # Crop to headshot. overlay = overlay.crop(box=(0, 0, w, w)) - + # Give it a little nudge. overlay = overlay.rotate((rng.random() - 0.5) * 100) @@ -162,6 +162,13 @@ class AvatarCache: def __init__(self): self.entries = {} + def reset(self): + self.entries = {} + + def reset_user(self, uid: str): + if uid in self.entries: + del self.entries[uid] + def get(self, uid: str, bust: bool = False) -> AvatarCacheEntry: """ Get avatar, either from cache or from LDAP on cache miss. If 'bust' is @@ -188,6 +195,11 @@ class AvatarCache: for attr, vs in res[0][1].items(): if attr == 'jpegPhoto': for v in vs: + # Temporary workaround: treat empty jpegPhoto as no avatar. + if v == b'': + avatar = None + break + try: avatar = base64.b64decode(v) except binascii.Error as e: diff --git a/webapp/context.py b/webapp/context.py index e5faefd..f09b9c6 100644 --- a/webapp/context.py +++ b/webapp/context.py @@ -5,7 +5,7 @@ import hashlib import flask import ldap -from webapp import app, config, validation +from webapp import app, config, validation, avatar class Attr(object): def __init__(self, name, value): @@ -45,5 +45,12 @@ def refresh_profile(dn=None): for v in vs: a = Attr(attr, v) profile[a.uid] = a + if attr == 'uid': + user_uid = v.decode('utf-8') app.profiles[dn] = profile + + # bust avatar cache + if user_uid: + avatar.cache.reset_user(user_uid) + return profile diff --git a/webapp/templates/ops/del.html b/webapp/templates/ops/del.html index 25db9d9..985886a 100644 --- a/webapp/templates/ops/del.html +++ b/webapp/templates/ops/del.html @@ -7,7 +7,12 @@