Skip to content

Commit

Permalink
Switchable OTP verification for email bcc fields (#70)
Browse files Browse the repository at this point in the history
Co-authored-by: Roman Kysil <[email protected]>
  • Loading branch information
folix-01 and Roman Kysil authored Sep 19, 2024
1 parent ef327ba commit dd5c500
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Changelog
3.1.4 (unreleased)
------------------

- Switchable email bcc fields OTP verification.
[folix-01]

- Added ISO formatted strings being allowed as date inputs
[JeffersonBledsoe]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ def validate_bcc(self):
continue

if data.get("field_id", "") in bcc_fields:
if not validate_email_token(
if self.block.get(
"email_otp_verification", True
) and not validate_email_token(
self.form_data.get("block_id", ""), data["value"], data["otp"]
):
raise BadRequest(
Expand Down
67 changes: 67 additions & 0 deletions src/collective/volto/formsupport/tests/test_send_action_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,73 @@ def test_email_field_used_as_bcc(
self.assertNotIn("To: [email protected]", bcc_msg)
self.assertIn("To: [email protected]", bcc_msg)

# Test send wrong otp
response = self.submit_form(
data={
"data": [
{"label": "Message", "value": "just want to say hi"},
{"label": "Name", "value": "Smith"},
{
"field_id": "contact",
"label": "Email",
"value": "[email protected]",
"otp": None,
},
],
"block_id": "form-id",
},
)

self.assertEqual(response.status_code, 400)

# Test do not verify opt if otp flag `email_otp_verification` is False
self.document.blocks = {
"text-id": {"@type": "text"},
"form-id": {
"@type": "form",
"default_subject": "block subject",
"default_from": "[email protected]",
"send": False,
"store": True,
"email_otp_verification": False,
"subblocks": [
{
"field_id": "contact",
"field_type": "from",
"use_as_bcc": True,
},
{
"field_id": "message",
"field_type": "text",
},
{
"field_id": "name",
"field_type": "text",
},
],
},
}

transaction.commit()

response = self.submit_form(
data={
"data": [
{"label": "Message", "value": "just want to say hi"},
{"label": "Name", "value": "Smith"},
{
"field_id": "contact",
"label": "Email",
"value": "[email protected]",
"otp": 123,
},
],
"block_id": "form-id",
},
)

self.assertEqual(response.status_code, 200)

def test_send_attachment(
self,
):
Expand Down

0 comments on commit dd5c500

Please sign in to comment.