From 6a8d87c7388832d14114ed3a11520001489ca518 Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Mon, 31 Jul 2023 15:10:35 +0200 Subject: [PATCH 1/3] IBX-6017: Avoid loading whole content in the Content Tree (#2104) * IBX-6017: Avoid loading whole content in the Content Tree * IBX-6017: Adapted solution to use `loadVersionInfoListByContentInfo` method * IBX-6017: CS --- src/lib/UI/Module/ContentTree/NodeFactory.php | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/lib/UI/Module/ContentTree/NodeFactory.php b/src/lib/UI/Module/ContentTree/NodeFactory.php index 422751f94e..70af18c88a 100644 --- a/src/lib/UI/Module/ContentTree/NodeFactory.php +++ b/src/lib/UI/Module/ContentTree/NodeFactory.php @@ -79,15 +79,24 @@ public function createNode( ): Node { $uninitializedContentInfoList = []; $containerLocations = []; - $node = $this->buildNode($location, $uninitializedContentInfoList, $containerLocations, $loadSubtreeRequestNode, $loadChildren, $depth, $sortClause, $sortOrder); - $contentById = $this->contentService->loadContentListByContentInfo($uninitializedContentInfoList); + $node = $this->buildNode( + $location, + $uninitializedContentInfoList, + $containerLocations, + $loadSubtreeRequestNode, + $loadChildren, + $depth, + $sortClause, + $sortOrder + ); + $versionInfoById = $this->contentService->loadVersionInfoListByContentInfo($uninitializedContentInfoList); $aggregatedChildrenCount = null; if ($this->searchService->supports(SearchService::CAPABILITY_AGGREGATIONS)) { $aggregatedChildrenCount = $this->countAggregatedSubitems($containerLocations); } - $this->supplyTranslatedContentName($node, $contentById); + $this->supplyTranslatedContentName($node, $versionInfoById); $this->supplyChildrenCount($node, $aggregatedChildrenCount); return $node; @@ -349,16 +358,16 @@ private function buildNode( } /** - * @param \eZ\Publish\API\Repository\Values\Content\Content[] $contentById + * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo[] $versionInfoById */ - private function supplyTranslatedContentName(Node $node, array $contentById): void + private function supplyTranslatedContentName(Node $node, array $versionInfoById): void { if ($node->contentId !== self::TOP_NODE_CONTENT_ID) { - $node->name = $this->translationHelper->getTranslatedContentName($contentById[$node->contentId]); + $node->name = $this->translationHelper->getTranslatedContentNameByVersionInfo($versionInfoById[$node->contentId]); } foreach ($node->children as $child) { - $this->supplyTranslatedContentName($child, $contentById); + $this->supplyTranslatedContentName($child, $versionInfoById); } } From 0ceabb118307ae554c53a04f6f13e768b3220458 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20D=C4=99bi=C5=84ski?= <58430570+mateuszdebinski@users.noreply.github.com> Date: Tue, 1 Aug 2023 16:04:45 +0200 Subject: [PATCH 2/3] IBX-5852: Created a new layout for error pages to prevent leak data (#2106) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * IBX-5852: Created a new layout for error pages to prevent leak data * Removed unnecessary code, Corrected CD --------- Co-authored-by: Mateusz Dębiński --- src/bundle/Resources/encore/ez.js.config.js | 3 ++ .../public/js/scripts/admin.error.page.js | 35 ++++++++++++++ .../themes/admin/ui/error_page/403.html.twig | 4 +- .../themes/admin/ui/error_page/404.html.twig | 8 +--- .../admin/ui/error_page/unknown.html.twig | 4 +- .../themes/admin/ui/layout_error.html.twig | 47 +++++++++++++++++++ 6 files changed, 88 insertions(+), 13 deletions(-) create mode 100644 src/bundle/Resources/public/js/scripts/admin.error.page.js create mode 100644 src/bundle/Resources/views/themes/admin/ui/layout_error.html.twig diff --git a/src/bundle/Resources/encore/ez.js.config.js b/src/bundle/Resources/encore/ez.js.config.js index d5d6ebcf5f..cedcf2b7f1 100644 --- a/src/bundle/Resources/encore/ez.js.config.js +++ b/src/bundle/Resources/encore/ez.js.config.js @@ -48,6 +48,9 @@ if (fs.existsSync(fieldTypesPath)) { module.exports = (Encore) => { Encore.addEntry('ezplatform-admin-ui-layout-js', layout) + .addEntry('ezplatform-admin-ui-error-page-js', [ + path.resolve(__dirname, '../public/js/scripts/admin.error.page.js'), + ]) .addEntry('ezplatform-admin-ui-bookmark-list-js', [ path.resolve(__dirname, '../public/js/scripts/button.state.toggle.js'), path.resolve(__dirname, '../public/js/scripts/button.content.edit.js'), diff --git a/src/bundle/Resources/public/js/scripts/admin.error.page.js b/src/bundle/Resources/public/js/scripts/admin.error.page.js new file mode 100644 index 0000000000..9bfa3b5970 --- /dev/null +++ b/src/bundle/Resources/public/js/scripts/admin.error.page.js @@ -0,0 +1,35 @@ +(function(doc) { + const notificationsContainer = doc.querySelector('.ez-notifications-container'); + const notifications = JSON.parse(notificationsContainer.dataset.notifications); + const template = notificationsContainer.dataset.template; + + const escapeHTML = (string) => { + const stringTempNode = doc.createElement('div'); + + stringTempNode.appendChild(doc.createTextNode(string)); + + return stringTempNode.innerHTML; + }; + + const addNotification = ({ detail }) => { + const { label, message } = detail; + const templateLabel = label === 'error' ? 'danger' : label; + const container = doc.createElement('div'); + let finalMessage = escapeHTML(message); + + const notification = template + .replace('{{ label }}', templateLabel) + .replace('{{ message }}', finalMessage) + .replace('{{ badge }}', label); + + container.insertAdjacentHTML('beforeend', notification); + + const notificationNode = container.querySelector('.alert'); + + notificationsContainer.append(notificationNode); + }; + + Object.entries(notifications).forEach(([label, messages]) => { + messages.forEach((message) => addNotification({ detail: { label, message } })); + }); +})(window.document); diff --git a/src/bundle/Resources/views/themes/admin/ui/error_page/403.html.twig b/src/bundle/Resources/views/themes/admin/ui/error_page/403.html.twig index bbbc2663c4..99b7feaf6f 100644 --- a/src/bundle/Resources/views/themes/admin/ui/error_page/403.html.twig +++ b/src/bundle/Resources/views/themes/admin/ui/error_page/403.html.twig @@ -1,6 +1,4 @@ -{% extends '@ezdesign/ui/layout.html.twig' %} - -{% block navigation %}{% endblock %} +{% extends '@ezdesign/ui/layout_error.html.twig' %} {% block body_class %}ez-has-no-sidebars ez-error-site{% endblock %} diff --git a/src/bundle/Resources/views/themes/admin/ui/error_page/404.html.twig b/src/bundle/Resources/views/themes/admin/ui/error_page/404.html.twig index f808a37e92..51fc4573eb 100644 --- a/src/bundle/Resources/views/themes/admin/ui/error_page/404.html.twig +++ b/src/bundle/Resources/views/themes/admin/ui/error_page/404.html.twig @@ -1,10 +1,4 @@ -{% extends '@ezdesign/ui/layout.html.twig' %} - -{% block navigation %} - {% if ez_admin_ui_config.user.user is not empty %} - {{ parent() }} - {% endif %} -{% endblock %} +{% extends '@ezdesign/ui/layout_error.html.twig' %} {% block body_class %}ez-has-no-sidebars ez-error-site{% endblock %} diff --git a/src/bundle/Resources/views/themes/admin/ui/error_page/unknown.html.twig b/src/bundle/Resources/views/themes/admin/ui/error_page/unknown.html.twig index 8c8e7db812..2c22d3827c 100644 --- a/src/bundle/Resources/views/themes/admin/ui/error_page/unknown.html.twig +++ b/src/bundle/Resources/views/themes/admin/ui/error_page/unknown.html.twig @@ -1,6 +1,4 @@ -{% extends '@ezdesign/ui/layout.html.twig' %} - -{% block navigation %}{% endblock %} +{% extends '@ezdesign/ui/layout_error.html.twig' %} {% block body_class %}ez-has-no-sidebars ez-error-site{% endblock %} diff --git a/src/bundle/Resources/views/themes/admin/ui/layout_error.html.twig b/src/bundle/Resources/views/themes/admin/ui/layout_error.html.twig new file mode 100644 index 0000000000..5072ea17a4 --- /dev/null +++ b/src/bundle/Resources/views/themes/admin/ui/layout_error.html.twig @@ -0,0 +1,47 @@ + + + + + {% block meta %} + {% endblock %} + {% if app.request.locale == 'ach_UG' %} + + + {% endif %} + {% block title %}Ibexa DXP{% endblock %} + {{ encore_entry_link_tags('ezplatform-admin-ui-layout-css', null, 'ezplatform') }} + + + + {% block stylesheets %}{% endblock %} + + + + + + +
+ {% block content %} + {% endblock content %} +
+ + {% block footer %} + {% include '@ezdesign/ui/footer.html.twig' %} + {% endblock %} + +
+ + {{ encore_entry_script_tags('ezplatform-admin-ui-error-page-js', null, 'ezplatform') }} + {{ ez_render_component_group('stylesheet-body') }} + + From 1305b1c9841866c11ebe9191ae258a62957d80e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20D=C4=99bi=C5=84ski?= Date: Tue, 1 Aug 2023 16:32:56 +0200 Subject: [PATCH 3/3] Merge remote-tracking branch 'origin/2.3' into temp_2.3_to_4.5 # Conflicts: # src/bundle/Resources/encore/ibexa.js.config.js # src/bundle/Resources/views/themes/admin/ui/error_page/403.html.twig # src/bundle/Resources/views/themes/admin/ui/error_page/404.html.twig # src/bundle/Resources/views/themes/admin/ui/error_page/unknown.html.twig # src/lib/UI/Module/ContentTree/NodeFactory.php --- .../Resources/encore/ibexa.js.config.js | 4 +- .../public/js/scripts/admin.error.page.js | 25 ++-- .../themes/admin/ui/layout_error.html.twig | 117 ++++++++++++------ 3 files changed, 98 insertions(+), 48 deletions(-) diff --git a/src/bundle/Resources/encore/ibexa.js.config.js b/src/bundle/Resources/encore/ibexa.js.config.js index 85841a3e08..45a476e77d 100644 --- a/src/bundle/Resources/encore/ibexa.js.config.js +++ b/src/bundle/Resources/encore/ibexa.js.config.js @@ -81,9 +81,7 @@ if (fs.existsSync(fieldTypesPath)) { module.exports = (Encore) => { Encore.addEntry('ibexa-admin-ui-layout-js', layout) - .addEntry('ibexa-admin-ui-error-page-js', [ - path.resolve(__dirname, '../public/js/scripts/admin.error.page.js'), - ]) + .addEntry('ibexa-admin-ui-error-page-js', [path.resolve(__dirname, '../public/js/scripts/admin.error.page.js')]) .addEntry('ibexa-admin-ui-bookmark-list-js', [ path.resolve(__dirname, '../public/js/scripts/button.state.toggle.js'), path.resolve(__dirname, '../public/js/scripts/button.content.edit.js'), diff --git a/src/bundle/Resources/public/js/scripts/admin.error.page.js b/src/bundle/Resources/public/js/scripts/admin.error.page.js index ae0868f514..32ef0fc1b2 100644 --- a/src/bundle/Resources/public/js/scripts/admin.error.page.js +++ b/src/bundle/Resources/public/js/scripts/admin.error.page.js @@ -1,8 +1,13 @@ -(function(doc) { +(function (global, doc, iconPaths) { const notificationsContainer = doc.querySelector('.ibexa-notifications-container'); const notifications = JSON.parse(notificationsContainer.dataset.notifications); - const template = notificationsContainer.dataset.template; - + const { template } = notificationsContainer.dataset; + const iconsMap = { + info: 'system-information', + error: 'circle-close', + warning: 'warning-triangle', + success: 'checkmark', + }; const escapeHTML = (string) => { const stringTempNode = doc.createElement('div'); @@ -10,17 +15,17 @@ return stringTempNode.innerHTML; }; - const addNotification = ({ detail }) => { const { label, message } = detail; - const templateLabel = label === 'error' ? 'danger' : label; const container = doc.createElement('div'); - let finalMessage = escapeHTML(message); + const iconSetPath = iconPaths.iconSets[iconPaths.defaultIconSet]; + const iconPath = `${iconSetPath}#${iconsMap[label]}`; + const finalMessage = escapeHTML(message); const notification = template - .replace('{{ label }}', templateLabel) + .replace('{{ label }}', label) .replace('{{ message }}', finalMessage) - .replace('{{ badge }}', label); + .replace('{{ icon_path }}', iconPath); container.insertAdjacentHTML('beforeend', notification); @@ -32,4 +37,6 @@ Object.entries(notifications).forEach(([label, messages]) => { messages.forEach((message) => addNotification({ detail: { label, message } })); }); -})(window.document); + + doc.body.addEventListener('ibexa-notify', addNotification, false); +})(window, window.document, window.ibexa.iconPaths); diff --git a/src/bundle/Resources/views/themes/admin/ui/layout_error.html.twig b/src/bundle/Resources/views/themes/admin/ui/layout_error.html.twig index fcc42b3a11..224b2cd32d 100644 --- a/src/bundle/Resources/views/themes/admin/ui/layout_error.html.twig +++ b/src/bundle/Resources/views/themes/admin/ui/layout_error.html.twig @@ -1,40 +1,85 @@ - - - {% block meta %} - {% endblock %} - {% if app.request.locale == 'ach_UG' %} - - - {% endif %} - {% block title %}Ibexa DXP{% endblock %} - {{ encore_entry_link_tags('ibexa-admin-ui-layout-css', null, 'ibexa') }} - - - {% block stylesheets %}{% endblock %} - - - - - - -
- {% block content %} - {% endblock content %} -
-
+ + + + {% if app.request.locale == 'ach_UG' %} + + + {% endif %} + {% block title %}Ibexa DXP{% endblock %} + {{ encore_entry_link_tags('ibexa-admin-ui-layout-css', null, 'ibexa') }} + {% block stylesheets %}{% endblock %} + + + + + + + + {% block header_row %} +
+
+ + Ibexa + +
+
+ {% block user_menu %} + {{ knp_menu_render('ezplatform_admin_ui.menu.user', { + 'depth': 1, + 'template': '@ibexadesign/ui/menu/user.html.twig' + }) }} + {% endblock %} +
+
+ {% endblock %} - {{ encore_entry_script_tags('ibexa-admin-ui-error-page-js', null, 'ibexa') }} - {{ ez_render_component_group('stylesheet-body') }} - + {% block main_container %} +
+ {% block content_column %} +
+
+ {% block content %}{% endblock %} +
+
+ {% endblock %} + +
+ {% endblock %} +
+ + {% if not is_back_to_top_disabled|default(false) %} + {% block back_to_top %} +
+ +
+ {% endblock %} + {% endif %} + + {{ encore_entry_script_tags('ibexa-admin-ui-error-page-js', null, 'ibexa') }} + {{ ibexa_render_component_group('stylesheet-body') }} +