Skip to content

Commit 056bcd2

Browse files
committed
[ADD] web_editor_clean_url
1 parent 6ece7e1 commit 056bcd2

21 files changed

Lines changed: 1009 additions & 0 deletions
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../web_editor_clean_url
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import setuptools
2+
3+
setuptools.setup(
4+
setup_requires=['setuptools-odoo'],
5+
odoo_addon=True,
6+
)

web_editor_clean_url/README.rst

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
============================
2+
Clean URLs in website editor
3+
============================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:2f68fbe3909f6e172b2af03d877a484e1b3690fd85a91b130e4ab51229b28034
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Alpha
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fwebsite-lightgray.png?logo=github
20+
:target: https://github.com/OCA/website/tree/16.0/web_editor_clean_url
21+
:alt: OCA/website
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/website-16-0/website-16-0-web_editor_clean_url
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/website&target_branch=16.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module allows administrators to configure cleanup rules for links
32+
inserted by their users, as inexperienced people tend to just copy&paste
33+
whatever they find in their address bar, which might contain data you do
34+
not want to see published on your website, be it tracking tokens or
35+
session identifiers.
36+
37+
.. IMPORTANT::
38+
This is an alpha version, the data model and design can change at any time without warning.
39+
Only for development or testing purpose, do not use in production.
40+
`More details on development status <https://odoo-community.org/page/development-status>`_
41+
42+
**Table of contents**
43+
44+
.. contents::
45+
:local:
46+
47+
Configuration
48+
=============
49+
50+
You find the configuration in Website / Configuration / Clean URLs.
51+
52+
For every configuration, you can fill in:
53+
54+
``Hostname``: allowing to restrict this configuration to some domain
55+
56+
``Remove Query Parameter``: removes parameters from the URL. Separate
57+
with comma
58+
59+
``Replace Regex``: replaces a whole portion of the url
60+
61+
``Substitution``: if the regex contains brackets, you can refer to the
62+
matched content with \\1, \\2 etc
63+
64+
Usage
65+
=====
66+
67+
To use this module, you need to:
68+
69+
1. Review the configuration
70+
2. Edit a website page, insert links and observe they are transformed as
71+
configured after saving
72+
73+
Bug Tracker
74+
===========
75+
76+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/website/issues>`_.
77+
In case of trouble, please check there if your issue has already been reported.
78+
If you spotted it first, help us to smash it by providing a detailed and welcomed
79+
`feedback <https://github.com/OCA/website/issues/new?body=module:%20web_editor_clean_url%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
80+
81+
Do not contact contributors directly about support or help with technical issues.
82+
83+
Credits
84+
=======
85+
86+
Authors
87+
-------
88+
89+
* Hunki Enterprises BV
90+
91+
Contributors
92+
------------
93+
94+
- Holger Brunn <mail@hunki-enterprises.com>
95+
(https://hunki-enterprises.com)
96+
97+
Maintainers
98+
-----------
99+
100+
This module is maintained by the OCA.
101+
102+
.. image:: https://odoo-community.org/logo.png
103+
:alt: Odoo Community Association
104+
:target: https://odoo-community.org
105+
106+
OCA, or the Odoo Community Association, is a nonprofit organization whose
107+
mission is to support the collaborative development of Odoo features and
108+
promote its widespread use.
109+
110+
.. |maintainer-hbrunn| image:: https://github.com/hbrunn.png?size=40px
111+
:target: https://github.com/hbrunn
112+
:alt: hbrunn
113+
114+
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
115+
116+
|maintainer-hbrunn|
117+
118+
This module is part of the `OCA/website <https://github.com/OCA/website/tree/16.0/web_editor_clean_url>`_ project on GitHub.
119+
120+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

web_editor_clean_url/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# from . import controllers
2+
from . import models
3+
4+
# from . import report
5+
# from . import wizards
6+
# from .hooks import post_init_hook, post_load, pre_init_hook, uninstall_hook
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2026 Hunki Enterprises BV
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0)
3+
4+
{
5+
"name": "Clean URLs in website editor",
6+
"summary": "Remove tracking, ephemeral and similar parameters from URLs",
7+
"version": "16.0.1.0.0",
8+
"development_status": "Alpha",
9+
"category": "Website/Website",
10+
"website": "https://github.com/OCA/website",
11+
"author": "Hunki Enterprises BV, Odoo Community Association (OCA)",
12+
"maintainers": ["hbrunn"],
13+
"license": "AGPL-3",
14+
"depends": [
15+
"website",
16+
],
17+
"data": [
18+
"data/ir_actions_server.xml",
19+
"data/web_editor_clean_url_configuration.xml",
20+
"security/ir.model.access.csv",
21+
"views/web_editor_clean_url_configuration.xml",
22+
"views/menu.xml",
23+
],
24+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<!-- Copyright 2026 Hunki Enterprises BV
3+
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) -->
4+
<data>
5+
<record id="action_apply" model="ir.actions.server">
6+
<field name="name">Apply to all views</field>
7+
<field name="model_id" ref="model_web_editor_clean_url_configuration" />
8+
<field name="state">code</field>
9+
<field name="code">records.apply_all()</field>
10+
<field name="binding_model_id" ref="model_web_editor_clean_url_configuration" />
11+
<field name="binding_type">action</field>
12+
</record>
13+
</data>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<!-- Copyright 2026 Hunki Enterprises BV
3+
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) -->
4+
<data>
5+
<record id="config_fbclid" model="web.editor.clean.url.configuration">
6+
<field name="remove_query_parameter">fbclid</field>
7+
</record>
8+
</data>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import ir_ui_view
2+
from . import web_editor_clean_url_configuration
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Copyright 2026 Hunki Enterprises BV
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0)
3+
4+
from urllib.parse import urlparse, urlunparse
5+
6+
from lxml import html
7+
8+
from odoo import models
9+
10+
11+
class IrUiView(models.Model):
12+
_inherit = "ir.ui.view"
13+
14+
def save(self, value, xpath=None):
15+
value = self._web_editor_clean_url_clean_arch(value)
16+
return super().save(value, xpath)
17+
18+
def _web_editor_clean_url_clean_arch(self, arch, configurations=None):
19+
"""
20+
Clean all urls in given arch
21+
"""
22+
arch = html.fromstring(arch, parser=html.HTMLParser(encoding="utf-8"))
23+
24+
for xpath, attributes in self._web_editor_clean_url_selectors():
25+
for element in arch.xpath(xpath):
26+
self._web_editor_clean_url_clean_element(
27+
element, attributes, configurations=configurations
28+
)
29+
30+
return html.tostring(arch)
31+
32+
def _web_editor_clean_url_selectors(self):
33+
"""
34+
Return xpaths for to find elements with urls to be cleaned and the attributes
35+
containing them
36+
"""
37+
return [
38+
("//a[@href]", ("href",)),
39+
]
40+
41+
def _web_editor_clean_url_clean_element(
42+
self, element, attributes, configurations=None
43+
):
44+
"""
45+
Clean urls of element found in attributes
46+
"""
47+
for attribute in attributes:
48+
if not element.get(attribute):
49+
continue
50+
element.attrib[attribute] = self._web_editor_clean_url(
51+
element.attrib[attribute],
52+
configurations=configurations,
53+
)
54+
55+
def _web_editor_clean_url(self, url, configurations=None):
56+
"""
57+
Clean url
58+
"""
59+
parsed_url = urlparse(url)
60+
for configuration in configurations or self.env[
61+
"web.editor.clean.url.configuration"
62+
].sudo().search([]):
63+
parsed_url = configuration.clean_url(parsed_url)
64+
return urlunparse(parsed_url)

0 commit comments

Comments
 (0)