aboutsummaryrefslogtreecommitdiff
path: root/lib/filesystem
diff options
context:
space:
mode:
authorPhilipp Schüttlöffel <schuettloeffel@zqs.uni-hannover.de>2024-09-24 10:53:31 +0200
committerPhilipp Schüttlöffel <schuettloeffel@zqs.uni-hannover.de>2024-09-24 10:53:31 +0200
commit4459dd7917f4d1c34f40bb68f0e991e9c3d53e4c (patch)
tree5c07151ae61276d334e88f6309c30d439a85c12e /lib/filesystem
parentda0022e5c1abbf9825ae76debaabdff7e8623bb4 (diff)
parent97a188592c679890a25c37ab78463add76a52ff7 (diff)
Merge branch 'main' into issue-3911issue-3911
Diffstat (limited to 'lib/filesystem')
-rw-r--r--lib/filesystem/CourseDateFolder.php6
-rw-r--r--lib/filesystem/CourseGroupFolder.php4
-rw-r--r--lib/filesystem/CoursePublicFolder.php2
-rw-r--r--lib/filesystem/FileArchiveManager.php (renamed from lib/filesystem/FileArchiveManager.class.php)2
-rw-r--r--lib/filesystem/FileArchiveManagerException.php (renamed from lib/filesystem/FileArchiveManagerException.class.php)0
-rw-r--r--lib/filesystem/FileType.php12
-rw-r--r--lib/filesystem/FolderType.php12
-rw-r--r--lib/filesystem/HiddenFolder.php2
-rw-r--r--lib/filesystem/HomeworkFolder.php28
-rw-r--r--lib/filesystem/InboxFolder.php2
-rw-r--r--lib/filesystem/InboxOutboxFolder.php10
-rw-r--r--lib/filesystem/LibraryFile.php (renamed from lib/filesystem/LibraryFile.class.php)2
-rw-r--r--lib/filesystem/MVVFolder.php2
-rw-r--r--lib/filesystem/MessageFolder.php2
-rw-r--r--lib/filesystem/OutboxFolder.php2
-rw-r--r--lib/filesystem/PermissionEnabledFolder.php23
-rw-r--r--lib/filesystem/PublicFolder.php2
-rw-r--r--lib/filesystem/ResourceFolder.php (renamed from lib/filesystem/ResourceFolder.class.php)0
-rw-r--r--lib/filesystem/RootFolder.php2
-rw-r--r--lib/filesystem/StandardFile.php29
-rw-r--r--lib/filesystem/StandardFolder.php19
-rw-r--r--lib/filesystem/TimedFolder.php25
-rw-r--r--lib/filesystem/UnknownFileType.php21
23 files changed, 120 insertions, 89 deletions
diff --git a/lib/filesystem/CourseDateFolder.php b/lib/filesystem/CourseDateFolder.php
index 2ab0435..8bd54d2 100644
--- a/lib/filesystem/CourseDateFolder.php
+++ b/lib/filesystem/CourseDateFolder.php
@@ -92,7 +92,7 @@ class CourseDateFolder extends PermissionEnabledFolder implements FolderType
/**
* This method returns the special part for the edit template
*
- * @return Flexi_Template edit template
+ * @return Flexi\Template edit template
*/
public function getEditTemplate()
{
@@ -119,14 +119,14 @@ class CourseDateFolder extends PermissionEnabledFolder implements FolderType
} else {
$this->folderdata['data_content']['permission'] = 5;
}
- $this->folderdata['description'] = $request['description'] ?: '';
+ $this->folderdata['description'] = $request['description'] ?? '';
return $this;
}
/**
* Returns the description template
*
- * @return Flexi_Template description template
+ * @return Flexi\Template description template
*/
public function getDescriptionTemplate()
{
diff --git a/lib/filesystem/CourseGroupFolder.php b/lib/filesystem/CourseGroupFolder.php
index 81867f6..36bbb92 100644
--- a/lib/filesystem/CourseGroupFolder.php
+++ b/lib/filesystem/CourseGroupFolder.php
@@ -123,7 +123,7 @@ class CourseGroupFolder extends StandardFolder
public function getEditTemplate()
{
$template = $GLOBALS['template_factory']->open('filesystem/group_folder/edit.php');
- $group = Statusgruppen::find($this->folderdata['data_content']['group']);
+ $group = Statusgruppen::find($this->folderdata['data_content']['group'] ?? null);
$template->set_attribute('group', $group);
$template->set_attribute('folder', $this);
return $template;
@@ -151,7 +151,7 @@ class CourseGroupFolder extends StandardFolder
*/
public function getDescriptionTemplate()
{
- $group = new Statusgruppen($this->folderdata['data_content']['group']);
+ $group = new Statusgruppen($this->folderdata['data_content']['group'] ?? null);
$template = $GLOBALS['template_factory']->open('filesystem/group_folder/description.php');
$template->type = self::getTypeName();
diff --git a/lib/filesystem/CoursePublicFolder.php b/lib/filesystem/CoursePublicFolder.php
index 463fe19..6fa722d 100644
--- a/lib/filesystem/CoursePublicFolder.php
+++ b/lib/filesystem/CoursePublicFolder.php
@@ -112,7 +112,7 @@ class CoursePublicFolder extends StandardFolder
/**
* Returns the edit template for this folder type.
*
- * @return Flexi_Template
+ * @return Flexi\Template
*/
public function getEditTemplate()
{
diff --git a/lib/filesystem/FileArchiveManager.class.php b/lib/filesystem/FileArchiveManager.php
index 704bb44..aded83c 100644
--- a/lib/filesystem/FileArchiveManager.class.php
+++ b/lib/filesystem/FileArchiveManager.php
@@ -1,6 +1,6 @@
<?php
/**
- * FileArchiveManager.class.php
+ * FileArchiveManager.php
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
diff --git a/lib/filesystem/FileArchiveManagerException.class.php b/lib/filesystem/FileArchiveManagerException.php
index 17b5306..17b5306 100644
--- a/lib/filesystem/FileArchiveManagerException.class.php
+++ b/lib/filesystem/FileArchiveManagerException.php
diff --git a/lib/filesystem/FileType.php b/lib/filesystem/FileType.php
index 5a53896..3dcd32f 100644
--- a/lib/filesystem/FileType.php
+++ b/lib/filesystem/FileType.php
@@ -177,10 +177,12 @@ interface FileType
public function convertToStandardFile();
/**
- * Returns the content for that additional column, if it exists. You can return null a string
- * or a Flexi_Template as the content.
+ * Returns the content for that additional column, if it exists. You can
+ * return null, a string or a Flexi\Template as the content.
+ *
* @param string $column_index
- * @return null|string|Flexi_Template
+ *
+ * @return null|string|Flexi\Template
*/
public function getContentForAdditionalColumn($column_index);
@@ -194,14 +196,14 @@ interface FileType
/**
- * Generates a Flexi_Template containing additional information that are
+ * Generates a Flexi\Template containing additional information that are
* displayes in the information dialog of a file.
*
* @param bool $include_downloadable_infos Whether to include information
* like file previews that can be downloaded (true) or to not
* include them (false). Defaults to false.
*
- * @returns Flexi_Template|null Either a Flexi_Template containing
+ * @returns Flexi\Template|null Either a Flexi\Template containing
* additional information or null if no such information shall be
* displayed in the information dialog.
*/
diff --git a/lib/filesystem/FolderType.php b/lib/filesystem/FolderType.php
index 94d8667..69dae30 100644
--- a/lib/filesystem/FolderType.php
+++ b/lib/filesystem/FolderType.php
@@ -119,7 +119,7 @@ interface FolderType
/**
* returns description of the folder
*
- * @return Flexi_Template | string
+ * @return Flexi\Template | string
*/
public function getDescriptionTemplate();
@@ -144,7 +144,7 @@ interface FolderType
/**
* returns template form, must not contain opening and closing <form> tags
*
- * @return Flexi_Template | string
+ * @return Flexi\Template | string
*/
public function getEditTemplate();
@@ -243,10 +243,12 @@ interface FolderType
public function getAdditionalColumns();
/**
- * Returns the content for that additional column, if it exists. You can return null a string
- * or a Flexi_Template as the content.
+ * Returns the content for that additional column, if it exists. You can
+ * return null, a string or a Flexi\Template as the content.
+ *
* @param string $column_index
- * @return null|string|Flexi_Template
+ *
+ * @return null|string|Flexi\Template
*/
public function getContentForAdditionalColumn($column_index);
diff --git a/lib/filesystem/HiddenFolder.php b/lib/filesystem/HiddenFolder.php
index b29f5fb..4daee0b 100644
--- a/lib/filesystem/HiddenFolder.php
+++ b/lib/filesystem/HiddenFolder.php
@@ -78,7 +78,7 @@ class HiddenFolder extends PermissionEnabledFolder
/**
* Returns the edit template for this folder type.
*
- * @return Flexi_Template
+ * @return Flexi\Template
*/
public function getEditTemplate()
{
diff --git a/lib/filesystem/HomeworkFolder.php b/lib/filesystem/HomeworkFolder.php
index 70447fb..f46b4a0 100644
--- a/lib/filesystem/HomeworkFolder.php
+++ b/lib/filesystem/HomeworkFolder.php
@@ -1,6 +1,6 @@
<?php
/**
- * HomeworkFolder.class.php
+ * HomeworkFolder.php
*
* This is a FolderType implementation for homework folders.
*
@@ -82,10 +82,6 @@ class HomeworkFolder extends PermissionEnabledFolder
$template = $GLOBALS['template_factory']->open('filesystem/homework_folder/description.php');
$template->folder = $this;
$template->folderdata = $this->folderdata;
- if (!Seminar_Perm::get()->have_studip_perm('tutor', $this->range_id)) {
- $files = new SimpleCollection($this->getFiles());
- $template->own_files = $files->findBy('user_id', $GLOBALS['user']->id)->orderBy('name');
- }
return $template;
}
@@ -101,6 +97,28 @@ class HomeworkFolder extends PermissionEnabledFolder
}
/**
+ * @param string $user_id
+ * @return bool
+ */
+ public function isReadable($user_id = null)
+ {
+ return StandardFolder::isReadable($user_id);
+ }
+
+ /**
+ * Determines if a user may see the file.
+ * @param FileRef|string $fileref_or_id
+ * @param string $user_id
+ * @return bool
+ */
+ public function isFileVisible($fileref_or_id, $user_id)
+ {
+ $fileref = FileRef::toObject($fileref_or_id);
+
+ return $fileref->user_id === $user_id || parent::isReadable($user_id);
+ }
+
+ /**
* @param FileRef|string $fileref_or_id
* @param string $user_id
* @return bool
diff --git a/lib/filesystem/InboxFolder.php b/lib/filesystem/InboxFolder.php
index 428bea5..d692158 100644
--- a/lib/filesystem/InboxFolder.php
+++ b/lib/filesystem/InboxFolder.php
@@ -1,6 +1,6 @@
<?php
/**
- * InboxFolder.class.php
+ * InboxFolder.php
*
* This is a FolderType implementation for file attachments of messages
* that were received by a user. It is a read-only folder.
diff --git a/lib/filesystem/InboxOutboxFolder.php b/lib/filesystem/InboxOutboxFolder.php
index 9386be4..33ba6d2 100644
--- a/lib/filesystem/InboxOutboxFolder.php
+++ b/lib/filesystem/InboxOutboxFolder.php
@@ -1,6 +1,6 @@
<?php
/**
- * InboxOutboxFolder.class.php
+ * InboxOutboxFolder.php
*
* This is a common FolderType implementation for inbox and outbox folders.
* It it not meant to be used directly! Instead use the InboxFolder and
@@ -269,10 +269,12 @@ class InboxOutboxFolder implements FolderType
}
/**
- * Returns the content for that additional column, if it exists. You can return null a string
- * or a Flexi_Template as the content.
+ * Returns the content for that additional column, if it exists. You can
+ * return null, a string or a Flexi\Template as the content.
+ *
* @param string $column_index
- * @return null|string|Flexi_Template
+ *
+ * @return null|string|Flexi\Template
*/
public function getContentForAdditionalColumn($column_index)
{
diff --git a/lib/filesystem/LibraryFile.class.php b/lib/filesystem/LibraryFile.php
index 0c2bcb6..c9524e3 100644
--- a/lib/filesystem/LibraryFile.class.php
+++ b/lib/filesystem/LibraryFile.php
@@ -212,7 +212,7 @@ class LibraryFile extends StandardFile
);
if (Config::get()->LITERATURE_ENABLE && Context::get() && $GLOBALS['perm']->have_studip_perm('tutor', Context::getId())) {
$plugin_manager = PluginManager::getInstance();
- $library_plugins = $plugin_manager->getPlugins('LibraryPlugin');
+ $library_plugins = $plugin_manager->getPlugins(LibraryPlugin::class);
if (count($library_plugins)) {
$plugin = $library_plugins[0];
$action_menu->addLink(
diff --git a/lib/filesystem/MVVFolder.php b/lib/filesystem/MVVFolder.php
index c5373b9..2d153dc 100644
--- a/lib/filesystem/MVVFolder.php
+++ b/lib/filesystem/MVVFolder.php
@@ -82,7 +82,7 @@ class MVVFolder extends StandardFolder
if ($folder) {
$topfolder = $folder->getTypedFolder();
}
- return $topfolder ?: null;
+ return $topfolder ?? null;
}
/**
diff --git a/lib/filesystem/MessageFolder.php b/lib/filesystem/MessageFolder.php
index 2e5c3af..2dfef0c 100644
--- a/lib/filesystem/MessageFolder.php
+++ b/lib/filesystem/MessageFolder.php
@@ -1,6 +1,6 @@
<?php
/**
- * MessageFolder.class.php
+ * MessageFolder.php
*
* This is a FolderType implementation for message folders.
* A message folder contains the attachments of a Stud.IP message.
diff --git a/lib/filesystem/OutboxFolder.php b/lib/filesystem/OutboxFolder.php
index 22170d5..5487258 100644
--- a/lib/filesystem/OutboxFolder.php
+++ b/lib/filesystem/OutboxFolder.php
@@ -1,6 +1,6 @@
<?php
/**
- * OutboxFolder.class.php
+ * OutboxFolder.php
*
* This is a FolderType implementation for file attachments of messages
* that were sent by a user. It is a read-only folder.
diff --git a/lib/filesystem/PermissionEnabledFolder.php b/lib/filesystem/PermissionEnabledFolder.php
index d41ebe3..c286c53 100644
--- a/lib/filesystem/PermissionEnabledFolder.php
+++ b/lib/filesystem/PermissionEnabledFolder.php
@@ -118,6 +118,27 @@ class PermissionEnabledFolder extends StandardFolder
}
/**
+ * @return FileType[]
+ */
+ public function getFiles()
+ {
+ return array_filter(parent::getFiles(), function($file) {
+ return $this->isFileVisible($file->getFileRef(), $GLOBALS['user']->id);
+ });
+ }
+
+ /**
+ * Determines if a user may see the file.
+ * @param FileRef|string $fileref_or_id
+ * @param string $user_id
+ * @return bool
+ */
+ public function isFileVisible($fileref_or_id, $user_id)
+ {
+ return $this->isReadable($user_id);
+ }
+
+ /**
* @param $fileref_or_id
* @param $user_id
* @return bool
@@ -127,7 +148,7 @@ class PermissionEnabledFolder extends StandardFolder
$fileref = FileRef::toObject($fileref_or_id);
if (is_object($fileref)) {
- if ($this->isVisible($user_id) && $this->isReadable($user_id)) {
+ if ($this->isVisible($user_id) && $this->isFileVisible($fileref, $user_id)) {
return $fileref->terms_of_use->isDownloadable($this->range_id, $this->range_type, true, $user_id);
}
}
diff --git a/lib/filesystem/PublicFolder.php b/lib/filesystem/PublicFolder.php
index 6b06ac9..2dc4847 100644
--- a/lib/filesystem/PublicFolder.php
+++ b/lib/filesystem/PublicFolder.php
@@ -160,7 +160,7 @@ class PublicFolder extends StandardFolder
/**
* Returns the edit template for this folder type.
*
- * @return Flexi_Template
+ * @return Flexi\Template
*/
public function getEditTemplate()
{
diff --git a/lib/filesystem/ResourceFolder.class.php b/lib/filesystem/ResourceFolder.php
index ce7b216..ce7b216 100644
--- a/lib/filesystem/ResourceFolder.class.php
+++ b/lib/filesystem/ResourceFolder.php
diff --git a/lib/filesystem/RootFolder.php b/lib/filesystem/RootFolder.php
index 0727770..9771c32 100644
--- a/lib/filesystem/RootFolder.php
+++ b/lib/filesystem/RootFolder.php
@@ -86,7 +86,7 @@ class RootFolder extends StandardFolder
}
/**
- * @return Flexi_Template
+ * @return Flexi\Template
*/
public function getEditTemplate()
{
diff --git a/lib/filesystem/StandardFile.php b/lib/filesystem/StandardFile.php
index e051871..4eb3140 100644
--- a/lib/filesystem/StandardFile.php
+++ b/lib/filesystem/StandardFile.php
@@ -112,46 +112,33 @@ class StandardFile implements FileType, ArrayAccess, StandardFileInterface
/**
* ArrayAccess: Check whether the given offset exists.
- *
- * @todo Add bool return type when Stud.IP requires PHP8 minimal
*/
- #[ReturnTypeWillChange]
- public function offsetExists($offset)
+ public function offsetExists($offset): bool
{
return $this->__isset($offset);
}
/**
* ArrayAccess: Get the value at the given offset.
- *
- * @todo Add mixed return type when Stud.IP requires PHP8 minimal
*/
- #[ReturnTypeWillChange]
- public function offsetGet($offset)
+ public function offsetGet($offset): mixed
{
return $this->__get($offset);
}
/**
* ArrayAccess: Set the value at the given offset.
- *
- * @todo Add void return type when Stud.IP requires PHP8 minimal
*/
- #[ReturnTypeWillChange]
- public function offsetSet($offset, $value)
+ public function offsetSet($offset, $value): void
{
$this->__set($offset, $value);
}
/**
* ArrayAccess: unset the value at the given offset (not applicable)
- *
- * @todo Add void return type when Stud.IP requires PHP8 minimal
*/
- #[ReturnTypeWillChange]
- public function offsetUnset($offset)
+ public function offsetUnset($offset): void
{
-
}
/**
@@ -473,9 +460,11 @@ class StandardFile implements FileType, ArrayAccess, StandardFileInterface
/**
* Returns the content for that additional column, if it exists. You can return null a string
- * or a Flexi_Template as the content.
+ * or a Flexi\Template as the content.
+ *
* @param string $column_index
- * @return null|string|Flexi_Template
+ *
+ * @return null|string|Flexi\Template
*/
public function getContentForAdditionalColumn($column_index)
{
@@ -510,7 +499,7 @@ class StandardFile implements FileType, ArrayAccess, StandardFileInterface
return null;
}
- $factory = new Flexi_TemplateFactory(
+ $factory = new Flexi\Factory(
$GLOBALS['STUDIP_BASE_PATH'] . '/templates/filesystem/file_types/'
);
$template = $factory->open('standard_file_info');
diff --git a/lib/filesystem/StandardFolder.php b/lib/filesystem/StandardFolder.php
index a34ca4a..c387bb9 100644
--- a/lib/filesystem/StandardFolder.php
+++ b/lib/filesystem/StandardFolder.php
@@ -186,7 +186,7 @@ class StandardFolder implements FolderType
}
/**
- * @return string|Flexi_Template
+ * @return string|Flexi\Template
*/
public function getDescriptionTemplate()
{
@@ -194,7 +194,7 @@ class StandardFolder implements FolderType
}
/**
- * @return string|Flexi_Template
+ * @return string|Flexi\Template
*/
public function getEditTemplate()
{
@@ -224,14 +224,13 @@ class StandardFolder implements FolderType
}
/**
- * @param FileType $newfile
- * @param string $user_id
+ * @param string $user_id
* @return string
*/
- public function validateUpload(FileType $newfile, $user_id)
+ public function validateUpload(FileType $file, $user_id)
{
$upload_type = FileManager::getUploadTypeConfig($this->range_id, $user_id);
- return $this->getValidationMessages($upload_type, $newfile);
+ return $this->getValidationMessages($upload_type, $file);
}
protected function getValidationMessages($upload_type, $newfile)
@@ -256,6 +255,8 @@ class StandardFolder implements FolderType
if (in_array($ext, $types) && $upload_type['type'] === 'allow') {
return sprintf(_('Sie dürfen den Dateityp %s nicht hochladen!'), $ext);
}
+
+ return null;
}
/**
@@ -509,9 +510,11 @@ class StandardFolder implements FolderType
/**
* Returns the content for that additional column, if it exists. You can return null a string
- * or a Flexi_Template as the content.
+ * or a Flexi\Template as the content.
+ *
* @param string $column_index
- * @return null|string|Flexi_Template
+ *
+ * @return null|string|Flexi\Template
*/
public function getContentForAdditionalColumn($column_index)
{
diff --git a/lib/filesystem/TimedFolder.php b/lib/filesystem/TimedFolder.php
index 442c084..0c159d6 100644
--- a/lib/filesystem/TimedFolder.php
+++ b/lib/filesystem/TimedFolder.php
@@ -81,7 +81,7 @@ class TimedFolder extends PermissionEnabledFolder
($this->end_time == 0 || $this->end_time >= $now)
||
$GLOBALS['perm']->have_studip_perm($this->must_have_perm, $this->range_id, $user_id)) &&
- parent::isReadable($user_id);
+ StandardFolder::isReadable($user_id);
}
public function isWritable($user_id = null)
@@ -96,6 +96,19 @@ class TimedFolder extends PermissionEnabledFolder
}
/**
+ * Determines if a user may see the file.
+ * @param FileRef|string $fileref_or_id
+ * @param string $user_id
+ * @return bool
+ */
+ public function isFileVisible($fileref_or_id, $user_id)
+ {
+ $fileref = FileRef::toObject($fileref_or_id);
+
+ return $fileref->user_id === $user_id || parent::isReadable($user_id);
+ }
+
+ /**
* This function returns the suitable Icon for this folder type (TimedFolder)
*
* @return Icon The icon object for this folder type
@@ -132,7 +145,7 @@ class TimedFolder extends PermissionEnabledFolder
/**
* Returns the description template for a instance of a TimedFolder type.
*
- * @return Flexi_Template A description template for a instance of the type TimedFolder
+ * @return Flexi\Template A description template for a instance of the type TimedFolder
*/
public function getDescriptionTemplate()
{
@@ -143,19 +156,13 @@ class TimedFolder extends PermissionEnabledFolder
$template->folder = $this;
$template->folderdata = $this->folderdata;
- if (!Seminar_Perm::get()->have_studip_perm('tutor', $this->range_id) &&
- $this->isWritable($GLOBALS['user']->id) && !$this->isReadable($GLOBALS['user']->id)) {
- $files = new SimpleCollection($this->getFiles());
- $template->own_files = $files->findBy('user_id', $GLOBALS['user']->id)->orderBy('name');
- }
-
return $template;
}
/**
* Returns the edit template for this folder type.
*
- * @return Flexi_Template
+ * @return Flexi\Template
*/
public function getEditTemplate()
{
diff --git a/lib/filesystem/UnknownFileType.php b/lib/filesystem/UnknownFileType.php
index bfd00ba..33d6c53 100644
--- a/lib/filesystem/UnknownFileType.php
+++ b/lib/filesystem/UnknownFileType.php
@@ -51,46 +51,33 @@ class UnknownFileType implements FileType, ArrayAccess
/**
* ArrayAccess: Check whether the given offset exists.
- *
- * @todo Add bool return type when Stud.IP requires PHP8 minimal
*/
- #[ReturnTypeWillChange]
- public function offsetExists($offset)
+ public function offsetExists($offset): bool
{
return $this->__isset($offset);
}
/**
* ArrayAccess: Get the value at the given offset.
- *
- * @todo Add mixed return type when Stud.IP requires PHP8 minimal
*/
- #[ReturnTypeWillChange]
- public function offsetGet($offset)
+ public function offsetGet($offset): mixed
{
return $this->__get($offset);
}
/**
* ArrayAccess: Set the value at the given offset.
- *
- * @todo Add void return type when Stud.IP requires PHP8 minimal
*/
- #[ReturnTypeWillChange]
- public function offsetSet($offset, $value)
+ public function offsetSet($offset, $value): void
{
$this->__set($offset, $value);
}
/**
* ArrayAccess: unset the value at the given offset (not applicable)
- *
- * @todo Add void return type when Stud.IP requires PHP8 minimal
*/
- #[ReturnTypeWillChange]
- public function offsetUnset($offset)
+ public function offsetUnset($offset): void
{
-
}
/**
* @inheritDoc