diff --git a/calendar/classes/local/event/forms/eventtype.php b/calendar/classes/local/event/forms/eventtype.php index b3d582694f1..d615a50804b 100644 --- a/calendar/classes/local/event/forms/eventtype.php +++ b/calendar/classes/local/event/forms/eventtype.php @@ -98,7 +98,7 @@ trait eventtype { $mform->hideIf('categoryid', 'eventtype', 'noteq', 'category'); } - $showall = $CFG->calendar_adminseesall && !has_capability('moodle/calendar:manageentries', \context_system::instance()); + $showall = is_siteadmin() && !empty($CFG->calendar_adminseesall); if (!empty($eventtypes['course'])) { $mform->addElement('course', 'courseid', get_string('course'), ['limittoenrolled' => !$showall]); $mform->hideIf('courseid', 'eventtype', 'noteq', 'course'); diff --git a/calendar/lib.php b/calendar/lib.php index 07ba6fd871c..0f0559a6899 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -3688,7 +3688,7 @@ function calendar_get_allowed_event_types(int $courseid = null) { $types['user'] = has_capability('moodle/calendar:manageownentries', $context); - if (has_capability('moodle/calendar:manageentries', $context) || !empty($CFG->calendar_adminseesall)) { + if (has_capability('moodle/calendar:manageentries', $context)) { $types['course'] = true; $types['group'] = (!empty($groups) && has_capability('moodle/site:accessallgroups', $context)) diff --git a/calendar/tests/behat/calendar.feature b/calendar/tests/behat/calendar.feature index 8dc6f3681a0..5f1ffaf5043 100644 --- a/calendar/tests/behat/calendar.feature +++ b/calendar/tests/behat/calendar.feature @@ -14,6 +14,8 @@ Feature: Perform basic calendar functionality And the following "courses" exist: | fullname | shortname | format | | Course 1 | C1 | topics | + | Course 2 | C2 | topics | + | Course 3 | C3 | topics | And the following "course enrolments" exist: | user | course | role | | student1 | C1 | student | @@ -188,3 +190,51 @@ Feature: Perform basic calendar functionality And I follow "This month" When I click on "New event" "button" Then the field "Type of event" matches value "Course" + + @javascript + Scenario: Admin can only see all courses if calendar_adminseesall setting is enabled. + Given I log in as "admin" + And I am on "Course 1" course homepage + And I enrol "admin" user as "Teacher" + And I am viewing site calendar + And I click on "New event" "button" + And I set the field "Type of event" to "Course" + When I open the autocomplete suggestions list + Then I should see "Course 1" in the ".form-autocomplete-suggestions" "css_element" + And I should not see "Course 2" in the ".form-autocomplete-suggestions" "css_element" + And I should not see "Course 3" in the ".form-autocomplete-suggestions" "css_element" + And I click on "Close" "button" + And I am on site homepage + And I navigate to "Appearance > Calendar" in site administration + And I set the field "Admins see all" to "1" + And I press "Save changes" + And I am viewing site calendar + And I click on "New event" "button" + And I set the field "Type of event" to "Course" + When I open the autocomplete suggestions list + Then I should see "Course 1" in the ".form-autocomplete-suggestions" "css_element" + And I should see "Course 2" in the ".form-autocomplete-suggestions" "css_element" + And I should see "Course 3" in the ".form-autocomplete-suggestions" "css_element" + + @javascript + Scenario: Students can only see user event type by default. + Given I log in as "student1" + And I am viewing site calendar + When I click on "New event" "button" + Then I should see "User" in the "div#fitem_id_staticeventtype" "css_element" + And I am on "Course 1" course homepage + And I follow "This month" + When I click on "New event" "button" + Then I should see "User" in the "div#fitem_id_staticeventtype" "css_element" + And I click on "Close" "button" + And I log out + Given I log in as "admin" + And I navigate to "Appearance > Calendar" in site administration + And I set the field "Admins see all" to "1" + And I press "Save changes" + And I log out + Given I log in as "student1" + And I am on "Course 1" course homepage + And I follow "This month" + When I click on "New event" "button" + Then I should see "User" in the "div#fitem_id_staticeventtype" "css_element"