Skip to content

Commit 3a10e5c

Browse files
committed
only working with playlist perms, adding the revoke perm event observer when user leaves
1 parent 519088e commit 3a10e5c

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

bootstrap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
NotificationCenter::addObserver('Opencast\Models\VideosUserPerms', 'setPermissions', 'OpencastVideoSync');
1010
NotificationCenter::addObserver('Opencast\Models\Helpers', 'notifyUsers', 'OpencastNotifyUsers');
1111
NotificationCenter::addObserver('Opencast\Models\Helpers', 'adjustVideoPermissionsForNewCourseTutors', 'UserDidEnterCourse');
12+
NotificationCenter::addObserver('Opencast\Models\Helpers', 'revokeTutorsVideoPermissions', 'UserDidLeaveCourse');

lib/Models/Helpers.php

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -464,28 +464,36 @@ public static function adjustVideoPermissionsForNewCourseTutors($eventType, $sem
464464

465465
$perm->store();
466466
}
467+
}
468+
}
467469

468-
// Now compile the list of playlist seminar videos, in order to add tutor perm to that video as well.
469-
$playlist_seminar_videos = PlaylistSeminarVideos::findBySQL('playlist_seminar_id = ?', [$playlist->id]);
470+
/**
471+
* Revoke the video permissions of the course tutors
472+
*
473+
* @Notification UserDidLeaveCourse
474+
*
475+
* @param string $eventType
476+
* @param string $seminar_id
477+
* @param string $user_id
478+
*/
479+
public static function revokeTutorsVideoPermissions($eventType, $seminar_id, $user_id) {
480+
global $perm;
470481

471-
if (empty($playlist_seminar_videos)) {
472-
// No videos found, so we can stop here.
473-
continue;
474-
}
482+
// First get the course playlists.
483+
$playlists = PlaylistSeminars::findBySQL('seminar_id = ?', [$seminar_id]);
475484

476-
foreach ($playlist_seminar_videos as $psv) {
477-
// Check if the user already has permissions on the video.
478-
$perm = VideosUserPerms::findOneBySQL('video_id = ? AND user_id = ?', [$psv->video_id, $user_id]);
485+
if (empty($playlists)) {
486+
// No playlists found, so we can stop here.
487+
return;
488+
}
479489

480-
if (empty($perm)) {
481-
// If not, create a new permission for the user.
482-
$perm = new VideosUserPerms();
483-
$perm->video_id = $psv->video_id;
484-
$perm->user_id = $user_id;
485-
$perm->perm = 'write';
490+
foreach ($playlists as $playlist) {
491+
// Check if the user has permissions on the playlist.
492+
$perm = PlaylistsUserPerms::findOneBySQL('playlist_id = ? AND user_id = ?', [$playlist->id, $user_id]);
486493

487-
$perm->store();
488-
}
494+
if (!empty($perm)) {
495+
// If yes, delete the permission for the user.
496+
$perm->delete();
489497
}
490498
}
491499
}

0 commit comments

Comments
 (0)