From 78f5ad6acc4e2c571e62e25f06105b9bed5f864c Mon Sep 17 00:00:00 2001
From: Ron Lucke <lucke@elan-ev.de>
Date: Fri, 25 Aug 2023 12:50:40 +0000
Subject: [PATCH] fix #3090

Closes #3090

Merge request studip/studip!2077
---
 .../CoursewareStructuralElement.vue           | 50 +++++++++++++------
 1 file changed, 36 insertions(+), 14 deletions(-)

diff --git a/resources/vue/components/courseware/CoursewareStructuralElement.vue b/resources/vue/components/courseware/CoursewareStructuralElement.vue
index 027326d49e1..1c07ee28e54 100644
--- a/resources/vue/components/courseware/CoursewareStructuralElement.vue
+++ b/resources/vue/components/courseware/CoursewareStructuralElement.vue
@@ -656,7 +656,12 @@
                     v-if="currentElement !== ''"
                     :msgCompanion="textCompanionWrongContext"
                     mood="sad"
-                />
+                >
+                    <template v-slot:companionActions >
+                        <a class="button" :href="unitRootUrl">{{ $gettext('Lernmaterial neu laden') }}</a>
+                        <a class="button" :href="shelfURL">{{ $gettext('Zurück zur Lernmaterialübersicht') }}</a>
+                    </template>
+                </courseware-companion-box>
             </div>
         </div>
     </focus-trap>
@@ -879,13 +884,26 @@ export default {
         },
 
         validContext() {
-            let valid = false;
+            if (this.context.type === 'sharedusers') {
+                if (this.context.id === this.courseware.relationships.root.data.id) {
+                    return true;
+                }
+            }
+
+            if (this.context.type === 'public') {
+                return true;
+            }
+
+            if (this.context.unit !== this.currentElement.relationships?.unit?.data?.id) {
+                return false;
+            }
+
             if (this.context.type === 'courses' && this.currentElement.relationships) {
                 if (
                     this.currentElement.relationships.course &&
                     this.context.id === this.currentElement.relationships.course.data.id
                 ) {
-                    valid = true;
+                    return true;
                 }
             }
 
@@ -894,20 +912,12 @@ export default {
                     this.currentElement.relationships.user &&
                     this.context.id === this.currentElement.relationships.user.data.id
                 ) {
-                    valid = true;
-                }
-            }
-            if (this.context.type === 'sharedusers') {
-                if (this.context.id === this.courseware.relationships.root.data.id) {
-                    valid = true;
+                    return true;
                 }
             }
+            
 
-            if (this.context.type === 'public') {
-                valid = true;
-            }
-
-            return valid;
+            return false;
         },
 
         image() {
@@ -1224,6 +1234,18 @@ export default {
                 return template.attributes.purpose === this.newChapterPurpose
             });
         },
+        shelfURL() {
+            return STUDIP.URLHelper.getURL(
+                'dispatch.php/course/courseware/',
+                {cid: this.context.id}
+            );
+        },
+        unitRootUrl() {
+            return STUDIP.URLHelper.getURL(
+                'dispatch.php/course/courseware/courseware/' + this.context.unit,
+                {cid: this.context.id}
+            );
+        }
     },
 
     methods: {
-- 
GitLab