From f5aac6c0476f32c2cddaccb660208c5cf418ed88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Gl=C3=B6ggler?= Date: Mon, 27 Jan 2025 13:45:06 +0100 Subject: [PATCH] fixes #1083 --- app/controllers/redirect.php | 32 +++++++++++++++++++ lib/Models/Videos.php | 14 +++++--- .../Videos/Actions/CaptionUpload.vue | 2 +- vueapp/components/Videos/Actions/VideoCut.vue | 2 +- .../Videos/Actions/VideoDownload.vue | 13 ++++---- vueapp/components/Videos/VideosTable.vue | 2 +- vueapp/templates/admin_index.php | 2 +- vueapp/templates/contents_index.php | 2 +- vueapp/templates/course_index.php | 2 +- 9 files changed, 55 insertions(+), 16 deletions(-) diff --git a/app/controllers/redirect.php b/app/controllers/redirect.php index cf135572..26b46efb 100644 --- a/app/controllers/redirect.php +++ b/app/controllers/redirect.php @@ -74,6 +74,38 @@ public function perform_action($action, $token) $this->set_layout(null); } + public function download_action($token, $type, $index) + { + $video = null; + $video = Videos::findByToken($token); + + if (empty($video)) { + $this->error = _('Das Video wurde nicht gefunden, ist defekt oder momentan (noch) nicht verfügbar.'); + } else if ($video->trashed) { + $this->error = _('Das Video wurde zur Löschung markiert und kann daher nicht abgerufen werden.'); + } + + $perm = $video->getUserPerm(); + + if ($perm) { + + $publication = $video->publication? json_decode($video->publication, true) : null; + if (!empty($publication) && isset($publication['downloads'][$type][$index]['url'])) { + $url = $publication['downloads'][$type][$index]['url']; + + $api_events = ApiEventsClient::getInstance($video->config_id); + $response = $api_events->fileRequest($url); + + header('Content-Type: '. $response['mimetype']); + + echo $response['body']; + die; + } + } + + throw new \AccessDeniedException(); + } + /** * Directly redirect to passed LTI endpoint * diff --git a/lib/Models/Videos.php b/lib/Models/Videos.php index 2d09b385..c9e9fb15 100644 --- a/lib/Models/Videos.php +++ b/lib/Models/Videos.php @@ -560,7 +560,7 @@ public function getUserPerm($user_id = null) } // check if user has permission on this video due to course ownership - if ($this->haveCoursePerm('dozent')) { + if ($this->haveCoursePerm('dozent', $user_id)) { return 'owner'; } @@ -574,7 +574,7 @@ public function getUserPerm($user_id = null) if (!$ret_perm) { // check if at least read perms are present due to course participation - if ($this->haveCoursePerm('user')) { + if ($this->haveCoursePerm('user', $user_id)) { return 'read'; } } @@ -585,13 +585,19 @@ public function getUserPerm($user_id = null) /** * Check if current user has permission for a course of this video */ - public function haveCoursePerm(string $perm) + public function haveCoursePerm(string $course_perm, string $user_id = null) { + global $user, $perm; + + if (!$user_id) { + $user_id = $user->id; + } + $video_courses = PlaylistSeminars::getCoursesOfVideo($this); if (!empty($video_courses)) { foreach ($video_courses as $video_course_id) { - if ($GLOBALS['perm']->have_studip_perm($perm, $video_course_id)) { + if ($perm->have_studip_perm($course_perm, $video_course_id, $user_id)) { return true; } } diff --git a/vueapp/components/Videos/Actions/CaptionUpload.vue b/vueapp/components/Videos/Actions/CaptionUpload.vue index 2c271e3e..5a1081c8 100644 --- a/vueapp/components/Videos/Actions/CaptionUpload.vue +++ b/vueapp/components/Videos/Actions/CaptionUpload.vue @@ -160,7 +160,7 @@ export default { }, annotation_tool_link() { - let redirectUrl = window.OpencastPlugin.REDIRECT_URL; + let redirectUrl = window.OpencastPlugin.REDIRECT_URL + '/perform'; let action = '/annotation/' + this.event.token; if (redirectUrl && this.event.publication.annotation_tool) { diff --git a/vueapp/components/Videos/Actions/VideoCut.vue b/vueapp/components/Videos/Actions/VideoCut.vue index 89531bcf..286e7604 100644 --- a/vueapp/components/Videos/Actions/VideoCut.vue +++ b/vueapp/components/Videos/Actions/VideoCut.vue @@ -27,7 +27,7 @@ export default { methods: { openEditor() { - let redirectUrl = window.OpencastPlugin.REDIRECT_URL + '/editor/' + this.event.token; + let redirectUrl = window.OpencastPlugin.REDIRECT_URL + '/perform/editor/' + this.event.token; window.open(redirectUrl, '_blank'); this.$emit('done'); }, diff --git a/vueapp/components/Videos/Actions/VideoDownload.vue b/vueapp/components/Videos/Actions/VideoDownload.vue index 2fd0085a..5608abc3 100644 --- a/vueapp/components/Videos/Actions/VideoDownload.vue +++ b/vueapp/components/Videos/Actions/VideoDownload.vue @@ -13,7 +13,7 @@ ReferentIn - + {{ getMediaText(media) }} @@ -42,7 +42,7 @@ Bildschirm - + {{ getMediaText(media) }} @@ -97,10 +97,11 @@ export default { }, methods: { - async downloadFile(media) { - axios.get(media.url, { - crossDomain: true, - withCredentials: true, + async downloadFile(media, type, index) { + let url = window.OpencastPlugin.REDIRECT_URL + '/download/' + this.event.token + '/' + type + '/' + index; + + console.log('Download URL:', url); + axios.get(url, { responseType: 'blob' }).then(response => { const blob = new Blob([response.data]); diff --git a/vueapp/components/Videos/VideosTable.vue b/vueapp/components/Videos/VideosTable.vue index baa30196..77a2eff7 100644 --- a/vueapp/components/Videos/VideosTable.vue +++ b/vueapp/components/Videos/VideosTable.vue @@ -562,7 +562,7 @@ export default { }, redirectAction(action) { - let redirectUrl = window.OpencastPlugin.REDIRECT_URL; + let redirectUrl = window.OpencastPlugin.REDIRECT_URL + '/perform'; if (redirectUrl) { redirectUrl = redirectUrl + action; diff --git a/vueapp/templates/admin_index.php b/vueapp/templates/admin_index.php index 52d6f611..828591d7 100644 --- a/vueapp/templates/admin_index.php +++ b/vueapp/templates/admin_index.php @@ -9,7 +9,7 @@ ICON_URL : '', ASSETS_URL : '', ROUTE : 'admin', - REDIRECT_URL: '', + REDIRECT_URL: '', AUTH_URL : '' }; ; diff --git a/vueapp/templates/contents_index.php b/vueapp/templates/contents_index.php index a8e4e770..74034ee4 100644 --- a/vueapp/templates/contents_index.php +++ b/vueapp/templates/contents_index.php @@ -10,7 +10,7 @@ ASSETS_URL : '', PLUGIN_ASSET_URL : 'getAssetsUrl() ?>', ROUTE : 'videos', - REDIRECT_URL: '', + REDIRECT_URL: '', AUTH_URL : '' }; ; diff --git a/vueapp/templates/course_index.php b/vueapp/templates/course_index.php index 2b3e570f..e3631154 100644 --- a/vueapp/templates/course_index.php +++ b/vueapp/templates/course_index.php @@ -10,7 +10,7 @@ ASSETS_URL : '', PLUGIN_ASSET_URL : 'getAssetsUrl() ?>', ROUTE : 'course', - REDIRECT_URL: '', + REDIRECT_URL: '', AUTH_URL: '' }; ;