Skip to content

Commit 34181c6

Browse files
authored
enable users wathcin videos in courseware block again, set correct permissions for videos that are only linked to a courseware block (#1092)
1 parent cb38199 commit 34181c6

File tree

5 files changed

+100
-23
lines changed

5 files changed

+100
-23
lines changed

courseware/vueapp/components/VideoRow.vue

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<template>
2-
<tr class="oc--episode" :class="{'oc-cw-video-selected' : selected}" v-if="event.refresh === undefined" :key="event.id" @click="$emit('setVideo', event)" style="cursor: pointer" title="Video auswählen">
2+
<tr class="oc--episode" :class="{'oc-cw-video-selected' : selected}"
3+
v-if="event.refresh === undefined"
4+
:key="event.id"
5+
@click="$emit('setVideo', event)"
6+
style="cursor: pointer"
7+
title="Video auswählen"
8+
>
39
<td class="oc--playercontainer">
410
<span v-if="event.publication && event.preview && (event.available && event.available != '0')">
511
<span class="oc--previewimage">

courseware/vueapp/courseware-plugin-opencast-video.vue

+35-22
Original file line numberDiff line numberDiff line change
@@ -230,30 +230,43 @@ export default {
230230
}
231231
},
232232
233-
loadVideos() {
233+
loadVideos()
234+
{
234235
let view = this;
235-
view.loadingVideos = true;
236-
const params = new URLSearchParams();
237-
params.append('offset', this.paging.currPage * this.limit);
238-
params.append('limit', this.limit);
239-
if (this.sortObj) {
240-
params.append('order', this.sortObj.field + "_" + this.sortObj.order)
241-
}
242-
if (this.searchText) {
243-
let filters = [{
244-
type: 'text',
245-
value: this.searchText
246-
}];
247-
params.append('filters', JSON.stringify(filters));
236+
237+
// if user can edit this block, load all accesible videos
238+
if (this.canEdit) {
239+
view.loadingVideos = true;
240+
const params = new URLSearchParams();
241+
params.append('offset', this.paging.currPage * this.limit);
242+
params.append('limit', this.limit);
243+
if (this.sortObj) {
244+
params.append('order', this.sortObj.field + "_" + this.sortObj.order)
245+
}
246+
if (this.searchText) {
247+
let filters = [{
248+
type: 'text',
249+
value: this.searchText
250+
}];
251+
params.append('filters', JSON.stringify(filters));
252+
}
253+
axios
254+
.get(STUDIP.ABSOLUTE_URI_STUDIP + 'plugins.php/opencastv3/api/videos', { params })
255+
.then(({ data }) => {
256+
view.paging.items = parseInt(data.count);
257+
view.paging.lastPage = parseInt(view.paging.items / view.limit);
258+
view.videos = data.videos;
259+
view.loadingVideos = false;
260+
})
261+
} else {
262+
// load only the current video if user has no edit perms
263+
axios
264+
.get(STUDIP.ABSOLUTE_URI_STUDIP + 'plugins.php/opencastv3/api/videos/' + view.currentVideoId)
265+
.then(({ data }) => {
266+
view.videos = [];
267+
view.videos.push(data.video);
268+
});
248269
}
249-
axios
250-
.get(STUDIP.ABSOLUTE_URI_STUDIP + 'plugins.php/opencastv3/api/videos', { params })
251-
.then(({ data }) => {
252-
view.paging.items = parseInt(data.count);
253-
view.paging.lastPage = parseInt(view.paging.items / view.limit);
254-
view.videos = data.videos;
255-
view.loadingVideos = false;
256-
})
257270
},
258271
259272
checkLTIAuthentication(server)

lib/RouteMap.php

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function authenticatedRoutes(RouteCollectorProxy $group)
5353
// Video routes
5454
$group->get("/videos", Routes\Video\VideoList::class);
5555

56+
$group->get("/videos/{token}", Routes\Video\VideoShow::class);
5657
$group->put("/videos/{token}", Routes\Video\VideoUpdate::class);
5758
$group->put("/videos/{token}/restore", Routes\Video\VideoRestore::class);
5859
$group->delete("/videos/{token}", Routes\Video\VideoDelete::class);

lib/Routes/Opencast/UserRoles.php

+13
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Opencast\Models\VideosShares;
1515
use Opencast\Models\Playlists;
1616
use Opencast\Models\PlaylistsUserPerms;
17+
use Opencast\Models\VideoCoursewareBlocks;
1718

1819

1920

@@ -99,6 +100,18 @@ public function __invoke(Request $request, Response $response, $args)
99100
}
100101
}
101102

103+
// get all videos in courseware blocks in courses and add them to the permission list as well
104+
$stmt_courseware = \DBManager::get()->prepare("SELECT episode FROM oc_video_cw_blocks
105+
LEFT JOIN oc_video USING (token)
106+
LEFT JOIN seminar_user USING (seminar_id)
107+
WHERE seminar_user.user_id = :user_id");#
108+
109+
$stmt_courseware->execute([':user_id' => $user_id]);
110+
111+
while($episode = $stmt_courseware->fetchColumn()) {
112+
$roles[$episode . '_read'] = $episode . '_read';
113+
}
114+
102115
$stmt_courses = \DBManager::get()->prepare("SELECT seminar_id FROM seminar_user
103116
WHERE user_id = ? AND status IN (:status)");
104117

lib/Routes/Video/VideoShow.php

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace Opencast\Routes\Video;
4+
5+
use Psr\Http\Message\ResponseInterface as Response;
6+
use Psr\Http\Message\ServerRequestInterface as Request;
7+
use Opencast\Errors\AuthorizationFailedException;
8+
use Opencast\Errors\Error;
9+
use Opencast\OpencastTrait;
10+
use Opencast\OpencastController;
11+
use Opencast\Models\Filter;
12+
use Opencast\Models\Videos;
13+
14+
class VideoShow extends OpencastController
15+
{
16+
use OpencastTrait;
17+
18+
public function __invoke(Request $request, Response $response, $args)
19+
{
20+
// select all videos the current user has perms on
21+
$video = Videos::findByToken($args['token']);
22+
23+
// if no perms are found only return the token back with the config_id the video resides on,
24+
// so the courseware-block can do its magic
25+
if (empty($video) || !$video->getUserPerm()) {
26+
return $this->createResponse([
27+
'video' => [
28+
'token' => $video->token,
29+
'config_id' => $video->config_id
30+
]
31+
], $response);
32+
}
33+
34+
$video_array = $video->toSanitizedArray();
35+
if (!empty($video_array['perm']) && ($video_array['perm'] == 'owner' || $video_array['perm'] == 'write'))
36+
{
37+
$video_array['perms'] = $video->perms->toSanitizedArray();
38+
}
39+
40+
return $this->createResponse([
41+
'video' => $video_array
42+
], $response);
43+
}
44+
}

0 commit comments

Comments
 (0)