-
Notifications
You must be signed in to change notification settings - Fork 10
[T2910] [MIG] - Migrate website_child_protection (Work In Progress, don't merge it) #272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 18.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../website_child_protection |
| 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, | ||
| ) |
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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") | ||
|
Comment on lines
+80
to
+81
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When the form is submitted without the 'agreed' checkbox checked, you redirect the user back to the form with 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", | ||
|
|
@@ -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", | ||
|
|
||
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using inline styles (
Suggested change
|
||||||||||||||||||||||||||||||||
| </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" /> | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The redirect to the confirmation page loses the original
redirectquery parameter. This can lead to incorrect navigation for users who have already agreed to the charter. Theredirectparameter should be preserved, similar to how it's handled in thechild_protection_charter_submitmethod.