Skip to content
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

Refactor editing ux #110

Draft
wants to merge 17 commits into
base: newsetup
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ clean: ## Clean environment

.PHONY: start
start: ## Start a Plone instance on localhost:8080
ALLOWED_DISTRIBUTIONS=portalbrasil-intranet PYTHONWARNINGS=ignore $(BIN_FOLDER)/runwsgi instance/etc/zope.ini
ENABLE_PRINTING_MAILHOST=True PYTHONWARNINGS=ignore $(BIN_FOLDER)/runwsgi instance/etc/zope.ini

.PHONY: console
console: instance/etc/zope.ini ## Start a console into a Plone instance
ALLOWED_DISTRIBUTIONS=portalbrasil-intranet PYTHONWARNINGS=ignore $(BIN_FOLDER)/zconsole debug instance/etc/zope.conf
PYTHONWARNINGS=ignore $(BIN_FOLDER)/zconsole debug instance/etc/zope.conf

.PHONY: create-site
create-site: instance/etc/zope.ini ## Create a new site from scratch
ALLOWED_DISTRIBUTIONS=portalbrasil-intranet PYTHONWARNINGS=ignore $(BIN_FOLDER)/zconsole run instance/etc/zope.conf ./scripts/create_site.py
PYTHONWARNINGS=ignore $(BIN_FOLDER)/zconsole run instance/etc/zope.conf ./scripts/create_site.py

# Example Content
.PHONY: update-example-content
Expand Down
2 changes: 1 addition & 1 deletion backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Works with volto-form-block >= v3.8.0

## plone.restapi endpoints

### `@submit-form`
### `@schemaform-data`

Endpoint that the frontend should call as a submit action.

Expand Down
2 changes: 2 additions & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ dependencies = [
"souper.plone",
"click",
"beautifulsoup4",
"jsonschema",
"pyotp",
]

Expand Down Expand Up @@ -101,6 +102,7 @@ dependencies = [
"plone.formwidget.recaptcha",
"plone.restapi[test]",
"Products.MailHost",
"Products.PrintingMailHost",
"pytest-cov==5.0.0",
"pytest-plone>=0.5.0",
"pytest",
Expand Down
4 changes: 4 additions & 0 deletions backend/src/collective/volto/formsupport/captcha/honeypot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from zExceptions import BadRequest
from zope.i18n import translate

import json


class HoneypotSupport(CaptchaSupport):
name = _("Honeypot Support")
Expand All @@ -31,6 +33,8 @@ def verify(self, data):
# first check if volto-form-block send the compiled token
# (because by default it does not insert the honeypot field into the submitted
# form)
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
# validation.
Expand Down
37 changes: 16 additions & 21 deletions backend/src/collective/volto/formsupport/datamanager/catalog.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from collective.volto.formsupport import logger
from collective.volto.formsupport.interfaces import IFormDataStore
from collective.volto.formsupport.utils import get_blocks
from copy import deepcopy
from datetime import datetime
from plone.dexterity.interfaces import IDexterityContent
from plone.restapi.deserializer import json_body
Expand Down Expand Up @@ -46,28 +45,24 @@ def block_id(self):

def get_form_fields(self):
blocks = get_blocks(self.context)

if not blocks:
return {}
form_block = {}
for id_, block in blocks.items():
if id_ != self.block_id:
continue
block_type = block.get("@type", "")
if block_type == "form":
form_block = deepcopy(block)
if not form_block:
return {}

subblocks = form_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 form_block.get(field["field_id"]):
subblocks[index]["custom_field_id"] = form_block.get(field["field_id"])

return subblocks
block = blocks.get(self.block_id, {})
block_type = block.get("@type", "")
if block_type == "schemaForm":
return [
{"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()
Expand Down
25 changes: 25 additions & 0 deletions backend/src/collective/volto/formsupport/interfaces.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from plone.dexterity.content import DexterityContent
from zope.interface import Attribute
from zope.interface import Interface
from zope.publisher.interfaces.browser import IDefaultBrowserLayer
from ZPublisher.BaseRequest import BaseRequest
import dataclasses


class ICollectiveVoltoFormsupportLayer(IDefaultBrowserLayer):
Expand Down Expand Up @@ -44,3 +48,24 @@ def verify(data):
"""Verify the captcha
@return: True if verified, Raise exception otherwise
"""


@dataclasses.dataclass
class FormSubmissionContext:
context: DexterityContent
block: dict
form_data: dict
attachments: dict
request: BaseRequest


class IFormSubmissionProcessor(Interface):
"""Subscriber which processes form data when it is submitted"""

order: int = Attribute("Processors with the lowest order are processed first")

def __init__(context: FormSubmissionContext):
pass

def __call__():
"""Process the data."""
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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()]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<configure
xmlns="http://namespaces.zope.org/zope"
>

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

</configure>
Loading
Loading