delete user avatar
parent
a38c451c66
commit
92a5ebac2f
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -7,7 +7,12 @@
|
|||
<h4 class="modal-title">Deleting {{ form.attr_data.readable_name }}</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
You are about to delete {{ form.attr_data }} from {{ form.attr_data.readable_name }}.
|
||||
{% if attr_name == 'jpegphoto' %}
|
||||
{% set value = 'avatar' %}
|
||||
{% else %}
|
||||
{% set value = form.attr_data %}
|
||||
{% endif %}
|
||||
You are about to delete {{ value }} from {{ form.attr_data.readable_name }}.
|
||||
{{ form.csrf_token }}
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
|
|
|
@ -46,6 +46,11 @@ def attr_op(op, attrName, uid = None, success_redirect='/vcard',
|
|||
if op == 'mod' and attrName not in ['commonname']:
|
||||
op = 'modreadd'
|
||||
|
||||
# Temporary workaround: deleting jpegPhoto doesn't work, set to empty instead
|
||||
if op == 'del' and attrName == 'jpegphoto':
|
||||
op = 'mod'
|
||||
new_value = ''
|
||||
|
||||
if op in ['del', 'modreadd']:
|
||||
conn.modify_s(dn, [(ldap.MOD_DELETE, attrName, str_to_ldap(old_value))])
|
||||
if op in ['add', 'modreadd']:
|
||||
|
|
Loading…
Reference in New Issue