Add factory.try_user for non-exception user lookup

This commit is contained in:
Tim Van Baak 2020-04-24 10:54:11 -07:00
parent 9252e524ae
commit 07e62b9665
1 changed files with 11 additions and 0 deletions

View File

@ -1,3 +1,5 @@
from typing import Optional
from amanuensis.config import is_guid, RootConfigDirectoryContext
from amanuensis.errors import ArgumentError
from amanuensis.models.user import UserModel
@ -8,6 +10,15 @@ class ModelFactory():
def __init__(self, root: RootConfigDirectoryContext):
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:
"""Get the user model for the given id or username"""
# Ensure we have something to work with