From 7a679d04c811065e94d7361e5e755ca8f60b294a Mon Sep 17 00:00:00 2001 From: Alzpetka Date: Wed, 18 Oct 2023 11:06:11 +0200 Subject: [PATCH 1/6] autoescape fix --- oarepo_ui/resources/catalog.py | 5 ++++- oarepo_ui/resources/resource.py | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/oarepo_ui/resources/catalog.py b/oarepo_ui/resources/catalog.py index 8c23c126..a3decb8d 100644 --- a/oarepo_ui/resources/catalog.py +++ b/oarepo_ui/resources/catalog.py @@ -74,6 +74,7 @@ def _get_component_path( f"Unable to find a file named {name}{file_ext} " f"or one following the pattern {name_dot}*{file_ext}" ) + def _get_from_file(self, *, prefix: str, name: str, url_prefix: str, file_ext: str) -> "Component": root_path, path = self._get_component_path(prefix, name, file_ext=file_ext) component = Component( @@ -87,7 +88,9 @@ def _get_from_file(self, *, prefix: str, name: str, url_prefix: str, file_ext: s return component -def get_jinja_template(_catalog, template_def, fields=[]): +def get_jinja_template(_catalog, template_def, fields=None): + if fields is None: + fields = [] jinja_content = None for component in _catalog.jinja_env.loader.searchpath: if component["component_file"].endswith(template_def["layout"]): diff --git a/oarepo_ui/resources/resource.py b/oarepo_ui/resources/resource.py index 7b6e0c55..e7df6db0 100644 --- a/oarepo_ui/resources/resource.py +++ b/oarepo_ui/resources/resource.py @@ -260,13 +260,13 @@ def search(self): ) search_config = partial(self.config.search_app_config, **search_options) + search_app_config = search_config(app_id=app_id) - json_data = json.dumps(search_app_config, default=lazy_string_encoder, indent=4) return _catalog.render( "search", __source=source, - search_app_config=json_data, + search_app_config=search_app_config, ui_config=self.config, ui_resource=self, layout=layout, From 1061c579a1220a44bf60333e598941f66b9bd634 Mon Sep 17 00:00:00 2001 From: Alzpetka Date: Wed, 18 Oct 2023 11:12:16 +0200 Subject: [PATCH 2/6] autoescape --- oarepo_ui/ext.py | 1 + 1 file changed, 1 insertion(+) diff --git a/oarepo_ui/ext.py b/oarepo_ui/ext.py index d3999d36..578617b3 100644 --- a/oarepo_ui/ext.py +++ b/oarepo_ui/ext.py @@ -101,6 +101,7 @@ def _catalog_config(self, catalog, env): env.policies.setdefault("json.dumps_kwargs", {}).setdefault("default", str) self.app.update_template_context(context) catalog.jinja_env.loader = env.loader + catalog.jinja_env.autoescape = env.autoescape context.update(catalog.jinja_env.globals) context.update(env.globals) catalog.jinja_env.globals = context From 8c7ca633d484a1f21c50df953dcf086910d32943 Mon Sep 17 00:00:00 2001 From: Alzpetka Date: Wed, 18 Oct 2023 14:43:15 +0200 Subject: [PATCH 3/6] tests --- tests/test_ui_resource.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/test_ui_resource.py b/tests/test_ui_resource.py index a1632d0e..032c8954 100644 --- a/tests/test_ui_resource.py +++ b/tests/test_ui_resource.py @@ -16,10 +16,12 @@ def test_permissions_on_detail( with client.get(f"/simple-model/{simple_record.id}") as c: assert c.status_code == 200 assert ( - "permissions={'can_edit': False, 'can_new_version': False, 'can_manage': " - "False, 'can_update_draft': False, 'can_read_files': True, 'can_review': " - "False, 'can_view': False, 'can_delete_draft': False, 'can_manage_files': " - "False, 'can_manage_record_access': False}" + 'permissions={'can_edit': False, 'can_new_version': False, ' + ''can_manage': False, 'can_update_draft': False, ' + ''can_read_files': True, 'can_review': False, ' + ''can_view': False, 'can_delete_draft': False, ' + ''can_manage_files': False, 'can_manage_record_access': ' + 'False}' ) in c.text @@ -36,7 +38,7 @@ def test_permissions_on_search( ): with client.get(f"/simple-model/") as c: assert c.status_code == 200 - assert ("permissions={'can_create': True}") in c.text + assert ("permissions={'can_create': True}") in c.text def test_filter_on_search( From d8bcce413e79cbd6176b095cc3e4c7ef4a612c56 Mon Sep 17 00:00:00 2001 From: Alzpetka Date: Wed, 18 Oct 2023 14:44:05 +0200 Subject: [PATCH 4/6] version --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index b621099c..6d8a494d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = oarepo-ui -version = 5.0.72 +version = 5.0.73 description = UI module for invenio 3.5+ long_description = file: README.md long_description_content_type = text/markdown From e26da5fe62eaa86c8d47ac3dac165a95ab624ca9 Mon Sep 17 00:00:00 2001 From: Mirek Simek Date: Wed, 18 Oct 2023 19:52:21 +0200 Subject: [PATCH 5/6] Removed sort option translation in react, is done inside python --- .../js/oarepo_ui/search/SearchAppResultOptions.jsx | 11 ----------- setup.cfg | 2 +- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/search/SearchAppResultOptions.jsx b/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/search/SearchAppResultOptions.jsx index b7c2cc24..5dd1af62 100644 --- a/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/search/SearchAppResultOptions.jsx +++ b/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/search/SearchAppResultOptions.jsx @@ -8,18 +8,7 @@ import { i18next } from "@translations/oarepo_ui/i18next"; import { SearchConfigurationContext } from "@js/invenio_search_ui/components"; import { SearchAppSort } from "./SearchAppSort"; -const sortTranslation = (sortOptions) => { - const translatedSortOptions = sortOptions.map((sortOption) => { - return { - ...sortOption, - text: i18next.t(sortOption.sortBy), - }; - }); - return translatedSortOptions; -}; - export const SearchAppResultOptions = ({ sortOptions, layoutOptions }) => { - sortOptions = sortTranslation(sortOptions); const { buildUID } = useContext(SearchConfigurationContext); const multipleLayouts = Object.values(layoutOptions).filter((i) => i).length > 1; diff --git a/setup.cfg b/setup.cfg index 6d8a494d..f8eed262 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = oarepo-ui -version = 5.0.73 +version = 5.0.74 description = UI module for invenio 3.5+ long_description = file: README.md long_description_content_type = text/markdown From ed7e99ecf3ccead6b80ee88d0436fa06fceaf54c Mon Sep 17 00:00:00 2001 From: Mirek Simek Date: Thu, 19 Oct 2023 08:44:57 +0200 Subject: [PATCH 6/6] Workaround for incorrect escaping inside jinjax (#98) * Workaround for incorrect escaping inside jinjax * version bump --- oarepo_ui/ext.py | 12 ++++++++++++ setup.cfg | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/oarepo_ui/ext.py b/oarepo_ui/ext.py index 578617b3..2210bc12 100644 --- a/oarepo_ui/ext.py +++ b/oarepo_ui/ext.py @@ -97,6 +97,18 @@ def catalog(self): return self._catalog_config(self._catalog, self.templates.jinja_env) def _catalog_config(self, catalog, env): + + # monkeypatch component - see https://github.com/jpsca/jinjax/issues/32 + from markupsafe import Markup + from jinjax.component import Component + + def render(self, **kwargs): + assert self.tmpl, f"Component {self.name} has no template" + return Markup(self.tmpl.render(**kwargs).strip()) + render.__name__ = 'render_patched_by_oarepo_ui' + Component.render = render + # monkeypatch end + context = {} env.policies.setdefault("json.dumps_kwargs", {}).setdefault("default", str) self.app.update_template_context(context) diff --git a/setup.cfg b/setup.cfg index f8eed262..3ef8702c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = oarepo-ui -version = 5.0.74 +version = 5.0.75 description = UI module for invenio 3.5+ long_description = file: README.md long_description_content_type = text/markdown