From 954e690edddaa54409ff2faaa2ca781740f281f3 Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Mon, 26 Sep 2022 13:12:39 +0000 Subject: [PATCH] [FIX] website: restore SCSS edition of auto-edited SCSS files If an user modifies a theme value through the "Theme" tab of the website builder, a custo of the related SCSS file is made. To make a SCSS custo, the related python methods need to know for which bundle the custo is made. This is to ensure that if a file appears in multiple bundles, the custo targets the right one (amongst other things). For those automatic SCSS custo made via the website builder, the given bundle does not matter as those are custo made in variables SCSS files, which appear in all bundles, more precisely in a sub-bundle included in all bundles. The code should be more robust to leverage that fact. When the "assets_frontend" received all "assets_common" files in order to only use one unique bundle for main frontend pages with [1], it was though smart to leave that given bundle to "assets_common" although "assets_common" is not used on the frontend anymore as it would allow to not care about migration of those automatically edit SCSS files and it was also "not wrong" as you effectively cannot edit those files without impacting all bundles. It was although very wrong as editing those variables files via the SCSS editor automatically considers them as part of "assets_frontend" and not "assets_common". So editing them via the SCSS editor would create/update the files relying on the fact the related bundle is "assets_frontend" but the website builder would create/update them relying on the fact the related bundle is "assets_common". This would lead to creating two ir.asset records trying to replace the same file in the sub-bundle which is used by both those assets... and thus to make the database crash. The work done at [1] actually forgot about other things related to all this. Those will of course be fixed but they are less urgent. This commit here just fixes the SCSS edition issue described above for now. [1]: https://github.com/odoo/odoo/commit/08dcbc8f1def06476d025b110049ee596e906816 task-2994071 closes odoo/odoo#101312 X-original-commit: 15e503a841d757e622c8ef2070043b766b28bfde Signed-off-by: Romain Derie (rde) Signed-off-by: Quentin Smetz (qsm) --- addons/website/models/assets.py | 12 +++++------- addons/website/tests/test_ui.py | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/addons/website/models/assets.py b/addons/website/models/assets.py index d60f6dc8558..14da04ee1f0 100644 --- a/addons/website/models/assets.py +++ b/addons/website/models/assets.py @@ -19,7 +19,7 @@ class Assets(models.AbstractModel): Params: url (str): the URL of the scss file to customize (supposed to be a variable - file which will appear in the assets_common bundle) + file which will appear in the assets_frontend bundle) values (dict): key,value mapping to integrate in the file's map (containing the @@ -27,8 +27,8 @@ class Assets(models.AbstractModel): overridden. """ if 'color-palettes-name' in values: - self.reset_asset('/website/static/src/scss/options/colors/user_color_palette.scss', 'web.assets_common') - self.reset_asset('/website/static/src/scss/options/colors/user_gray_color_palette.scss', 'web.assets_common') + self.reset_asset('/website/static/src/scss/options/colors/user_color_palette.scss', 'web.assets_frontend') + self.reset_asset('/website/static/src/scss/options/colors/user_gray_color_palette.scss', 'web.assets_frontend') # Do not reset all theme colors for compatibility (not removing alpha -> epsilon colors) self.make_scss_customization('/website/static/src/scss/options/colors/user_theme_color_palette.scss', { 'success': 'null', @@ -44,7 +44,7 @@ class Assets(models.AbstractModel): 'copyright-gradient': 'null', }) - custom_url = self._make_custom_asset_url(url, 'web.assets_common') + custom_url = self._make_custom_asset_url(url, 'web.assets_frontend') updatedFileContent = self._get_content_from_url(custom_url) or self._get_content_from_url(url) updatedFileContent = updatedFileContent.decode('utf-8') for name, value in values.items(): @@ -56,9 +56,7 @@ class Assets(models.AbstractModel): else: updatedFileContent = re.sub(r'( *)(.*hook.*)', r'\1%s\1\2' % replacement, updatedFileContent) - # Bundle is 'assets_common' as this route is only meant to update - # variables scss files - self.save_asset(url, 'web.assets_common', updatedFileContent, 'scss') + self.save_asset(url, 'web.assets_frontend', updatedFileContent, 'scss') @api.model def _get_custom_attachment(self, custom_url, op='='): diff --git a/addons/website/tests/test_ui.py b/addons/website/tests/test_ui.py index d30ed22e38a..9e05486ed55 100644 --- a/addons/website/tests/test_ui.py +++ b/addons/website/tests/test_ui.py @@ -30,7 +30,7 @@ class TestUiCustomizeTheme(odoo.tests.HttpCase): website_test = Website.create({'name': 'Website Test'}) # simulate attachment state when editing 2 theme through customize - custom_url = '/TEST/website/static/src/scss/options/colors/user_theme_color_palette.custom.web.assets_common.scss' + custom_url = '/TEST/website/static/src/scss/options/colors/user_theme_color_palette.custom.web.assets_frontend.scss' scss_attachment = Attachment.create({ 'name': custom_url, 'type': 'binary',