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

Handle the massive upload #13

Closed
wants to merge 3 commits into from
Closed
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
50 changes: 34 additions & 16 deletions collective/limitfilesizepanel/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,55 @@
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:plone="http://namespaces.plone.org/plone"
xmlns:zcml="http://namespaces.zope.org/zcml"
i18n_domain="collective.limitfilesizepanel">
i18n_domain="collective.limitfilesizepanel"
>


<browser:resourceDirectory
name="collective.limitfilesizepanel.images"
directory="images"
/>
<browser:resourceDirectory
name="collective.limitfilesizepanel.images"
directory="images"
/>

<browser:page
name="limitfilesize-settings"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
class=".controlpanel.LimitFileSizeControlPanel"
layer="collective.limitfilesizepanel.interfaces.ILimitFileSizePanelLayer"
permission="collective.limitfilesizepanel.LimitFileSizePanel"
/>
<browser:page
name="limitfilesize-settings"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
class=".controlpanel.LimitFileSizeControlPanel"
permission="collective.limitfilesizepanel.LimitFileSizePanel"
layer="collective.limitfilesizepanel.interfaces.ILimitFileSizePanelLayer"
/>

<browser:page
<browser:page
name="lfsp_helpers_view"
for="*"
class=".limitfilesizepanel_view.View"
allowed_interface=".limitfilesizepanel_view.IHelpersView"
permission="zope2.View"
for="*"
layer="collective.limitfilesizepanel.interfaces.ILimitFileSizePanelLayer"
allowed_interface=".limitfilesizepanel_view.IHelpersView"
/>

<browser:page
zcml:condition="have plone-5"
name="fileUpload"
for="Products.CMFCore.interfaces._content.IFolderish"
class=".tinymce_upload_p5.FileUpload"
permission="zope2.View"
layer="collective.limitfilesizepanel.interfaces.ILimitFileSizePanelLayer"
zcml:condition="have plone-5"
/>

<browser:page
name="fileUpload"
for="Products.CMFPlone.interfaces.siteroot.IPloneSiteRoot"
class=".folder_contents_upload.FileUpload"
permission="zope2.View"
layer="collective.limitfilesizepanel.interfaces.ILimitFileSizePanelLayer"
/>

<browser:page
name="fileUpload"
for="plone.dexterity.interfaces.IDexterityContainer"
class=".folder_contents_upload.FileUpload"
permission="zope2.View"
layer="collective.limitfilesizepanel.interfaces.ILimitFileSizePanelLayer"
/>

</configure>
47 changes: 47 additions & 0 deletions collective/limitfilesizepanel/browser/folder_contents_upload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-
from plone import api
from plone.app.content.browser.file import FileUploadView as BaseFileUploadView

import mimetypes


class FileUpload(BaseFileUploadView):
"""
Add filetype validation for folder_contents massive upload view.
This view is a merge from collective.limitfilesizepanel and rer.hardening
customizations.
"""

def __call__(self):
filedata = self.request.form.get("file", None)

if not filedata:
return super(FileUpload, self).__call__()

# limitfilesizepanel check
filename = filedata.filename
content_type = mimetypes.guess_type(filename)[0] or ""
ctr = api.portal.get_tool(name="content_type_registry")
portal_type = ctr.findTypeName(filename.lower(), content_type, "") or "File"

helper_view = api.content.get_view(
name="lfsp_helpers_view",
context=self.context,
request=self.context.REQUEST,
)

if helper_view.newDataOnly() and "/edit" in self.request.get(
"HTTP_REFERER"
Copy link
Contributor

Choose a reason for hiding this comment

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

@folix-01 l'header REFERER non è garantito che i browser lo passano durante le richieste, se anche la pagina precendete era /edit ma il browser non ti passa il REFERER, il funzionamento normale è comunque garantito?

Copy link
Member Author

Choose a reason for hiding this comment

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

Tutto questo è copiato da rer.base, facendo le prove, funziona

): # noqa
return super(FileUpload, self).__call__()
maxsize = helper_view.get_maxsize_tiny((portal_type,))
if not maxsize:
return super(FileUpload, self).__call__()

size_check = helper_view.check_size(maxsize=maxsize, uploadfile=filedata)
if size_check and not size_check.get("valid", False):
response = self.request.RESPONSE
response.setStatus(403)
return size_check.get("error", "")

return super(FileUpload, self).__call__()
40 changes: 24 additions & 16 deletions collective/limitfilesizepanel/configure.zcml
Original file line number Diff line number Diff line change
@@ -1,50 +1,58 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:zcml="http://namespaces.zope.org/zcml"
xmlns:five="http://namespaces.zope.org/five"
xmlns:i18n="http://namespaces.zope.org/i18n"
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
xmlns:monkey="http://namespaces.plone.org/monkey"
i18n_domain="collective.limitfilesizepanel">
xmlns:i18n="http://namespaces.zope.org/i18n"
xmlns:monkey="http://namespaces.plone.org/monkey"
xmlns:zcml="http://namespaces.zope.org/zcml"
i18n_domain="collective.limitfilesizepanel"
>

<five:registerPackage package="." />

<include package="plone.app.registry" />
<include package="collective.monkeypatcher" />

<i18n:registerTranslations directory="locales" />

<permission
id="collective.limitfilesizepanel.LimitFileSizePanel"
title="collective.limitfilesizepanel: Manage limit file size settings"
/>
id="collective.limitfilesizepanel.LimitFileSizePanel"
title="collective.limitfilesizepanel: Manage limit file size settings"
/>
<permission
id="collective.limitfilesizepanel.BypassLimitSize"
title="collective.limitfilesizepanel: Bypass limit size"
/>
id="collective.limitfilesizepanel.BypassLimitSize"
title="collective.limitfilesizepanel: Bypass limit size"
/>

<include package=".browser" />
<include file="upgrades.zcml" />


<genericsetup:registerProfile
name="default"
title="Limit files and images size"
directory="profiles/default"
description="Configure the file size limit from control panel"
provides="Products.GenericSetup.interfaces.EXTENSION"
directory="profiles/default"
/>
<genericsetup:registerProfile
name="uninstall"
title="Remove collective.limitfilesizepanel"
directory="profiles/uninstall"
description=""
provides="Products.GenericSetup.interfaces.EXTENSION"
directory="profiles/uninstall"
/>

<!-- <adapter factory=".dx_validators.FileSizeValidator" />
<!-- <adapter factory=".dx_validators.FileSizeValidator" />
<adapter factory=".dx_validators.ImageFileSizeValidator" /> -->
<adapter factory=".dx_validators.FileSizeValidator" name="collective.limitfilesizepanel.file_size_validator" />
<adapter factory=".dx_validators.ImageSizeValidator" name="collective.limitfilesizepanel.image_size_validator" />
<adapter
factory=".dx_validators.FileSizeValidator"
name="collective.limitfilesizepanel.file_size_validator"
/>
<adapter
factory=".dx_validators.ImageSizeValidator"
name="collective.limitfilesizepanel.image_size_validator"
/>



Expand Down
Loading