From f80d62439057eb8a410b092850c9994a91670388 Mon Sep 17 00:00:00 2001 From: Rasmus Fuhse <fuhse@data-quest.de> Date: Mon, 15 May 2023 14:44:23 +0000 Subject: [PATCH] =?UTF-8?q?Resolve=20"Hauptordner=20der=20Veranstaltung=20?= =?UTF-8?q?optional=20f=C3=BCr=20Studierende=20sperren"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #1908 Merge request studip/studip!1250 --- app/controllers/course/files.php | 2 +- app/controllers/file.php | 25 +++++++++++----- app/views/file/new_edit_folder_form.php | 6 +++- lib/filesystem/RootFolder.php | 35 +++++++++++++++++++++-- templates/filesystem/root_folder/edit.php | 8 ++++++ 5 files changed, 64 insertions(+), 12 deletions(-) create mode 100644 templates/filesystem/root_folder/edit.php diff --git a/app/controllers/course/files.php b/app/controllers/course/files.php index 91d19184066..19f3e70c171 100644 --- a/app/controllers/course/files.php +++ b/app/controllers/course/files.php @@ -50,7 +50,7 @@ class Course_FilesController extends AuthenticatedController $actions = new ActionsWidget(); - if ($this->topFolder->isEditable($GLOBALS['user']->id) && $this->topFolder->parent_id) { + if ($this->topFolder->isEditable($GLOBALS['user']->id)) { $actions->addLink( _("Ordner bearbeiten"), $this->url_for("file/edit_folder/".$this->topFolder->getId()), diff --git a/app/controllers/file.php b/app/controllers/file.php index 4895eabc4a0..40012620430 100644 --- a/app/controllers/file.php +++ b/app/controllers/file.php @@ -1933,7 +1933,10 @@ class FileController extends AuthenticatedController throw new AccessDeniedException(); } $parent_folder = $folder->getParent(); - $folder_types = FileManager::getAvailableFolderTypes($parent_folder->range_id, $GLOBALS['user']->id); + $folder_types = FileManager::getAvailableFolderTypes( + $parent_folder ? $parent_folder->range_id : null, + $GLOBALS['user']->id + ); $this->name = Request::get('name', $folder->name); $this->description = Request::get('description', $folder->description); @@ -1942,7 +1945,7 @@ class FileController extends AuthenticatedController $this->folder_types = []; - if (!is_a($folder, 'VirtualFolderType')) { + if (!is_a($folder, 'VirtualFolderType') && $parent_folder) { foreach ($folder_types as $folder_type) { $folder_type_instance = new $folder_type( [ @@ -1952,15 +1955,21 @@ class FileController extends AuthenticatedController ] ); $this->folder_types[] = [ - 'class' => $folder_type, + 'class' => $folder_type, 'instance' => $folder_type_instance, - 'name' => $folder_type::getTypeName(), - 'icon' => $folder_type_instance->getIcon('clickable') + 'name' => $folder_type::getTypeName(), + 'icon' => $folder_type_instance->getIcon('clickable') ]; } + } elseif (!$parent_folder) { + $this->folder_types[] = [ + 'class' => get_class($folder), + 'instance' => $folder, + 'name' => $folder::getTypeName(), + 'icon' => $folder->getIcon('clickable') + ]; } - if (Request::submitted('edit')) { CSRFProtection::verifyUnsafeRequest(); if (!is_a($folder, 'VirtualFolderType')) { @@ -1973,7 +1982,9 @@ class FileController extends AuthenticatedController } } $request = Request::getInstance(); - $request->offsetSet('parent_id', $folder->getParent()->getId()); + if ($folder->getParent()) { + $request->offsetSet('parent_id', $folder->getParent()->getId()); + } $result = $folder->setDataFromEditTemplate($request); if ($result instanceof FolderType) { if ($folder->store()) { diff --git a/app/views/file/new_edit_folder_form.php b/app/views/file/new_edit_folder_form.php index 2c7a80188b8..c1301d42fe0 100644 --- a/app/views/file/new_edit_folder_form.php +++ b/app/views/file/new_edit_folder_form.php @@ -1,3 +1,4 @@ +<? if (!is_a($folder, 'RootFolder')) : ?> <fieldset> <legend> <?= _('Ordnereigenschaften') ?> @@ -11,12 +12,15 @@ <textarea name="description" class="wysiwyg" placeholder="<?= _('Optionale Beschreibung') ?>"><?= htmlReady($description); ?></textarea> </label> </fieldset> +<? endif ?> -<? if (!is_a($folder, 'VirtualFolderType')): ?> +<? if (!is_a($folder, 'VirtualFolderType') && $folder_types && count($folder_types) > 0): ?> <fieldset class="select_terms_of_use"> + <? if (count($folder_types) > 1) : ?> <legend> <?= _('Ordnertyp auswählen') ?> </legend> + <? endif ?> <? foreach ($folder_types as $folder_type) : ?> <input type="radio" name="folder_type" value="<?= htmlReady($folder_type['class']) ?>" diff --git a/lib/filesystem/RootFolder.php b/lib/filesystem/RootFolder.php index 6c01e82f7f0..dbdbc8b0d08 100644 --- a/lib/filesystem/RootFolder.php +++ b/lib/filesystem/RootFolder.php @@ -48,7 +48,14 @@ class RootFolder extends StandardFolder public function isWritable($user_id) { return ($this->range_type === 'user' && $this->range_id === $user_id) - || Seminar_Perm::get()->have_studip_perm('autor', $this->range_id, $user_id); + || $this->isEditable($user_id) + || ( + Seminar_Perm::get()->have_studip_perm('autor', $this->range_id, $user_id) + && ( + !$this->folderdata['data_content'] + || !$this->folderdata['data_content']['locked'] + ) + ); } /** @@ -57,7 +64,7 @@ class RootFolder extends StandardFolder */ public function isEditable($user_id) { - return false; + return Seminar_Perm::get()->have_studip_perm('tutor', $this->range_id, $user_id); } /** @@ -77,4 +84,26 @@ class RootFolder extends StandardFolder $this->folderdata['parent_id'] = ''; return $this->folderdata->store(); } -} \ No newline at end of file + + /** + * @return Flexi_Template + */ + public function getEditTemplate() + { + $template = $GLOBALS['template_factory']->open('filesystem/root_folder/edit'); + $template->folder = $this; + return $template; + } + + /** + * @param array $request + * @return FolderType|MessageBox + */ + public function setDataFromEditTemplate($request) + { + $this->folderdata['data_content'] = [ + 'locked' => $request['locked'] ? 1 : 0 + ]; + return parent::setDataFromEditTemplate($request); + } +} diff --git a/templates/filesystem/root_folder/edit.php b/templates/filesystem/root_folder/edit.php new file mode 100644 index 00000000000..c22803b3bfc --- /dev/null +++ b/templates/filesystem/root_folder/edit.php @@ -0,0 +1,8 @@ +<label> + <input type="checkbox" + name="locked" + <?= $folder->data_content && $folder->data_content['locked'] ? 'checked' : '' ?> + value="1"> + <?= _('Upload für Studierende sperren') ?> +</label> +<?= _('Uploads sind weiterhin in entsprechenden Unterordnern möglich') ?> -- GitLab