-
Notifications
You must be signed in to change notification settings - Fork 3
Rework mime type white list #2198
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
Changes from 29 commits
8699bc1
66ac404
5ebe0fb
9416abf
7eed62a
4ab42df
cf252e2
6e9afd6
3f718d2
5572020
a6bd385
1293c8e
af685f5
a50f6f0
458a82d
8d99429
c31d0e3
eee980c
248819a
5621994
21274d1
c4a1eef
e77bc49
9a6a187
d122951
1e7b28b
427563e
fa438e0
0f7b210
e5552d6
a545477
5f7bcb2
5c54c06
f839024
ef4b1fe
789e503
f6f9d7c
c170834
00b1614
0e9c164
a7a000f
2511b0b
9d9a819
15d752d
44c347b
03aa665
8a8b6d0
e313a24
d4eabb6
5b4cfa5
85084a5
7be6af8
01b0af2
0b047e1
20b5c85
f92840a
39b3ce0
4b21d7d
e6422d5
0ca7d5a
d7db252
6424a66
7b7a450
cf903fe
8ec5407
fe8496c
597d67d
6ebaf81
0e03033
a67425f
eb7d29a
d3b3249
9e89796
64123ac
76c94cb
00b76b6
b24c85f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ | |
| from onegov.file.utils import IMAGE_MIME_TYPES_AND_SVG | ||
| from onegov.form import log, _ | ||
| from onegov.form.utils import path_to_filename | ||
| from onegov.form.validators import ValidPhoneNumber | ||
| from onegov.form.validators import ValidPhoneNumber, WhitelistedMimeType | ||
| from onegov.form.widgets import ChosenSelectWidget | ||
| from onegov.form.widgets import LinkPanelWidget | ||
| from onegov.form.widgets import DurationInput | ||
|
|
@@ -59,7 +59,7 @@ | |
| if TYPE_CHECKING: | ||
| from collections.abc import Callable, Iterator, Sequence | ||
| from datetime import datetime | ||
| from onegov.core.types import FileDict as StrictFileDict | ||
| from onegov.core.types import FileDict as StrictFileDict, LaxFileDict | ||
| from onegov.file import File | ||
| from onegov.form import Form | ||
| from onegov.form.types import ( | ||
|
|
@@ -261,28 +261,58 @@ class UploadField(FileField): | |
| file: IO[bytes] | None | ||
| filename: str | None | ||
|
|
||
| if TYPE_CHECKING: | ||
| def __init__( | ||
| self, | ||
| label: str | None = None, | ||
| validators: Validators[FormT, Self] | None = None, | ||
| filters: Sequence[Filter] = (), | ||
| description: str = '', | ||
| id: str | None = None, | ||
| default: Sequence[StrictFileDict] = (), | ||
| widget: Widget[Self] | None = None, | ||
| render_kw: dict[str, Any] | None = None, | ||
| name: str | None = None, | ||
| _form: BaseForm | None = None, | ||
| _prefix: str = '', | ||
| _translations: _SupportsGettextAndNgettext | None = None, | ||
| _meta: DefaultMeta | None = None, | ||
| # onegov specific kwargs that get popped off | ||
| *, | ||
| fieldset: str | None = None, | ||
| depends_on: Sequence[Any] | None = None, | ||
| pricing: PricingRules | None = None, | ||
| ): ... | ||
| def __init__( | ||
Tschuppi81 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| self, | ||
| label: str | None = None, | ||
| validators: Validators[FormT, Self] | None = None, | ||
| filters: Sequence[Filter] = (), | ||
| description: str = '', | ||
| id: str | None = None, | ||
| default: LaxFileDict | None = None, | ||
Tschuppi81 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| widget: Widget[Self] | None = None, | ||
| render_kw: dict[str, Any] | None = None, | ||
| name: str | None = None, | ||
| allowed_mimetypes: Sequence[str] | None = None, | ||
| _form: BaseForm | None = None, | ||
| _prefix: str = '', | ||
| _translations: _SupportsGettextAndNgettext | None = None, | ||
| _meta: DefaultMeta | None = None, | ||
| # onegov specific kwargs that get popped off | ||
| *, | ||
| fieldset: str | None = None, | ||
| depends_on: Sequence[Any] | None = None, | ||
| pricing: PricingRules | None = None, | ||
| ): | ||
| validator = ( | ||
| WhitelistedMimeType(allowed_mimetypes) | ||
| if allowed_mimetypes | ||
| else WhitelistedMimeType() | ||
| ) | ||
|
|
||
| if validators: | ||
| validators = list(validators) | ||
| if not any(isinstance(validator, WhitelistedMimeType) | ||
| for validator in validators | ||
| ): | ||
| validators.append(validator) | ||
|
||
| else: | ||
| validators = [validator] | ||
|
|
||
| super().__init__( | ||
| label=label, | ||
| validators=validators, | ||
| filters=filters, | ||
| description=description, | ||
| id=id, | ||
| default=default, | ||
| widget=widget, | ||
| render_kw=render_kw, | ||
| name=name, | ||
| _form=_form, | ||
| _prefix=_prefix, | ||
| _translations=_translations, | ||
| _meta=_meta, | ||
| ) | ||
|
|
||
| # this is not quite accurate, since it is either a dictionary with all | ||
| # the keys or none of the keys, which would make type narrowing easier | ||
|
|
@@ -461,6 +491,7 @@ def __init__( | |
| render_kw: dict[str, Any] | None = None, | ||
| name: str | None = None, | ||
| upload_widget: Widget[UploadField] | None = None, | ||
| allowed_mimetypes: Sequence[str] | None = None, | ||
| _form: BaseForm | None = None, | ||
| _prefix: str = '', | ||
| _translations: _SupportsGettextAndNgettext | None = None, | ||
|
|
@@ -479,11 +510,11 @@ def __init__( | |
|
|
||
| # a lot of the arguments we just pass through to the subfield | ||
| unbound_field = self.upload_field_class( | ||
| validators=validators, # type:ignore[arg-type] | ||
| filters=filters, | ||
| description=description, | ||
| widget=upload_widget, | ||
| render_kw=render_kw, | ||
| allowed_mimetypes=allowed_mimetypes, | ||
| **extra_arguments | ||
| ) | ||
| super().__init__( | ||
|
|
@@ -494,6 +525,7 @@ def __init__( | |
| id=id, | ||
| default=default, | ||
| widget=widget, # type:ignore[arg-type] | ||
| validators=[*(validators or ())], | ||
|
||
| render_kw=render_kw, | ||
| name=name, | ||
| _form=_form, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.