From 1284afc1159e665910c91ceb6a591a8511ed72de Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Willms <tleilax+studip@gmail.com> Date: Thu, 30 Jun 2022 05:46:44 +0000 Subject: [PATCH] fix errors in filesystem, fixes #1231 Closes #1231 Merge request studip/studip!743 --- lib/filesystem/CourseDateFolder.php | 9 +++++---- lib/filesystem/CourseGroupFolder.php | 10 ++++++---- lib/filesystem/CoursePublicFolder.php | 1 + lib/filesystem/CourseTopicFolder.php | 10 +++++----- lib/filesystem/FileManager.php | 4 ++-- lib/filesystem/FileType.php | 8 ++++++++ lib/filesystem/HomeworkFolder.php | 1 + lib/filesystem/InboxOutboxFolder.php | 3 ++- lib/filesystem/MessageFolder.php | 2 ++ lib/filesystem/StandardFile.php | 2 +- lib/filesystem/StandardFolder.php | 4 +++- lib/filesystem/TimedFolder.php | 1 + lib/filesystem/UnknownFileType.php | 6 +++++- lib/filesystem/UnknownFolderType.php | 6 +++--- lib/filesystem/VirtualFolderType.php | 5 ++--- 15 files changed, 47 insertions(+), 25 deletions(-) diff --git a/lib/filesystem/CourseDateFolder.php b/lib/filesystem/CourseDateFolder.php index 0973a1f516a..1c42799a7b8 100644 --- a/lib/filesystem/CourseDateFolder.php +++ b/lib/filesystem/CourseDateFolder.php @@ -40,6 +40,8 @@ class CourseDateFolder extends PermissionEnabledFolder implements FolderType return Seminar_Perm::get()->have_studip_perm('tutor', $course->id, $user_id) && CourseDate::countBySql("range_id = ?" , [$course->id]); } + + return false; } public function __construct($folderdata = null) @@ -56,10 +58,7 @@ class CourseDateFolder extends PermissionEnabledFolder implements FolderType ); } - /** - * @return CourseDate - */ - public function getDate() + public function getDate(): ?CourseDate { if (isset($this->folderdata['data_content']['termin_id'])) { if ($this->date === null) { @@ -72,6 +71,8 @@ class CourseDateFolder extends PermissionEnabledFolder implements FolderType } return $this->date; } + + return null; } /** diff --git a/lib/filesystem/CourseGroupFolder.php b/lib/filesystem/CourseGroupFolder.php index e71da7e3a46..81867f66491 100644 --- a/lib/filesystem/CourseGroupFolder.php +++ b/lib/filesystem/CourseGroupFolder.php @@ -40,12 +40,14 @@ class CourseGroupFolder extends StandardFolder if ($course && !$course->isNew()) { return Seminar_Perm::get()->have_studip_perm('tutor', $course->id, $user_id) && Statusgruppen::countBySql("range_id = ?" , [$course->id]); } + + return false; } /** * This method check the permission (global and if he is in the group) for a given user * - * @param $user_id The User-ID + * @param string $user_id The User-ID * @return bool True if user have permission, False otherwise */ public function checkPermission($user_id) @@ -60,7 +62,7 @@ class CourseGroupFolder extends StandardFolder /** * Check if this GroupFolder instance is visible for this user or not. * - * @param user_id The User-ID + * @param string $user_id The User-ID * @return bool True, if the user is in this group or is the lecturer, false otherwise */ public function isVisible($user_id) @@ -71,7 +73,7 @@ class CourseGroupFolder extends StandardFolder /** * Check if this GroupFolder instance is readable for this user or not. * - * @param user_id The User-ID + * @param string $user_id The User-ID * @return bool True, if the user is in this group or is the lecturer, false otherwise */ public function isReadable($user_id) @@ -82,7 +84,7 @@ class CourseGroupFolder extends StandardFolder /** * Check if this GroupFolder instance is writable for this user or not. * - * @param user_id The User-ID + * @param string $user_id The User-ID * @return bool True, if the user is in this group or is the lecturer, false otherwise */ public function isWritable($user_id) diff --git a/lib/filesystem/CoursePublicFolder.php b/lib/filesystem/CoursePublicFolder.php index a55539dea77..a86b251744f 100644 --- a/lib/filesystem/CoursePublicFolder.php +++ b/lib/filesystem/CoursePublicFolder.php @@ -38,6 +38,7 @@ class CoursePublicFolder extends StandardFolder if ($course && !$course->isNew()) { return Seminar_Perm::get()->have_studip_perm('tutor', $course->id, $user_id); } + return false; } public function getIcon($role = Icon::DEFAULT_ROLE) diff --git a/lib/filesystem/CourseTopicFolder.php b/lib/filesystem/CourseTopicFolder.php index f49ea8801f7..3d358366e76 100644 --- a/lib/filesystem/CourseTopicFolder.php +++ b/lib/filesystem/CourseTopicFolder.php @@ -31,6 +31,7 @@ class CourseTopicFolder extends PermissionEnabledFolder implements FolderType if ($course && !$course->isNew()) { return Seminar_Perm::get()->have_studip_perm('tutor', $course->id, $user_id) && CourseTopic::countBySql("seminar_id = ?" , [$course->id]); } + return false; } public function __construct($folderdata = null) @@ -47,10 +48,7 @@ class CourseTopicFolder extends PermissionEnabledFolder implements FolderType ); } - /** - * @return CourseTopic - */ - public function getTopic() + public function getTopic(): ?CourseTopic { if (isset($this->folderdata['data_content']['topic_id'])) { if ($this->topic === null) { @@ -64,13 +62,15 @@ class CourseTopicFolder extends PermissionEnabledFolder implements FolderType } return $this->topic; } + + return null; } /** * @param CourseTopic $topic * @return CourseTopic */ - public function setTopic(CourseTopic $topic) + public function setTopic(CourseTopic $topic): ?CourseTopic { $this->topic = $topic; $this->folderdata['data_content']['topic_id'] = $this->topic->id; diff --git a/lib/filesystem/FileManager.php b/lib/filesystem/FileManager.php index b5c96bbac43..48d09ab1f19 100644 --- a/lib/filesystem/FileManager.php +++ b/lib/filesystem/FileManager.php @@ -742,7 +742,7 @@ class FileManager return [_('Datei konnte nicht gespeichert werden.')]; } } else { - return $error; + return [$error]; } } else { @@ -1081,7 +1081,7 @@ class FileManager $file_ref = FileRef::build((array) $file_ref, false); $file_ref->setFolderType('foldertype', $source_folder); } - $result = self::moveFileRef($file_ref, $new_folder, $user); + $result = self::moveFile($file_ref->getFileType(), $new_folder, $user); if (!$result instanceof FileRef) { //error return $result; diff --git a/lib/filesystem/FileType.php b/lib/filesystem/FileType.php index 003ee856a9a..60bfa441eab 100644 --- a/lib/filesystem/FileType.php +++ b/lib/filesystem/FileType.php @@ -2,6 +2,14 @@ interface FileType { + /** + * StandardFile constructor. + * @param $fileref + * @param null $file : (optional) Is set if fileref and file are both new and not connected with + * each other in the database. + */ + public function __construct($fileref, $file = null); + /** * Returns the name of the icon shape that shall be used with the FileType implementation. * diff --git a/lib/filesystem/HomeworkFolder.php b/lib/filesystem/HomeworkFolder.php index 8c811f3e461..70447fb6cf6 100644 --- a/lib/filesystem/HomeworkFolder.php +++ b/lib/filesystem/HomeworkFolder.php @@ -37,6 +37,7 @@ class HomeworkFolder extends PermissionEnabledFolder if ($course && !$course->isNew()) { return Seminar_Perm::get()->have_studip_perm('tutor', $course->id, $user_id); } + return false; } public function __construct($folderdata = null) diff --git a/lib/filesystem/InboxOutboxFolder.php b/lib/filesystem/InboxOutboxFolder.php index ff75988753d..9386be426da 100644 --- a/lib/filesystem/InboxOutboxFolder.php +++ b/lib/filesystem/InboxOutboxFolder.php @@ -175,9 +175,10 @@ class InboxOutboxFolder implements FolderType _('InboxOutbox-Ordner können nicht bearbeitet werden!') ); } + public function store() { - + return false; } /** diff --git a/lib/filesystem/MessageFolder.php b/lib/filesystem/MessageFolder.php index 34c99cf128a..2e5c3afbc25 100644 --- a/lib/filesystem/MessageFolder.php +++ b/lib/filesystem/MessageFolder.php @@ -236,6 +236,7 @@ class MessageFolder extends StandardFolder implements FolderType */ public function setDataFromEditTemplate($request) { + return MessageBox::error('Not applicable for message folders'); } /** @@ -307,6 +308,7 @@ class MessageFolder extends StandardFolder implements FolderType */ public function deleteSubfolder($subfolder_id) { + return false; } /** diff --git a/lib/filesystem/StandardFile.php b/lib/filesystem/StandardFile.php index 208e447f35a..3fe3672e723 100644 --- a/lib/filesystem/StandardFile.php +++ b/lib/filesystem/StandardFile.php @@ -30,7 +30,7 @@ class StandardFile implements FileType, ArrayAccess * @param null|string $user_id : the id of the user that should own the new file * @return FileType|array : FileType (of called class) on success or an array with errors if an error occurred. */ - static public function create($data, $user_id = null) + public static function create($data, $user_id = null) { $errors = []; $user_id || $user_id = $GLOBALS['user']->id; diff --git a/lib/filesystem/StandardFolder.php b/lib/filesystem/StandardFolder.php index 269f64a017f..a34ca4ae820 100644 --- a/lib/filesystem/StandardFolder.php +++ b/lib/filesystem/StandardFolder.php @@ -202,7 +202,7 @@ class StandardFolder implements FolderType } /** - * @param Request $request + * @param array $request * @return FolderType|MessageBox */ public function setDataFromEditTemplate($request) @@ -357,6 +357,8 @@ class StandardFolder implements FolderType if ($file_ref) { return $file_ref->delete(); } + + return 0; } diff --git a/lib/filesystem/TimedFolder.php b/lib/filesystem/TimedFolder.php index aa08df3819b..f2c66dbf3e1 100644 --- a/lib/filesystem/TimedFolder.php +++ b/lib/filesystem/TimedFolder.php @@ -42,6 +42,7 @@ class TimedFolder extends PermissionEnabledFolder if ($course && !$course->isNew()) { return Seminar_Perm::get()->have_studip_perm('tutor', $course->id, $user_id); } + return false; } /** diff --git a/lib/filesystem/UnknownFileType.php b/lib/filesystem/UnknownFileType.php index 7d5a0bcfaeb..c8df875fe09 100644 --- a/lib/filesystem/UnknownFileType.php +++ b/lib/filesystem/UnknownFileType.php @@ -20,7 +20,7 @@ class UnknownFileType implements FileType, ArrayAccess */ protected $fileref = null; - public function __construct($fileref = null) + public function __construct($fileref = null, $file = null) { $this->fileref = $fileref; } @@ -151,6 +151,7 @@ class UnknownFileType implements FileType, ArrayAccess */ public function getPath(): string { + return ''; } /** @@ -210,6 +211,7 @@ class UnknownFileType implements FileType, ArrayAccess */ public function delete() { + return 0; } /** @@ -272,6 +274,7 @@ class UnknownFileType implements FileType, ArrayAccess */ public function getAdditionalColumnOrderWeigh($column_index) { + return 0; } /** @@ -279,5 +282,6 @@ class UnknownFileType implements FileType, ArrayAccess */ public function getInfoTemplate(bool $include_downloadable_infos = false) { + return ''; } } diff --git a/lib/filesystem/UnknownFolderType.php b/lib/filesystem/UnknownFolderType.php index 46907180e09..a7ba5f1dd03 100644 --- a/lib/filesystem/UnknownFolderType.php +++ b/lib/filesystem/UnknownFolderType.php @@ -136,7 +136,7 @@ class UnknownFolderType implements FolderType */ public function getDescriptionTemplate() { - + return ''; } @@ -145,7 +145,7 @@ class UnknownFolderType implements FolderType */ public function getEditTemplate() { - + return ''; } /** @@ -153,7 +153,7 @@ class UnknownFolderType implements FolderType */ public function setDataFromEditTemplate($request) { - + return MessageBox::error('Not applicable for unknown folder type'); } /** diff --git a/lib/filesystem/VirtualFolderType.php b/lib/filesystem/VirtualFolderType.php index ec2d773802c..36ad3fed062 100644 --- a/lib/filesystem/VirtualFolderType.php +++ b/lib/filesystem/VirtualFolderType.php @@ -165,6 +165,7 @@ class VirtualFolderType implements FolderType */ public function setDataFromEditTemplate($request) { + return MessageBox::error('Not applicable for virtual folder type'); } /** @@ -257,11 +258,9 @@ class VirtualFolderType implements FolderType return true; } - /** - * - */ public function store() { + return 0; } /** -- GitLab