Add factory.try_user for non-exception user lookup
This commit is contained in:
parent
9252e524ae
commit
07e62b9665
|
@ -1,3 +1,5 @@
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from amanuensis.config import is_guid, RootConfigDirectoryContext
|
from amanuensis.config import is_guid, RootConfigDirectoryContext
|
||||||
from amanuensis.errors import ArgumentError
|
from amanuensis.errors import ArgumentError
|
||||||
from amanuensis.models.user import UserModel
|
from amanuensis.models.user import UserModel
|
||||||
|
@ -8,6 +10,15 @@ class ModelFactory():
|
||||||
def __init__(self, root: RootConfigDirectoryContext):
|
def __init__(self, root: RootConfigDirectoryContext):
|
||||||
self.root: RootConfigDirectoryContext = root
|
self.root: RootConfigDirectoryContext = root
|
||||||
|
|
||||||
|
def try_user(self, identifier: str) -> Optional[UserModel]:
|
||||||
|
user: Optional[UserModel] = None
|
||||||
|
try:
|
||||||
|
user = self.user(identifier)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
finally:
|
||||||
|
return user
|
||||||
|
|
||||||
def user(self, identifier: str) -> UserModel:
|
def user(self, identifier: str) -> UserModel:
|
||||||
"""Get the user model for the given id or username"""
|
"""Get the user model for the given id or username"""
|
||||||
# Ensure we have something to work with
|
# Ensure we have something to work with
|
||||||
|
|
Loading…
Reference in New Issue