odoo/odoo#116839
Created by Website, Benoit Socias (bso)
Blocked
- Merge method
- Review
-
CI
- legal/cla: Contributor License Agreement check
- ci/runbot: Odoo Test Suite
- ci/upgrade_enterprise: Test upgrades for enterprise master
- ci/template: Contact runbot team on discord for help.
- ci/style: Optional style check. Ignore it only if strictly necessary.
- ci/security: Required security check. Can only be ignored by security team.
- label
- odoo-dev:14.0-warn_media_deletion-bso
- head
- 8cb347152d47d1c51e46eb04f2cc60910f52ccb4
- target
- 15.0
[FIX] web_editor, website: prevent deletion of used attachment
The deletion of used attachments from the media dialog is prevented
since [1]. It is possible that it worked at the time, but that it
stopped working in [2] when the routes for attachments have been
updated.
Also, it only checked for the presence of attachments in views,
ignoring other HTML fields.
This commit fixes the existing mechanism and also limits the search on
views to QWeb views, and adds the check across other HTML fields.
The fields inside ir.action models and mail messages are explicitly
blacklisted, similarly to what exists in 15.0.
This commit also detects non-image attachments which are obtained
through the `/web/content/...` route.
It also adapts the link within the warning so that the website page of
the blocking object is reached if there is one, otherwise it falls back
onto the backend page of the object.
In 15.0, the list of fields should be obtained from `website`'s
`_get_html_fields` instead of duplicating its mechanism.
In 16.0, apply the same principle to the menu dependencies which were
restored by [3] and [4].
Steps to reproduce:
- Drop a Text - Image block on a website page/a product page.
- Upload an attachment in that block.
- Save.
- Edit another page.
- In the media dialog, delete the uploaded attachment.
=> Attachment is deleted and page contains a missing image/document.
[1]: https://github.com/odoo/odoo/commit/e78a3b18cc6c049a712d594ab70287c486447f0a
[2]: https://github.com/odoo/odoo/commit/6baf611df1064a3ae5f6368d3a35b3c3d7779543
[3]: https://github.com/odoo/odoo/commit/11db2f6ed81419ac724ff27ac95a4438d670cbd5
[4]: https://github.com/odoo/odoo/commit/6ac17b93437868cbefbe13448a6fcbb29953f221
task-3223788