From 6bab7a6ae58b9d2df4e3d1ce0a475ce89f937280 Mon Sep 17 00:00:00 2001 From: Damien Bouvy Date: Mon, 2 Oct 2023 10:52:51 +0200 Subject: [PATCH] [IMP] base: reflect html sanitization attributes Up until this commit, HTML fields created from the UI or via data modules or via Studio where alway sanitized, without any possibility of control by the developper or db admin. This commit makes it possible to override these attributes for data-defined fields (python-defined fields cannot be overriden). This makes it possible to create fields that can e.g. be used as 'block targets' in the website editor for data modules. closes odoo/odoo#130544 Related: odoo/enterprise#47116 Related: odoo/upgrade#5290 Signed-off-by: Lucas Perais (lpe) --- odoo/addons/base/models/ir_model.py | 28 +++++++++++++++++++++ odoo/addons/base/views/ir_model_views.xml | 30 +++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/odoo/addons/base/models/ir_model.py b/odoo/addons/base/models/ir_model.py index 64ff764146d..97befdf3df5 100644 --- a/odoo/addons/base/models/ir_model.py +++ b/odoo/addons/base/models/ir_model.py @@ -550,6 +550,16 @@ class IrModelFields(models.Model): " name, partner_id.name") store = fields.Boolean(string='Stored', default=True, help="Whether the value is stored in the database.") currency_field = fields.Char(string="Currency field", help="Name of the Many2one field holding the res.currency") + # HTML sanitization reflection, useless for other kinds of fields + sanitize = fields.Boolean(string='Sanitize HTML', default=True) + sanitize_overridable = fields.Boolean(string='Sanitize HTML overridable', default=False) + sanitize_tags = fields.Boolean(string='Sanitize HTML Tags', default=True) + sanitize_attributes = fields.Boolean(string='Sanitize HTML Attributes', default=True) + sanitize_style = fields.Boolean(string='Sanitize HTML Style', default=False) + sanitize_form = fields.Boolean(string='Sanitize HTML Form', default=True) + strip_style = fields.Boolean(string='Strip Style Attribute', default=False) + strip_classes = fields.Boolean(string='Strip Class Attribute', default=False) + @api.depends('relation', 'relation_field') def _compute_relation_field_id(self): @@ -1091,6 +1101,15 @@ class IrModelFields(models.Model): 'column1': field.column1 if field.type == 'many2many' else None, 'column2': field.column2 if field.type == 'many2many' else None, 'currency_field': field.currency_field if field.type == 'monetary' else None, + # html sanitization attributes (useless for other fields) + 'sanitize': field.sanitize if field.type == 'html' else None, + 'sanitize_overridable': field.sanitize_overridable if field.type == 'html' else None, + 'sanitize_tags': field.sanitize_tags if field.type == 'html' else None, + 'sanitize_attributes': field.sanitize_attributes if field.type == 'html' else None, + 'sanitize_style': field.sanitize_style if field.type == 'html' else None, + 'sanitize_form': field.sanitize_form if field.type == 'html' else None, + 'strip_style': field.strip_style if field.type == 'html' else None, + 'strip_classes': field.strip_classes if field.type == 'html' else None, } def _reflect_fields(self, model_names): @@ -1192,6 +1211,15 @@ class IrModelFields(models.Model): attrs['translate'] = bool(field_data['translate']) if field_data['ttype'] == 'char': attrs['size'] = field_data['size'] or None + elif field_data['ttype'] == 'html': + attrs['sanitize'] = field_data['sanitize'] + attrs['sanitize_overridable'] = field_data['sanitize_overridable'] + attrs['sanitize_tags'] = field_data['sanitize_tags'] + attrs['sanitize_attributes'] = field_data['sanitize_attributes'] + attrs['sanitize_style'] = field_data['sanitize_style'] + attrs['sanitize_form'] = field_data['sanitize_form'] + attrs['strip_style'] = field_data['strip_style'] + attrs['strip_classes'] = field_data['strip_classes'] elif field_data['ttype'] in ('selection', 'reference'): attrs['selection'] = self.env['ir.model.fields.selection']._get_selection_data(field_data['id']) if field_data['ttype'] == 'selection': diff --git a/odoo/addons/base/views/ir_model_views.xml b/odoo/addons/base/views/ir_model_views.xml index c4d084b17a2..2304e19e045 100644 --- a/odoo/addons/base/views/ir_model_views.xml +++ b/odoo/addons/base/views/ir_model_views.xml @@ -309,6 +309,36 @@ required="ttype == 'monetary'"/> + + + + + + + + + + + + + +