-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into krist/be-443-configur…
…e-notifications # Conflicts: # tests/conftest.py
- Loading branch information
Showing
95 changed files
with
1,304 additions
and
560 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Any, TYPE_CHECKING | ||
|
||
from invenio_pidstore.errors import PersistentIdentifierError | ||
|
||
from oarepo_requests.resolvers.ui import resolve | ||
import logging | ||
if TYPE_CHECKING: | ||
from invenio_requests.records import Request | ||
log = logging.getLogger(__name__) | ||
|
||
# todo consider - we are not using this strictly in the ui context - so how should we separate these things in the future | ||
def resolve_entity(entity: str, obj: Request, ctx: dict[str, Any]) -> dict: | ||
"""Resolve the entity and put it into the context cache. | ||
:param obj: Request object | ||
:param ctx: Context cache | ||
:return: The resolved entity | ||
""" | ||
entity_field_value = getattr(obj, entity) | ||
if not entity_field_value: | ||
return {} | ||
|
||
reference_dict: dict = entity_field_value.reference_dict | ||
|
||
key = entity_context_key(reference_dict) | ||
if key in ctx: | ||
return ctx[key] | ||
try: | ||
entity = resolve(ctx["identity"], reference_dict) | ||
except Exception as e: # noqa | ||
if not isinstance(e, PersistentIdentifierError): | ||
log.exception( | ||
"Error resolving %s for identity %s", | ||
reference_dict, | ||
ctx["identity"], | ||
) | ||
entity = {"links": {}} | ||
ctx[key] = entity | ||
return entity | ||
|
||
|
||
def entity_context_key(reference_dict: dict) -> str: | ||
return "entity:" + ":".join( | ||
f"{x[0]}:{x[1]}" for x in sorted(reference_dict.items()) | ||
) |
Oops, something went wrong.