diff --git a/mod/bigbluebuttonbn/classes/instance.php b/mod/bigbluebuttonbn/classes/instance.php index d3298f8eddd..2092c083850 100644 --- a/mod/bigbluebuttonbn/classes/instance.php +++ b/mod/bigbluebuttonbn/classes/instance.php @@ -766,6 +766,18 @@ EOF; return $this->is_feature_enabled('importrecordings'); } + /** + * Get recordings_imported from instancedata. + * + * @return bool + */ + public function get_recordings_imported(): bool { + if (config::get('recordings_imported_editable')) { + return (bool) $this->get_instance_var('recordings_imported'); + } + return config::get('recordings_imported_default'); + } + /** * Whether this instance is recorded from the start. * diff --git a/mod/bigbluebuttonbn/classes/local/bigbluebutton/recordings/recording_data.php b/mod/bigbluebuttonbn/classes/local/bigbluebutton/recordings/recording_data.php index 7d52dbe40f7..0fa9e437f46 100644 --- a/mod/bigbluebuttonbn/classes/local/bigbluebutton/recordings/recording_data.php +++ b/mod/bigbluebuttonbn/classes/local/bigbluebutton/recordings/recording_data.php @@ -296,6 +296,10 @@ class recording_data { if ($rec->get('imported')) { return true; } + // When show imported recordings only is enabled, exclude all other recordings. + if ($instance->get_recordings_imported() && !$rec->get('imported')) { + return false; + } // Administrators and moderators are always allowed. if ($instance->is_admin() || $instance->is_moderator()) { return true; diff --git a/mod/bigbluebuttonbn/tests/external/get_recordings_test.php b/mod/bigbluebuttonbn/tests/external/get_recordings_test.php index 73dd34a8b08..d4c16f129bc 100644 --- a/mod/bigbluebuttonbn/tests/external/get_recordings_test.php +++ b/mod/bigbluebuttonbn/tests/external/get_recordings_test.php @@ -314,6 +314,57 @@ class get_recordings_test extends \externallib_advanced_testcase { } } + /** + * Check we can see only imported recordings in a recordings only instance when "Show only imported links" enabled. + * @covers \mod_bigbluebuttonbn\external\get_recordings::execute + */ + public function test_get_imported_recordings_only() { + $this->resetAfterTest(); + set_config('bigbluebuttonbn_importrecordings_enabled', 1); + $dataset = [ + 'type' => instance::TYPE_ALL, + 'groups' => null, + 'users' => [['username' => 's1', 'role' => 'student']], + 'recordingsdata' => [ + [['name' => 'Recording1']], + [['name' => 'Recording2']] + ], + ]; + $activityid = $this->create_from_dataset($dataset); + $instance = instance::get_from_instanceid($activityid); + + // Now create a recording only activity. + $plugingenerator = $this->getDataGenerator()->get_plugin_generator('mod_bigbluebuttonbn'); + // Now create a new activity and import the first record. + $newactivity = $plugingenerator->create_instance([ + 'course' => $instance->get_course_id(), + 'type' => instance::TYPE_RECORDING_ONLY, + 'name' => 'Example 2' + ]); + $plugingenerator->create_meeting([ + 'instanceid' => $newactivity->id, + ]); // We need to have a meeting created in order to import recordings. + $newinstance = instance::get_from_instanceid($newactivity->id); + $recordings = $instance->get_recordings(); + foreach ($recordings as $recording) { + if ($recording->get('name') == 'Recording1') { + $recording->create_imported_recording($newinstance); + } + } + $user = \core_user::get_user_by_username('s1'); + $this->setUser($user); + $getrecordings = $this->get_recordings($newinstance->get_instance_id()); + $data = json_decode($getrecordings['tabledata']['data']); + // Check that all recordings including the imported recording appear. + $this->assertCount(3, $data); + // Set the flags to enable "Show only imported links". + set_config('bigbluebuttonbn_recordings_imported_default', 1); + set_config('bigbluebuttonbn_recordings_imported_editable', 0); + $getrecordings = $this->get_recordings($newinstance->get_instance_id()); + $data = json_decode($getrecordings['tabledata']['data']); + $this->assertCount(1, $data); + } + /** * Check if recording are visible/invisible depending on the group. *