Skip to content

Commit

Permalink
Merge pull request #312 from coopiteasy/12.0-komunigi-cooperator_webs…
Browse files Browse the repository at this point in the history
…ite_recaptcha

[REF] Split cooperator_website into cooperator_website_recaptcha
  • Loading branch information
victor-champonnois committed May 3, 2022
2 parents 5b06e54 + dd7c4d2 commit 279d34b
Show file tree
Hide file tree
Showing 18 changed files with 119 additions and 46 deletions.
1 change: 0 additions & 1 deletion cooperator_website/__init__.py
@@ -1,2 +1 @@
from . import controllers
from . import models
2 changes: 0 additions & 2 deletions cooperator_website/__manifest__.py
Expand Up @@ -9,7 +9,6 @@
"depends": [
"cooperator",
"website",
"portal_recaptcha",
],
"author": "Coop IT Easy SCRLfs",
"category": "Cooperative management",
Expand All @@ -21,7 +20,6 @@
""",
"data": [
"views/subscription_template.xml",
"views/res_company_view.xml",
"data/website_cooperator_data.xml",
],
"installable": True,
Expand Down
24 changes: 0 additions & 24 deletions cooperator_website/controllers/main.py
Expand Up @@ -257,30 +257,6 @@ def validation( # noqa: C901 (method too complex)
is_company = True
redirect = "cooperator_website.becomecompanycooperator"
email = kwargs.get("company_email")
# TODO: Use a overloaded function with the captcha implementation
if request.env["res.company"].captcha_type == "google":
if (
"g-recaptcha-response" not in kwargs
or kwargs["g-recaptcha-response"] == ""
):
values = self.fill_values(values, is_company, logged)
values.update(kwargs)
values["error_msg"] = _(
"the captcha has not been validated," " please fill in the captcha"
)

return request.render(redirect, values)
elif not request.env["portal.mixin"].is_captcha_valid(
kwargs["g-recaptcha-response"]
):
values = self.fill_values(values, is_company, logged)
values.update(kwargs)
values["error_msg"] = _(
"the captcha has not been validated," " please fill in the captcha"
)

return request.render(redirect, values)

# Check that required field from model subscription_request exists
required_fields = sub_req_obj.sudo().get_required_field()
error = {field for field in required_fields if not values.get(field)} # noqa
Expand Down
1 change: 0 additions & 1 deletion cooperator_website/models/__init__.py

This file was deleted.

2 changes: 2 additions & 0 deletions cooperator_website/readme/newsfragments/312.removal.rst
@@ -0,0 +1,2 @@
Removed reCAPTCHA logic out of this module. Install
``cooperator_website_recaptcha`` to regain the functionality.
17 changes: 0 additions & 17 deletions cooperator_website/views/subscription_template.xml
Expand Up @@ -417,16 +417,6 @@
</div>
</template>

<template id="captcha_template" name="captcha_template">
<div
class="g-recaptcha text-xs-center"
t-if="res_company.captcha_type == 'google'"
t-att-data-sitekey="request.env['ir.config_parameter'].sudo().get_param('portal_recaptcha.recaptcha_key_site')"
data-theme="green"
name="recaptcha_key_site"
/>
</template>

<template id="error_message_template" name="error_message_template">
<p style="color:red;">
<!-- <t t-debug="ipdb"></t> -->
Expand Down Expand Up @@ -563,11 +553,6 @@

<t t-call="cooperator_website.rules_template" />

<!-- </div> -->
<!-- </div> -->
<!-- TODO: Use a overloaded function with the captcha implementation !-->
<t t-call="cooperator_website.captcha_template" />

<div class="text-center">
<button
class="btn btn-primary mt-3 mb-3 text-center"
Expand Down Expand Up @@ -771,8 +756,6 @@

<t t-call="cooperator_website.rules_template" />

<t t-call="cooperator_website.captcha_template" />

<div class="text-center">
<button
class="btn btn-primary mt-3 mb-3 text-center"
Expand Down
2 changes: 2 additions & 0 deletions cooperator_website_recaptcha/__init__.py
@@ -0,0 +1,2 @@
from . import controllers
from . import models
25 changes: 25 additions & 0 deletions cooperator_website_recaptcha/__manifest__.py
@@ -0,0 +1,25 @@
# Copyright 2022 Coop IT Easy SCRLfs
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Cooperators Website Recaptcha",
"summary": """
TODO""",
"version": "12.0.1.0.0",
"category": "Cooperative management",
"website": "https://coopiteasy.be",
"author": "Coop IT Easy SCRLfs",
"license": "AGPL-3",
"application": False,
"depends": [
"cooperator_website",
"portal_recaptcha",
],
"excludes": [],
"data": [
"views/res_company_views.xml",
"views/subscription_template.xml",
],
"demo": [],
"qweb": [],
}
1 change: 1 addition & 0 deletions cooperator_website_recaptcha/controllers/__init__.py
@@ -0,0 +1 @@
from . import main
43 changes: 43 additions & 0 deletions cooperator_website_recaptcha/controllers/main.py
@@ -0,0 +1,43 @@
from odoo.http import request
from odoo.tools.translate import _

from odoo.addons.cooperator_website.controllers.main import WebsiteSubscription


class RecaptchaWebsiteSubscription(WebsiteSubscription):
def validation( # noqa: C901 (method too complex)
self, kwargs, logged, values, post_file
):
result = super().validation(kwargs, logged, values, post_file)
if result is not True:
return result

redirect = "cooperator_website.becomecooperator"

is_company = kwargs.get("is_company") == "on"

# TODO: Use a overloaded function with the captcha implementation
if request.env["res.company"].captcha_type == "google":
if (
"g-recaptcha-response" not in kwargs
or kwargs["g-recaptcha-response"] == ""
):
values = self.fill_values(values, is_company, logged)
values.update(kwargs)
values["error_msg"] = _(
"the captcha has not been validated," " please fill in the captcha"
)

return request.render(redirect, values)
elif not request.env["portal.mixin"].is_captcha_valid(
kwargs["g-recaptcha-response"]
):
values = self.fill_values(values, is_company, logged)
values.update(kwargs)
values["error_msg"] = _(
"the captcha has not been validated," " please fill in the captcha"
)

return request.render(redirect, values)

return True
1 change: 1 addition & 0 deletions cooperator_website_recaptcha/models/__init__.py
@@ -0,0 +1 @@
from . import res_company
File renamed without changes.
3 changes: 3 additions & 0 deletions cooperator_website_recaptcha/readme/CONTRIBUTORS.rst
@@ -0,0 +1,3 @@
* `Coop IT Easy SCRLfs <https://coopiteasy.be>`_:

* Carmen Bianca Bakker
Empty file.
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record model="ir.ui.view" id="view_company_inherit_captcha">
<field name="name">res.company.form.captcha.easymy.coop</field>
<field name="name">res.company.form.captcha</field>
<field name="inherit_id" ref="cooperator.view_company_form" />
<field name="model">res.company</field>
<field name="arch" type="xml">
Expand Down
34 changes: 34 additions & 0 deletions cooperator_website_recaptcha/views/subscription_template.xml
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<template id="captcha_template" name="captcha_template">
<div
class="g-recaptcha text-xs-center"
t-if="res_company.captcha_type == 'google'"
t-att-data-sitekey="request.env['ir.config_parameter'].sudo().get_param('portal_recaptcha.recaptcha_key_site')"
data-theme="green"
name="recaptcha_key_site"
/>
</template>

<template
id="becomecooperator"
inherit_id="cooperator_website.becomecooperator"
name="Become Cooperator"
>
<xpath expr="//t[@t-call='cooperator_website.rules_template']" position="after">
<t t-call="cooperator_website.captcha_template" />
</xpath>
</template>

<template
id="becomecompanycooperator"
inherit_id="cooperator_website.becomecompanycooperator"
name="Become Cooperator"
>
<xpath expr="//t[@t-call='cooperator_website.rules_template']" position="after">
<t t-call="cooperator_website.captcha_template" />
</xpath>
</template>

</odoo>
6 changes: 6 additions & 0 deletions setup/cooperator_website_recaptcha/setup.py
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 279d34b

Please sign in to comment.