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

Limit ZIP Exports Size #1592

Merged
merged 2 commits into from
Mar 28, 2019
Merged
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
2 changes: 1 addition & 1 deletion onadata/libs/tests/utils/test_viewer_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def test_get_form_url(self):
url = get_form_url(request, username='bob', xform_pk=1)
self.assertEqual(url, 'https://ona.io/bob/1')

@override_settings(ZIP_REPORT_ATTACHMENT_LIMMIT=8)
@override_settings(ZIP_REPORT_ATTACHMENT_LIMIT=8)
@patch('onadata.libs.utils.viewer_tools.report_exception')
def test_create_attachments_zipfile_file_too_big(self, rpt_mock):
"""
Expand Down
14 changes: 7 additions & 7 deletions onadata/libs/utils/viewer_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@
import sys
import zipfile
from builtins import open
from future.utils import iteritems
from tempfile import NamedTemporaryFile
from xml.dom import minidom

from future.moves.urllib.parse import urljoin

import requests
from django.conf import settings
from django.core.files.storage import get_storage_class
from django.core.files.uploadedfile import InMemoryUploadedFile
from django.utils.translation import ugettext as _

import requests
from future.moves.urllib.parse import urljoin
from future.utils import iteritems

from onadata.libs.exceptions import EnketoError
from onadata.libs.utils import common_tags
Expand Down Expand Up @@ -254,16 +252,18 @@ def create_attachments_zipfile(attachments):
if default_storage.exists(filename):
try:
with default_storage.open(filename) as f:
if f.size > settings.ZIP_REPORT_ATTACHMENT_LIMMIT:
if f.size > settings.ZIP_REPORT_ATTACHMENT_LIMIT:
report_exception(
"Create attachment zip exception",
"File is greater than {} bytes".format(
settings.ZIP_REPORT_ATTACHMENT_LIMMIT)
settings.ZIP_REPORT_ATTACHMENT_LIMIT)
)
break
else:
z.writestr(attachment.media_file.name, f.read())
except IOError as e:
report_exception("Create attachment zip exception", e)
break

return tmp

Expand Down
12 changes: 4 additions & 8 deletions onadata/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@
import sys
from imp import reload

from future.moves.urllib.parse import urljoin

from past.builtins import basestring

from celery.signals import after_setup_logger
from django.core.exceptions import SuspiciousOperation
from django.utils.log import AdminEmailHandler

from celery.signals import after_setup_logger

from future.moves.urllib.parse import urljoin
from past.builtins import basestring

# setting default encoding to utf-8
if sys.version[0] == '2':
Expand Down Expand Up @@ -439,7 +435,7 @@ def configure_logging(logger, **kwargs):

CSV_FILESIZE_IMPORT_ASYNC_THRESHOLD = 100000 # Bytes
GOOGLE_SHEET_UPLOAD_BATCH = 1000
ZIP_REPORT_ATTACHMENT_LIMMIT = 5242880000 # 500 MB in Bytes
ZIP_REPORT_ATTACHMENT_LIMIT = 5242880000 # 500 MB in Bytes

# duration to keep zip exports before deletion (in seconds)
ZIP_EXPORT_COUNTDOWN = 3600 # 1 hour
Expand Down