Skip to content

Commit

Permalink
fixes #1083
Browse files Browse the repository at this point in the history
  • Loading branch information
tgloeggl committed Jan 27, 2025
1 parent b7944a0 commit f5aac6c
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 16 deletions.
32 changes: 32 additions & 0 deletions app/controllers/redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
14 changes: 10 additions & 4 deletions lib/Models/Videos.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

Expand All @@ -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';
}
}
Expand All @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion vueapp/components/Videos/Actions/CaptionUpload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion vueapp/components/Videos/Actions/VideoCut.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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');
},
Expand Down
13 changes: 7 additions & 6 deletions vueapp/components/Videos/Actions/VideoDownload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
ReferentIn
</h2>
<a v-for="(media, index) in presenters" :key="index">
<StudipButton @click.prevent="downloadFile(media)">
<StudipButton @click.prevent="downloadFile(media, 'presenter', media.size)">
{{ getMediaText(media) }}
</StudipButton>

Expand Down Expand Up @@ -42,7 +42,7 @@
Bildschirm
</h2>
<a v-for="(media, index) in presentations" :key="index">
<StudipButton @click.prevent="downloadFile(media)">
<StudipButton @click.prevent="downloadFile(media, 'presentation', media.size)">
{{ getMediaText(media) }}
</StudipButton>

Expand Down Expand Up @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion vueapp/components/Videos/VideosTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion vueapp/templates/admin_index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
ICON_URL : '<?= Assets::url('images/icons/') ?>',
ASSETS_URL : '<?= Assets::url('') ?>',
ROUTE : 'admin',
REDIRECT_URL: '<?= PluginEngine::getURL('opencastv3', [], 'redirect/perform', true) ?>',
REDIRECT_URL: '<?= PluginEngine::getURL('opencastv3', [], 'redirect', true) ?>',
AUTH_URL : '<?= PluginEngine::getURL('opencastv3', [], 'redirect/authenticate', true) ?>'
};
<?= isset($languages) ? "window.OpencastPlugin.STUDIP_LANGUAGES = $languages;" : '' ?>;
Expand Down
2 changes: 1 addition & 1 deletion vueapp/templates/contents_index.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
ASSETS_URL : '<?= Assets::url('') ?>',
PLUGIN_ASSET_URL : '<?= $plugin->getAssetsUrl() ?>',
ROUTE : 'videos',
REDIRECT_URL: '<?= PluginEngine::getURL('opencastv3', [], 'redirect/perform') ?>',
REDIRECT_URL: '<?= PluginEngine::getURL('opencastv3', [], 'redirect') ?>',
AUTH_URL : '<?= PluginEngine::getURL('opencastv3', [], 'redirect/authenticate') ?>'
};
<?= isset($languages) ? "window.OpencastPlugin.STUDIP_LANGUAGES = $languages;" : '' ?>;
Expand Down
2 changes: 1 addition & 1 deletion vueapp/templates/course_index.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
ASSETS_URL : '<?= Assets::url('') ?>',
PLUGIN_ASSET_URL : '<?= $plugin->getAssetsUrl() ?>',
ROUTE : 'course',
REDIRECT_URL: '<?= PluginEngine::getURL('opencastv3', [], 'redirect/perform', true) ?>',
REDIRECT_URL: '<?= PluginEngine::getURL('opencastv3', [], 'redirect', true) ?>',
AUTH_URL: '<?= PluginEngine::getURL('opencastv3', [], 'redirect/authenticate', true) ?>'
};
<?= isset($languages) ? "window.OpencastPlugin.STUDIP_LANGUAGES = $languages;" : '' ?>;
Expand Down

0 comments on commit f5aac6c

Please sign in to comment.