From dfe49d61389934a3497b9413c1df029b693f2887 Mon Sep 17 00:00:00 2001
From: Moritz Strohm <strohm@data-quest.de>
Date: Tue, 16 Aug 2022 14:04:28 +0000
Subject: [PATCH] show course details for booking on the same conditions like
 in the booking plan, closes #1411

Closes #1411

Merge request studip/studip!889
---
 app/controllers/resources/booking.php | 12 ++++++++++++
 app/views/resources/booking/index.php |  2 +-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/app/controllers/resources/booking.php b/app/controllers/resources/booking.php
index e0ebe28412e..72b28040e50 100644
--- a/app/controllers/resources/booking.php
+++ b/app/controllers/resources/booking.php
@@ -91,6 +91,18 @@ class Resources_BookingController extends AuthenticatedController
             )
             || $this->make_comment_editable
         );
+        $this->user_may_see_course_data = false;
+        if ($this->booking->getAssignedUserType() === 'course') {
+            $course = $this->booking->assigned_course_date->course;
+            if ($course instanceof Course) {
+                $has_perms = $GLOBALS['perm']->have_studip_perm('user', $course->id, $user->id);
+                $vis_perms = $GLOBALS['perm']->have_perm(Config::get()->SEM_VISIBILITY_PERM, $user->id);
+                if ($has_perms || $vis_perms || $course->visible) {
+                    $this->user_may_see_course_data = true;
+                }
+            }
+            Seminar_Perm::get()->have_studip_perm('user', $this->booking->getAssignedUser()->id);
+        }
 
         if ($this->make_comment_editable && Request::submitted('save')) {
             CSRFProtection::verifyUnsafeRequest();
diff --git a/app/views/resources/booking/index.php b/app/views/resources/booking/index.php
index bad981970a5..3c56bd9ba57 100644
--- a/app/views/resources/booking/index.php
+++ b/app/views/resources/booking/index.php
@@ -80,7 +80,7 @@
             <? endif ?>
         <? endif ?>
     <? endif ?>
-    <? if ($booking->getAssignedUserType() === 'course'): ?>
+    <? if ($user_may_see_course_data): ?>
         <h3><?= _('Gebucht für:') ?></h3>
         <a href="<?= URLHelper::getScriptLink(
                  'dispatch.php/course/details/index/'
-- 
GitLab