Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions setup/web_editor_clean_url/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
120 changes: 120 additions & 0 deletions web_editor_clean_url/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
============================
Clean URLs in website editor
============================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:2f68fbe3909f6e172b2af03d877a484e1b3690fd85a91b130e4ab51229b28034
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fwebsite-lightgray.png?logo=github
:target: https://github.com/OCA/website/tree/16.0/web_editor_clean_url
:alt: OCA/website
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/website-16-0/website-16-0-web_editor_clean_url
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/website&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows administrators to configure cleanup rules for links
inserted by their users, as inexperienced people tend to just copy&paste
whatever they find in their address bar, which might contain data you do
not want to see published on your website, be it tracking tokens or
session identifiers.

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
:local:

Configuration
=============

You find the configuration in Website / Configuration / Clean URLs.

For every configuration, you can fill in:

``Hostname``: allowing to restrict this configuration to some domain

``Remove Query Parameter``: removes parameters from the URL. Separate
with comma

``Replace Regex``: replaces a whole portion of the url

``Substitution``: if the regex contains brackets, you can refer to the
matched content with \\1, \\2 etc

Usage
=====

To use this module, you need to:

1. Review the configuration
2. Edit a website page, insert links and observe they are transformed as
configured after saving

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/website/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`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**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Hunki Enterprises BV

Contributors
------------

- Holger Brunn <mail@hunki-enterprises.com>
(https://hunki-enterprises.com)

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-hbrunn| image:: https://github.com/hbrunn.png?size=40px
:target: https://github.com/hbrunn
:alt: hbrunn

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-hbrunn|

This module is part of the `OCA/website <https://github.com/OCA/website/tree/16.0/web_editor_clean_url>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
6 changes: 6 additions & 0 deletions web_editor_clean_url/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# from . import controllers
from . import models

# from . import report
# from . import wizards
# from .hooks import post_init_hook, post_load, pre_init_hook, uninstall_hook
24 changes: 24 additions & 0 deletions web_editor_clean_url/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2026 Hunki Enterprises BV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0)

{
"name": "Clean URLs in website editor",
"summary": "Remove tracking, ephemeral and similar parameters from URLs",
"version": "16.0.1.0.0",
"development_status": "Alpha",
"category": "Website/Website",
"website": "https://github.com/OCA/website",
"author": "Hunki Enterprises BV, Odoo Community Association (OCA)",
"maintainers": ["hbrunn"],
"license": "AGPL-3",
"depends": [
"website",
],
"data": [
"data/ir_actions_server.xml",
"data/web_editor_clean_url_configuration.xml",
"security/ir.model.access.csv",
"views/web_editor_clean_url_configuration.xml",
"views/menu.xml",
],
}
13 changes: 13 additions & 0 deletions web_editor_clean_url/data/ir_actions_server.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2026 Hunki Enterprises BV
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) -->
<data>
<record id="action_apply" model="ir.actions.server">
<field name="name">Apply to all views</field>
<field name="model_id" ref="model_web_editor_clean_url_configuration" />
<field name="state">code</field>
<field name="code">records.apply_all()</field>
<field name="binding_model_id" ref="model_web_editor_clean_url_configuration" />
<field name="binding_type">action</field>
</record>
</data>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2026 Hunki Enterprises BV
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) -->
<data>
<record id="config_fbclid" model="web.editor.clean.url.configuration">
<field name="remove_query_parameter">fbclid</field>
</record>
</data>
2 changes: 2 additions & 0 deletions web_editor_clean_url/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import ir_ui_view
from . import web_editor_clean_url_configuration
60 changes: 60 additions & 0 deletions web_editor_clean_url/models/ir_ui_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright 2026 Hunki Enterprises BV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0)


from lxml import html

from odoo import models


class IrUiView(models.Model):
_inherit = "ir.ui.view"

def save(self, value, xpath=None):
arch = html.fromstring(value, parser=html.HTMLParser(encoding="utf-8"))
value = html.tostring(self._web_editor_clean_url_clean_arch(arch))
return super().save(value, xpath)

def _web_editor_clean_url_clean_arch(self, arch, configurations=None):
"""
Clean all urls in given arch
"""
for xpath, attributes in self._web_editor_clean_url_selectors():
for element in arch.xpath(xpath):
self._web_editor_clean_url_clean_element(
element, attributes, configurations=configurations
)
return arch

def _web_editor_clean_url_selectors(self):
"""
Return xpaths for to find elements with urls to be cleaned and the attributes
containing them
"""
return [
("//a[@href]", ("href",)),
]

def _web_editor_clean_url_clean_element(
self, element, attributes, configurations=None
):
"""
Clean urls of element found in attributes
"""
for attribute in attributes:
if not element.get(attribute):
continue
element.attrib[attribute] = self._web_editor_clean_url(
element.attrib[attribute],
configurations=configurations,
)

def _web_editor_clean_url(self, url, configurations=None):
"""
Clean url
"""
for configuration in configurations or self.env[
"web.editor.clean.url.configuration"
].sudo().search([]):
url = configuration.clean_url(url)
return url
Loading