Skip to content

Commit

Permalink
Merge branch 'main' into tool_issue_56
Browse files Browse the repository at this point in the history
  • Loading branch information
bluetom authored Jan 13, 2025
2 parents 8c34031 + a5b9f27 commit c516040
Show file tree
Hide file tree
Showing 18 changed files with 255 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ jobs:
with:
requires-tool-plugin: true
requires-mod-plugin: true
branch-tool-plugin: issue-56
branch-tool-plugin: main
branch-mod-plugin: main
branch-opencast-docker-default: 16.7
2 changes: 1 addition & 1 deletion amd/build/block_form_handler.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion amd/build/block_form_handler.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion amd/build/block_manage_series.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion amd/build/block_manage_series.min.js.map

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions amd/src/block_form_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,33 @@ define(['jquery'], function($) {
setDefaultTitle($(span[0]).text());
}
}, 500);
// Enable/Disable "Add video" button for chunkuploader as well.
var parent = e.currentTarget.closest('.local_chunkupload');
var progressbar = parent ? parent.querySelector('.chunkupload-progress') : null;
if (progressbar) {
var videoIdentifier = e.currentTarget.getAttribute('id');
var isvalid = ['id_video_presenter_chunk_file', 'id_video_presentation_chunk_file'].includes(videoIdentifier);
if (isvalid) {
document.querySelector('[name="submitbutton"]').disabled = true;
}
if (videoIdentifier == 'id_video_presenter_chunk_file') {
window.presenterIntervalHandle = setInterval(() => {
window.presenterRun = true;
if (progressbar.offsetWidth == 0) {
window.presenterRun = false;
afterUpload();
}
}, 500);
} else if (videoIdentifier == 'id_video_presentation_chunk_file') {
window.presenterIntervalHandle = setInterval(() => {
window.presentationRun = true;
if (progressbar.offsetWidth == 0) {
window.presentationRun = false;
afterUpload();
}
}, 500);
}
}
});

$('.filepickerhidden').on('change', function(e) {
Expand Down
2 changes: 1 addition & 1 deletion amd/src/block_manage_series.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ export const init = (contextid, ocinstanceid, createseries, series, numseriesall
fail: function(er) {
modal.destroy();
var message = jsstrings[11];
if (er.errorcode === 'importseries_alreadyexists') {
if (['importseries_alreadyexists', 'importseries_notallowed'].includes(er.errorcode)) {
message = er.message;
}
displayError(message);
Expand Down
7 changes: 6 additions & 1 deletion classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,13 @@ public static function import_series(int $contextid, int $ocinstanceid, string $
throw new moodle_exception('importseries_alreadyexists', 'block_opencast');
}

// Perform ACL change.
$apibridge = apibridge::get_instance($params['ocinstanceid']);
// Ensure the import series is allowed.
if (!$apibridge->can_user_import_arbitrary_series($params['seriesid'], $USER->id)) {
throw new moodle_exception('importseries_notallowed', 'block_opencast');
}

// Perform ACL change.
$result = $apibridge->import_series_to_course_with_acl_change($course->id, $params['seriesid'], $USER->id);

if ($result->error) {
Expand Down
28 changes: 27 additions & 1 deletion classes/local/addvideo_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ public function definition() {
});
}

// Converting value to default value if exists in params JSON.
$configureddefault = null;
if (isset($param['value'])) {
$configureddefault = $param['value'];
// We unset this here, to make it clean.
unset($param['value']);
}

// Get the created element back from addElement function, in order to further use its attrs.
$element = $mform->addElement($field->datatype, $field->name, $this->try_get_string($field->name, 'block_opencast'),
$param, $attributes);
Expand All @@ -194,7 +202,25 @@ public function definition() {
}
}
$mform->setAdvanced($field->name, !$field->required);
$default = (isset($eventdefaults[$field->name]) ? $eventdefaults[$field->name] : null);

$default = null;
if (!empty($configureddefault)) {
$default = $configureddefault;
// If the default value from the param JSON is used (configured default) and the field is read-only,
// this indicates that the field should be displayed in read-only mode and the default value must
// also be included in the metadata catalog.
if ($field->readonly) {
// We now make sure that the read-only field send its value by form submit.
$element->setPersistantFreeze(true);
}
}

// We give precedence to the event defaults configured in the course through "Manage default values".
if (isset($eventdefaults[$field->name])) {
$default = $eventdefaults[$field->name];
}

// In case we have default value.
if ($default) {
$mform->setDefault($field->name, $default);
}
Expand Down
39 changes: 39 additions & 0 deletions classes/local/apibridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -3147,4 +3147,43 @@ public function can_start_workflow_massaction($courseid) {
$context = context_course::instance($courseid);
return has_capability('block/opencast:startworkflow', $context);
}

/**
* Checks if the user has the capability to import arbitrary series into a course.
* This method looks for the current series mapping records based on the series id, and checks if the user has
* the capability to import series in any of the currently mapped courses to the series.
* If there is no mapping record, it allows the user to import the series.
*
* @param string $seriesid The ID of the series to be imported.
* @param int $userid The ID of the user performing the import.
*
* @return bool True if the user is somehow capable to import the series to any mapped courses, false otherwise.
*/
public function can_user_import_arbitrary_series(string $seriesid, int $userid): bool {
// Step 1: Get current series mapping records.
$mappings = seriesmapping::get_records(['series' => $seriesid, 'ocinstanceid' => $this->ocinstanceid], 'courseid');

// Step 2: Check if the mapping is empty, then allow it to be imported.
// It makes sense to allow it to be imported, because it means the series is new and it has never been introduced
// into the Moodle Opencast world!
if (empty($mappings)) {
return true;
}

// Step 3: create a flag to hold the validation value.
$isallowed = false;

// Step 4: Loop through the series mapping records,
// to find out if the user is by any chance the capability to import series in any of the mapped courses.
foreach ($mappings as $mapping) {
$context = context_course::instance($mapping->get('courseid'));
if (has_capability('block/opencast:importseriesintocourse', $context, $userid)) {
$isallowed = true;
break;
}
}

// Finall, we return the result of the check.
return $isallowed;
}
}
28 changes: 27 additions & 1 deletion classes/local/batchupload_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ public function definition() {
});
}

// Converting value to default value if exists in params JSON.
$configureddefault = null;
if (isset($param['value'])) {
$configureddefault = $param['value'];
// We unset this here, to make it clean.
unset($param['value']);
}

// Get the created element back from addElement function, in order to further use its attrs.
$element = $mform->addElement($field->datatype, $field->name, $this->try_get_string($field->name, 'block_opencast'),
$param, $attributes);
Expand All @@ -174,7 +182,25 @@ public function definition() {
}
}
$mform->setAdvanced($field->name, !$field->required);
$default = (isset($eventdefaults[$field->name]) ? $eventdefaults[$field->name] : null);

$default = null;
if (!empty($configureddefault)) {
$default = $configureddefault;
// If the default value from the param JSON is used (configured default) and the field is read-only,
// this indicates that the field should be displayed in read-only mode and the default value must
// also be included in the metadata catalog.
if ($field->readonly) {
// We now make sure that the read-only field send its value by form submit.
$element->setPersistantFreeze(true);
}
}

// We give precedence to the event defaults configured in the course through "Manage default values".
if (isset($eventdefaults[$field->name])) {
$default = $eventdefaults[$field->name];
}

// In case we have default value.
if ($default) {
$mform->setDefault($field->name, $default);
}
Expand Down
4 changes: 3 additions & 1 deletion classes/setting_default_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ public static function get_default_metadata() {
'{"name":"creator","datatype":"autocomplete","required":0,"readonly":0,"param_json":null,"defaultable":0,' .
'"batchable":0},' .
'{"name":"contributor","datatype":"autocomplete","required":0,"readonly":0,"param_json":null,"defaultable":0,' .
'"batchable":0}]';
'"batchable":0},' .
'{"name":"location","datatype":"text","required":0,"readonly":1,"param_json":"{\"value\":\"Moodle\"}"' .
',"defaultable":0,"batchable":0}]';
}

/**
Expand Down
45 changes: 45 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -885,5 +885,50 @@ function xmldb_block_opencast_upgrade($oldversion) {
upgrade_block_savepoint(true, 2024093000, 'opencast');
}

// Taking care of new "location" metadata field for events.
if ($oldversion < 2024111103) {
// First, we read all the current "metadata" config settings if exist.

$params = ['plugin' => 'block_opencast', 'configname' => '%metadata\_%'];
$whereclause = $DB->sql_equal('plugin', ':plugin') . ' AND ' . $DB->sql_like('name', ':configname');
if ($entries = $DB->get_records_select('config_plugins', $whereclause, $params, '', 'name, value')) {
foreach ($entries as $entry) {
$eventmetadata = $entry->value;
// We only need to add the new location if the metadata config is not empty,
// if it is empty, it means it is not properly saved yet, so we do not need to do anything.
if (!empty($entry->value)) {
// Decode the existing metadata JSON to an array.
$metadata = json_decode($entry->value, true);
// Check if the location metadata already exists.
$locationmetadataexists = array_filter($metadata, function ($metadataentry) {
return $metadataentry['name'] === 'location';
});
// If the location metadata already exists, we do not need to add it again.
if (!empty($locationmetadataexists)) {
continue;
}
// If the location metadata does not exist, we create a new entry for it.
// Create a new entry for the location metadata.
$locationmetadataarray = [
"name" => "location",
"datatype" => "text",
"required" => 0,
"readonly" => 1,
"param_json" => "{\"value\":\"Moodle\"}", // Default value for the location metadata.
"defaultable" => 0,
"batchable" => 0,
];
// Add the new location entry to the metadata array.
$metadata[] = $locationmetadataarray;
// Encode the metadata array back to JSON.
$newmetadata = json_encode($metadata);
// Save the new metadata back to the config with added location metadata.
set_config($entry->name, $newmetadata, 'block_opencast');
}
}
}
upgrade_block_savepoint(true, 2024111103, 'opencast');
}

return true;
}
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@
if (!empty(get_config('block_opencast', 'swprivacynoticeinfotext_' . $ocinstanceid))) {
$privacynoticetitle = get_config('block_opencast', 'swprivacynoticetitle_' . $ocinstanceid);
if (empty($privacynoticetitle)) {
$privacynoticetitle = get_string('privacynoticedefaulttitle', 'block_opencast');
$privacynoticetitle = get_string('swprivacynoticedefaulttitle', 'block_opencast');
}
$targetedworkflows = [];
$swprivacynoticewfds = get_config('block_opencast', 'swprivacynoticewfds_' . $ocinstanceid);
Expand Down
Loading

0 comments on commit c516040

Please sign in to comment.