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

Support for allowed content types. #158

Merged
merged 2 commits into from Mar 15, 2024
Merged

Conversation

thet
Copy link
Member

@thet thet commented Mar 13, 2024

Support to constrain files to specific content types with a "allowedContentTypes" attribute on file and image fields.

Fixes: #157

@mister-roboto
Copy link

@thet thanks for creating this Pull Request and helping to improve Plone!

TL;DR: Finish pushing changes, pass all other checks, then paste a comment:

@jenkins-plone-org please run jobs

To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass, but it takes 30-60 min. Other CI checks are usually much faster and the Plone Jenkins resources are limited, so when done pushing changes and all other checks pass either start all Jenkins PR jobs yourself, or simply add the comment above in this PR to start all the jobs automatically.

Happy hacking!

@thet thet marked this pull request as draft March 13, 2024 18:20
@thet thet marked this pull request as ready for review March 13, 2024 18:26
@thet
Copy link
Member Author

thet commented Mar 13, 2024

@jenkins-plone-org please run jobs

@thet
Copy link
Member Author

thet commented Mar 13, 2024

@jenkins-plone-org please run jobs

thet added a commit to plone/plone.formwidget.namedfile that referenced this pull request Mar 13, 2024
If the widget's field - if there is one - has `allowedContentTypes` set (the
`NamedImage` field has `image/*` set by default) the allowed content types are
rendered as `accept` attribute on the file input.

This already restricts the allowed file types before uploading while still
being checked on the server side too.

Fixes: #66
Depeds on: plone/plone.namedfile#158
thet added a commit to plone/plone.app.z3cform that referenced this pull request Mar 14, 2024
If the widget's field - if there is one - has  set (the  field has  set by default) the allowed content types are rendered as  attribute on the file input.

This already restricts the allowed file types before uploading while still being checked on the server side too.

Fixes: plone/plone.formwidget.namedfile#66
Depeds on:
- plone/plone.namedfile#158
- plone/plone.formwidget.namedfile#67
thet added a commit to plone/plone.app.z3cform that referenced this pull request Mar 14, 2024
If the widget's field - if there is one - has  set (the  field has  set by
default) the allowed content types are rendered as  attribute on the file input.

This already restricts the allowed file types before uploading while still
being checked on the server side too.

Fixes: plone/plone.formwidget.namedfile#66
Depeds on:
- plone/plone.namedfile#158
- plone/plone.formwidget.namedfile#67
thet added a commit to plone/plone.formwidget.namedfile that referenced this pull request Mar 14, 2024
If the widget's field - if there is one - has `allowedContentTypes` set (the `NamedImage` field has `image/*` set by default) the allowed content types are rendered as `accept` attribute on the file input.

This already restricts the allowed file types before uploading while still being checked on the server side too.

Fixes: #66
Depends on: plone/plone.namedfile#158
thet added a commit to plone/plone.formwidget.namedfile that referenced this pull request Mar 14, 2024
If the widget's field - if there is one - has `allowedContentTypes` set (the `NamedImage` field has `image/*` set by default) the allowed content types are rendered as `accept` attribute on the file input.

This already restricts the allowed file types before uploading while still being checked on the server side too.

Fixes: #66
Depends on: plone/plone.namedfile#158
thet added a commit to plone/plone.app.z3cform that referenced this pull request Mar 14, 2024
If the widget's field - if there is one - has `allowedContentTypes` set (the `NamedImage` field has `image/*` set by default) the allowed content types are rendered as `accept` attribute on the file input.

This already restricts the allowed file types before uploading while still being checked on the server side too.

Fixes: plone/plone.formwidget.namedfile#66
Depends on:
- plone/plone.namedfile#158
- plone/plone.formwidget.namedfile#67
thet added a commit to plone/plone.app.z3cform that referenced this pull request Mar 14, 2024
If the widget's field - if there is one - has `allowedContentTypes` set (the `NamedImage` field has `image/*` set by default) the allowed content types are rendered as `accept` attribute on the file input.

This already restricts the allowed file types before uploading while still being checked on the server side too.

Fixes: plone/plone.formwidget.namedfile#66
Depends on:
- plone/plone.namedfile#158
- plone/plone.formwidget.namedfile#67
Copy link
Member

@petschki petschki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thet
Copy link
Member Author

thet commented Mar 14, 2024

@petschki tnx for the feedback!
I will quickly simplify some parts for some feedback I got from @ale-rt and will re-submit again.

@thet thet marked this pull request as draft March 14, 2024 14:25
@thet thet force-pushed the allowed_content_types branch 2 times, most recently from 9b4cdab to 514b4eb Compare March 14, 2024 19:57
Support to constrain files to specific media types with a "accept" attribute on
file and image fields, just like the "accept" attribute of the HTML file input.

Fixes: #157
Change get_contenttype to support common types which are or were not registered
with IANA, like image/webp or audio/midi.

Note: image/webp is already a IANA registered type and also added by
Products.MimetypesRegistry.
thet added a commit to plone/plone.formwidget.namedfile that referenced this pull request Mar 14, 2024
If the widget's field - if there is one - has the "accept" attribute set (the
`NamedImage` field has `image/*` set by default) then this is rendered as an
`accept` attribute on the file input.

This would restrict the allowed file types before uploading while still being
checked on the server side.

Fixes: #66
Depends on: plone/plone.namedfile#158
[thet]
thet added a commit to plone/plone.formwidget.namedfile that referenced this pull request Mar 14, 2024
If the widget's field - if there is one - has the "accept" attribute set (the
`NamedImage` field has `image/*` set by default) then this is rendered as an
`accept` attribute on the file input.

This would restrict the allowed file types before uploading while still being
checked on the server side.

Fixes: #66
Depends on: plone/plone.namedfile#158
[thet]
thet added a commit to plone/plone.app.z3cform that referenced this pull request Mar 14, 2024
If the widget's field - if there is one - has the "accept" attribute set (the
`NamedImage` field has `image/*` set by default) then this is rendered as an
`accept` attribute on the file input.

This would restrict the allowed file types before uploading while still being
checked on the server side.

Fixes: plone/plone.formwidget.namedfile#66
Depends on:
- plone/plone.namedfile#158
- plone/plone.formwidget.namedfile#67
thet added a commit to plone/plone.app.z3cform that referenced this pull request Mar 14, 2024
If the widget's field - if there is one - has the "accept" attribute set (the
`NamedImage` field has `image/*` set by default) then this is rendered as an
`accept` attribute on the file input.

This would restrict the allowed file types before uploading while still being
checked on the server side.

Fixes: plone/plone.formwidget.namedfile#66
Depends on:
- plone/plone.namedfile#158
- plone/plone.formwidget.namedfile#67
@thet
Copy link
Member Author

thet commented Mar 14, 2024

@jenkins-plone-org please run jobs

thet added a commit to plone/plone.app.z3cform that referenced this pull request Mar 14, 2024
If the widget's field - if there is one - has the "accept" attribute set (the
`NamedImage` field has `image/*` set by default) then this is rendered as an
`accept` attribute on the file input.

This would restrict the allowed file types before uploading while still being
checked on the server side.

Fixes: plone/plone.formwidget.namedfile#66
Depends on:
- plone/plone.namedfile#158
- plone/plone.formwidget.namedfile#67
thet added a commit to plone/plone.app.z3cform that referenced this pull request Mar 14, 2024
If the widget's field - if there is one - has the "accept" attribute set (the
`NamedImage` field has `image/*` set by default) then this is rendered as an
`accept` attribute on the file input.

This would restrict the allowed file types before uploading while still being
checked on the server side.

Fixes: plone/plone.formwidget.namedfile#66
Depends on:
- plone/plone.namedfile#158
- plone/plone.formwidget.namedfile#67
thet added a commit to plone/plone.formwidget.namedfile that referenced this pull request Mar 14, 2024
If the widget's field - if there is one - has the "accept" attribute set (the
`NamedImage` field has `image/*` set by default) then this is rendered as an
`accept` attribute on the file input.

This would restrict the allowed file types before uploading while still being
checked on the server side.

Fixes: #66
Depends on: plone/plone.namedfile#158
[thet]
@thet thet marked this pull request as ready for review March 14, 2024 22:03
Copy link
Sponsor Member

@mauritsvanrees mauritsvanrees left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks.

@mauritsvanrees mauritsvanrees merged commit c1a80f7 into master Mar 15, 2024
11 of 12 checks passed
@mauritsvanrees mauritsvanrees deleted the allowed_content_types branch March 15, 2024 10:16
thet added a commit to plone/plone.formwidget.namedfile that referenced this pull request Mar 15, 2024
If the widget's field - if there is one - has the "accept" attribute set (the
`NamedImage` field has `image/*` set by default) then this is rendered as an
`accept` attribute on the file input.

This would restrict the allowed file types before uploading while still being
checked on the server side.

Fixes: #66
Depends on: plone/plone.namedfile#158
[thet]
thet added a commit to plone/plone.formwidget.namedfile that referenced this pull request Mar 15, 2024
If the widget's field - if there is one - has the "accept" attribute set (the
`NamedImage` field has `image/*` set by default) then this is rendered as an
`accept` attribute on the file input.

This would restrict the allowed file types before uploading while still being
checked on the server side.

Fixes: #66
Depends on: plone/plone.namedfile#158
[thet]
mister-roboto pushed a commit to plone/buildout.coredev that referenced this pull request Mar 15, 2024
Branch: refs/heads/master
Date: 2024-03-15T12:23:27+01:00
Author: Johannes Raggam (thet) <thetetet@gmail.com>
Commit: plone/plone.formwidget.namedfile@49d47c6

Add support for the "accept" attribute on file inputs.

If the widget's field - if there is one - has the "accept" attribute set (the
`NamedImage` field has `image/*` set by default) then this is rendered as an
`accept` attribute on the file input.

This would restrict the allowed file types before uploading while still being
checked on the server side.

Fixes: plone/plone.formwidget.namedfile#66
Depends on: plone/plone.namedfile#158
[thet]

Files changed:
A news/67.feature
M plone/formwidget/namedfile/file_input.pt
M plone/formwidget/namedfile/image_input.pt
M plone/formwidget/namedfile/widget.py
M plone/formwidget/namedfile/widget.rst
M setup.py
Repository: plone.formwidget.namedfile

Branch: refs/heads/master
Date: 2024-03-15T12:23:27+01:00
Author: Johannes Raggam (thet) <thetetet@gmail.com>
Commit: plone/plone.formwidget.namedfile@57815fe

file input: Show accepted media types.

Files changed:
M plone/formwidget/namedfile/file_input.pt
M plone/formwidget/namedfile/image_input.pt
M plone/formwidget/namedfile/widget.rst
Repository: plone.formwidget.namedfile

Branch: refs/heads/master
Date: 2024-03-15T13:46:12+01:00
Author: Johannes Raggam (thet) <thetetet@gmail.com>
Commit: plone/plone.formwidget.namedfile@462d8f1

Merge pull request #67 from plone/allowed_content_types

Add support for accept attribute on file input.

Files changed:
A news/67.feature
M plone/formwidget/namedfile/file_input.pt
M plone/formwidget/namedfile/image_input.pt
M plone/formwidget/namedfile/widget.py
M plone/formwidget/namedfile/widget.rst
M setup.py
mister-roboto pushed a commit to plone/buildout.coredev that referenced this pull request Mar 15, 2024
Branch: refs/heads/master
Date: 2024-03-15T12:23:27+01:00
Author: Johannes Raggam (thet) <thetetet@gmail.com>
Commit: plone/plone.formwidget.namedfile@49d47c6

Add support for the "accept" attribute on file inputs.

If the widget's field - if there is one - has the "accept" attribute set (the
`NamedImage` field has `image/*` set by default) then this is rendered as an
`accept` attribute on the file input.

This would restrict the allowed file types before uploading while still being
checked on the server side.

Fixes: plone/plone.formwidget.namedfile#66
Depends on: plone/plone.namedfile#158
[thet]

Files changed:
A news/67.feature
M plone/formwidget/namedfile/file_input.pt
M plone/formwidget/namedfile/image_input.pt
M plone/formwidget/namedfile/widget.py
M plone/formwidget/namedfile/widget.rst
M setup.py
Repository: plone.formwidget.namedfile

Branch: refs/heads/master
Date: 2024-03-15T12:23:27+01:00
Author: Johannes Raggam (thet) <thetetet@gmail.com>
Commit: plone/plone.formwidget.namedfile@57815fe

file input: Show accepted media types.

Files changed:
M plone/formwidget/namedfile/file_input.pt
M plone/formwidget/namedfile/image_input.pt
M plone/formwidget/namedfile/widget.rst
Repository: plone.formwidget.namedfile

Branch: refs/heads/master
Date: 2024-03-15T13:46:12+01:00
Author: Johannes Raggam (thet) <thetetet@gmail.com>
Commit: plone/plone.formwidget.namedfile@462d8f1

Merge pull request #67 from plone/allowed_content_types

Add support for accept attribute on file input.

Files changed:
A news/67.feature
M plone/formwidget/namedfile/file_input.pt
M plone/formwidget/namedfile/image_input.pt
M plone/formwidget/namedfile/widget.py
M plone/formwidget/namedfile/widget.rst
M setup.py
mister-roboto pushed a commit to plone/buildout.coredev that referenced this pull request Mar 15, 2024
Branch: refs/heads/4.3.x
Date: 2024-03-14T21:26:02+01:00
Author: Johannes Raggam (thet) <thetetet@gmail.com>
Commit: plone/plone.app.z3cform@dada24f

Add support for the "accept" attribute on file inputs.

If the widget's field - if there is one - has the "accept" attribute set (the
`NamedImage` field has `image/*` set by default) then this is rendered as an
`accept` attribute on the file input.

This would restrict the allowed file types before uploading while still being
checked on the server side.

Fixes: plone/plone.formwidget.namedfile#66
Depends on:
- plone/plone.namedfile#158
- plone/plone.formwidget.namedfile#67

Files changed:
A news/198.feature
M plone/app/z3cform/templates/file_input.pt
M plone/app/z3cform/templates/image_input.pt
M setup.py
Repository: plone.app.z3cform

Branch: refs/heads/4.3.x
Date: 2024-03-14T23:01:38+01:00
Author: Johannes Raggam (thet) <thetetet@gmail.com>
Commit: plone/plone.app.z3cform@623e413

file input: Show accepted media types.

Files changed:
M plone/app/z3cform/templates/file_input.pt
M plone/app/z3cform/templates/image_input.pt
Repository: plone.app.z3cform

Branch: refs/heads/4.3.x
Date: 2024-03-15T12:40:14+01:00
Author: Johannes Raggam (thet) <thetetet@gmail.com>
Commit: plone/plone.app.z3cform@e58d843

Update plone/app/z3cform/templates/image_input.pt

Co-authored-by: Maurits van Rees &lt;maurits@vanrees.org&gt;

Files changed:
M plone/app/z3cform/templates/image_input.pt
Repository: plone.app.z3cform

Branch: refs/heads/4.3.x
Date: 2024-03-15T12:40:23+01:00
Author: Johannes Raggam (thet) <thetetet@gmail.com>
Commit: plone/plone.app.z3cform@cd8690a

Update plone/app/z3cform/templates/image_input.pt

Co-authored-by: Maurits van Rees &lt;maurits@vanrees.org&gt;

Files changed:
M plone/app/z3cform/templates/image_input.pt
Repository: plone.app.z3cform

Branch: refs/heads/4.3.x
Date: 2024-03-15T12:40:38+01:00
Author: Johannes Raggam (thet) <thetetet@gmail.com>
Commit: plone/plone.app.z3cform@be47183

Update plone/app/z3cform/templates/file_input.pt

Co-authored-by: Maurits van Rees &lt;maurits@vanrees.org&gt;

Files changed:
M plone/app/z3cform/templates/file_input.pt
Repository: plone.app.z3cform

Branch: refs/heads/4.3.x
Date: 2024-03-15T12:40:49+01:00
Author: Johannes Raggam (thet) <thetetet@gmail.com>
Commit: plone/plone.app.z3cform@2071ff4

Update plone/app/z3cform/templates/file_input.pt

Co-authored-by: Maurits van Rees &lt;maurits@vanrees.org&gt;

Files changed:
M plone/app/z3cform/templates/file_input.pt
Repository: plone.app.z3cform

Branch: refs/heads/4.3.x
Date: 2024-03-15T14:40:15+01:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.app.z3cform@f327f33

Depend on the just released plone.formwidget.namedfile 3.1.0.

Files changed:
M setup.py
Repository: plone.app.z3cform

Branch: refs/heads/4.3.x
Date: 2024-03-15T16:35:05+01:00
Author: Johannes Raggam (thet) <thetetet@gmail.com>
Commit: plone/plone.app.z3cform@dc9ccae

Merge pull request #199 from plone/allowed_content_types--4.3.x

Add support for accept attribute on file input (4.3.x branch)

Files changed:
A news/198.feature
M plone/app/z3cform/templates/file_input.pt
M plone/app/z3cform/templates/image_input.pt
M setup.py
mister-roboto pushed a commit to plone/buildout.coredev that referenced this pull request Mar 15, 2024
Branch: refs/heads/master
Date: 2024-03-14T21:25:17+01:00
Author: Johannes Raggam (thet) <thetetet@gmail.com>
Commit: plone/plone.app.z3cform@c52dd4e

Add support for the "accept" attribute on file inputs.

If the widget's field - if there is one - has the "accept" attribute set (the
`NamedImage` field has `image/*` set by default) then this is rendered as an
`accept` attribute on the file input.

This would restrict the allowed file types before uploading while still being
checked on the server side.

Fixes: plone/plone.formwidget.namedfile#66
Depends on:
- plone/plone.namedfile#158
- plone/plone.formwidget.namedfile#67

Files changed:
A news/198.feature
M plone/app/z3cform/templates/file_input.pt
M plone/app/z3cform/templates/image_input.pt
M setup.py
Repository: plone.app.z3cform

Branch: refs/heads/master
Date: 2024-03-14T23:02:39+01:00
Author: Johannes Raggam (thet) <thetetet@gmail.com>
Commit: plone/plone.app.z3cform@c6e1d78

file input: Show accepted media types.

Files changed:
M plone/app/z3cform/templates/file_input.pt
M plone/app/z3cform/templates/image_input.pt
Repository: plone.app.z3cform

Branch: refs/heads/master
Date: 2024-03-15T12:41:28+01:00
Author: Johannes Raggam (thet) <thetetet@gmail.com>
Commit: plone/plone.app.z3cform@f7236d3

Update plone/app/z3cform/templates/image_input.pt

Co-authored-by: Maurits van Rees &lt;maurits@vanrees.org&gt;

Files changed:
M plone/app/z3cform/templates/image_input.pt
Repository: plone.app.z3cform

Branch: refs/heads/master
Date: 2024-03-15T12:41:38+01:00
Author: Johannes Raggam (thet) <thetetet@gmail.com>
Commit: plone/plone.app.z3cform@5d6d0e7

Update plone/app/z3cform/templates/image_input.pt

Co-authored-by: Maurits van Rees &lt;maurits@vanrees.org&gt;

Files changed:
M plone/app/z3cform/templates/image_input.pt
Repository: plone.app.z3cform

Branch: refs/heads/master
Date: 2024-03-15T12:41:47+01:00
Author: Johannes Raggam (thet) <thetetet@gmail.com>
Commit: plone/plone.app.z3cform@e4b11e6

Update plone/app/z3cform/templates/file_input.pt

Co-authored-by: Maurits van Rees &lt;maurits@vanrees.org&gt;

Files changed:
M plone/app/z3cform/templates/file_input.pt
Repository: plone.app.z3cform

Branch: refs/heads/master
Date: 2024-03-15T12:41:54+01:00
Author: Johannes Raggam (thet) <thetetet@gmail.com>
Commit: plone/plone.app.z3cform@b45fb30

Update plone/app/z3cform/templates/file_input.pt

Co-authored-by: Maurits van Rees &lt;maurits@vanrees.org&gt;

Files changed:
M plone/app/z3cform/templates/file_input.pt
Repository: plone.app.z3cform

Branch: refs/heads/master
Date: 2024-03-15T14:33:28+01:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.app.z3cform@dc8eaac

Depend on the just released plone.formwidget.namedfile 3.1.0.

Files changed:
M setup.py
Repository: plone.app.z3cform

Branch: refs/heads/master
Date: 2024-03-15T14:45:09+01:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.app.z3cform@4262f25

Configuring with plone/meta

Files changed:
A dependabot.yml
M .editorconfig
M .flake8
M .github/workflows/meta.yml
M .gitignore
M .meta.toml
M .pre-commit-config.yaml
M pyproject.toml
M tox.ini
Repository: plone.app.z3cform

Branch: refs/heads/master
Date: 2024-03-15T14:50:51+01:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.app.z3cform@8b5d2aa

dependencychecker: ignore plone.formwidget.namedfile.

z3c.dependencychecker says this dependency is not needed, but it is wrong:
it is used in widgets.zcml.

Files changed:
M .meta.toml
M pyproject.toml
Repository: plone.app.z3cform

Branch: refs/heads/master
Date: 2024-03-15T16:37:34+01:00
Author: Johannes Raggam (thet) <thetetet@gmail.com>
Commit: plone/plone.app.z3cform@f081ed7

Merge pull request #200 from plone/allowed_content_types

Add support for accept attribute on file input.

Files changed:
A dependabot.yml
A news/198.feature
M .editorconfig
M .flake8
M .github/workflows/meta.yml
M .gitignore
M .meta.toml
M .pre-commit-config.yaml
M plone/app/z3cform/templates/file_input.pt
M plone/app/z3cform/templates/image_input.pt
M pyproject.toml
M setup.py
M tox.ini
Copy link
Sponsor Member

@davisagli davisagli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thet Nice one!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing support to constrain allowed content types
5 participants