(auth_ldap) add get_last_modified from provider
This commit is contained in:
parent
9077c9fd11
commit
4be7cccadb
|
@ -2,7 +2,7 @@ import re
|
|||
import secrets
|
||||
|
||||
from io import BytesIO
|
||||
from typing import Optional
|
||||
from typing import Optional, Union
|
||||
from sqlalchemy import exc
|
||||
from sqlalchemy_utils import merge_references
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
@ -262,7 +262,12 @@ def register(data, passwd=None):
|
|||
return user
|
||||
|
||||
|
||||
def load_avatar(user: User):
|
||||
def get_last_modified(user: User):
|
||||
"""Get the last modification date of the user"""
|
||||
return get_provider(user.userid).get_last_modified(user)
|
||||
|
||||
|
||||
def load_avatar(user: User, etag: Union[str, None] = None):
|
||||
if user.avatar_ is not None:
|
||||
return imageController.send_image(image=user.avatar_)
|
||||
else:
|
||||
|
|
|
@ -248,6 +248,16 @@ class AuthPlugin(Plugin):
|
|||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def get_modified_time(self, user):
|
||||
"""If backend is using external data, then return the timestamp of the last modification
|
||||
|
||||
Args:
|
||||
user: User object
|
||||
Returns:
|
||||
Timestamp of last modification
|
||||
"""
|
||||
pass
|
||||
|
||||
def get_avatar(self, user) -> _Avatar:
|
||||
"""Retrieve avatar for given user (if supported by auth backend)
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@ from ldap3.core.exceptions import LDAPPasswordIsMandatoryError, LDAPBindError
|
|||
from werkzeug.exceptions import BadRequest, InternalServerError, NotFound
|
||||
from werkzeug.datastructures import FileStorage
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from flaschengeist import logger
|
||||
from flaschengeist.config import config
|
||||
from flaschengeist.controller import userController
|
||||
|
@ -158,6 +160,17 @@ class AuthLDAP(AuthPlugin):
|
|||
except (LDAPPasswordIsMandatoryError, LDAPBindError):
|
||||
raise BadRequest
|
||||
|
||||
def get_modified_time(self, user):
|
||||
self.ldap.connection.search(
|
||||
self.search_dn,
|
||||
"(uid={})".format(user.userid),
|
||||
SUBTREE,
|
||||
attributes=["modifyTimestamp"],
|
||||
)
|
||||
r = self.ldap.connection.response[0]["attributes"]
|
||||
modified_time = r["modifyTimestamp"][0]
|
||||
return datetime.strptime(modified_time, "%Y%m%d%H%M%SZ")
|
||||
|
||||
def get_avatar(self, user):
|
||||
self.ldap.connection.search(
|
||||
self.search_dn,
|
||||
|
|
Loading…
Reference in New Issue