From c0f574b2f9142a56558e96af59fb9525b575b0c4 Mon Sep 17 00:00:00 2001
From: Dennis Benz <dennis.benz@uni-osnabrueck.de>
Date: Sat, 21 Oct 2023 07:07:06 +0000
Subject: [PATCH] =?UTF-8?q?Raumverwaltung:=20Fehler=20bei=20Dokumenten=20i?=
 =?UTF-8?q?n=20R=C3=A4umen,=20fixes=20#2829?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #2829

Merge request studip/studip!2208
---
 app/controllers/file.php                       |  4 ++++
 app/controllers/resources/resource.php         |  2 ++
 .../_standard_properties_display_part.php      |  2 +-
 app/views/resources/resource/files.php         | 18 +++++++++---------
 app/views/resources/room/index.php             |  4 ----
 lib/filesystem/StandardFile.php                |  2 ++
 resources/assets/javascripts/lib/files.js      |  5 +++++
 7 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/app/controllers/file.php b/app/controllers/file.php
index 34f1fe9edb2..cd60699c2ec 100644
--- a/app/controllers/file.php
+++ b/app/controllers/file.php
@@ -149,6 +149,10 @@ class FileController extends AuthenticatedController
                     $changes['redirect'] = $this->url_for("file/edit_license/{$folder->getId()}", [
                         'file_refs' => $ref_ids,
                     ]);
+                } elseif ($folder->range_type === 'Resource') {
+                    $changes['close_dialog'] = [
+                        'reload-on-close' => true
+                    ];
                 } else {
                     $changes['close_dialog'] = true;
                 }
diff --git a/app/controllers/resources/resource.php b/app/controllers/resources/resource.php
index 6bec6e277d3..59cd68137b2 100644
--- a/app/controllers/resources/resource.php
+++ b/app/controllers/resources/resource.php
@@ -1471,5 +1471,7 @@ class Resources_ResourceController extends AuthenticatedController
 
         //Set the last visit date to the current timestamp:
         $this->last_visitdate = time();
+
+        $this->show_bulk_checkboxes = true;
     }
 }
diff --git a/app/views/resources/resource/_standard_properties_display_part.php b/app/views/resources/resource/_standard_properties_display_part.php
index 48946c98ab8..890b3f719d9 100644
--- a/app/views/resources/resource/_standard_properties_display_part.php
+++ b/app/views/resources/resource/_standard_properties_display_part.php
@@ -24,7 +24,7 @@
 
             <table class="default">
                 <colgroup>
-                    <col style="width: 70%">
+                    <col style="width: 30%">
                     <col>
                 </colgroup>
                 <thead>
diff --git a/app/views/resources/resource/files.php b/app/views/resources/resource/files.php
index dd3df9afa1b..fc46b92e1e5 100644
--- a/app/views/resources/resource/files.php
+++ b/app/views/resources/resource/files.php
@@ -70,16 +70,16 @@
                                     ]
                                 ) ?>
                             <? endif ?>
-                            <? if ($folder->isWritable($GLOBALS['user']->id)): ?>
-                                <?= Studip\LinkButton::create(
-                                    _('Dokument hinzufügen'),
-                                    '#',
-                                    [
-                                        'onclick' => 'STUDIP.Files.openAddFilesWindow(); return false;'
-                                    ]
-                                ) ?>
-                            <? endif ?>
                         </span>
+                        <? if ($folder->isWritable($GLOBALS['user']->id)): ?>
+                            <?= Studip\LinkButton::create(
+                                _('Dokument hinzufügen'),
+                                '#',
+                                [
+                                    'onclick' => 'STUDIP.Files.openAddFilesWindow(); return false;'
+                                ]
+                            ) ?>
+                        <? endif ?>
                     </td>
                 </tr>
             </tfoot>
diff --git a/app/views/resources/room/index.php b/app/views/resources/room/index.php
index 8782832e503..658994409ff 100644
--- a/app/views/resources/room/index.php
+++ b/app/views/resources/room/index.php
@@ -51,10 +51,6 @@
             <h1><?= _('Dateien') ?></h1>
         </header>
         <table class="default sortable-table" data-sortlist="[[2, 0]]">
-            <colgroup>
-                <col style="width: 70%">
-                <col>
-            </colgroup>
             <?= $this->render_partial('files/_files_thead') ?>
             <? foreach ($resource_folder->getFiles() as $file): ?>
                 <? if ($file->isVisible($GLOBALS['user']->id)) : ?>
diff --git a/lib/filesystem/StandardFile.php b/lib/filesystem/StandardFile.php
index 5723ef48f65..4f7c6164b15 100644
--- a/lib/filesystem/StandardFile.php
+++ b/lib/filesystem/StandardFile.php
@@ -298,6 +298,7 @@ class StandardFile implements FileType, ArrayAccess, StandardFileInterface
             $this->isEditable($GLOBALS['user']->id)
             && Config::get()->OERCAMPUS_ENABLED
             && $GLOBALS['perm']->have_perm(Config::get()->OER_PUBLIC_STATUS)
+            && in_array($this->fileref->folder->range_type, ['course', 'user'])
         ) {
             $actionMenu->addLink(
                 URLHelper::getURL('dispatch.php/file/share_oer/' . $this->fileref->id),
@@ -311,6 +312,7 @@ class StandardFile implements FileType, ArrayAccess, StandardFileInterface
             $GLOBALS['user']->id !== 'nobody' && $this->fileref->user_id !== $GLOBALS['user']->id &&
             !$this->isEditable($GLOBALS['user']->id) &&
             in_array($this->fileref->content_terms_of_use_id, ['SELFMADE_NONPUB', 'FREE_LICENSE'])
+            && $this->fileref->folder->range_type === 'course'
         ) {
             $actionMenu->addLink(
                 URLHelper::getURL('dispatch.php/file/suggest_oer/' . $this->fileref->id),
diff --git a/resources/assets/javascripts/lib/files.js b/resources/assets/javascripts/lib/files.js
index f806787d158..7b628f60311 100644
--- a/resources/assets/javascripts/lib/files.js
+++ b/resources/assets/javascripts/lib/files.js
@@ -241,6 +241,11 @@ const Files = {
     },
 
     addFileDisplay: (html, delay = 0) => {
+        // Prevent undefined filesapp errors
+        if (STUDIP.Files.filesapp === undefined) {
+            return;
+        }
+
         if (!Array.isArray(html)) {
             html = html === null ? [] : [html];
         }
-- 
GitLab