From b8cb95a5b4e203f178f4e31c50e951242d25d86b Mon Sep 17 00:00:00 2001
From: Elmar Ludwig <elmar.ludwig@uni-osnabrueck.de>
Date: Tue, 15 Aug 2023 11:25:56 +0000
Subject: [PATCH] don't offer OER actions when module is disabled, fixes #2769

Closes #2769

Merge request studip/studip!2027
---
 app/controllers/contents/courseware.php                  | 8 +++-----
 app/controllers/course/courseware.php                    | 3 ++-
 app/views/contents/courseware/courseware.php             | 2 +-
 app/views/course/courseware/courseware.php               | 2 +-
 .../vue/components/courseware/CoursewareExportWidget.vue | 6 +++++-
 .../courseware/CoursewareStructuralElement.vue           | 9 +++++++--
 6 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/app/controllers/contents/courseware.php b/app/controllers/contents/courseware.php
index 61b5115e794..0183655cdef 100644
--- a/app/controllers/contents/courseware.php
+++ b/app/controllers/contents/courseware.php
@@ -23,6 +23,7 @@ class Contents_CoursewareController extends CoursewareController
 
         $this->user = $GLOBALS['user'];
         $this->licenses = $this->getLicenses();
+        $this->oer_enabled = Config::get()->OERCAMPUS_ENABLED && $GLOBALS['perm']->have_perm(Config::get()->OER_PUBLIC_STATUS);
         $this->unitsNotFound = Unit::countBySql('range_id = ?', [$this->user->id]) === 0;
     }
 
@@ -61,7 +62,7 @@ class Contents_CoursewareController extends CoursewareController
      */
     public function courseware_action($unit_id = null): void
     {
-        global $perm, $user;
+        global $user;
 
         Navigation::activateItem('/contents/courseware/courseware');
         if ($this->unitsNotFound) {
@@ -297,7 +298,7 @@ class Contents_CoursewareController extends CoursewareController
      */
     public function shared_content_courseware_action($entry_element_id): void
     {
-        global $perm, $user;
+        global $user;
 
         $navigation = new Navigation(_('Geteiltes Lernmaterial'), 'dispatch.php/contents/courseware/shared_content_courseware/' . $entry_element_id);
         Navigation::addItem('/contents/courseware/shared_content_courseware', $navigation);
@@ -320,9 +321,6 @@ class Contents_CoursewareController extends CoursewareController
 
         $this->user_id = $struct->owner_id;
 
-
-        $this->oer_enabled = Config::get()->OERCAMPUS_ENABLED && $perm->have_perm(Config::get()->OER_PUBLIC_STATUS);
-
         $this->setCoursewareSidebar();
     }
 }
diff --git a/app/controllers/course/courseware.php b/app/controllers/course/courseware.php
index 29c48d9e032..46419a88e85 100644
--- a/app/controllers/course/courseware.php
+++ b/app/controllers/course/courseware.php
@@ -31,6 +31,7 @@ class Course_CoursewareController extends CoursewareController
         object_set_visit_module($this->studip_module->getPluginId());
         $this->last_visitdate = object_get_visit(Context::getId(), $this->studip_module->getPluginId());
         $this->licenses = $this->getLicenses();
+        $this->oer_enabled = Config::get()->OERCAMPUS_ENABLED && $GLOBALS['perm']->have_perm(Config::get()->OER_PUBLIC_STATUS);
         $this->unitsNotFound = Unit::countBySql('range_id = ?', [Context::getId()]) === 0;
     }
 
@@ -42,7 +43,7 @@ class Course_CoursewareController extends CoursewareController
 
     public function courseware_action($unit_id = null):  void
     {
-        global $perm, $user;
+        global $user;
         Navigation::activateItem('course/courseware/unit');
         if ($this->unitsNotFound) {
             PageLayout::postMessage(MessageBox::info(_('Es wurde kein Lernmaterial gefunden.')));
diff --git a/app/views/contents/courseware/courseware.php b/app/views/contents/courseware/courseware.php
index ba4a48e5467..683f07e4748 100644
--- a/app/views/contents/courseware/courseware.php
+++ b/app/views/contents/courseware/courseware.php
@@ -5,7 +5,7 @@
         entry-type="users"
         entry-id="<?= htmlReady($user_id) ?>"
         unit-id="<?= htmlReady($unit_id) ?>"
-        oer-enabled='<?= htmlReady(Config::get()->OERCAMPUS_ENABLED) ?>'
+        oer-enabled='<?= htmlReady($oer_enabled) ?>'
         licenses='<?= htmlReady($licenses) ?>'
         >
     </div>
diff --git a/app/views/course/courseware/courseware.php b/app/views/course/courseware/courseware.php
index 5440c973f14..1abb48a667f 100644
--- a/app/views/course/courseware/courseware.php
+++ b/app/views/course/courseware/courseware.php
@@ -5,7 +5,7 @@
         entry-type="courses"
         entry-id="<?= htmlReady(Context::getId()) ?>"
         unit-id="<?= htmlReady($unit_id) ?>"
-        oer-enabled="<?= htmlReady(Config::get()->OERCAMPUS_ENABLED) ?>"
+        oer-enabled='<?= htmlReady($oer_enabled) ?>'
         licenses='<?= htmlReady($licenses) ?>'
         >
     </div>
diff --git a/resources/vue/components/courseware/CoursewareExportWidget.vue b/resources/vue/components/courseware/CoursewareExportWidget.vue
index c8baa4fac8d..89ecf1cbb83 100644
--- a/resources/vue/components/courseware/CoursewareExportWidget.vue
+++ b/resources/vue/components/courseware/CoursewareExportWidget.vue
@@ -64,11 +64,15 @@ export default {
             return this.canVisit;
         },
         showOer() {
+            if (!this.oerEnabled) {
+                return false;
+            }
+
             if (this.context.type === 'users') {
                 return true;
             }
 
-            return this.oerEnabled && this.userIsTeacher && this.canVisit
+            return this.userIsTeacher && this.canVisit;
         }
     },
     methods: {
diff --git a/resources/vue/components/courseware/CoursewareStructuralElement.vue b/resources/vue/components/courseware/CoursewareStructuralElement.vue
index 3ee6ca2f3d2..40c43d728ef 100644
--- a/resources/vue/components/courseware/CoursewareStructuralElement.vue
+++ b/resources/vue/components/courseware/CoursewareStructuralElement.vue
@@ -1030,10 +1030,15 @@ export default {
             let menu = [
                 { id: 4, label: this.$gettext('Informationen anzeigen'), icon: 'info', emit: 'showInfo' },
                 { id: 5, label: this.$gettext('Lesezeichen setzen'), icon: 'star', emit: 'setBookmark' },
-                { id: 6, label: this.$gettext('Lerninhalt für OER Campus vorschlagen'), icon: 'oer-campus',
-                    emit: 'showSuggest' }
             ];
 
+            if (this.oerEnabled) {
+                menu.push(
+                    { id: 6, label: this.$gettext('Lerninhalt für OER Campus vorschlagen'), icon: 'oer-campus',
+                        emit: 'showSuggest' }
+                );
+            }
+
             if (!document.documentElement.classList.contains('responsive-display')) {
                 menu.push(
                     { id: 7, label: this.$gettext('Als Vollbild anzeigen'), icon: 'screen-full',
-- 
GitLab