Skip to content

Commit

Permalink
Make seriesmanagement work properly with or without capabilities to c…
Browse files Browse the repository at this point in the history
…reate or import series.

Remove defineseriesforcourse capability. Require manageseriesforcourse for manageseries.php
and show import series / create new series depending on capabilities.
Give teachers manageseriesforcourse and createnewseries capabilities by default.
  • Loading branch information
justusdieckmann committed Jan 8, 2024
1 parent 02acb6c commit fe6b207
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 46 deletions.
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.

20 changes: 10 additions & 10 deletions amd/src/block_manage_series.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ function submitFormAjax(e) {
seriestable.addRow({'seriesname': s.seriestitle, 'series': s.series, 'isdefault': s.isdefault});

if (seriestable.getRows().length >= numseriesallowed) {
$("#createseries").hide();
$("#importseries").hide();
$("#createseries")?.hide();
$("#importseries")?.hide();
}
}
},
Expand Down Expand Up @@ -325,10 +325,10 @@ export const init = (contextid, ocinstanceid, createseries, series, numseriesall
cell.getRow().delete();
const createseries = $("#createseries");
const importseries = $("#importseries");
createseries.show();
createseries.removeClass('d-none');
importseries.show();
importseries.removeClass('d-none');
createseries?.show();
createseries?.removeClass('d-none');
importseries?.show();
importseries?.removeClass('d-none');
}
},
fail: function(e) {
Expand All @@ -349,7 +349,7 @@ export const init = (contextid, ocinstanceid, createseries, series, numseriesall

// Create new series in modal
// Button for connection a new series
$('#createseries').click(function() {
$('#createseries')?.click(function() {
ModalFactory.create({
type: ModalFactory.types.SAVE_CANCEL,
title: jsstrings[4],
Expand Down Expand Up @@ -388,7 +388,7 @@ export const init = (contextid, ocinstanceid, createseries, series, numseriesall
});

// Import new series in modal
$('#importseries').click(function() {
$('#importseries')?.click(function() {
let context = {
label: jsstrings[12],
required: false,
Expand Down Expand Up @@ -431,8 +431,8 @@ export const init = (contextid, ocinstanceid, createseries, series, numseriesall
seriestable.addRow({'seriesname': s.title, 'series': s.id, 'isdefault': s.isdefault});

if (seriestable.getRows().length >= numseriesallowed) {
$("#createseries").hide();
$("#importseries").hide();
$("#createseries")?.hide();
$("#importseries")?.hide();
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public static function get_series_titles(int $contextid, int $ocinstanceid, stri

$context = context::instance_by_id($params['contextid']);
self::validate_context($context);
require_capability('block/opencast:defineseriesforcourse', $context);
require_capability('block/opencast:manageseriesforcourse', $context);

$serialiseddata = json_decode($params['series']);
$seriestitles = [];
Expand Down
10 changes: 2 additions & 8 deletions db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,6 @@
'manager' => CAP_ALLOW,
],
],
'block/opencast:defineseriesforcourse' => [
'riskbitmask' => RISK_SPAM,
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => [
'manager' => CAP_ALLOW,
],
],
'block/opencast:importseriesintocourse' => [
'riskbitmask' => RISK_SPAM,
'captype' => 'write',
Expand Down Expand Up @@ -160,6 +152,7 @@
'contextlevel' => CONTEXT_COURSE,
'archetypes' => [
'manager' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW
],
],
'block/opencast:manageseriesforcourse' => [
Expand All @@ -168,6 +161,7 @@
'contextlevel' => CONTEXT_COURSE,
'archetypes' => [
'manager' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW
],
],
'block/opencast:deleteevent' => [
Expand Down
2 changes: 1 addition & 1 deletion db/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
'description' => 'Retrieves series titles',
'type' => 'read',
'ajax' => true,
'capabilities' => 'block/opencast:defineseriesforcourse',
'capabilities' => 'block/opencast:manageseriesforcourse',
],
'block_opencast_import_series' => [
'classname' => 'block_opencast_external',
Expand Down
5 changes: 2 additions & 3 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,14 @@
$ocseriesid = $apibridge->get_default_course_series($courseid);

if ($seriesid && !$ocseriesid) {
if (has_capability('block/opencast:defineseriesforcourse', $coursecontext)) {
if (has_capability('block/opencast:importseriesintocourse', $coursecontext)) {
echo $OUTPUT->notification(get_string('series_does_not_exist_admin', 'block_opencast', $seriesid));
} else {
echo $OUTPUT->notification(get_string('series_does_not_exist', 'block_opencast'));
}
}

if (!$opencasterror && (has_capability('block/opencast:createseriesforcourse', $coursecontext)
|| has_capability('block/opencast:defineseriesforcourse', $coursecontext))) {
if (!$opencasterror && has_capability('block/opencast:manageseriesforcourse', $coursecontext)) {
echo $renderer->render_series_settings_actions($ocinstanceid, $courseid);
}

Expand Down
3 changes: 1 addition & 2 deletions lang/en/block_opencast.php
Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,8 @@
$string['opencast:addvideo'] = 'Add a new video to opencast upload block';
$string['opencast:createseriesforcourse'] = 'Create a new series in opencast for a moodle course';
$string['opencast:deleteevent'] = 'Finally delete a video (event) in opencast';
$string['opencast:defineseriesforcourse'] = 'Link an existing opencast series to a moodle course';
$string['opencast:importseriesintocourse'] = 'Import an existing opencast series to a moodle course';
$string['opencast:manageseriesforcourse'] = 'Manage the opencast series of a moodle course';
$string['opencast:manageseriesforcourse'] = 'Manage the opencast series of a moodle course: Access manageseries.php, unlink series from course and select default series.';
$string['opencast:downloadvideo'] = 'Download processed videos';
$string['opencast:startworkflow'] = 'Manually start workflows for videos';
$string['opencast:manualimportsource'] = 'Manually import videos from this course';
Expand Down
2 changes: 1 addition & 1 deletion manageseries.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
$PAGE->navbar->add(get_string('manageseriesforcourse', 'block_opencast'), $baseurl);

// Capability check.
require_capability('block/opencast:defineseriesforcourse', $coursecontext);
require_capability('block/opencast:manageseriesforcourse', $coursecontext);

$apibridge = apibridge::get_instance($ocinstanceid);

Expand Down
7 changes: 5 additions & 2 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1328,10 +1328,13 @@ public function render_report_problem_icon($identifier) {
*/
public function render_manage_series_table($ocinstanceid, $courseid) {
global $DB;
$series = $DB->get_records('tool_opencast_series', ['ocinstanceid' => $ocinstanceid, 'courseid' => $courseid]);
$coursecontext = context_course::instance($courseid);
$countseries = $DB->count_records('tool_opencast_series', ['ocinstanceid' => $ocinstanceid, 'courseid' => $courseid]);

$context = new stdClass();
$context->addseriesallowed = count($series) < get_config('block_opencast', 'maxseries_' . $ocinstanceid);
$context->maxseriesreached = $countseries >= get_config('block_opencast', 'maxseries_' . $ocinstanceid);
$context->cancreateseries = has_capability('block/opencast:createseriesforcourse', $coursecontext);
$context->canimportseries = has_capability('block/opencast:importseriesintocourse', $coursecontext);

return $this->render_from_template('block_opencast/series_table', $context);
}
Expand Down
27 changes: 11 additions & 16 deletions templates/series_table.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,20 @@
Example context (json):
{
"series": "",
"numseriesallowed": 3,
"addseriesallowed": true
"cancreateseries": true,
"canimportseries": false,
"maxseriesreached": false
}
}}
<div class="mt-3" id="seriestable">
</div>
{{#addseriesallowed}}
<button type="button" class="btn btn-primary mt-3" id="createseries">
{{#cancreateseries}}
<button type="button" class="btn btn-primary mt-3 {{#maxseriesreached}}d-none{{/maxseriesreached}}" id="createseries">
{{# str}}createseriesforcourse, block_opencast {{/ str}}
</button>
<button type="button" class="btn btn-primary mt-3" id="importseries">
{{# str}}importseries, block_opencast {{/ str}}
{{/addseriesallowed}}
{{^addseriesallowed}}
<button type="button" class="btn btn-primary mt-3 d-none" id="createseries">
{{# str}}createseriesforcourse, block_opencast {{/ str}}
</button>
<button type="button" class="btn btn-primary mt-3 d-none" id="importseries">
{{# str}}importseries, block_opencast {{/ str}}
{{/addseriesallowed}}
</button>
{{/cancreateseries}}
{{#canimportseries}}
<button type="button" class="btn btn-primary mt-3 {{#maxseriesreached}}d-none{{/maxseriesreached}}" id="importseries">
{{# str}}importseries, block_opencast {{/ str}}
</button>
{{/canimportseries}}

0 comments on commit fe6b207

Please sign in to comment.