From ec07c50364a509345c17ab9f18b3bffe3bec94a7 Mon Sep 17 00:00:00 2001
From: Moritz Strohm <strohm@data-quest.de>
Date: Tue, 30 Aug 2022 15:26:59 +0000
Subject: [PATCH] allow people without user permissions access to the booking
 plan in a new tab, closes #836

Closes #836

Merge request studip/studip!862
---
 app/controllers/resources/room_planning.php | 47 +++++++++++----------
 app/views/resources/room/index.php          |  8 ++--
 app/views/resources/search/rooms.php        | 24 +++--------
 3 files changed, 36 insertions(+), 43 deletions(-)

diff --git a/app/controllers/resources/room_planning.php b/app/controllers/resources/room_planning.php
index 9fb0ab698a4..d0a0b895ae8 100644
--- a/app/controllers/resources/room_planning.php
+++ b/app/controllers/resources/room_planning.php
@@ -296,44 +296,47 @@ class Resources_RoomPlanningController extends AuthenticatedController
                     Icon::create('add')
                 )->asDialog('size=auto');
             }
-            if ($this->resource->userHasPermission($this->user)) {
+
+            if ($this->resource->bookingPlanVisibleForUser($this->user)) {
                 $actions->addLink(
                     _('Belegungsplan drucken'),
                     'javascript:void(window.print());',
                     Icon::create('print')
                 );
-                if ($this->resource instanceof Room) {
+                if ($this->resource->userHasPermission($this->user)) {
+                    if ($this->resource instanceof Room) {
+                        $actions->addLink(
+                            _('Individuelle Druckansicht'),
+                            URLHelper::getURL(
+                                'dispatch.php/resources/print/individual_booking_plan/'
+                                . $this->resource->id,
+                                [
+                                    'timestamp' => $week_timestamp,
+                                    'defaultDate' => date('Y-m-d', $week_timestamp)
+                                ]
+                            ),
+                            Icon::create('print'),
+                            [
+                                'class' => 'resource-bookings-actions'
+                            ]
+                        );
+                    }
                     $actions->addLink(
-                        _('Individuelle Druckansicht'),
+                        _('Buchungen exportieren'),
                         URLHelper::getURL(
-                            'dispatch.php/resources/print/individual_booking_plan/'
-                            . $this->resource->id,
+                            'dispatch.php/resources/export/resource_bookings/' . $this->resource->id,
                             [
                                 'timestamp' => $week_timestamp,
                                 'defaultDate' => date('Y-m-d', $week_timestamp)
                             ]
                         ),
-                        Icon::create('print'),
+                        Icon::create('file-excel'),
                         [
-                            'class'  => 'resource-bookings-actions'
+                            'data-dialog' => 'size=auto',
+                            'class' => 'resource-bookings-actions'
                         ]
                     );
                 }
-                $actions->addLink(
-                    _('Buchungen exportieren'),
-                    URLHelper::getURL(
-                        'dispatch.php/resources/export/resource_bookings/' . $this->resource->id,
-                        [
-                            'timestamp' => $week_timestamp,
-                            'defaultDate' => date('Y-m-d', $week_timestamp)
-                        ]
-                    ),
-                    Icon::create('file-excel'),
-                    [
-                        'data-dialog' => 'size=auto',
-                        'class'       => 'resource-bookings-actions'
-                    ]
-                );
             }
             if($GLOBALS['perm']->have_perm('admin')) {
                 if ($this->resource instanceof Room) {
diff --git a/app/views/resources/room/index.php b/app/views/resources/room/index.php
index 92143b960fa..3d1fc590338 100644
--- a/app/views/resources/room/index.php
+++ b/app/views/resources/room/index.php
@@ -81,12 +81,12 @@
     <? elseif ($room->bookingPlanVisibleForUser(User::findCurrent())) : ?>
         <?= \Studip\LinkButton::create(
             _('Belegungsplan'),
-            $room->getActionURL('booking_plan'),
-            ['data-dialog' => 'size=big']) ?>
+            $room->getActionURL('booking_plan')
+        ) ?>
         <?= \Studip\LinkButton::create(
             _('Semesterbelegung'),
-            $room->getActionURL('semester_plan'),
-            ['data-dialog' => 'size=big']) ?>
+            $room->getActionURL('semester_plan')
+        ) ?>
     <? endif ?>
 
     <? if ($geo_coordinates_object instanceof ResourceProperty): ?>
diff --git a/app/views/resources/search/rooms.php b/app/views/resources/search/rooms.php
index e9505013bd4..2d24b249176 100644
--- a/app/views/resources/search/rooms.php
+++ b/app/views/resources/search/rooms.php
@@ -55,10 +55,15 @@
                             Icon::create('info-circle'),
                             ['data-dialog' => '']
                         );
-                        if ($room->userHasPermission($current_user, 'autor')) {
+                        if (($room->booking_plan_is_public && Config::get()->RESOURCES_SHOW_PUBLIC_ROOM_PLANS)
+                            || ($room->userHasPermission($current_user, 'autor'))) {
                             $actions->addLink(
                                 $room->getActionURL('booking_plan', $booking_plan_action_params),
-                                _('Wochenbelegung'),
+                                (
+                                    $room->userHasPermission($current_user, 'autor')
+                                        ? _('Wochenbelegung')
+                                        : _('Belegungsplan')
+                                ),
                                 Icon::create('timetable'),
                                 ['target' => '_blank']
                             );
@@ -68,21 +73,6 @@
                                 Icon::create('timetable'),
                                 ['target' => '_blank']
                             );
-                        } else {
-                            if ($room->booking_plan_is_public && Config::get()->RESOURCES_SHOW_PUBLIC_ROOM_PLANS) {
-                                $actions->addLink(
-                                    $room->getActionURL('booking_plan', $booking_plan_action_params),
-                                    _('Belegungsplan'),
-                                    Icon::create('timetable'),
-                                    ['data-dialog' => 'size=big']
-                                );
-                                $actions->addLink(
-                                    $room->getActionURL('semester_plan'),
-                                    _('Semesterbelegung'),
-                                    Icon::create('timetable'),
-                                    ['data-dialog' => 'size=big']
-                                );
-                            }
                         }
                         if ($room->requestable && $room->userHasRequestRights($current_user)) {
                             $actions->addLink(
-- 
GitLab