MDL-73683 core_courseformat: match hasRestrictions criteria
Orignally, the lock icon in the course index and the course content represents different things and it was confusing for users. Now both section and cm state data calculate the hasRestrictions attribute the same way as the course content lock icons.
This commit is contained in:
Vendored
+1
-1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -846,11 +846,7 @@ define(
|
||||
|
||||
case 'hide':
|
||||
case 'show':
|
||||
cm.visible = (action === 'show') ? true : false;
|
||||
break;
|
||||
|
||||
case 'duplicate':
|
||||
// Duplicate requires to get extra data from the server.
|
||||
courseeditor.dispatch('cmState', affectedids);
|
||||
break;
|
||||
}
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -50,7 +50,7 @@ export default class Component extends DndCmItem {
|
||||
this.classes = {
|
||||
CMHIDDEN: 'dimmed',
|
||||
LOCKED: 'editinprogress',
|
||||
RESTRICTIONS: 'rectrictions',
|
||||
RESTRICTIONS: 'restrictions',
|
||||
PAGEITEM: 'pageitem',
|
||||
};
|
||||
// We need our id to watch specific events.
|
||||
@@ -131,7 +131,7 @@ export default class Component extends DndCmItem {
|
||||
this.getElement(this.selectors.CM_NAME).innerHTML = element.name;
|
||||
this.element.classList.toggle(this.classes.DRAGGING, element.dragging ?? false);
|
||||
this.element.classList.toggle(this.classes.LOCKED, element.locked ?? false);
|
||||
this.element.classList.toggle(this.classes.RESTRICTIONS, element.hascmrectrictions ?? false);
|
||||
this.element.classList.toggle(this.classes.RESTRICTIONS, element.hascmrestrictions ?? false);
|
||||
this.locked = element.locked;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ export default class Component extends DndSection {
|
||||
SECTIONHIDDEN: 'dimmed',
|
||||
SECTIONCURRENT: 'current',
|
||||
LOCKED: 'editinprogress',
|
||||
RESTRICTIONS: 'rectrictions',
|
||||
RESTRICTIONS: 'restrictions',
|
||||
PAGEITEM: 'pageitem',
|
||||
};
|
||||
|
||||
@@ -127,10 +127,10 @@ export default class Component extends DndSection {
|
||||
// Update classes.
|
||||
const sectionItem = this.getElement(this.selectors.SECTION_ITEM);
|
||||
sectionItem.classList.toggle(this.classes.SECTIONHIDDEN, !element.visible);
|
||||
sectionItem.classList.toggle(this.classes.RESTRICTIONS, element.hasrestrictions ?? false);
|
||||
this.element.classList.toggle(this.classes.SECTIONCURRENT, element.current);
|
||||
this.element.classList.toggle(this.classes.DRAGGING, element.dragging ?? false);
|
||||
this.element.classList.toggle(this.classes.LOCKED, element.locked ?? false);
|
||||
this.element.classList.toggle(this.classes.RESTRICTIONS, element.hasrestrictions ?? false);
|
||||
this.locked = element.locked;
|
||||
// Update title.
|
||||
this.getElement(this.selectors.SECTION_TITLE).innerHTML = element.title;
|
||||
|
||||
@@ -86,26 +86,13 @@ class cm implements renderable {
|
||||
'sectionid' => $section->id,
|
||||
'sectionnumber' => $section->section,
|
||||
'uservisible' => $cm->uservisible,
|
||||
'hascmrestrictions' => $this->get_has_restrictions(),
|
||||
];
|
||||
|
||||
// Check the user access type to this cm.
|
||||
$info = new info_module($cm);
|
||||
$data->accessvisible = ($data->visible && $info->is_available_for_all());
|
||||
|
||||
// Check if restriction access are visible to the user.
|
||||
$canviewhidden = has_capability('moodle/course:viewhiddenactivities', $cm->context);
|
||||
if (!empty($CFG->enableavailability) && $canviewhidden) {
|
||||
if (has_capability('moodle/course:manageactivities', $cm->context)) {
|
||||
// Course editors can see all restrictions.
|
||||
$data->hascmrectrictions = !empty($cm->availability);
|
||||
} else {
|
||||
// Some users can see restrictions even if it does not apply to them.
|
||||
$data->hascmrectrictions = !empty($cm->availableinfo);
|
||||
}
|
||||
} else {
|
||||
$data->hascmrectrictions = !$data->accessvisible || !$cm->uservisible;
|
||||
}
|
||||
|
||||
// Add url if the activity is compatible.
|
||||
$url = $cm->url;
|
||||
if ($url) {
|
||||
@@ -126,4 +113,33 @@ class cm implements renderable {
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if the activity has a restrictions icon displayed or not.
|
||||
*
|
||||
* @return bool if the activity has visible restrictions for the user.
|
||||
*/
|
||||
protected function get_has_restrictions(): bool {
|
||||
global $CFG;
|
||||
$cm = $this->cm;
|
||||
|
||||
if (empty($cm->visible) || empty($CFG->enableavailability)) {
|
||||
return false;
|
||||
}
|
||||
// Nothing to be displayed to the user.
|
||||
if (!$cm->is_visible_on_course_page()) {
|
||||
return false;
|
||||
}
|
||||
// Not allowed to see the module but might be allowed to see some availability.
|
||||
if (!$cm->uservisible) {
|
||||
return !empty($cm->availableinfo);
|
||||
}
|
||||
// Content editors can see all restrictions if the activity is visible.
|
||||
if (has_capability('moodle/course:viewhiddenactivities', $cm->context)) {
|
||||
$ci = new info_module($cm);
|
||||
return !empty($ci->get_full_information());
|
||||
}
|
||||
// Regular users can only see restrictions if apply to them.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,21 +117,19 @@ class section implements renderable {
|
||||
$context = context_course::instance($course->id);
|
||||
|
||||
// Hidden sections have no restriction indicator displayed.
|
||||
if (!$section->visible || empty($CFG->enableavailability)) {
|
||||
if (empty($section->visible) || empty($CFG->enableavailability)) {
|
||||
return false;
|
||||
}
|
||||
if (!has_capability('moodle/course:viewhiddenactivities', $context)) {
|
||||
// If the section is visible but not user visible means it has some locking rule.
|
||||
return empty($section->uservisible);
|
||||
}
|
||||
|
||||
if (has_capability('moodle/course:manageactivities', $context)) {
|
||||
// Course editors can see all restrictions if the section is visible.
|
||||
$ci = new info_section($section);
|
||||
return !empty($ci->get_full_information());
|
||||
} else {
|
||||
// Some users can see restrictions even if it does not apply to them.
|
||||
// The activity is not visible to the user but it may have some availability information.
|
||||
if (!$section->uservisible) {
|
||||
return !empty($section->availableinfo);
|
||||
}
|
||||
// Course editors can see all restrictions if the section is visible.
|
||||
if (has_capability('moodle/course:viewhiddensections', $context)) {
|
||||
$ci = new info_section($section);
|
||||
return !empty($ci->get_full_information());
|
||||
}
|
||||
// Regular users can only see restrictions if apply to them.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,12 +28,12 @@
|
||||
"isactive": 1,
|
||||
"uniqid": "0",
|
||||
"accessvisible": 1,
|
||||
"hascmrectrictions": 0
|
||||
"hascmrestrictions": 0
|
||||
}
|
||||
}}
|
||||
<li class="courseindex-item
|
||||
{{#isactive}}active{{/isactive}}
|
||||
{{#hascmrectrictions}}rectrictions{{/hascmrectrictions}}
|
||||
{{#hascmrestrictions}}restrictions{{/hascmrestrictions}}
|
||||
{{^accessvisible}}dimmed{{/accessvisible}}
|
||||
{{#url}} d-flex {{/url}} {{^url}} d-flex-noedit {{/url}}"
|
||||
id="{{uniqid}}-course-index-cm-{{id}}"
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
"indexcollapsed": 0,
|
||||
"current": 1,
|
||||
"visible": 1,
|
||||
"hasrectrictions": 0,
|
||||
"hasrestrictions": 0,
|
||||
"cms": [
|
||||
{
|
||||
"id": 10,
|
||||
@@ -66,7 +66,7 @@
|
||||
>
|
||||
<div class="courseindex-item d-flex
|
||||
{{^visible}}dimmed{{/visible}}
|
||||
{{#hasrestrictions}}rectrictions{{/hasrestrictions}}
|
||||
{{#hasrestrictions}}restrictions{{/hasrestrictions}}
|
||||
courseindex-section-title"
|
||||
id="courseindexsection{{number}}"
|
||||
data-for="section_item"
|
||||
|
||||
@@ -49,7 +49,6 @@ class cm_test extends \advanced_testcase {
|
||||
* @covers ::export_for_template
|
||||
*
|
||||
* @param string $format the course format
|
||||
* @param bool $addcanviewhidden if the canviewhidden capabilities must be added to the role.
|
||||
* @param string $rolename the user role name (editingteacher or student)
|
||||
* @param bool $hasavailability if the activity|section has availability
|
||||
* @param bool $available if the activity availability condition is available or not to the user
|
||||
@@ -57,13 +56,12 @@ class cm_test extends \advanced_testcase {
|
||||
*/
|
||||
public function test_cm_hasrestrictions_state(
|
||||
string $format = 'topics',
|
||||
bool $addcanviewhidden = false,
|
||||
string $rolename = 'editingteacher',
|
||||
bool $hasavailability = false,
|
||||
bool $available = false,
|
||||
bool $expected = false
|
||||
) {
|
||||
$data = $this->setup_hasrestrictions_scenario($format, $addcanviewhidden, $rolename, $hasavailability, $available);
|
||||
$data = $this->setup_hasrestrictions_scenario($format, $rolename, $hasavailability, $available);
|
||||
|
||||
// Get the cm state.
|
||||
$courseformat = $data->courseformat;
|
||||
@@ -78,14 +76,13 @@ class cm_test extends \advanced_testcase {
|
||||
);
|
||||
$state = $cmstate->export_for_template($renderer);
|
||||
|
||||
$this->assertEquals($expected, $state->hascmrectrictions);
|
||||
$this->assertEquals($expected, $state->hascmrestrictions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup section or cm has restrictions scenario.
|
||||
*
|
||||
* @param string $format the course format
|
||||
* @param bool $addcanviewhidden if the canviewhidden capabilities must be added to the role.
|
||||
* @param string $rolename the user role name (editingteacher or student)
|
||||
* @param bool $hasavailability if the activity|section has availability
|
||||
* @param bool $available if the activity availability condition is available or not to the user
|
||||
@@ -93,7 +90,6 @@ class cm_test extends \advanced_testcase {
|
||||
*/
|
||||
private function setup_hasrestrictions_scenario(
|
||||
string $format = 'topics',
|
||||
bool $addcanviewhidden = false,
|
||||
string $rolename = 'editingteacher',
|
||||
bool $hasavailability = false,
|
||||
bool $available = false
|
||||
@@ -101,6 +97,8 @@ class cm_test extends \advanced_testcase {
|
||||
global $PAGE, $DB;
|
||||
$this->resetAfterTest();
|
||||
|
||||
set_config('enableavailability', 1);
|
||||
|
||||
$course = $this->getDataGenerator()->create_course(['numsections' => 1, 'format' => $format]);
|
||||
|
||||
// Create and enrol user.
|
||||
@@ -112,13 +110,6 @@ class cm_test extends \advanced_testcase {
|
||||
);
|
||||
$this->setUser($user);
|
||||
|
||||
// Add capabilities if necessary.
|
||||
if ($addcanviewhidden) {
|
||||
$roleid = $DB->get_field('role', 'id', array('shortname' => $rolename), MUST_EXIST);
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
assign_capability('moodle/course:viewhiddenactivities', CAP_ALLOW, $roleid, $coursecontext->id);
|
||||
}
|
||||
|
||||
// Create an activity.
|
||||
$activity = $this->getDataGenerator()->create_module('page', ['course' => $course->id], [
|
||||
'section' => 1,
|
||||
@@ -165,225 +156,198 @@ class cm_test extends \advanced_testcase {
|
||||
public function hasrestrictions_state_provider(): array {
|
||||
return [
|
||||
// Teacher scenarios (topics).
|
||||
'Topics, can edit, has availability and is available' => [
|
||||
'Teacher, Topics, can edit, has availability and is available' => [
|
||||
'format' => 'topics',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => true,
|
||||
],
|
||||
'Topics, can edit, has availability and is not available' => [
|
||||
'Teacher, Topics, can edit, has availability and is not available' => [
|
||||
'format' => 'topics',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Topics, can edit and has not availability' => [
|
||||
'Teacher, Topics, can edit and has not availability' => [
|
||||
'format' => 'topics',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Teacher scenarios (weeks).
|
||||
'Weeks, can edit, has availability and is available' => [
|
||||
'Teacher, Weeks, can edit, has availability and is available' => [
|
||||
'format' => 'weeks',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => true,
|
||||
],
|
||||
'Weeks, can edit, has availability and is not available' => [
|
||||
'Teacher, Weeks, can edit, has availability and is not available' => [
|
||||
'format' => 'weeks',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Weeks, can edit and has not availability' => [
|
||||
'Teacher, Weeks, can edit and has not availability' => [
|
||||
'format' => 'weeks',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Teacher scenarios (mock format).
|
||||
'Mock format, can edit, has availability and is available' => [
|
||||
'Teacher, Mock format, can edit, has availability and is available' => [
|
||||
'format' => 'theunittest',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => true,
|
||||
],
|
||||
'Mock format, can edit, has availability and is not available' => [
|
||||
'Teacher, Mock format, can edit, has availability and is not available' => [
|
||||
'format' => 'theunittest',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Mock format, can edit and has not availability' => [
|
||||
'Teacher, Mock format, can edit and has not availability' => [
|
||||
'format' => 'theunittest',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Non editing teacher scenarios (topics).
|
||||
'Non editing teacher, Topics, can edit, has availability and is available' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => true,
|
||||
],
|
||||
'Non editing teacher, Topics, can edit, has availability and is not available' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Non editing teacher, Topics, can edit and has not availability' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Non editing teacher scenarios (weeks).
|
||||
'Non editing teacher, Weeks, can edit, has availability and is available' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => true,
|
||||
],
|
||||
'Non editing teacher, Weeks, can edit, has availability and is not available' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Non editing teacher, Weeks, can edit and has not availability' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Non editing teacher scenarios (mock format).
|
||||
'Non editing teacher, Mock format, can edit, has availability and is available' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => true,
|
||||
],
|
||||
'Non editing teacher, Mock format, can edit, has availability and is not available' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Non editing teacher, Mock format, can edit and has not availability' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Student scenarios (topics).
|
||||
'Topics, cannot edit, has availability and is available' => [
|
||||
'Student, Topics, cannot edit, has availability and is available' => [
|
||||
'format' => 'topics',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
'Topics, cannot edit, has availability and is not available' => [
|
||||
'Student, Topics, cannot edit, has availability and is not available' => [
|
||||
'format' => 'topics',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Topics, cannot edit and has not availability' => [
|
||||
'Student, Topics, cannot edit and has not availability' => [
|
||||
'format' => 'topics',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Student scenarios (weeks).
|
||||
'Weeks, cannot edit, has availability and is available' => [
|
||||
'Student, Weeks, cannot edit, has availability and is available' => [
|
||||
'format' => 'weeks',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
'Weeks, cannot edit, has availability and is not available' => [
|
||||
'Student, Weeks, cannot edit, has availability and is not available' => [
|
||||
'format' => 'weeks',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Weeks, cannot edit and has not availability' => [
|
||||
'Student, Weeks, cannot edit and has not availability' => [
|
||||
'format' => 'weeks',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Student scenarios (mock format).
|
||||
'Mock format, cannot edit, has availability and is available' => [
|
||||
'Student, Mock format, cannot edit, has availability and is available' => [
|
||||
'format' => 'theunittest',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
'Mock format, cannot edit, has availability and is not available' => [
|
||||
'Student, Mock format, cannot edit, has availability and is not available' => [
|
||||
'format' => 'theunittest',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Mock format, cannot edit and has not availability' => [
|
||||
'Student, Mock format, cannot edit and has not availability' => [
|
||||
'format' => 'theunittest',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Students with view hidden activities capabilities (topics).
|
||||
'Topics, can view hidden but not edit, has availability and is available' => [
|
||||
'format' => 'topics',
|
||||
'addcanviewhidden' => true,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
'Topics, can view hidden but not edit, has availability and is not available' => [
|
||||
'format' => 'topics',
|
||||
'addcanviewhidden' => true,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Topics, can view hidden but not edit and has not availability' => [
|
||||
'format' => 'topics',
|
||||
'addcanviewhidden' => true,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Students with view hidden activities capabilities (weeks).
|
||||
'Weeks, can view hidden but not edit, has availability and is available' => [
|
||||
'format' => 'weeks',
|
||||
'addcanviewhidden' => true,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
'Weeks, can view hidden but not edit, has availability and is not available' => [
|
||||
'format' => 'weeks',
|
||||
'addcanviewhidden' => true,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Weeks, can view hidden but not edit and has not availability' => [
|
||||
'format' => 'weeks',
|
||||
'addcanviewhidden' => true,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Students with view hidden activities capabilities (mock format).
|
||||
'Mock format, can view hidden but not edit, has availability and is available' => [
|
||||
'format' => 'theunittest',
|
||||
'addcanviewhidden' => true,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
'Mock format, can view hidden but not edit, has availability and is not available' => [
|
||||
'format' => 'theunittest',
|
||||
'addcanviewhidden' => true,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Mock format, can view hidden but not edit and has not availability' => [
|
||||
'format' => 'theunittest',
|
||||
'addcanviewhidden' => true,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
|
||||
@@ -49,7 +49,6 @@ class section_test extends \advanced_testcase {
|
||||
* @covers ::export_for_template
|
||||
*
|
||||
* @param string $format the course format
|
||||
* @param bool $addcanviewhidden if the canviewhidden capabilities must be added to the role.
|
||||
* @param string $rolename the user role name (editingteacher or student)
|
||||
* @param bool $hasavailability if the activity|section has availability
|
||||
* @param bool $available if the activity availability condition is available or not to the user
|
||||
@@ -57,13 +56,12 @@ class section_test extends \advanced_testcase {
|
||||
*/
|
||||
public function test_section_hasrestrictions_state(
|
||||
string $format = 'topics',
|
||||
bool $addcanviewhidden = false,
|
||||
string $rolename = 'editingteacher',
|
||||
bool $hasavailability = false,
|
||||
bool $available = false,
|
||||
bool $expected = false
|
||||
) {
|
||||
$data = $this->setup_hasrestrictions_scenario($format, $addcanviewhidden, $rolename, $hasavailability, $available);
|
||||
$data = $this->setup_hasrestrictions_scenario($format, $rolename, $hasavailability, $available);
|
||||
|
||||
// Get the cm state.
|
||||
$courseformat = $data->courseformat;
|
||||
@@ -84,7 +82,6 @@ class section_test extends \advanced_testcase {
|
||||
* Setup section or cm has restrictions scenario.
|
||||
*
|
||||
* @param string $format the course format
|
||||
* @param bool $addcanviewhidden if the canviewhidden capabilities must be added to the role.
|
||||
* @param string $rolename the user role name (editingteacher or student)
|
||||
* @param bool $hasavailability if the section has availability
|
||||
* @param bool $available if the section availability condition is available or not to the user
|
||||
@@ -92,7 +89,6 @@ class section_test extends \advanced_testcase {
|
||||
*/
|
||||
private function setup_hasrestrictions_scenario(
|
||||
string $format = 'topics',
|
||||
bool $addcanviewhidden = false,
|
||||
string $rolename = 'editingteacher',
|
||||
bool $hasavailability = false,
|
||||
bool $available = false
|
||||
@@ -111,13 +107,6 @@ class section_test extends \advanced_testcase {
|
||||
);
|
||||
$this->setUser($user);
|
||||
|
||||
// Add capabilities if necessary.
|
||||
if ($addcanviewhidden) {
|
||||
$roleid = $DB->get_field('role', 'id', array('shortname' => $rolename), MUST_EXIST);
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
assign_capability('moodle/course:viewhiddenactivities', CAP_ALLOW, $roleid, $coursecontext->id);
|
||||
}
|
||||
|
||||
// Set up the availability settings.
|
||||
if ($hasavailability) {
|
||||
$operation = ($available) ? condition::DIRECTION_UNTIL : condition::DIRECTION_FROM;
|
||||
@@ -159,84 +148,140 @@ class section_test extends \advanced_testcase {
|
||||
public function hasrestrictions_state_provider(): array {
|
||||
return [
|
||||
// Teacher scenarios (topics).
|
||||
'Topics, can edit, has availability and is available' => [
|
||||
'Teacher, Topics, can edit, has availability and is available' => [
|
||||
'format' => 'topics',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => true,
|
||||
],
|
||||
'Topics, can edit, has availability and is not available' => [
|
||||
'Teacher, Topics, can edit, has availability and is not available' => [
|
||||
'format' => 'topics',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Topics, can edit and has not availability' => [
|
||||
'Teacher, Topics, can edit and has not availability' => [
|
||||
'format' => 'topics',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Teacher scenarios (weeks).
|
||||
'Weeks, can edit, has availability and is available' => [
|
||||
'Teacher, Weeks, can edit, has availability and is available' => [
|
||||
'format' => 'weeks',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => true,
|
||||
],
|
||||
'Weeks, can edit, has availability and is not available' => [
|
||||
'Teacher, Weeks, can edit, has availability and is not available' => [
|
||||
'format' => 'weeks',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Weeks, can edit and has not availability' => [
|
||||
'Teacher, Weeks, can edit and has not availability' => [
|
||||
'format' => 'weeks',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Teacher scenarios (mock format).
|
||||
'Mock format, can edit, has availability and is available' => [
|
||||
'Teacher, Mock format, can edit, has availability and is available' => [
|
||||
'format' => 'theunittest',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => true,
|
||||
],
|
||||
'Mock format, can edit, has availability and is not available' => [
|
||||
'Teacher, Mock format, can edit, has availability and is not available' => [
|
||||
'format' => 'theunittest',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Mock format, can edit and has not availability' => [
|
||||
'Teacher, Mock format, can edit and has not availability' => [
|
||||
'format' => 'theunittest',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'editingteacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Non editing teacher scenarios (topics).
|
||||
'Non editing teacher, Topics, can edit, has availability and is available' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
'Non editing teacher, Topics, can edit, has availability and is not available' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => false,
|
||||
],
|
||||
'Non editing teacher, Topics, can edit and has not availability' => [
|
||||
'format' => 'topics',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Non editing teacher scenarios (weeks).
|
||||
'Non editing teacher, Weeks, can edit, has availability and is available' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
'Non editing teacher, Weeks, can edit, has availability and is not available' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => false,
|
||||
],
|
||||
'Non editing teacher, Weeks, can edit and has not availability' => [
|
||||
'format' => 'weeks',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Non editing teacher scenarios (mock format).
|
||||
'Non editing teacher, Mock format, can edit, has availability and is available' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
'Non editing teacher, Mock format, can edit, has availability and is not available' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => false,
|
||||
],
|
||||
'Non editing teacher, Mock format, can edit and has not availability' => [
|
||||
'format' => 'theunittest',
|
||||
'rolename' => 'teacher',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Student scenarios (topics).
|
||||
'Topics, cannot edit, has availability and is available' => [
|
||||
'format' => 'topics',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
@@ -244,7 +289,6 @@ class section_test extends \advanced_testcase {
|
||||
],
|
||||
'Topics, cannot edit, has availability and is not available' => [
|
||||
'format' => 'topics',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
@@ -252,7 +296,6 @@ class section_test extends \advanced_testcase {
|
||||
],
|
||||
'Topics, cannot edit and has not availability' => [
|
||||
'format' => 'topics',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
@@ -261,7 +304,6 @@ class section_test extends \advanced_testcase {
|
||||
// Student scenarios (weeks).
|
||||
'Weeks, cannot edit, has availability and is available' => [
|
||||
'format' => 'weeks',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
@@ -269,7 +311,6 @@ class section_test extends \advanced_testcase {
|
||||
],
|
||||
'Weeks, cannot edit, has availability and is not available' => [
|
||||
'format' => 'weeks',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
@@ -277,7 +318,6 @@ class section_test extends \advanced_testcase {
|
||||
],
|
||||
'Weeks, cannot edit and has not availability' => [
|
||||
'format' => 'weeks',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
@@ -286,7 +326,6 @@ class section_test extends \advanced_testcase {
|
||||
// Student scenarios (mock format).
|
||||
'Mock format, cannot edit, has availability and is available' => [
|
||||
'format' => 'theunittest',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
@@ -294,7 +333,6 @@ class section_test extends \advanced_testcase {
|
||||
],
|
||||
'Mock format, cannot edit, has availability and is not available' => [
|
||||
'format' => 'theunittest',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
@@ -302,82 +340,6 @@ class section_test extends \advanced_testcase {
|
||||
],
|
||||
'Mock format, cannot edit and has not availability' => [
|
||||
'format' => 'theunittest',
|
||||
'addcanviewhidden' => false,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Students with view hidden activities capabilities (topics).
|
||||
'Topics, can view hidden but not edit, has availability and is available' => [
|
||||
'format' => 'topics',
|
||||
'addcanviewhidden' => true,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
'Topics, can view hidden but not edit, has availability and is not available' => [
|
||||
'format' => 'topics',
|
||||
'addcanviewhidden' => true,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Topics, can view hidden but not edit and has not availability' => [
|
||||
'format' => 'topics',
|
||||
'addcanviewhidden' => true,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Students with view hidden activities capabilities (weeks).
|
||||
'Weeks, can view hidden but not edit, has availability and is available' => [
|
||||
'format' => 'weeks',
|
||||
'addcanviewhidden' => true,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
'Weeks, can view hidden but not edit, has availability and is not available' => [
|
||||
'format' => 'weeks',
|
||||
'addcanviewhidden' => true,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Weeks, can view hidden but not edit and has not availability' => [
|
||||
'format' => 'weeks',
|
||||
'addcanviewhidden' => true,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
// Students with view hidden activities capabilities (mock format).
|
||||
'Mock format, can view hidden but not edit, has availability and is available' => [
|
||||
'format' => 'theunittest',
|
||||
'addcanviewhidden' => true,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => true,
|
||||
'expected' => false,
|
||||
],
|
||||
'Mock format, can view hidden but not edit, has availability and is not available' => [
|
||||
'format' => 'theunittest',
|
||||
'addcanviewhidden' => true,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => true,
|
||||
'available' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'Mock format, can view hidden but not edit and has not availability' => [
|
||||
'format' => 'theunittest',
|
||||
'addcanviewhidden' => true,
|
||||
'rolename' => 'student',
|
||||
'hasavailability' => false,
|
||||
'available' => true,
|
||||
|
||||
@@ -89,7 +89,7 @@ $courseindex-item-current: $primary !default;
|
||||
.courseindex-locked {
|
||||
display: none;
|
||||
}
|
||||
&.rectrictions {
|
||||
&.restrictions {
|
||||
.courseindex-locked {
|
||||
display: block;
|
||||
}
|
||||
|
||||
@@ -21376,7 +21376,7 @@ div.editor_atto_toolbar button .icon {
|
||||
color: #6a737b; }
|
||||
.courseindex .courseindex-item .courseindex-locked {
|
||||
display: none; }
|
||||
.courseindex .courseindex-item.rectrictions .courseindex-locked {
|
||||
.courseindex .courseindex-item.restrictions .courseindex-locked {
|
||||
display: block; }
|
||||
.courseindex .courseindex-item.pageitem {
|
||||
background-color: #0f6cbf;
|
||||
|
||||
@@ -21322,7 +21322,7 @@ div.editor_atto_toolbar button .icon {
|
||||
color: #6a737b; }
|
||||
.courseindex .courseindex-item .courseindex-locked {
|
||||
display: none; }
|
||||
.courseindex .courseindex-item.rectrictions .courseindex-locked {
|
||||
.courseindex .courseindex-item.restrictions .courseindex-locked {
|
||||
display: block; }
|
||||
.courseindex .courseindex-item.pageitem {
|
||||
background-color: #0f6cbf;
|
||||
|
||||
Reference in New Issue
Block a user