diff --git a/app/controllers/course/files.php b/app/controllers/course/files.php index 3e6e1356db4e160f12c8fdf6828e70917cb83b98..d98ef9a606e379b456bb32869f51f2887f6539ca 100644 --- a/app/controllers/course/files.php +++ b/app/controllers/course/files.php @@ -35,13 +35,11 @@ class Course_FilesController extends AuthenticatedController Navigation::activateItem('/course/files'); if (is_object($GLOBALS['user']) && $GLOBALS['user']->id !== 'nobody') { + $constraints = FileManager::getUploadTypeConfig($this->course->id); + PageLayout::addHeadElement('script', ['type' => 'text/javascript'], sprintf( 'STUDIP.Files.setUploadConstraints(%s);', - json_encode([ - 'filesize' => $GLOBALS['UPLOAD_TYPES']['default']['file_sizes'][$GLOBALS['user']->perms], - 'type' => $GLOBALS['UPLOAD_TYPES']['default']['type'], - 'file_types' => $GLOBALS['UPLOAD_TYPES']['default']['file_types'], - ]) + json_encode($constraints) )); } } diff --git a/app/controllers/files.php b/app/controllers/files.php index bfc2e98af1096a810650ad9e1b868a51647d4697..4e114409ba6a82ce14f9835ac25a14c12510eefb 100644 --- a/app/controllers/files.php +++ b/app/controllers/files.php @@ -46,13 +46,11 @@ class FilesController extends AuthenticatedController throw new AccessDeniedException(); } + $constraints = FileManager::getUploadTypeConfig($this->user->id); + PageLayout::addHeadElement('script', ['type' => 'text/javascript'], sprintf( 'STUDIP.Files.setUploadConstraints(%s);', - json_encode([ - 'filesize' => $GLOBALS['UPLOAD_TYPES']['personalfiles']['file_sizes'][$this->user->perms], - 'type' => $GLOBALS['UPLOAD_TYPES']['personalfiles']['type'], - 'file_types' => $GLOBALS['UPLOAD_TYPES']['personalfiles']['file_types'], - ]) + json_encode($constraints) )); } diff --git a/app/controllers/institute/files.php b/app/controllers/institute/files.php index 9f3f7a0afdc93047c03f2aa0272d3898980a4b94..e7a21d13a63a4f07c4132e5057de2f364d203c5d 100644 --- a/app/controllers/institute/files.php +++ b/app/controllers/institute/files.php @@ -37,13 +37,11 @@ class Institute_FilesController extends AuthenticatedController Navigation::activateItem('/course/files'); if (is_object($GLOBALS['user']) && $GLOBALS['user']->id !== 'nobody') { + $constraints = FileManager::getUploadTypeConfig($this->institute->id); + PageLayout::addHeadElement('script', ['type' => 'text/javascript'], sprintf( 'STUDIP.Files.setUploadConstraints(%s);', - json_encode([ - 'filesize' => $GLOBALS['UPLOAD_TYPES']['default']['file_sizes'][$GLOBALS['user']->perms], - 'type' => $GLOBALS['UPLOAD_TYPES']['default']['type'], - 'file_types' => $GLOBALS['UPLOAD_TYPES']['default']['file_types'], - ]) + json_encode($constraints) )); } } diff --git a/lib/filesystem/FileManager.php b/lib/filesystem/FileManager.php index f573be8f9f2fb8624c7581d2be7fae50b5e6441b..6109776b34dbc6c1b947a5dc3985ce8c4b05b3ad 100644 --- a/lib/filesystem/FileManager.php +++ b/lib/filesystem/FileManager.php @@ -1736,17 +1736,21 @@ class FileManager if (is_null($user_id)) { $user_id = $GLOBALS['user']->id; } + + $status = $GLOBALS['perm']->get_perm($user_id); + $active_upload_type = 'default'; + $range_object = get_object_by_range_id($range_id); - $active_upload_type = null; if ($range_object instanceof Course) { $status = $GLOBALS['perm']->get_studip_perm($range_id, $user_id); $active_upload_type = $range_object->status; } elseif ($range_object instanceof Institute) { $status = $GLOBALS['perm']->get_studip_perm($range_id, $user_id); $active_upload_type = 'institute'; - } else { - $status = $GLOBALS['perm']->get_perm($user_id); - $active_upload_type = "personalfiles"; + } elseif ($range_object instanceof User) { + $active_upload_type = 'personalfiles'; + } elseif (Message::exists($range_id)) { + $active_upload_type = 'attachments'; } if (!isset($GLOBALS['UPLOAD_TYPES'][$active_upload_type])) { diff --git a/lib/filesystem/MessageFolder.php b/lib/filesystem/MessageFolder.php index b3c45f5fe76857ec4d13ed5538da46c1f8f106d0..c42ddef90589a09482c84cbc602b8d76537702eb 100644 --- a/lib/filesystem/MessageFolder.php +++ b/lib/filesystem/MessageFolder.php @@ -238,26 +238,6 @@ class MessageFolder extends StandardFolder implements FolderType { } - /** - * This method handles file upload validation. - * - * @param array $uploaded_file The uploaded file that shall be validated. - * @param string $user_id The user who wishes to upload a file - * in this MessageFolder. - * - * @return string|null An error message on failure, null on success. - */ - public function validateUpload(FileType $newfile, $user_id) - { - $status = $GLOBALS['perm']->get_perm($user_id); - $upload_type = [ - 'type' => $GLOBALS['UPLOAD_TYPES']['attachments']['type'], - 'file_types' => $GLOBALS['UPLOAD_TYPES']['attachments']['file_types'], - 'file_size' => $GLOBALS['UPLOAD_TYPES']['attachments']['file_sizes'][$status] - ]; - return $this->getValidationMessages($upload_type, $newfile); - } - /** * Handles the deletion of a file inside this folder. * diff --git a/lib/models/Courseware/Filesystem/PublicFolder.php b/lib/models/Courseware/Filesystem/PublicFolder.php index 5622f79568dd380dc16ed9a9ce39c18a29cad273..94a7b54a4b69244e8bfc2ae001bfd7211f25239e 100755 --- a/lib/models/Courseware/Filesystem/PublicFolder.php +++ b/lib/models/Courseware/Filesystem/PublicFolder.php @@ -165,21 +165,6 @@ class PublicFolder extends StandardFolder { } - /** - * {@inheritdoc} - */ - public function validateUpload(FileType $newfile, $userId) - { - $status = $GLOBALS['perm']->get_perm($userId); - $uploadType = [ - 'type' => $GLOBALS['UPLOAD_TYPES']['default']['type'], - 'file_types' => $GLOBALS['UPLOAD_TYPES']['default']['file_types'], - 'file_size' => $GLOBALS['UPLOAD_TYPES']['default']['file_sizes'][$status], - ]; - - return $this->getValidationMessages($uploadType, $newfile); - } - /** * {@inheritdoc} */ diff --git a/resources/assets/javascripts/lib/files.js b/resources/assets/javascripts/lib/files.js index 716219e9a359b6234ba113e90e28a44d1ab53cf9..08adc296c0e51b43f5e69833f37438be0cb3be0c 100644 --- a/resources/assets/javascripts/lib/files.js +++ b/resources/assets/javascripts/lib/files.js @@ -75,7 +75,7 @@ const Files = { if (!Files.uploadConstraints) { return true; } - if (file.size > Files.uploadConstraints.filesize) { + if (file.size > Files.uploadConstraints.file_size) { return false; } var ending = file.name.lastIndexOf('.') !== -1 ? file.name.substr(file.name.lastIndexOf('.') + 1) : '';