diff --git a/backend/Makefile b/backend/Makefile index 1e62119..e0b19f4 100644 --- a/backend/Makefile +++ b/backend/Makefile @@ -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 diff --git a/backend/src/collective/volto/formsupport/datamanager/catalog.py b/backend/src/collective/volto/formsupport/datamanager/catalog.py index 0209a30..032bce9 100644 --- a/backend/src/collective/volto/formsupport/datamanager/catalog.py +++ b/backend/src/collective/volto/formsupport/datamanager/catalog.py @@ -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 diff --git a/backend/src/collective/volto/formsupport/restapi/services/form_data/form_data.py b/backend/src/collective/volto/formsupport/restapi/services/form_data/form_data.py index d1ad74b..9d86c69 100644 --- a/backend/src/collective/volto/formsupport/restapi/services/form_data/form_data.py +++ b/backend/src/collective/volto/formsupport/restapi/services/form_data/form_data.py @@ -81,7 +81,8 @@ def form_block(self): if not blocks: return {} for id_, block in blocks.items(): - if block.get("@type", "") in ("form", "schemaForm") and block.get("store", False): + is_form_block = block.get("@type", "") in ("form", "schemaForm") + if is_form_block and block.get("store", False): if not self.block_id or self.block_id == id_: return block return {} diff --git a/backend/src/collective/volto/formsupport/restapi/services/submit_form/post.py b/backend/src/collective/volto/formsupport/restapi/services/submit_form/post.py index 3826d20..e6447f3 100644 --- a/backend/src/collective/volto/formsupport/restapi/services/submit_form/post.py +++ b/backend/src/collective/volto/formsupport/restapi/services/submit_form/post.py @@ -55,16 +55,13 @@ def __init__(self, context, data): class SubmitPost(Service): - def __init__(self, context, request): - super().__init__(context, request) - + def reply(self): self.block = {} self.form_data = self.cleanup_data() self.block_id = self.form_data.get("block_id", "") if self.block_id: self.block = self.get_block_data(block_id=self.block_id) - def reply(self): self.validate_form() store_action = self.block.get("store", False) @@ -109,7 +106,7 @@ def cleanup_data(self): block = self.get_block_data(block_id=form_data.get("block_id", "")) - if block["@type"] == "form": + if block.get("@type") == "form": block_fields = [x.get("field_id", "") for x in block.get("subblocks", [])] # cleanup form data if it's a form block for form_field in form_data.get("data", []): @@ -184,23 +181,18 @@ def validate_form(self): (self.context, self.request), ICaptchaSupport, name=self.block["captcha"], - ).verify( - self.form_data.get("captcha") - or self.form_data["data"].get("captchaWidget") - ) + ).verify(self.form_data.get("captcha")) self.validate_email_fields() self.validate_bcc() def validate_schema(self): - if self.block["@type"] != "schemaForm": + if self.block.get("@type") != "schemaForm": return validator = jsonschema.Draft202012Validator(self.block["schema"]) errors = [] for err in validator.iter_errors(self.form_data["data"]): - error = { - "message": err.message - } + error = {"message": err.message} if err.path: error["field"] = ".".join(err.path) errors.append(error) @@ -356,7 +348,11 @@ def get_acknowledgement_field_value(self): return data.get("value") def get_subject(self): - subject = self.block.get("default_subject") or "${subject}" + subject = ( + self.form_data.get("subject") + or self.block.get("default_subject") + or "${subject}" + ) subject = self.substitute_variables(subject) return subject @@ -496,11 +492,16 @@ def filter_parameters(self): """ # TODO: handle attachments for schemaForm block if self.block["@type"] == "schemaForm": - return [{ - "field_id": k, - "value": v, - "label": self.block["schema"]["properties"].get(k, {}).get("title", k), - } for k, v in self.form_data["data"].items()] + return [ + { + "field_id": k, + "value": v, + "label": self.block["schema"]["properties"] + .get(k, {}) + .get("title", k), + } + for k, v in self.form_data["data"].items() + ] skip_fields = [ x.get("field_id", "") diff --git a/backend/src/collective/volto/formsupport/testing/__init__.py b/backend/src/collective/volto/formsupport/testing/__init__.py index 89dde79..47fb8f9 100644 --- a/backend/src/collective/volto/formsupport/testing/__init__.py +++ b/backend/src/collective/volto/formsupport/testing/__init__.py @@ -29,7 +29,7 @@ def setUpPloneSite(self, portal): applyProfile(portal, "plone.restapi:blocks") applyProfile(portal, "collective.volto.formsupport:default") - # Mock the validate email tocken function + # Mock the validate email token function def validate_email_token_mock(*args, **kwargs): return True diff --git a/frontend/packages/volto-form-block/src/components/Widget/HoneypotCaptchaWidget.jsx b/frontend/packages/volto-form-block/src/components/Widget/HoneypotCaptchaWidget.jsx index c14ba24..a8e65ec 100644 --- a/frontend/packages/volto-form-block/src/components/Widget/HoneypotCaptchaWidget.jsx +++ b/frontend/packages/volto-form-block/src/components/Widget/HoneypotCaptchaWidget.jsx @@ -40,7 +40,6 @@ const HoneypotCaptchaWidget = ({ }, []); const [value, setValue] = useState(); - console.log('oldWidget', value); return (
diff --git a/frontend/packages/volto-form-block/src/schemaFormBlock/ViewSchemaForm.jsx b/frontend/packages/volto-form-block/src/schemaFormBlock/ViewSchemaForm.jsx index 19a6c10..2a2abb5 100644 --- a/frontend/packages/volto-form-block/src/schemaFormBlock/ViewSchemaForm.jsx +++ b/frontend/packages/volto-form-block/src/schemaFormBlock/ViewSchemaForm.jsx @@ -1,9 +1,8 @@ -import React, { useState, useEffect, useReducer, useRef } from 'react'; -import { useSelector, useDispatch } from 'react-redux'; +import React from 'react'; +import { useDispatch } from 'react-redux'; import { defineMessages, useIntl } from 'react-intl'; import { Form } from '@plone/volto/components/manage/Form'; import { submitForm } from 'volto-form-block/actions'; -import { Captcha } from 'volto-form-block/components/Widget'; import { tryParseJSON, extractInvariantErrors } from '@plone/volto/helpers'; import { toast } from 'react-toastify'; import { Toast } from '@plone/volto/components';