From c9dec92c88f2ff6dfa75afd1a88360a28b01c681 Mon Sep 17 00:00:00 2001 From: SlWa99 Date: Fri, 30 Jan 2026 14:25:47 +0100 Subject: [PATCH] [T2910] MIG: Work in progress, see PR for explanation --- .pre-commit-config.yaml | 2 - .../odoo/addons/website_child_protection | 1 + setup/website_child_protection/setup.py | 6 + website_child_protection/README.rst | 2 +- website_child_protection/__init__.py | 2 +- website_child_protection/__manifest__.py | 9 +- website_child_protection/controllers/main.py | 63 +++++++++-- website_child_protection/data/form_data.xml | 21 ---- .../security/ir.model.access.csv | 2 - .../static/description/index.html | 7 +- .../static/src/js/website_child_protection.js | 25 ----- website_child_protection/templates/assets.xml | 8 -- .../templates/child_protection_charter.xml | 103 +++++------------- website_child_protection/wizards/__init__.py | 3 - ...agreement_child_protection_charter_form.py | 35 ------ 15 files changed, 93 insertions(+), 196 deletions(-) create mode 120000 setup/website_child_protection/odoo/addons/website_child_protection create mode 100644 setup/website_child_protection/setup.py delete mode 100644 website_child_protection/data/form_data.xml delete mode 100644 website_child_protection/security/ir.model.access.csv delete mode 100644 website_child_protection/static/src/js/website_child_protection.js delete mode 100644 website_child_protection/templates/assets.xml delete mode 100644 website_child_protection/wizards/__init__.py delete mode 100644 website_child_protection/wizards/agreement_child_protection_charter_form.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f32877a75..7daa91d64 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,10 +9,8 @@ exclude: | ^theme_compassion_2025/| ^theme_crowdfunding/| ^theme_muskathlon/| - ^website_child_protection/| ^website_crm_request/| ^website_event_compassion/| - ^website_remove_shop/| ^website_sale_donation/| ^website_sponsorship/| # END NOT INSTALLABLE ADDONS diff --git a/setup/website_child_protection/odoo/addons/website_child_protection b/setup/website_child_protection/odoo/addons/website_child_protection new file mode 120000 index 000000000..a66f4946c --- /dev/null +++ b/setup/website_child_protection/odoo/addons/website_child_protection @@ -0,0 +1 @@ +../../../../website_child_protection \ No newline at end of file diff --git a/setup/website_child_protection/setup.py b/setup/website_child_protection/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/website_child_protection/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/website_child_protection/README.rst b/website_child_protection/README.rst index 66965cf4c..1cf5f3cc7 100644 --- a/website_child_protection/README.rst +++ b/website_child_protection/README.rst @@ -51,7 +51,7 @@ Authors Contributors ------------ -- Emanuel Cino +- Emanuel Cino Maintainers ----------- diff --git a/website_child_protection/__init__.py b/website_child_protection/__init__.py index 98309e532..9613a24bd 100644 --- a/website_child_protection/__init__.py +++ b/website_child_protection/__init__.py @@ -1,3 +1,3 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from . import controllers, wizards +from . import controllers diff --git a/website_child_protection/__manifest__.py b/website_child_protection/__manifest__.py index f06942c66..953007fb5 100644 --- a/website_child_protection/__manifest__.py +++ b/website_child_protection/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Website - Child protection agreement", "summary": "Adds a form for letting partners agree with the child protection", - "version": "14.0.1.0.0", + "version": "18.0.1.0.0", "development_status": "Beta", "category": "Website", "website": "https://github.com/CompassionCH/compassion-website", @@ -11,15 +11,12 @@ "maintainers": ["ecino"], "license": "AGPL-3", "application": False, - "installable": False, + "installable": True, "depends": [ - "website_form", + "website", "child_protection", ], "data": [ - "security/ir.model.access.csv", - "templates/assets.xml", "templates/child_protection_charter.xml", - "data/form_data.xml", ], } diff --git a/website_child_protection/controllers/main.py b/website_child_protection/controllers/main.py index 72e8a0752..589667b1f 100644 --- a/website_child_protection/controllers/main.py +++ b/website_child_protection/controllers/main.py @@ -34,32 +34,71 @@ def child_protection_charter(self, partner_uuid=None, **kwargs): :param kwargs: The remaining query string parameters. :return: The rendered web page. """ + partner = None + # Need sudo() to bypass domain restriction on res.partner for anonymous # users. if partner_uuid: partner = ( request.env["res.partner"].sudo().search([("uuid", "=", partner_uuid)]) ) - else: + + if not partner and not request.env.user._is_public(): partner = request.env.user.partner_id partner_uuid = partner.uuid if not partner: return request.redirect("/") - current_time = datetime.datetime.now() date_signed = partner.date_agreed_child_protection_charter - if date_signed and (current_time - date_signed).days < 365: - return self.child_protection_charter_agreed(**kwargs) - else: - values = { - "partner_uuid": partner_uuid, - "redirect": kwargs.get("redirect"), - } - return request.render( - "website_child_protection.child_protection_charter_page", values + if date_signed and (datetime.datetime.now() - date_signed).days < 365: + return request.redirect("/partner/child-protection-charter-agreed") + + values = { + "partner_uuid": partner_uuid, + "redirect": kwargs.get("redirect"), + } + return request.render( + "website_child_protection.child_protection_charter_page", values + ) + + @http.route( + "/partner/child-protection-charter/submit", + type="http", + auth="public", + methods=["POST"], + website=True, + csrf=True, + ) + def child_protection_charter_submit(self, **kwargs): + partner_uuid = kwargs.get("partner_uuid") + agreed = kwargs.get("agreed") + + if not partner_uuid and not request.env.user._is_public(): + partner_uuid = request.env.user.partner_id.uuid + + if not agreed: + return request.redirect(request.httprequest.referrer + "?error=required") + + partner = ( + request.env["res.partner"] + .sudo() + .search([("uuid", "=", partner_uuid)], limit=1) + ) + + if partner: + partner.sudo().write( + {"date_agreed_child_protection_charter": datetime.datetime.now()} ) + redirect_url = kwargs.get("redirect") + target = "/partner/child-protection-charter-agreed" + if redirect_url: + target += "?redirect=" + redirect_url + return request.redirect(target) + + return request.redirect("/") + @http.route( route="/partner/child-protection-charter-agreed", auth="public", @@ -68,7 +107,7 @@ def child_protection_charter(self, partner_uuid=None, **kwargs): ) def child_protection_charter_agreed(self, redirect=None, **kwargs): values = { - "redirect": redirect or request.httprequest.host_url, + "redirect": redirect or "/", } return request.render( "website_child_protection.child_protection_charter_confirmation_page", diff --git a/website_child_protection/data/form_data.xml b/website_child_protection/data/form_data.xml deleted file mode 100644 index 7ea30aa27..000000000 --- a/website_child_protection/data/form_data.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - child_protection - - True - Agree the child protection charter - - - cms.form.partner.child.protection.charter - - - diff --git a/website_child_protection/security/ir.model.access.csv b/website_child_protection/security/ir.model.access.csv deleted file mode 100644 index 6b8619f51..000000000 --- a/website_child_protection/security/ir.model.access.csv +++ /dev/null @@ -1,2 +0,0 @@ -id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_child_protection_charter_form,Permission to access child protection charter form,model_cms_form_partner_child_protection_charter,,1,1,1,1 diff --git a/website_child_protection/static/description/index.html b/website_child_protection/static/description/index.html index dafac7c14..904801801 100644 --- a/website_child_protection/static/description/index.html +++ b/website_child_protection/static/description/index.html @@ -8,11 +8,10 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ +:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. -Despite the name, some widely supported CSS2 features are used. See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to customize this style sheet. @@ -275,7 +274,7 @@ margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: gray; } /* line numbers */ +pre.code .ln { color: grey; } /* line numbers */ pre.code, code { background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } @@ -301,7 +300,7 @@ span.pre { white-space: pre } -span.problematic, pre.problematic { +span.problematic { color: red } span.section-subtitle { diff --git a/website_child_protection/static/src/js/website_child_protection.js b/website_child_protection/static/src/js/website_child_protection.js deleted file mode 100644 index 31b429163..000000000 --- a/website_child_protection/static/src/js/website_child_protection.js +++ /dev/null @@ -1,25 +0,0 @@ -odoo.define("website_child_protection.form", function (require) { - "use strict"; - - var core = require("web.core"); - var FormEditorRegistry = require("website_form.form_editor_registry"); - - var _t = core._t; - - FormEditorRegistry.add("child_protection", { - formFields: [ - { - type: "boolean", - modelRequired: true, - name: "agreed", - string: _t("Check to agree to this charter"), - }, - { - type: "hidden", - modelRequired: true, - name: "partner_uuid", - string: "UUID", - }, - ], - }); -}); diff --git a/website_child_protection/templates/assets.xml b/website_child_protection/templates/assets.xml deleted file mode 100644 index 826dd97ce..000000000 --- a/website_child_protection/templates/assets.xml +++ /dev/null @@ -1,8 +0,0 @@ - - -