Skip to content

Commit 3955345

Browse files
author
David Monllao
committed
Merge branch 'MDL-62944-m34' of https://github.com/NeillM/moodle into MOODLE_34_STABLE
2 parents 2df693e + 9d9d5af commit 3955345

35 files changed

+737
-35
lines changed

calendar/classes/external/event_exporter_base.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ protected function get_other_values(renderer_base $output) {
247247
$values['iscourseevent'] = false;
248248
$values['iscategoryevent'] = false;
249249
if ($moduleproxy = $event->get_course_module()) {
250+
// We need a separate property to flag if an event is action event.
251+
// That's required because canedit return true but action action events cannot be edited on the calendar UI.
252+
// But they are considered editable because you can drag and drop the event on the month view.
250253
$values['isactionevent'] = true;
251254
} else if ($event->get_type() == 'course') {
252255
$values['iscourseevent'] = true;

calendar/templates/event_item.mustache

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@
4949
{{#pix}}t/delete, core, {{#str}}delete{{/str}}{{/pix}}
5050
</a>
5151
{{/candelete}}
52-
<a href="{{editurl}}" data-action="edit">
53-
{{#pix}}t/edit, core, {{#str}}edit{{/str}}{{/pix}}
54-
</a>
52+
{{^isactionevent}}
53+
<a href="{{editurl}}" data-action="edit">
54+
{{#pix}}t/edit, core, {{#str}}edit{{/str}}{{/pix}}
55+
</a>
56+
{{/isactionevent}}
5557
{{/canedit}}
5658
</div>
5759
{{#icon}}{{#pix}} {{key}}, {{component}}, {{alttext}} {{/pix}}{{/icon}}

completion/classes/api.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public static function update_completion_date_event($cmid, $modulename, $instanc
9494
$event->timeduration = 0;
9595

9696
$calendarevent = \calendar_event::load($event->id);
97-
$calendarevent->update($event);
97+
$calendarevent->update($event, false);
9898
} else {
9999
// Calendar event is no longer needed.
100100
$calendarevent = \calendar_event::load($event->id);
@@ -115,7 +115,7 @@ public static function update_completion_date_event($cmid, $modulename, $instanc
115115
$event->visible = instance_is_visible($modulename, $instance);
116116
$event->timeduration = 0;
117117

118-
\calendar_event::create($event);
118+
\calendar_event::create($event, false);
119119
}
120120
}
121121

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
@core @core_completion
2+
Feature: Completion with no calendar capabilites
3+
In order to allow work effectively
4+
As a teacher
5+
I need to be able to create activities with completion enabled without calendar capabilities
6+
7+
Background:
8+
Given the following "courses" exist:
9+
| fullname | shortname | category | groupmode | enablecompletion |
10+
| Course 1 | C1 | 0 | 1 | 1 |
11+
And the following "users" exist:
12+
| username | firstname | lastname | email |
13+
| teacher1 | Teacher | 1 | teacher1@example.com |
14+
And the following "course enrolments" exist:
15+
| user | course | role |
16+
| teacher1 | C1 | editingteacher |
17+
And I log in as "admin"
18+
And I am on "Course 1" course homepage
19+
And I navigate to "Users > Permissions" in current page administration
20+
And I override the system permissions of "Teacher" role with:
21+
| capability | permission |
22+
| moodle/calendar:manageentries | Prohibit |
23+
And I log out
24+
25+
Scenario: Editing completion date
26+
Given I log in as "admin"
27+
And I am on "Course 1" course homepage with editing mode on
28+
When I add a "Forum" to section "1" and I fill the form with:
29+
| Forum name | Test forum name |
30+
| Description | Test forum description |
31+
| Completion tracking | Show activity as complete when conditions are met |
32+
| id_completionexpected_enabled | 1 |
33+
| id_completionexpected_day | 1 |
34+
| id_completionexpected_month | 1 |
35+
| id_completionexpected_year | 2017 |
36+
And I log out
37+
When I log in as "teacher1"
38+
And I am on "Course 1" course homepage with editing mode on
39+
And I follow "Test forum name"
40+
And I navigate to "Edit settings" in current page administration
41+
And I set the following fields to these values:
42+
| id_completionexpected_year | 2018 |
43+
And I press "Save and return to course"
44+
Then I should see "Test forum name"
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Tests that completion works without requiring unnecessary capabilities.
19+
*
20+
* @package core_completion
21+
* @copyright 2018 University of Nottingham
22+
* @author Neill Magill <neill.magill@nottingham.ac.uk>
23+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24+
*/
25+
26+
defined('MOODLE_INTERNAL') || die();
27+
28+
/**
29+
* Tests that completion works without requiring unnecessary capabilities.
30+
*
31+
* @package core_completion
32+
* @copyright 2018 University of Nottingham
33+
* @author Neill Magill <neill.magill@nottingham.ac.uk>
34+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35+
*/
36+
class core_completion_capabilities_testcase extends advanced_testcase {
37+
/**
38+
* A user who does not have capabilities to add events to the calendar should be able to create activities.
39+
*/
40+
public function test_creation_with_no_calendar_capabilities() {
41+
$this->resetAfterTest();
42+
$course = self::getDataGenerator()->create_course(['enablecompletion' => 1]);
43+
$context = context_course::instance($course->id);
44+
$user = self::getDataGenerator()->create_and_enrol($course, 'editingteacher');
45+
$roleid = self::getDataGenerator()->create_role();
46+
self::getDataGenerator()->role_assign($roleid, $user->id, $context->id);
47+
assign_capability('moodle/calendar:manageentries', CAP_PROHIBIT, $roleid, $context, true);
48+
$generator = self::getDataGenerator()->get_plugin_generator('mod_forum');
49+
// Create an instance as a user without the calendar capabilities.
50+
$this->setUser($user);
51+
$params = array(
52+
'course' => $course->id,
53+
'completionexpected' => time() + 2000,
54+
);
55+
$generator->create_instance($params);
56+
}
57+
}

mod/assign/lib.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ function assign_update_events($assign, $override = null) {
345345
unset($event->id);
346346
}
347347
$event->name = $eventname.' ('.get_string('duedate', 'assign').')';
348-
calendar_event::create($event);
348+
calendar_event::create($event, false);
349349
}
350350
}
351351

mod/assign/locallib.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,9 +1332,9 @@ public function update_calendar($coursemoduleid) {
13321332
// Now process the event.
13331333
if ($event->id) {
13341334
$calendarevent = calendar_event::load($event->id);
1335-
$calendarevent->update($event);
1335+
$calendarevent->update($event, false);
13361336
} else {
1337-
calendar_event::create($event);
1337+
calendar_event::create($event, false);
13381338
}
13391339
} else {
13401340
$DB->delete_records('event', array('modulename' => 'assign', 'instance' => $instance->id,
@@ -1353,9 +1353,9 @@ public function update_calendar($coursemoduleid) {
13531353
// Now process the event.
13541354
if ($event->id) {
13551355
$calendarevent = calendar_event::load($event->id);
1356-
$calendarevent->update($event);
1356+
$calendarevent->update($event, false);
13571357
} else {
1358-
calendar_event::create($event);
1358+
calendar_event::create($event, false);
13591359
}
13601360
} else {
13611361
$DB->delete_records('event', array('modulename' => 'assign', 'instance' => $instance->id,
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
@mod @mod_assign
2+
Feature: Assignment with no calendar capabilites
3+
In order to allow work effectively
4+
As a teacher
5+
I need to be able to create assignments even when I cannot edit calendar events
6+
7+
Background:
8+
Given the following "courses" exist:
9+
| fullname | shortname | category | groupmode |
10+
| Course 1 | C1 | 0 | 1 |
11+
And the following "users" exist:
12+
| username | firstname | lastname | email |
13+
| teacher1 | Teacher | 1 | teacher1@example.com |
14+
And the following "course enrolments" exist:
15+
| user | course | role |
16+
| teacher1 | C1 | editingteacher |
17+
And I log in as "admin"
18+
And I am on "Course 1" course homepage
19+
And I navigate to "Users > Permissions" in current page administration
20+
And I override the system permissions of "Teacher" role with:
21+
| capability | permission |
22+
| moodle/calendar:manageentries | Prohibit |
23+
And I log out
24+
25+
Scenario: Editing an assignment
26+
Given I log in as "admin"
27+
And I am on "Course 1" course homepage with editing mode on
28+
When I add a "Assignment" to section "1" and I fill the form with:
29+
| Assignment name | Test assignment name |
30+
| Description | Test assignment description |
31+
| id_allowsubmissionsfromdate_enabled | 1 |
32+
| id_allowsubmissionsfromdate_day | 1 |
33+
| id_allowsubmissionsfromdate_month | 1 |
34+
| id_allowsubmissionsfromdate_year | 2017 |
35+
| id_duedate_enabled | 1 |
36+
| id_duedate_day | 1 |
37+
| id_duedate_month | 2 |
38+
| id_duedate_year | 2017 |
39+
| id_cutoffdate_enabled | 1 |
40+
| id_cutoffdate_day | 2 |
41+
| id_cutoffdate_month | 2 |
42+
| id_cutoffdate_year | 2017 |
43+
| id_gradingduedate_enabled | 1 |
44+
| id_gradingduedate_day | 1 |
45+
| id_gradingduedate_month | 3 |
46+
| id_gradingduedate_year | 2017 |
47+
And I log out
48+
When I log in as "teacher1"
49+
And I am on "Course 1" course homepage with editing mode on
50+
And I follow "Test assignment name"
51+
And I navigate to "Edit settings" in current page administration
52+
And I set the following fields to these values:
53+
| id_allowsubmissionsfromdate_year | 2018 |
54+
| id_duedate_year | 2018 |
55+
| id_cutoffdate_year | 2018 |
56+
| id_gradingduedate_year | 2018 |
57+
And I press "Save and return to course"
58+
Then I should see "Test assignment name"

mod/assign/tests/lib_test.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,4 +1472,29 @@ public function test_teacher_role_can_update_due_event() {
14721472
// is changed.
14731473
$this->assertNotEmpty($moduleupdatedevents);
14741474
}
1475+
1476+
/**
1477+
* A user who does not have capabilities to add events to the calendar should be able to create an assignment.
1478+
*/
1479+
public function test_creation_with_no_calendar_capabilities() {
1480+
$this->resetAfterTest();
1481+
$course = self::getDataGenerator()->create_course();
1482+
$context = context_course::instance($course->id);
1483+
$user = self::getDataGenerator()->create_and_enrol($course, 'editingteacher');
1484+
$roleid = self::getDataGenerator()->create_role();
1485+
self::getDataGenerator()->role_assign($roleid, $user->id, $context->id);
1486+
assign_capability('moodle/calendar:manageentries', CAP_PROHIBIT, $roleid, $context, true);
1487+
$generator = self::getDataGenerator()->get_plugin_generator('mod_assign');
1488+
// Create an instance as a user without the calendar capabilities.
1489+
$this->setUser($user);
1490+
$time = time();
1491+
$params = array(
1492+
'course' => $course->id,
1493+
'allowsubmissionsfromdate' => $time,
1494+
'duedate' => $time + 500,
1495+
'cutoffdate' => $time + 600,
1496+
'gradingduedate' => $time + 700,
1497+
);
1498+
$generator->create_instance($params);
1499+
}
14751500
}

mod/chat/lib.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ function chat_add_instance($chat) {
131131
$event->timesort = $chat->chattime;
132132
$event->timeduration = 0;
133133

134-
calendar_event::create($event);
134+
calendar_event::create($event, false);
135135
}
136136

137137
if (!empty($chat->completionexpected)) {
@@ -171,7 +171,7 @@ function chat_update_instance($chat) {
171171
$event->timesort = $chat->chattime;
172172

173173
$calendarevent = calendar_event::load($event->id);
174-
$calendarevent->update($event);
174+
$calendarevent->update($event, false);
175175
} else {
176176
// Do not publish this event, so delete it.
177177
$calendarevent = calendar_event::load($event->id);
@@ -194,7 +194,7 @@ function chat_update_instance($chat) {
194194
$event->timesort = $chat->chattime;
195195
$event->timeduration = 0;
196196

197-
calendar_event::create($event);
197+
calendar_event::create($event, false);
198198
}
199199
}
200200

@@ -498,7 +498,7 @@ function chat_prepare_update_events($chat, $cm = null) {
498498
if ($event->id = $DB->get_field('event', 'id', array('modulename' => 'chat', 'instance' => $chat->id,
499499
'eventtype' => CHAT_EVENT_TYPE_CHATTIME))) {
500500
$calendarevent = calendar_event::load($event->id);
501-
$calendarevent->update($event);
501+
$calendarevent->update($event, false);
502502
} else if ($chat->schedule > 0) {
503503
// The chat is scheduled and the event should be published.
504504
$event->courseid = $chat->course;
@@ -509,7 +509,7 @@ function chat_prepare_update_events($chat, $cm = null) {
509509
$event->eventtype = CHAT_EVENT_TYPE_CHATTIME;
510510
$event->timeduration = 0;
511511
$event->visible = $cm->visible;
512-
calendar_event::create($event);
512+
calendar_event::create($event, false);
513513
}
514514
}
515515

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
@mod @mod_chat
2+
Feature: Chat with no calendar capabilites
3+
In order to allow work effectively
4+
As a teacher
5+
I need to be able to create chats even when I cannot edit calendar events
6+
7+
Background:
8+
Given the following "courses" exist:
9+
| fullname | shortname | category | groupmode |
10+
| Course 1 | C1 | 0 | 1 |
11+
And the following "users" exist:
12+
| username | firstname | lastname | email |
13+
| teacher1 | Teacher | 1 | teacher1@example.com |
14+
And the following "course enrolments" exist:
15+
| user | course | role |
16+
| teacher1 | C1 | editingteacher |
17+
And I log in as "admin"
18+
And I am on "Course 1" course homepage
19+
And I navigate to "Users > Permissions" in current page administration
20+
And I override the system permissions of "Teacher" role with:
21+
| capability | permission |
22+
| moodle/calendar:manageentries | Prohibit |
23+
And I log out
24+
25+
Scenario: Editing a chat
26+
Given I log in as "admin"
27+
And I am on "Course 1" course homepage with editing mode on
28+
When I add a "Chat" to section "1" and I fill the form with:
29+
| Name of this chat room | Test chat name |
30+
| Description | Test chat description |
31+
| Repeat/publish session times | No repeats - publish the specified time only |
32+
| id_chattime_day | 1 |
33+
| id_chattime_month | 1 |
34+
| id_chattime_year | 2017 |
35+
And I log out
36+
When I log in as "teacher1"
37+
And I am on "Course 1" course homepage with editing mode on
38+
And I follow "Test chat name"
39+
And I navigate to "Edit settings" in current page administration
40+
And I set the following fields to these values:
41+
| id_chattime_year | 2018 |
42+
And I press "Save and return to course"
43+
Then I should see "Test chat name"

mod/chat/tests/lib_test.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,25 @@ private function create_action_event($courseid, $instanceid, $eventtype) {
163163

164164
return calendar_event::create($event);
165165
}
166+
167+
/**
168+
* A user who does not have capabilities to add events to the calendar should be able to create an chat.
169+
*/
170+
public function test_creation_with_no_calendar_capabilities() {
171+
$this->resetAfterTest();
172+
$course = self::getDataGenerator()->create_course();
173+
$context = context_course::instance($course->id);
174+
$user = self::getDataGenerator()->create_and_enrol($course, 'editingteacher');
175+
$roleid = self::getDataGenerator()->create_role();
176+
self::getDataGenerator()->role_assign($roleid, $user->id, $context->id);
177+
assign_capability('moodle/calendar:manageentries', CAP_PROHIBIT, $roleid, $context, true);
178+
$generator = self::getDataGenerator()->get_plugin_generator('mod_chat');
179+
// Create an instance as a user without the calendar capabilities.
180+
$this->setUser($user);
181+
$params = array(
182+
'course' => $course->id,
183+
'chattime' => time() + 500,
184+
);
185+
$generator->create_instance($params);
186+
}
166187
}

0 commit comments

Comments
 (0)