Skip to content

Commit

Permalink
progress on new email processor
Browse files Browse the repository at this point in the history
  • Loading branch information
davisagli committed Sep 23, 2024
1 parent 8b7f82b commit eb20843
Show file tree
Hide file tree
Showing 17 changed files with 351 additions and 725 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
id: vars
run: |
echo 'BASE_TAG=sha-$(git rev-parse --short HEAD)' >> $GITHUB_OUTPUT
python3 -c 'import json; data = json.load(open("./mrs.developer.json")); print("VOLTO_VERSION=" + data["core"].get("tag") or "latest")' >> $GITHUB_OUTPUT
python3 -c 'import json; data = json.load(open("./mrs.developer.json")); print("VOLTO_VERSION=" + data["core"].get("tag") or data["core"].get("branch") or "latest")' >> $GITHUB_OUTPUT
- name: Test vars
run: |
echo 'BASE_TAG=${{ steps.vars.outputs.BASE_TAG }}'
Expand Down Expand Up @@ -97,7 +97,6 @@ jobs:
packages: write

steps:

- name: Checkout
uses: actions/checkout@v4

Expand All @@ -109,8 +108,7 @@ jobs:
${{ env.IMAGE_NAME_PREFIX }}-${{ env.IMAGE_NAME_SUFFIX }}
labels: |
org.label-schema.docker.cmd=docker run -d -p 3000:3000 ${{ env.IMAGE_NAME_PREFIX }}-${{ env.IMAGE_NAME_SUFFIX }}:latest
flavor:
latest=false
flavor: latest=false
tags: |
type=ref,event=branch
type=sha
Expand Down
49 changes: 20 additions & 29 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# collective.volto.formsupport

Add some helper routes and functionalities for Volto sites with ``form`` blocks provided by `volto-form-block <https://github.com/collective/volto-form-block>`_ Volto plugin.
Add some helper routes and functionalities for Volto sites with `form` blocks provided by `volto-form-block <https://github.com/collective/volto-form-block>`\_ Volto plugin.

## volto-form-block version

Expand All @@ -15,7 +15,7 @@ Endpoint that the frontend should call as a submit action.
You can call it with a POST on the context where the block form is stored like this:

```shell
> curl -i -X POST http://localhost:8080/Plone/my-form/@submit-form -H 'Accept: application/json' -H 'Content-Type: application/json' --data-raw '{"block_id": "123456789", "data": [{"field_id": "foo", "value":"foo", "label": "Foo"},{"field_id": "from", "value": "[email protected]"}, {"field_id":"name", "value": "John Doe", "label": "Name"}]}'
> curl -i -X POST http://localhost:8080/Plone/my-form/@schemaform-data -H 'Accept: application/json' -H 'Content-Type: application/json' --data-raw '{"block_id": "123456789", "data": [{"field_id": "foo", "value":"foo", "label": "Foo"},{"field_id": "from", "value": "[email protected]"}, {"field_id":"name", "value": "John Doe", "label": "Name"}]}'
```

where:
Expand All @@ -26,7 +26,6 @@ where:

Calling this endpoint, it will do some actions (based on block settings) and returns a `200` response with the submitted data.


### `@form-data`

This is an expansion component.
Expand Down Expand Up @@ -86,8 +85,8 @@ Reset the store (only for users that have **Modify portal content** permission):

Optional parameters could be passed in the payload:

* `block_id` to delete only data related to a specific block on the page, otherwise data from all form blocks on the page will be deleted
* `expired` a boolean that, if `true`, removes only records older than the value of days specified in the block configuration (the above `block_id` parameter is required)
- `block_id` to delete only data related to a specific block on the page, otherwise data from all form blocks on the page will be deleted
- `expired` a boolean that, if `true`, removes only records older than the value of days specified in the block configuration (the above `block_id` parameter is required)

### `@validate-email-address`

Expand All @@ -100,8 +99,8 @@ Returns a HTTP 204 in case of success or HTTP 400 in case the email is badly com

parameters:

* `email` email address.
* `uid` uid related to email field
- `email` email address.
- `uid` uid related to email field

### `@validate-email-token`

Expand All @@ -114,13 +113,13 @@ Returns HTTP 204 in case of success or HTTP 400 in case of failure ::

parameters:

* `email` email address
* `uid` uid used to generate the OTP
* `otp` OTP code
- `email` email address
- `uid` uid used to generate the OTP
- `otp` OTP code

## Form actions

Using `volto-form-block <https://github.com/collective/volto-form-block>`_ you can set if the form submit should send data to an email address
Using `volto-form-block <https://github.com/collective/volto-form-block>`\_ you can set if the form submit should send data to an email address
or store it into an internal catalog (or both).

### Send
Expand Down Expand Up @@ -149,13 +148,13 @@ Set the 'Send to' value to include `acknowledgement` to enable this behaviour. T

### Store

If block is set to store data, we store it into the content that has that block (with a `souper.plone <https://pypi.org/project/souper.plone>`_ catalog).
If block is set to store data, we store it into the content that has that block (with a `souper.plone <https://pypi.org/project/souper.plone>`\_ catalog).

The store is an adapter registered for *IFormDataStore* interface, so you can override it easily.
The store is an adapter registered for _IFormDataStore_ interface, so you can override it easily.

Only fields that are also in block settings are stored. Missing ones will be skipped.

Each Record stores also two *service* attributes:
Each Record stores also two _service_ attributes:

- **fields_labels**: a mapping of field ids to field labels. This is useful when we export csv files, so we can labels for the columns.
- **fields_order**: sorted list of field ids. This can be used in csv export to keep the order of fields.
Expand All @@ -168,14 +167,14 @@ The exported CSV file may need to be used by further processes which require spe

## Block serializer

There is a custom block serializer for type ``form``.
There is a custom block serializer for type `form`.

This serializer removes all fields that start with "\**default_**\" if the user can't edit the current context.
This serializer removes all fields that start with "\*\*default\_\*\*\" if the user can't edit the current context.

This is useful because we don't want to expose some internals configurations (for example the recipient email address)
to external users that should only fill the form.

If the block has a field ``captcha``, an additional property ``captcha_props`` is serialized by the ``serialize``
If the block has a field `captcha`, an additional property `captcha_props` is serialized by the `serialize`
method provided by the ICaptchaSupport named adapter, the result contains useful metadata for the client, as the
captcha public_key, ie:

Expand All @@ -202,7 +201,6 @@ This product contains implementations for:
- Custom questions and answers (collective.z3cform.norobots)
- Honeypot (collective.honeypot)


Each implementation must be included, installed and configured separately.

To include one implementation, you need to install the egg with the needed extras_require:
Expand All @@ -220,7 +218,7 @@ For captcha support `volto-form-block` version >= 2.4.0 is required.

If honeypot dependency is available in the buildout, the honeypot validation is enabled and selectable in forms.

Default field name is `protected_1` and you can change it with an environment variable. See `collective.honeypot <https://github.com/collective/collective.honeypot#id7>`_ for details.
Default field name is `protected_1` and you can change it with an environment variable. See `collective.honeypot <https://github.com/collective/collective.honeypot#id7>`\_ for details.

## Attachments upload limits

Expand Down Expand Up @@ -257,12 +255,10 @@ This is useful for some SMTP servers that have problems with `quoted-printable`
By default the content-transfer-encoding is `quoted-printable` as overridden in
https://github.com/zopefoundation/Products.MailHost/blob/master/src/Products/MailHost/MailHost.py#L65


## Email subject templating

You can also interpolate the form values to the email subject using the field id, in this way: ${123321123}


## Header forwarding

It is possible to configure some headers from the form POST request to be included in the email's headers by configuring the `httpHeaders` field in your volto block.
Expand Down Expand Up @@ -302,14 +298,12 @@ This add-on can be seen in action at the following sites:

- https://www.comune.modena.it/form/contatti


## Translations

This product has been translated into

- Italian


## Installation

Install collective.volto.formsupport by adding it to your buildout::
Expand All @@ -323,15 +317,13 @@ Install collective.volto.formsupport by adding it to your buildout::
collective.volto.formsupport
```

and then running ``bin/buildout``

and then running `bin/buildout`

## Contribute

- Issue Tracker: https://github.com/collective/volto-form-block/issues
- Source Code: https://github.com/collective/volto-form-block


## License

The project is licensed under the GPLv2.
Expand All @@ -341,9 +333,8 @@ The project is licensed under the GPLv2.
This product was developed by **RedTurtle Technology** team.

.. image:: https://avatars1.githubusercontent.com/u/1087171?s=100&v=4
:alt: RedTurtle Technology Site
:target: https://www.redturtle.it/

:alt: RedTurtle Technology Site
:target: https://www.redturtle.it/

## Credits and Acknowledgements 🙏

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def verify(self, data):
if isinstance(data, str):
data = json.loads(data)
if not data:
# @submit-form has been called not from volto-form-block so do the standard
# @schemaform-data has been called not from volto-form-block so do the standard
# validation.
form_data = json_body(self.request).get("data", [])
form = {x["label"]: x["value"] for x in form_data}
Expand Down
1 change: 1 addition & 0 deletions backend/src/collective/volto/formsupport/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
<include package=".datamanager" />
<include package=".restapi" />
<include package=".captcha" />
<include package=".processors" />

</configure>
10 changes: 1 addition & 9 deletions backend/src/collective/volto/formsupport/datamanager/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,13 @@ def get_form_fields(self):
{"field_id": name, "label": field.get("title", name)}
for name, field in block["schema"]["properties"].items()
]
elif block_type == "form":
subblocks = block.get("subblocks", [])
# Add the 'custom_field_id' field back in as this isn't stored with each
# subblock
for index, field in enumerate(subblocks):
if block.get(field["field_id"]):
subblocks[index]["custom_field_id"] = block.get(field["field_id"])
return subblocks
return {}

def add(self, data):
form_fields = self.get_form_fields()
if not form_fields:
logger.error(
f'Block with id {self.block_id} and type "form" not found in context: {self.context.absolute_url()}.' # noqa: E501
f'Block with id {self.block_id} and type "schemaForm" not found in context: {self.context.absolute_url()}.' # noqa: E501
)
return None

Expand Down
1 change: 1 addition & 0 deletions backend/src/collective/volto/formsupport/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from zope.interface import Interface
from zope.publisher.interfaces.browser import IDefaultBrowserLayer
from ZPublisher.BaseRequest import BaseRequest

import dataclasses


Expand Down
13 changes: 8 additions & 5 deletions backend/src/collective/volto/formsupport/processors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ def filter_parameters(data, block):
"""
TODO do not send attachments fields.
"""
return [{
"field_id": k,
"value": v,
"label": block["schema"]["properties"].get(k, {}).get("title", k),
} for k, v in data.items()]
return [
{
"field_id": k,
"value": v,
"label": block["schema"]["properties"].get(k, {}).get("title", k),
}
for k, v in data.items()
]
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<configure
xmlns="http://namespaces.zope.org/zope"
>
<configure xmlns="http://namespaces.zope.org/zope">

<subscriber name="email" factory=".email.EmailFormProcessor" />
<subscriber name="store" factory=".store.StoreFormProcessor" />
<subscriber factory=".email.EmailFormProcessor" />
<subscriber factory=".store.StoreFormProcessor" />

</configure>
Loading

0 comments on commit eb20843

Please sign in to comment.