|
@@ -9,7 +9,7 @@ from sqlalchemy.orm import Session
|
9
|
9
|
from tracim import CFG
|
10
|
10
|
from tracim.models.auth import User, Group
|
11
|
11
|
from sqlalchemy.orm.exc import NoResultFound
|
12
|
|
-from tracim.exceptions import WrongUserPassword, UserNotExist
|
|
12
|
+from tracim.exceptions import WrongUserPassword, UserDoesNotExist
|
13
|
13
|
from tracim.exceptions import AuthenticationFailed
|
14
|
14
|
from tracim.models.context_models import UserInContext
|
15
|
15
|
|
|
@@ -48,8 +48,8 @@ class UserApi(object):
|
48
|
48
|
"""
|
49
|
49
|
try:
|
50
|
50
|
user = self._base_query().filter(User.user_id == user_id).one()
|
51
|
|
- except NoResultFound:
|
52
|
|
- raise UserNotExist()
|
|
51
|
+ except NoResultFound as exc:
|
|
52
|
+ raise UserDoesNotExist('User "{}" not found in database'.format(user_id)) from exc # nopep8
|
53
|
53
|
return user
|
54
|
54
|
|
55
|
55
|
def get_one_by_email(self, email: str) -> User:
|
|
@@ -60,8 +60,8 @@ class UserApi(object):
|
60
|
60
|
"""
|
61
|
61
|
try:
|
62
|
62
|
user = self._base_query().filter(User.email == email).one()
|
63
|
|
- except NoResultFound:
|
64
|
|
- raise UserNotExist()
|
|
63
|
+ except NoResultFound as exc:
|
|
64
|
+ raise UserDoesNotExist('User "{}" not found in database'.format(email)) from exc # nopep8
|
65
|
65
|
return user
|
66
|
66
|
|
67
|
67
|
# FIXME - G.M - 24-04-2018 - Duplicate method with get_one.
|
|
@@ -73,7 +73,7 @@ class UserApi(object):
|
73
|
73
|
Get current_user
|
74
|
74
|
"""
|
75
|
75
|
if not self._user:
|
76
|
|
- raise UserNotExist()
|
|
76
|
+ raise UserDoesNotExist()
|
77
|
77
|
return self._user
|
78
|
78
|
|
79
|
79
|
def get_all(self) -> typing.Iterable[User]:
|
|
@@ -103,7 +103,7 @@ class UserApi(object):
|
103
|
103
|
return user
|
104
|
104
|
else:
|
105
|
105
|
raise WrongUserPassword()
|
106
|
|
- except (WrongUserPassword, NoResultFound, UserNotExist):
|
|
106
|
+ except (WrongUserPassword, UserDoesNotExist):
|
107
|
107
|
raise AuthenticationFailed()
|
108
|
108
|
|
109
|
109
|
# Actions
|