diff options
| author | nie <nie@odoo.com> | 2021-01-18 14:32:46 +0000 |
|---|---|---|
| committer | nie <nie@odoo.com> | 2021-01-19 08:32:14 +0000 |
| commit | 604c07edcd4da8cf2a663d06ba91f137eb74691b (patch) | |
| tree | e940dce74ed6f76c6e44e108757ffe9e5637e94c /addons/web/static | |
| parent | 8bfa9efd989f4123b021c47f13cfe324eeb14013 (diff) | |
[FIX] website: an erroneous Google font makes website not editable
Steps:
- Go to "Website" > "Go to Website"
- Click Edit in the top right corner
- Click Options
- Select "Add a Google Font" in the Font Family field
- Insert an erroneous Google Font link (e.g. https://fonts.google.com/specimen/Robotoj )
- Save & Reload
- Click Edit again
Bug:
The Edit button is not responding anymore
Explanation:
We try to `@import` the link in multiple files.
For example, here: https://github.com/odoo/odoo/blob/70eb39b0cf30c1acf9a7116e109874b60e27aa2c/addons/website/static/src/scss/website.scss#L10
An erroneous font family results in an error 400 from the Google Fonts
server. This prevents parts of the JS to load and makes it impossible to
enter the edition mode.
`EditPageMenu` handles the behavior when clicking on the Edit button.
This menu depends on `website.compiled_assets_wysiwyg` as seen here:
https://github.com/odoo/odoo/blob/b02a99bec709b5a6dc4dabb6cb81435dadc24e7e/addons/website/static/src/js/menu/edit.js#L10-L14
Since there is an error generating the file, the Promise fails but the
error is not handled:
https://github.com/odoo/odoo/blob/70eb39b0cf30c1acf9a7116e109874b60e27aa2c/addons/web/static/src/js/core/ajax.js#L164-L168
This commit prevents CSS loading errors from silently failing. The crash
screen will only show up if the user is logged in and has edition
rights.
This commit also prevents the user from posting the form if the font is
not accessible. At the moment, querying an unknown Google font from a
script will result in a CORS error. A valid one will pass just fine. In
case Google changes the behavior of these queries and allows the 400 to
be sent, the fix also checks if the query returned an `ok` status code.
opw:2439073
closes odoo/odoo#64695
Signed-off-by: backspac <backspac@users.noreply.github.com>
Diffstat (limited to 'addons/web/static')
| -rw-r--r-- | addons/web/static/src/js/core/ajax.js | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/addons/web/static/src/js/core/ajax.js b/addons/web/static/src/js/core/ajax.js index ae3194e2a45..a35c793e5c6 100644 --- a/addons/web/static/src/js/core/ajax.js +++ b/addons/web/static/src/js/core/ajax.js @@ -164,6 +164,8 @@ var loadCSS = (function () { urlDefs[url] = new Promise(function (resolve, reject) { $link.on('load', function () { resolve(); + }).on('error', function () { + reject(new Error("Couldn't load css dependency: " + $link[0].href)); }); }); $('head').append($link); |
