From 842d4418276d1baabe39396c9f140a0a62372cc8 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Willms <tleilax+studip@gmail.com> Date: Thu, 9 Dec 2021 09:15:12 +0000 Subject: [PATCH] fixes #448 --- app/controllers/course/files.php | 8 +++----- app/controllers/files.php | 8 +++----- app/controllers/institute/files.php | 8 +++----- lib/filesystem/FileManager.php | 12 +++++++---- lib/filesystem/MessageFolder.php | 20 ------------------- .../Courseware/Filesystem/PublicFolder.php | 15 -------------- resources/assets/javascripts/lib/files.js | 2 +- 7 files changed, 18 insertions(+), 55 deletions(-) diff --git a/app/controllers/course/files.php b/app/controllers/course/files.php index 3e6e1356db4..d98ef9a606e 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 bfc2e98af10..4e114409ba6 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 9f3f7a0afdc..e7a21d13a63 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 f573be8f9f2..6109776b34d 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 b3c45f5fe76..c42ddef9058 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 5622f79568d..94a7b54a4b6 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 716219e9a35..08adc296c0e 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) : ''; -- GitLab