|
7 | 7 | from models_library.rest_error import LogMessageType |
8 | 8 | from models_library.users import UserID |
9 | 9 | from pydantic import PositiveInt |
10 | | -from servicelib.aiohttp import observer |
11 | | -from servicelib.aiohttp.status import HTTP_200_OK |
12 | | -from servicelib.mimetype_constants import MIMETYPE_APPLICATION_JSON |
| 10 | +from servicelib.aiohttp import observer, status |
13 | 11 | from simcore_postgres_database.models.users import UserRole |
14 | 12 |
|
15 | 13 | from ..db.models import ConfirmationAction, UserStatus |
@@ -57,25 +55,21 @@ def validate_user_status(*, user: dict, support_email: str): |
57 | 55 | if user_status == DELETED: |
58 | 56 | raise web.HTTPUnauthorized( |
59 | 57 | text=MSG_USER_DELETED.format(support_email=support_email), |
60 | | - content_type=MIMETYPE_APPLICATION_JSON, |
61 | 58 | ) # 401 |
62 | 59 |
|
63 | 60 | if user_status == BANNED or user["role"] == ANONYMOUS: |
64 | 61 | raise web.HTTPUnauthorized( |
65 | 62 | text=MSG_USER_BANNED.format(support_email=support_email), |
66 | | - content_type=MIMETYPE_APPLICATION_JSON, |
67 | 63 | ) # 401 |
68 | 64 |
|
69 | 65 | if user_status == EXPIRED: |
70 | 66 | raise web.HTTPUnauthorized( |
71 | 67 | text=MSG_USER_EXPIRED.format(support_email=support_email), |
72 | | - content_type=MIMETYPE_APPLICATION_JSON, |
73 | 68 | ) # 401 |
74 | 69 |
|
75 | 70 | if user_status == CONFIRMATION_PENDING: |
76 | 71 | raise web.HTTPUnauthorized( |
77 | 72 | text=MSG_ACTIVATION_REQUIRED, |
78 | | - content_type=MIMETYPE_APPLICATION_JSON, |
79 | 73 | ) # 401 |
80 | 74 |
|
81 | 75 | assert user_status == ACTIVE # nosec |
@@ -117,15 +111,15 @@ async def notify_user_logout( |
117 | 111 |
|
118 | 112 |
|
119 | 113 | def flash_response( |
120 | | - message: str, level: str = "INFO", *, status: int = HTTP_200_OK |
| 114 | + message: str, level: str = "INFO", *, status: int = status.HTTP_200_OK |
121 | 115 | ) -> web.Response: |
122 | 116 | return envelope_response( |
123 | 117 | data=asdict(LogMessageType(message, level)), |
124 | 118 | status=status, |
125 | 119 | ) |
126 | 120 |
|
127 | 121 |
|
128 | | -def envelope_response(data: Any, *, status: int = HTTP_200_OK) -> web.Response: |
| 122 | +def envelope_response(data: Any, *, status: int = status.HTTP_200_OK) -> web.Response: |
129 | 123 | return web.json_response( |
130 | 124 | { |
131 | 125 | "data": data, |
|
0 commit comments