Invariant Error not displaying properly in Volto

Good evening Plone Community!

I am currently working on a field validator/invariant for fields in a custom content type created. Currently, the Invariant Error is not displaying correctly in Volto. It shows up as the following:

Here is the code for the invariant i am currently using in Plone classic backend:

class CheckFields(Invalid):
    __doc__ = _(u'This field is required')


class IFinancialAidDocs(model.Schema):

# Fields go here!!

    @invariant
    def validate_attachment(data):
        if data.attachment_type is None and data.attachment_file is not None:
            raise CheckFields(_(u'Required input for Attachments Type 1 is missing'))
        if data.attachment_type is not None and data.attachment_file is None:
            raise CheckFields(_(u'Required input for Attachments File 1 is missing'))

    @invariant
    def validate_attachment1(data):
        if data.attachment_type1 is None and data.attachment_file1 is not None:
            raise CheckFields(_(u'Required input for Attachments Type 2 is missing'))
        if data.attachment_type1 is not None and data.attachment_file1 is None:
            raise CheckFields(_(u'Required input for Attachments File 2 is missing'))

    @invariant
    def validate_attachment2(data):
        if data.attachment_type2 is None and data.attachment_file2 is not None:
            raise CheckFields(_(u'Required input for Attachments Type 3 is missing'))
        if data.attachment_type2 is not None and data.attachment_file2 is None:
            raise CheckFields(_(u'Required input for Attachments File 3 is missing'))

    @invariant
    def validate_attachment3(data):
        if data.attachment_type3 is None and data.attachment_file3 is not None:
            raise CheckFields(_(u'Required input for Attachments Type 4 is missing'))
        if data.attachment_type3 is not None and data.attachment_file3 is None:
            raise CheckFields(_(u'Required input for Attachments File 4 is missing'))

    @invariant
    def validate_attachment4(data):
        if data.attachment_type4 is None and data.attachment_file4 is not None:
            raise CheckFields(_(u'Required input for Attachments Type 5 is missing'))
        if data.attachment_type4 is not None and data.attachment_file4 is None:
            raise CheckFields(_(u'Required input for Attachments File 5 is missing'))

How can I get the invariant to display in Volto as well as Plone Classic?

I thank you kindly.

Sincerely,

rbrown12

How do you expect it to show?

Granted, we could improve the human readability on this kind of messages. Right now, it shows what the server responds: returns a 400 since it had the validation errors, and it shows it to you in a toast.

Good morning, @sneridagh,

Just to clarify, I was expecting it to display the way a typical validation error would show when a required field is not filled out.

I thank you kindly.

Sincerely,

rbrown12

The error message should display like the other validator errors
Screenshot 2022-09-06 at 12.01.35 PM

Heya Plone/Voltoistas,

Continuing on the issue we're having with Invariant/Validation.

I've added collective.clamav and configured clamscan on the backend.

When I visit plone classic (our dev box for this project client1 on 8080)

  • Plone 5.2.5 (5213)
  • CMF 2.5.4
  • Zope 4.6.3
  • Python 3.8.10 (default, Jun 22 2022, 20:18:18) [GCC 9.4.0]
  • PIL 6.2.2 (Pillow)
  • WSGI: On
  • Server: waitress 2.1.2

Plone Classic acknowledges that my sample files are indeed infected and can't be uploaded

Problem is when I visit the Volto side of the project:

  • Volto 16.0.0-alpha.30
  • Plone 5.2.5
  • plone.restapi 8.23.0
  • CMF 2.5.4
  • Zope 4.6.3
  • Python 3.8.10 (default, Jun 22 2022, 20:18:18) [GCC 9.4.0]
  • PIL 6.2.2 (Pillow)

Add-ons

  • volto-yc-documents 0.1.0
  • volto-yc-graduateapplication 0.1.0

Volto allows me to upload the infected files:

no validation errors or notification...

there is no control panel setting similar in classic to see if Volto is even aware other than that it appears as active under add-ons

On the React side of things, do we need to hook into clamscan? or do we need some sort of endpoint in collective.clamav? Any comments, suggestions, are greatly appreciated.

--riker11451

to have the control panel available in Volto, you need the control panel to be exposed through the rest API declaring an adapter.

You can check a couple of examples here:

I think the problem is that Volto doesn't use the z3c.form library in any way, so the clamav validator is not executed. collective.clamav/validator.py at f95bde0d98530f1a82d18ba7bae4fe7560e4702e · collective/collective.clamav · GitHub

I think one of the issues is that plone.restapi (AFAIK) doesn't use schemas to define its endpoint operations, which would allow the registration of validators over the input values. CC @sneridagh @tisto

1 Like

Right, the clamav validator should be implemented on the schema, not on the z3c.form. This would mean to modify the File/Image content types FTI, but IMO it is the clean way.

1 Like

Thanks tiberiuichim & jensens

I had hypothesized that something was amiss with the way this add-on (and some others) especially forms were not validating properly.

Being of limited skill (programmatically) I will see if I can modify locally to fix. Any thoughts in the Volto camp on what path form validation will take? will there be an associated library like z3c.from to take advantage of?

thanks for the input! :slight_smile: