Skip to content

Commit

Permalink
Support maximum file count and size config switches.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Jan 7, 2016
1 parent 684e774 commit 4a2b76f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions kronolith/config/conf.xml
Expand Up @@ -20,6 +20,12 @@
<configsection name="documents">
<configheader>Virtual File Storage</configheader>
<configvfs switchname="type" />
<configinteger name="size_limit" desc="The maximum total size of
documents allowed per event (in bytes)? Set to 0 for no limit. [The
maximum allowable size of any individual attachment is set via the PHP
'upload_max_filesize' parameter; see kronolith/docs/INSTALL]">0</configinteger>
<configinteger name="count_limit" desc="The maximum total number of
documents allowed per event? Set to 0 for no limit.">0</configinteger>
</configsection>

<configsection name="storage">
Expand Down
12 changes: 9 additions & 3 deletions kronolith/lib/Ajax/Application/Handler.php
Expand Up @@ -1541,7 +1541,7 @@ public function checkResources()
*/
public function addFile()
{
global $notification;
global $notification, $conf;

$result = new stdClass;
$result->success = 0;
Expand All @@ -1552,7 +1552,13 @@ public function addFile()
try {
$event = $this->_getDriver($this->vars->c)->getEvent($this->vars->i);
if ($this->_canUploadFiles()) {
$max_files = $conf['documents']['count_limit'];
foreach ($this->_addFileFromUpload() as $f) {
if (!empty($conf['documents']['count_limit']) &&
count($event->listFiles()) >= $max_files) {
$notification->push(_("You have reached the maximum number of allowed files."), 'horde.notification');
break;
}
if ($f instanceof Kronolith_Exception) {
$notification->push($f, 'horde.error');
} else {
Expand Down Expand Up @@ -1613,9 +1619,9 @@ protected function _canUploadFiles()
global $browser, $conf;

$size = $browser->allowFileUploads();
return empty($conf['file_uploads'])
return empty($conf['documents']['size_limit'])
? $size
: min($size, $conf['file_uploads']['size_limit']);
: min($size, $conf['documents']['size_limit']);
}

/**
Expand Down

0 comments on commit 4a2b76f

Please sign in to comment.