Skip to content

Commit

Permalink
Only add owner video perm to uploader or scheduler of the recording
Browse files Browse the repository at this point in the history
Currently, all dozent get write perms to an uploaded course video or to a scheduled recording. This patch changes this behaviour based on elan-ev#1216.

close elan-ev#1216
  • Loading branch information
dennis531 committed Feb 21, 2025
1 parent 1199da6 commit 58fb3e0
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 26 deletions.
3 changes: 3 additions & 0 deletions lib/Models/ScheduleHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ public static function validateCourseAndResource($course_id, $resource_config_id
*/
private static function scheduleRecording($course_id, $resource_id, $date_id, $event_id, $livestream)
{
global $user;

$series = SeminarSeries::getSeries($course_id);
$serie = $series[0];

Expand All @@ -457,6 +459,7 @@ private static function scheduleRecording($course_id, $resource_id, $date_id, $e
$success = ScheduledRecordings::setScheduleRecording(
$course_id,
$serie['series_id'],
$user->id,
$date_id,
$resource_id,
$date->date,
Expand Down
2 changes: 2 additions & 0 deletions lib/Models/ScheduledRecordings.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ protected static function configure($config = array())
public static function setScheduleRecording(
$seminar_id,
$series_id,
$user_id,
$date_id,
$resource_id,
$start,
Expand All @@ -54,6 +55,7 @@ public static function setScheduleRecording(
compact(
'seminar_id',
'series_id',
'user_id',
'date_id',
'resource_id',
'start',
Expand Down
44 changes: 23 additions & 21 deletions lib/Models/VideosUserPerms.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,29 @@ public static function setPermissions($eventType, $episode, $video)
return;
}

// Determine if the event is scheduled recordings
$scheduled_recording = ScheduledRecordings::findOneBySql(
'event_id = ? AND series_id = ? AND user_id IS NOT NULL AND is_livestream = 0',
[$video->episode, $episode->is_part_of]
);
if (!empty($scheduled_recording)) {
// check, if there is already an entry for this user-video combination
$perm = self::findOneBySQL('video_id = :video_id AND user_id = :user_id', [
':video_id' => $video->id,
':user_id' => $scheduled_recording->user_id
]);

if (empty($perm)) {
$perm = new self();
$perm->user_id = $scheduled_recording->user_id;
$perm->video_id = $video->id;
$perm->perm = 'owner';
$perm->store();
}

return;
}

// check if a series is assigned to this event
if ($episode->is_part_of) {
// get the courses this series belongs to
Expand Down Expand Up @@ -132,25 +155,4 @@ public static function setPermissions($eventType, $episode, $video)
}

}

public static function assignCourseLecturerPermissions($course_id, $video_id, $perm_type = 'write', $member_course_status = 'dozent')
{
$course = \Course::find($course_id);
$lecturers_obj = $course->getMembersWithStatus($member_course_status);
foreach ($lecturers_obj as $lecturer) {
// check, if there is already an entry for this user-video combination
$perm_record = self::findOneBySQL('video_id = :video_id AND user_id = :user_id', [
':video_id' => $video_id,
':user_id' => $lecturer->user_id
]);

if (empty($perm_record)) {
$perm_record = new self();
$perm_record->user_id = $lecturer->user_id;
$perm_record->video_id = $video_id;
$perm_record->perm = $perm_type;
$perm_record->store();
}
}
}
}
5 changes: 0 additions & 5 deletions lib/Routes/Video/VideoAdd.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ public function __invoke(Request $request, Response $response, $args)
$oc_perm->store();
}

// Assign permissions to teachers of the course, when it is a student upload in a course.
if (!empty($course_id) && $perm->have_studip_perm('user', $course_id, $user->id)) {
VideosUserPerms::assignCourseLecturerPermissions($course_id, $video->id);
}

$ret = $video->toSanitizedArray();

$message = [
Expand Down
24 changes: 24 additions & 0 deletions migrations/102_add_user_to_scheduled_recordings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

class AddUserToScheduledRecordings extends Migration
{
public function description()
{
return 'Add user id to oc_scheduled_recordings to identify the user who scheduled the recording';
}

public function up()
{
$db = DBManager::get();

$db->exec('ALTER TABLE `oc_scheduled_recordings`
ADD COLUMN `user_id` varchar(32) CHARACTER SET latin1 COLLATE latin1_bin NULL AFTER `series_id`');
}

public function down()
{
$db = DBManager::get();

$db->exec('ALTER TABLE `oc_scheduled_recordings` DROP COLUMN `user_id`');
}
}

0 comments on commit 58fb3e0

Please sign in to comment.