Skip to content
Open
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
2 changes: 0 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions setup/website_child_protection/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,
)
2 changes: 1 addition & 1 deletion website_child_protection/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Authors
Contributors
------------

- Emanuel Cino <ecino@compassion.ch>
- Emanuel Cino <ecino@compassion.ch>

Maintainers
-----------
Expand Down
2 changes: 1 addition & 1 deletion website_child_protection/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import controllers, wizards
from . import controllers
9 changes: 3 additions & 6 deletions website_child_protection/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,20 @@
{
"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",
"author": "Compassion Switzerland",
"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",
],
}
63 changes: 51 additions & 12 deletions website_child_protection/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Comment on lines +54 to +55
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The redirect to the confirmation page loses the original redirect query parameter. This can lead to incorrect navigation for users who have already agreed to the charter. The redirect parameter should be preserved, similar to how it's handled in the child_protection_charter_submit method.

        if date_signed and (datetime.datetime.now() - date_signed).days < 365:
            target = "/partner/child-protection-charter-agreed"
            redirect_url = kwargs.get("redirect")
            if redirect_url:
                target += "?redirect=" + redirect_url
            return request.redirect(target)


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")
Comment on lines +80 to +81
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When the form is submitted without the 'agreed' checkbox checked, you redirect the user back to the form with ?error=required. However, the template child_protection_charter.xml does not handle this query parameter to display an error message to the user. This results in a poor user experience as they are not informed why the submission failed.

You should add logic to the template to display an error message. For example:

<t t-if="request.params.get('error') == 'required'">
    <div class="alert alert-danger" role="alert">
        You must agree to the charter to continue.
    </div>
</t>


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",
Expand All @@ -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",
Expand Down
21 changes: 0 additions & 21 deletions website_child_protection/data/form_data.xml

This file was deleted.

2 changes: 0 additions & 2 deletions website_child_protection/security/ir.model.access.csv

This file was deleted.

7 changes: 3 additions & 4 deletions website_child_protection/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 }
Expand All @@ -301,7 +300,7 @@
span.pre {
white-space: pre }

span.problematic, pre.problematic {
span.problematic {
color: red }

span.section-subtitle {
Expand Down
25 changes: 0 additions & 25 deletions website_child_protection/static/src/js/website_child_protection.js

This file was deleted.

8 changes: 0 additions & 8 deletions website_child_protection/templates/assets.xml

This file was deleted.

103 changes: 27 additions & 76 deletions website_child_protection/templates/child_protection_charter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -186,89 +186,40 @@
data-for="child_protection_form"
t-att-data-values="{'partner_uuid': partner_uuid}"
/>
<section
class="s_website_form pt16 pb16 o_colored_level"
data-vcss="001"
data-snippet="s_website_form"
data-name="Form"
>
<section class="pt16 pb48">
<div class="container">
<form
id="child_protection_form"
action="/website_form/"
method="post"
enctype="multipart/form-data"
class="o_mark_required"
data-mark="*"
data-success-mode="redirect"
t-attf-data-success-page="/partner/#{partner_uuid}/child-protection-charter#{'?redirect=' + redirect if redirect else ''}"
data-model_name="cms.form.partner.child.protection.charter"
>
<div class="s_website_form_rows row s_col_no_bgcolor">
<div
class="form-group s_website_form_field col-12 s_website_form_model_required "
data-type="boolean"
data-name="Field"
<div class="row">
<div class="col-12">
<form
action="/partner/child-protection-charter/submit"
method="post"
enctype="multipart/form-data"
>
<div class="row s_col_no_resize s_col_no_bgcolor">
<label
class="col-sm-auto s_website_form_label"
style="width: 200px"
for="partner_uuid"
>
<span class="s_website_form_label_content">
<input type="hidden" name="csrf_token" t-att-value="request.csrf_token()" />
<input type="hidden" name="partner_uuid" t-att-value="partner_uuid" />
<input type="hidden" name="redirect" t-att-value="redirect" />
<div class="d-flex align-items-center">
<label class="form-check-label me-2" for="agreed">
<b>
Check to agree to this charter
</span>
<span class="s_website_form_mark">*</span>
<span class="text-danger">*</span>
</b>
</label>
<div class="col-sm">
<input
type="checkbox"
value="Yes"
class="s_website_form_input"
name="agreed"
required="true"
id="agreed"
/>
</div>
<input
class="form-check-input"
type="checkbox"
name="agreed"
id="agreed"
required="required"
style="margin-top:0;"
/>
Comment on lines +208 to +215
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using inline styles (style="margin-top:0;") is generally discouraged for maintainability. It's better to use CSS classes. Since you are using Bootstrap, you can use a margin utility class like mt-0 to achieve the same result while keeping the markup cleaner.

Suggested change
<input
class="form-check-input"
type="checkbox"
name="agreed"
id="agreed"
required="required"
style="margin-top:0;"
/>
<input
class="form-check-input mt-0"
type="checkbox"
name="agreed"
id="agreed"
required="required"
/>

</div>
</div>
<div
class="form-group s_website_form_field col-12 s_website_form_model_required s_website_form_dnone"
data-type="hidden"
data-name="Field"
>
<div class="row s_col_no_resize s_col_no_bgcolor">
<label
class="col-form-label col-sm-auto s_website_form_label "
style="width: 200px"
for="agreed"
>
<span class="s_website_form_label_content">UUID</span>
</label>
<div class="col-sm">
<input
type="hidden"
class="form-control s_website_form_input"
name="partner_uuid"
id="partner_uuid"
/>
</div>
<div class="mt-4 text-center">
<button type="submit" class="btn btn-primary btn-lg px-5">Submit</button>
</div>
</div>
<div class="form-group col-12 s_website_form_submit" data-name="Submit Button">
<div style="width: 200px;" class="s_website_form_label" />
<a
href="#"
role="button"
class="btn btn-primary btn-lg s_website_form_send o_default_snippet_text"
>
Submit
</a>
<span id="s_website_form_result" />
</div>
</form>
</div>
</form>
</div>
</div>
</section>
<div class="oe_structure mt-2" />
Expand Down
3 changes: 0 additions & 3 deletions website_child_protection/wizards/__init__.py

This file was deleted.

Loading