Skip to content

Commit 5127137

Browse files
committed
cleanup
1 parent 8f1c4e3 commit 5127137

File tree

9 files changed

+29
-31
lines changed

9 files changed

+29
-31
lines changed

services/web/server/src/simcore_service_webserver/_constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929

3030

3131
__all__: tuple[str, ...] = (
32-
"APP_CONFIG_KEY",
3332
"APP_AIOPG_ENGINE_KEY",
33+
"APP_CONFIG_KEY",
3434
"APP_FIRE_AND_FORGET_TASKS_KEY",
3535
"APP_SETTINGS_KEY",
3636
"RQT_USERID_KEY",

services/web/server/src/simcore_service_webserver/studies_dispatcher/_catalog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
2+
from collections.abc import AsyncIterator
23
from contextlib import suppress
34
from dataclasses import dataclass
4-
from typing import AsyncIterator
55

66
import sqlalchemy as sa
77
from aiohttp import web

services/web/server/src/simcore_service_webserver/studies_dispatcher/_constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
)
2929

3030
MSG_UNEXPECTED_DISPATCH_ERROR: Final[str] = (
31-
"Sorry, but looks like something unexpected went wrong!<br/>"
32-
"We track these errors automatically, but if the problem persists feel free to contact us. "
31+
"Sorry, but looks like something unexpected went wrong!"
32+
"We track these errors automatically, but if the problem persists feel free to contact us."
3333
"In the meantime, try refreshing."
3434
)

services/web/server/src/simcore_service_webserver/studies_dispatcher/_core.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
@lru_cache
2929
def compose_uuid_from(*values) -> uuid.UUID:
3030
composition: str = "/".join(map(str, values))
31-
new_uuid = uuid.uuid5(_BASE_UUID, composition)
32-
return new_uuid
31+
return uuid.uuid5(_BASE_UUID, composition)
3332

3433

3534
async def list_viewers_info(
@@ -58,9 +57,8 @@ async def list_viewers_info(
5857
async for row in await conn.execute(query):
5958
try:
6059
# TODO: filter in database (see test_list_default_compatible_services )
61-
if only_default:
62-
if row["filetype"] in listed_filetype:
63-
continue
60+
if only_default and row["filetype"] in listed_filetype:
61+
continue
6462
listed_filetype.add(row["filetype"])
6563
consumer = ViewerInfo.create_from_db(row)
6664
consumers.append(consumer)

services/web/server/src/simcore_service_webserver/studies_dispatcher/_projects.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def _create_project(
9292
access_rights.write = access_rights.delete = False
9393

9494
# Assambles project instance
95-
project = Project(
95+
return Project(
9696
uuid=project_id,
9797
name=name,
9898
description=description,
@@ -105,8 +105,6 @@ def _create_project(
105105
ui=StudyUI(workbench=workbench_ui), # type: ignore[arg-type]
106106
)
107107

108-
return project
109-
110108

111109
def _create_project_with_service(
112110
project_id: ProjectID,
@@ -275,7 +273,7 @@ async def get_or_create_project_with_file_and_service(
275273
download_link,
276274
)
277275
# FIXME: CANNOT GUARANTEE!!, DELETE?? ERROR?? and cannot be viewed until verified?
278-
raise web.HTTPInternalServerError()
276+
raise web.HTTPInternalServerError
279277

280278
except (ProjectNotFoundError, ProjectInvalidRightsError):
281279
exists = False

services/web/server/src/simcore_service_webserver/studies_dispatcher/_projects_permalinks.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class _GroupAccessRightsDict(TypedDict):
3131

3232
def create_permalink_for_study(
3333
request: web.Request,
34+
*,
3435
project_uuid: ProjectID | ProjectIDStr,
3536
project_type: ProjectType,
3637
project_access_rights: dict[_GroupID, _GroupAccessRightsDict],
@@ -44,19 +45,21 @@ def create_permalink_for_study(
4445

4546
# check: criterias/conditions on a project to have a permalink
4647
if project_type != ProjectType.TEMPLATE:
47-
raise PermalinkNotAllowedError(
48+
msg = (
4849
"Can only create permalink from a template project. "
4950
f"Got {project_uuid=} with {project_type=}"
5051
)
52+
raise PermalinkNotAllowedError(msg)
5153

5254
project_access_rights_group_1_or_empty: _GroupAccessRightsDict | dict = (
5355
project_access_rights.get("1", {})
5456
)
5557
if not project_access_rights_group_1_or_empty.get("read", False):
56-
raise PermalinkNotAllowedError(
58+
msg = (
5759
"Cannot create permalink if not shared with everyone. "
5860
f"Got {project_uuid=} with {project_access_rights=}"
5961
)
62+
raise PermalinkNotAllowedError(msg)
6063

6164
# create
6265
url_for = create_url_for_function(request)
@@ -114,14 +117,13 @@ async def permalink_factory(
114117
if not row:
115118
raise ProjectNotFoundError(project_uuid=project_uuid)
116119

117-
permalink_info = create_permalink_for_study(
120+
return create_permalink_for_study(
118121
request,
119122
project_uuid=row.uuid,
120123
project_type=row.type,
121124
project_access_rights=row.access_rights,
122125
project_is_public=row.published,
123126
)
124-
return permalink_info
125127

126128

127129
def setup_projects_permalinks(

services/web/server/src/simcore_service_webserver/studies_dispatcher/_redirects_handlers.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ def _create_redirect_response_to_error_page(
7373

7474

7575
def _create_service_info_from(service: ValidService) -> ServiceInfo:
76-
values_map = dict(
77-
key=service.key,
78-
version=service.version,
79-
label=service.title,
80-
is_guest_allowed=service.is_public,
81-
)
76+
values_map = {
77+
"key": service.key,
78+
"version": service.version,
79+
"label": service.title,
80+
"is_guest_allowed": service.is_public,
81+
}
8282
if service.thumbnail:
8383
values_map["thumbnail"] = service.thumbnail
8484
return ServiceInfo.model_construct(_fields_set=set(values_map.keys()), **values_map)
@@ -335,7 +335,7 @@ async def get_redirection_to_viewer(request: web.Request):
335335

336336
else:
337337
# NOTE: if query is done right, this should never happen
338-
raise InvalidRedirectionParams()
338+
raise InvalidRedirectionParams
339339

340340
# Adds auth cookies (login)
341341
await ensure_authentication(user, request, response)

services/web/server/src/simcore_service_webserver/utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,13 @@ def get_tracemalloc_info(top=10) -> list[str]:
156156
def compose_support_error_msg(
157157
msg: str, error_code: ErrorCodeStr, support_email: str = "support"
158158
) -> str:
159-
sentences = []
160-
for line in msg.split("\n"):
161-
if sentence := line.strip(" ."):
162-
sentences.append(sentence[0].upper() + sentence[1:])
163-
159+
sentences = [
160+
sentence[0].upper() + sentence[1:]
161+
for line in msg.split("\n")
162+
if (sentence := line.strip(" ."))
163+
]
164164
sentences.append(
165-
f"For more information please forward this message to {support_email} [{error_code}]"
165+
f"For more information please forward this message to {support_email} (supportID={error_code})"
166166
)
167167

168168
return ". ".join(sentences)

services/web/server/tests/unit/isolated/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,5 @@ def test_compose_support_error_msg():
128128
)
129129
assert (
130130
msg == "First sentence for Mr.X. Second sentence."
131-
" For more information please forward this message to [email protected] [OEC:139641204989600]"
131+
" For more information please forward this message to [email protected] (supportID=OEC:139641204989600)"
132132
)

0 commit comments

Comments
 (0)