Skip to content

Commit eb20843

Browse files
committed
progress on new email processor
1 parent 8b7f82b commit eb20843

File tree

17 files changed

+351
-725
lines changed

17 files changed

+351
-725
lines changed

.github/workflows/frontend.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
id: vars
2727
run: |
2828
echo 'BASE_TAG=sha-$(git rev-parse --short HEAD)' >> $GITHUB_OUTPUT
29-
python3 -c 'import json; data = json.load(open("./mrs.developer.json")); print("VOLTO_VERSION=" + data["core"].get("tag") or "latest")' >> $GITHUB_OUTPUT
29+
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
3030
- name: Test vars
3131
run: |
3232
echo 'BASE_TAG=${{ steps.vars.outputs.BASE_TAG }}'
@@ -97,7 +97,6 @@ jobs:
9797
packages: write
9898

9999
steps:
100-
101100
- name: Checkout
102101
uses: actions/checkout@v4
103102

@@ -109,8 +108,7 @@ jobs:
109108
${{ env.IMAGE_NAME_PREFIX }}-${{ env.IMAGE_NAME_SUFFIX }}
110109
labels: |
111110
org.label-schema.docker.cmd=docker run -d -p 3000:3000 ${{ env.IMAGE_NAME_PREFIX }}-${{ env.IMAGE_NAME_SUFFIX }}:latest
112-
flavor:
113-
latest=false
111+
flavor: latest=false
114112
tags: |
115113
type=ref,event=branch
116114
type=sha

backend/README.md

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# collective.volto.formsupport
22

3-
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.
3+
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.
44

55
## volto-form-block version
66

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

1717
```shell
18-
> 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"}]}'
18+
> 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"}]}'
1919
```
2020

2121
where:
@@ -26,7 +26,6 @@ where:
2626

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

29-
3029
### `@form-data`
3130

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

8786
Optional parameters could be passed in the payload:
8887

89-
* `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
90-
* `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)
88+
- `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
89+
- `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)
9190

9291
### `@validate-email-address`
9392

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

101100
parameters:
102101

103-
* `email` email address.
104-
* `uid` uid related to email field
102+
- `email` email address.
103+
- `uid` uid related to email field
105104

106105
### `@validate-email-token`
107106

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

115114
parameters:
116115

117-
* `email` email address
118-
* `uid` uid used to generate the OTP
119-
* `otp` OTP code
116+
- `email` email address
117+
- `uid` uid used to generate the OTP
118+
- `otp` OTP code
120119

121120
## Form actions
122121

123-
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
122+
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
124123
or store it into an internal catalog (or both).
125124

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

150149
### Store
151150

152-
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).
151+
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).
153152

154-
The store is an adapter registered for *IFormDataStore* interface, so you can override it easily.
153+
The store is an adapter registered for _IFormDataStore_ interface, so you can override it easily.
155154

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

158-
Each Record stores also two *service* attributes:
157+
Each Record stores also two _service_ attributes:
159158

160159
- **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.
161160
- **fields_order**: sorted list of field ids. This can be used in csv export to keep the order of fields.
@@ -168,14 +167,14 @@ The exported CSV file may need to be used by further processes which require spe
168167

169168
## Block serializer
170169

171-
There is a custom block serializer for type ``form``.
170+
There is a custom block serializer for type `form`.
172171

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

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

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

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

205-
206204
Each implementation must be included, installed and configured separately.
207205

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

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

223-
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.
221+
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.
224222

225223
## Attachments upload limits
226224

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

260-
261258
## Email subject templating
262259

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

265-
266262
## Header forwarding
267263

268264
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.
@@ -302,14 +298,12 @@ This add-on can be seen in action at the following sites:
302298

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

305-
306301
## Translations
307302

308303
This product has been translated into
309304

310305
- Italian
311306

312-
313307
## Installation
314308

315309
Install collective.volto.formsupport by adding it to your buildout::
@@ -323,15 +317,13 @@ Install collective.volto.formsupport by adding it to your buildout::
323317
collective.volto.formsupport
324318
```
325319

326-
and then running ``bin/buildout``
327-
320+
and then running `bin/buildout`
328321

329322
## Contribute
330323

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

334-
335327
## License
336328

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

343335
.. image:: https://avatars1.githubusercontent.com/u/1087171?s=100&v=4
344-
:alt: RedTurtle Technology Site
345-
:target: https://www.redturtle.it/
346-
336+
:alt: RedTurtle Technology Site
337+
:target: https://www.redturtle.it/
347338

348339
## Credits and Acknowledgements 🙏
349340

backend/src/collective/volto/formsupport/captcha/honeypot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def verify(self, data):
3636
if isinstance(data, str):
3737
data = json.loads(data)
3838
if not data:
39-
# @submit-form has been called not from volto-form-block so do the standard
39+
# @schemaform-data has been called not from volto-form-block so do the standard
4040
# validation.
4141
form_data = json_body(self.request).get("data", [])
4242
form = {x["label"]: x["value"] for x in form_data}

backend/src/collective/volto/formsupport/configure.zcml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717
<include package=".datamanager" />
1818
<include package=".restapi" />
1919
<include package=".captcha" />
20+
<include package=".processors" />
2021

2122
</configure>

backend/src/collective/volto/formsupport/datamanager/catalog.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,13 @@ def get_form_fields(self):
5454
{"field_id": name, "label": field.get("title", name)}
5555
for name, field in block["schema"]["properties"].items()
5656
]
57-
elif block_type == "form":
58-
subblocks = block.get("subblocks", [])
59-
# Add the 'custom_field_id' field back in as this isn't stored with each
60-
# subblock
61-
for index, field in enumerate(subblocks):
62-
if block.get(field["field_id"]):
63-
subblocks[index]["custom_field_id"] = block.get(field["field_id"])
64-
return subblocks
6557
return {}
6658

6759
def add(self, data):
6860
form_fields = self.get_form_fields()
6961
if not form_fields:
7062
logger.error(
71-
f'Block with id {self.block_id} and type "form" not found in context: {self.context.absolute_url()}.' # noqa: E501
63+
f'Block with id {self.block_id} and type "schemaForm" not found in context: {self.context.absolute_url()}.' # noqa: E501
7264
)
7365
return None
7466

backend/src/collective/volto/formsupport/interfaces.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from zope.interface import Interface
44
from zope.publisher.interfaces.browser import IDefaultBrowserLayer
55
from ZPublisher.BaseRequest import BaseRequest
6+
67
import dataclasses
78

89

backend/src/collective/volto/formsupport/processors/__init__.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ def filter_parameters(data, block):
22
"""
33
TODO do not send attachments fields.
44
"""
5-
return [{
6-
"field_id": k,
7-
"value": v,
8-
"label": block["schema"]["properties"].get(k, {}).get("title", k),
9-
} for k, v in data.items()]
5+
return [
6+
{
7+
"field_id": k,
8+
"value": v,
9+
"label": block["schema"]["properties"].get(k, {}).get("title", k),
10+
}
11+
for k, v in data.items()
12+
]
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
<configure
2-
xmlns="http://namespaces.zope.org/zope"
3-
>
1+
<configure xmlns="http://namespaces.zope.org/zope">
42

5-
<subscriber name="email" factory=".email.EmailFormProcessor" />
6-
<subscriber name="store" factory=".store.StoreFormProcessor" />
3+
<subscriber factory=".email.EmailFormProcessor" />
4+
<subscriber factory=".store.StoreFormProcessor" />
75

86
</configure>

0 commit comments

Comments
 (0)