Skip to content

Commit

Permalink
Merge branch 'main' into COPDS-2157-origin-in-job-response
Browse files Browse the repository at this point in the history
  • Loading branch information
mcucchi9 committed Nov 13, 2024
2 parents 0da1153 + 4587c6f commit 9fee8e2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions cads_processing_api_service/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ def post_process_execution(
)
structlog.contextvars.bind_contextvars(user_uid=auth_info.user_uid)
request_body = execution_content.model_dump()
portals = (
[p.strip() for p in auth_info.portal_header.split(",")]
if auth_info.portal_header
else None
)
catalogue_sessionmaker = db_utils.get_catalogue_sessionmaker(
db_utils.ConnectionMode.read
)
Expand All @@ -228,6 +233,7 @@ def post_process_execution(
table=self.process_table,
session=catalogue_session,
load_messages=True,
portals=tuple(portals),
)
auth.verify_if_disabled(dataset.disabled_reason, auth_info.user_role)
adaptor_properties = adaptors.get_adaptor_properties(dataset)
Expand Down
8 changes: 7 additions & 1 deletion cads_processing_api_service/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ class JobSortCriterion(str, enum.Enum):
key=lambda resource_id,
table,
session,
load_messages=False: cachetools.keys.hashkey(resource_id, table, load_messages),
load_messages=False,
portals=None: cachetools.keys.hashkey(resource_id, table, load_messages, portals),
)
def lookup_resource_by_id(
resource_id: str,
table: type[cads_catalogue.database.Resource],
session: sqlalchemy.orm.Session,
load_messages: bool = False,
portals: tuple[str] | None = None,
) -> cads_catalogue.database.Resource:
"""Look for the resource identified by `id` into the Catalogue database.
Expand All @@ -82,6 +84,8 @@ def lookup_resource_by_id(
Catalogue database session.
load_messages : bool, optional
If True, load resource messages, by default False.
portals: tuple[str] | None, optional
Portals to filter resources by, by default None.
Returns
-------
Expand All @@ -100,6 +104,8 @@ def lookup_resource_by_id(
)
if load_messages:
statement = statement.options(sqlalchemy.orm.joinedload(table.messages))
if portals:
statement = statement.filter(table.portal.in_(portals))
statement = statement.filter(table.resource_uid == resource_id)
try:
row: cads_catalogue.database.Resource = (
Expand Down

0 comments on commit 9fee8e2

Please sign in to comment.