Skip to content

Commit

Permalink
Merge pull request #93 from oarepo/krist/autoapprove-ui-serializer
Browse files Browse the repository at this point in the history
Krist/autoapprove UI serializer
  • Loading branch information
mesemus authored Dec 2, 2024
2 parents f394f76 + 70c5586 commit c988a8f
Show file tree
Hide file tree
Showing 10 changed files with 259 additions and 126 deletions.
2 changes: 2 additions & 0 deletions oarepo_requests/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
WorkflowTransitionComponent,
)
from oarepo_requests.resolvers.ui import (
AutoApproveUIEntityResolver,
FallbackEntityReferenceUIResolver,
GroupEntityReferenceUIResolver,
UserEntityReferenceUIResolver,
Expand Down Expand Up @@ -63,6 +64,7 @@
"user": UserEntityReferenceUIResolver("user"),
"fallback": FallbackEntityReferenceUIResolver("fallback"),
"group": GroupEntityReferenceUIResolver("group"),
"auto_approve": AutoApproveUIEntityResolver("auto_approve"),
}

REQUESTS_UI_SERIALIZATION_REFERENCED_FIELDS = ["created_by", "receiver", "topic"]
Expand Down
64 changes: 63 additions & 1 deletion oarepo_requests/resolvers/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,9 @@ def _search_many(
f"No service found for handling reference type {self.reference_type}"
)
extra_filter = dsl.Q("terms", **{"id": list(ids)})
return service.search(identity, extra_filter=extra_filter).to_dict()["hits"]["hits"]
return service.search(identity, extra_filter=extra_filter).to_dict()["hits"][
"hits"
]

@override
def _search_one(
Expand Down Expand Up @@ -543,3 +545,63 @@ def _get_entity_ui_representation(
label=label,
links=self._extract_links_from_resolved_reference(entity),
)


class KeywordUIEntityResolver(OARepoUIResolver):
keyword = None

@override
def _get_id(self, entity: dict) -> str:
"""Get the id of the serialized entity.
:result: value of the keyword of the entity
"""
return list(entity.values())[0]

@override
def _search_many(
self, identity: Identity, ids: list[str], *args: Any, **kwargs: Any
) -> list[dict]:
"""Returns list of references of keyword entities.
:param identity: identity of the user
:param ids: ids to search for
:param args: additional arguments
:param kwargs: additional keyword arguments
:return: list of records found
"""
return [{self.keyword: _id} for _id in ids]

@override
def _search_one(
self, identity: Identity, _id: str, *args: Any, **kwargs: Any
) -> dict | None:
"""Returns keyword entity reference.
:param identity: identity of the user
:param _id: the keyword value
:return: API serialization of the data
"""
return {self.keyword: _id}


class AutoApproveUIEntityResolver(KeywordUIEntityResolver):
keyword = "auto_approve"

@override
def _get_entity_ui_representation(
self, entity: dict, reference: EntityReference
) -> UIResolvedReference:
"""Create a UI representation of an auto approve entity.
:entity: resolved entity
:reference: reference to the entity
:return: UI representation of the entity
"""

return UIResolvedReference(
reference=reference,
type=self.keyword,
label=_("Auto approve"),
links={},
)
Binary file modified oarepo_requests/translations/cs/LC_MESSAGES/messages.mo
Binary file not shown.
14 changes: 14 additions & 0 deletions oarepo_requests/translations/cs/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -726,3 +726,17 @@ msgstr "smazal(a) komentář"

msgid "Remaining characters: "
msgstr "Zbývající znaky: "

#: /home/ron/prace/oarepo-requests/oarepo_requests/resolvers/ui.py:594
msgid "Auto approve"
msgstr "Automaticky schváleno"

#: /home/ron/prace/oarepo-requests/oarepo_requests/types/publish_draft.py:120
msgid ""
"Missing uploaded files. To disable files for this record please mark it as "
"metadata-only."
msgstr "Chybí nahrané soubory. Označte záznam jako 'pouze metadata' pokud je nahrávat neplánujete."

#: /home/ron/prace/oarepo-requests/oarepo_requests/types/publish_draft.py:124
msgid "Missing uploaded files."
msgstr "Chybí nahrané soubory."
Binary file modified oarepo_requests/translations/en/LC_MESSAGES/messages.mo
Binary file not shown.
14 changes: 14 additions & 0 deletions oarepo_requests/translations/en/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -696,5 +696,19 @@ msgstr ""
msgid "Remaining characters: "
msgstr ""

#: /home/ron/prace/oarepo-requests/oarepo_requests/resolvers/ui.py:594
msgid "Auto approve"
msgstr ""

#: /home/ron/prace/oarepo-requests/oarepo_requests/types/publish_draft.py:120
msgid ""
"Missing uploaded files. To disable files for this record please mark it as "
"metadata-only."
msgstr ""

#: /home/ron/prace/oarepo-requests/oarepo_requests/types/publish_draft.py:124
msgid "Missing uploaded files."
msgstr ""

#~ msgid "No status"
#~ msgstr ""
Binary file modified oarepo_requests/translations/messages.mo
Binary file not shown.
Loading

0 comments on commit c988a8f

Please sign in to comment.