mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
Merge branch 'MDL-62944' of https://github.com/NeillM/moodle
This commit is contained in:
commit
ffc4cc9a25
@ -255,6 +255,9 @@ class event_exporter_base extends exporter {
|
|||||||
$values['iscourseevent'] = false;
|
$values['iscourseevent'] = false;
|
||||||
$values['iscategoryevent'] = false;
|
$values['iscategoryevent'] = false;
|
||||||
if ($moduleproxy = $event->get_course_module()) {
|
if ($moduleproxy = $event->get_course_module()) {
|
||||||
|
// We need a separate property to flag if an event is action event.
|
||||||
|
// That's required because canedit return true but action action events cannot be edited on the calendar UI.
|
||||||
|
// But they are considered editable because you can drag and drop the event on the month view.
|
||||||
$values['isactionevent'] = true;
|
$values['isactionevent'] = true;
|
||||||
} else if ($event->get_type() == 'course') {
|
} else if ($event->get_type() == 'course') {
|
||||||
$values['iscourseevent'] = true;
|
$values['iscourseevent'] = true;
|
||||||
|
@ -426,11 +426,20 @@ class calendar_event {
|
|||||||
* Pass in a object containing the event properties and this function will
|
* Pass in a object containing the event properties and this function will
|
||||||
* insert it into the database and deal with any associated files
|
* insert it into the database and deal with any associated files
|
||||||
*
|
*
|
||||||
|
* Capability checking should be performed if the user is directly manipulating the event
|
||||||
|
* and no other capability has been tested. However if the event is not being manipulated
|
||||||
|
* directly by the user and another capability has been checked for them to do this then
|
||||||
|
* capabilites should not be checked.
|
||||||
|
*
|
||||||
|
* For example if a user is editing an event in the calendar the check should be true,
|
||||||
|
* but if you are updating an event in an activities settings are changed then the calendar
|
||||||
|
* capabilites should not be checked.
|
||||||
|
*
|
||||||
* @see self::create()
|
* @see self::create()
|
||||||
* @see self::update()
|
* @see self::update()
|
||||||
*
|
*
|
||||||
* @param \stdClass $data object of event
|
* @param \stdClass $data object of event
|
||||||
* @param bool $checkcapability if moodle should check calendar managing capability or not
|
* @param bool $checkcapability If Moodle should check the user can manage the calendar events for this call or not.
|
||||||
* @return bool event updated
|
* @return bool event updated
|
||||||
*/
|
*/
|
||||||
public function update($data, $checkcapability=true) {
|
public function update($data, $checkcapability=true) {
|
||||||
@ -914,10 +923,19 @@ class calendar_event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new event and returns an event object
|
* Creates a new event and returns an event object.
|
||||||
|
*
|
||||||
|
* Capability checking should be performed if the user is directly creating the event
|
||||||
|
* and no other capability has been tested. However if the event is not being created
|
||||||
|
* directly by the user and another capability has been checked for them to do this then
|
||||||
|
* capabilites should not be checked.
|
||||||
|
*
|
||||||
|
* For example if a user is creating an event in the calendar the check should be true,
|
||||||
|
* but if you are creating an event in an activity when it is created then the calendar
|
||||||
|
* capabilites should not be checked.
|
||||||
*
|
*
|
||||||
* @param \stdClass|array $properties An object containing event properties
|
* @param \stdClass|array $properties An object containing event properties
|
||||||
* @param bool $checkcapability Check caps or not
|
* @param bool $checkcapability If Moodle should check the user can manage the calendar events for this call or not.
|
||||||
* @throws \coding_exception
|
* @throws \coding_exception
|
||||||
*
|
*
|
||||||
* @return calendar_event|bool The event object or false if it failed
|
* @return calendar_event|bool The event object or false if it failed
|
||||||
|
@ -49,9 +49,11 @@
|
|||||||
{{#pix}}t/delete, core, {{#str}}delete{{/str}}{{/pix}}
|
{{#pix}}t/delete, core, {{#str}}delete{{/str}}{{/pix}}
|
||||||
</a>
|
</a>
|
||||||
{{/candelete}}
|
{{/candelete}}
|
||||||
|
{{^isactionevent}}
|
||||||
<a href="{{editurl}}" data-action="edit">
|
<a href="{{editurl}}" data-action="edit">
|
||||||
{{#pix}}t/edit, core, {{#str}}edit{{/str}}{{/pix}}
|
{{#pix}}t/edit, core, {{#str}}edit{{/str}}{{/pix}}
|
||||||
</a>
|
</a>
|
||||||
|
{{/isactionevent}}
|
||||||
{{/canedit}}
|
{{/canedit}}
|
||||||
</div>
|
</div>
|
||||||
{{#icon}}<div class="d-inline-block mt-1 align-top">{{#pix}} {{key}}, {{component}}, {{alttext}} {{/pix}}</div>{{/icon}}
|
{{#icon}}<div class="d-inline-block mt-1 align-top">{{#pix}} {{key}}, {{component}}, {{alttext}} {{/pix}}</div>{{/icon}}
|
||||||
|
@ -94,7 +94,7 @@ class api {
|
|||||||
$event->timeduration = 0;
|
$event->timeduration = 0;
|
||||||
|
|
||||||
$calendarevent = \calendar_event::load($event->id);
|
$calendarevent = \calendar_event::load($event->id);
|
||||||
$calendarevent->update($event);
|
$calendarevent->update($event, false);
|
||||||
} else {
|
} else {
|
||||||
// Calendar event is no longer needed.
|
// Calendar event is no longer needed.
|
||||||
$calendarevent = \calendar_event::load($event->id);
|
$calendarevent = \calendar_event::load($event->id);
|
||||||
@ -115,7 +115,7 @@ class api {
|
|||||||
$event->visible = instance_is_visible($modulename, $instance);
|
$event->visible = instance_is_visible($modulename, $instance);
|
||||||
$event->timeduration = 0;
|
$event->timeduration = 0;
|
||||||
|
|
||||||
\calendar_event::create($event);
|
\calendar_event::create($event, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,44 @@
|
|||||||
|
@core @core_completion
|
||||||
|
Feature: Completion with no calendar capabilites
|
||||||
|
In order to allow work effectively
|
||||||
|
As a teacher
|
||||||
|
I need to be able to create activities with completion enabled without calendar capabilities
|
||||||
|
|
||||||
|
Background:
|
||||||
|
Given the following "courses" exist:
|
||||||
|
| fullname | shortname | category | groupmode | enablecompletion |
|
||||||
|
| Course 1 | C1 | 0 | 1 | 1 |
|
||||||
|
And the following "users" exist:
|
||||||
|
| username | firstname | lastname | email |
|
||||||
|
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||||
|
And the following "course enrolments" exist:
|
||||||
|
| user | course | role |
|
||||||
|
| teacher1 | C1 | editingteacher |
|
||||||
|
And I log in as "admin"
|
||||||
|
And I am on "Course 1" course homepage
|
||||||
|
And I navigate to "Users > Permissions" in current page administration
|
||||||
|
And I override the system permissions of "Teacher" role with:
|
||||||
|
| capability | permission |
|
||||||
|
| moodle/calendar:manageentries | Prohibit |
|
||||||
|
And I log out
|
||||||
|
|
||||||
|
Scenario: Editing completion date
|
||||||
|
Given I log in as "admin"
|
||||||
|
And I am on "Course 1" course homepage with editing mode on
|
||||||
|
When I add a "Forum" to section "1" and I fill the form with:
|
||||||
|
| Forum name | Test forum name |
|
||||||
|
| Description | Test forum description |
|
||||||
|
| Completion tracking | Show activity as complete when conditions are met |
|
||||||
|
| id_completionexpected_enabled | 1 |
|
||||||
|
| id_completionexpected_day | 1 |
|
||||||
|
| id_completionexpected_month | 1 |
|
||||||
|
| id_completionexpected_year | 2017 |
|
||||||
|
And I log out
|
||||||
|
When I log in as "teacher1"
|
||||||
|
And I am on "Course 1" course homepage with editing mode on
|
||||||
|
And I follow "Test forum name"
|
||||||
|
And I navigate to "Edit settings" in current page administration
|
||||||
|
And I set the following fields to these values:
|
||||||
|
| id_completionexpected_year | 2018 |
|
||||||
|
And I press "Save and return to course"
|
||||||
|
Then I should see "Test forum name"
|
57
completion/tests/capabilities_test.php
Normal file
57
completion/tests/capabilities_test.php
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that completion works without requiring unnecessary capabilities.
|
||||||
|
*
|
||||||
|
* @package core_completion
|
||||||
|
* @copyright 2018 University of Nottingham
|
||||||
|
* @author Neill Magill <neill.magill@nottingham.ac.uk>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that completion works without requiring unnecessary capabilities.
|
||||||
|
*
|
||||||
|
* @package core_completion
|
||||||
|
* @copyright 2018 University of Nottingham
|
||||||
|
* @author Neill Magill <neill.magill@nottingham.ac.uk>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class core_completion_capabilities_testcase extends advanced_testcase {
|
||||||
|
/**
|
||||||
|
* A user who does not have capabilities to add events to the calendar should be able to create activities.
|
||||||
|
*/
|
||||||
|
public function test_creation_with_no_calendar_capabilities() {
|
||||||
|
$this->resetAfterTest();
|
||||||
|
$course = self::getDataGenerator()->create_course(['enablecompletion' => 1]);
|
||||||
|
$context = context_course::instance($course->id);
|
||||||
|
$user = self::getDataGenerator()->create_and_enrol($course, 'editingteacher');
|
||||||
|
$roleid = self::getDataGenerator()->create_role();
|
||||||
|
self::getDataGenerator()->role_assign($roleid, $user->id, $context->id);
|
||||||
|
assign_capability('moodle/calendar:manageentries', CAP_PROHIBIT, $roleid, $context, true);
|
||||||
|
$generator = self::getDataGenerator()->get_plugin_generator('mod_forum');
|
||||||
|
// Create an instance as a user without the calendar capabilities.
|
||||||
|
$this->setUser($user);
|
||||||
|
$params = array(
|
||||||
|
'course' => $course->id,
|
||||||
|
'completionexpected' => time() + 2000,
|
||||||
|
);
|
||||||
|
$generator->create_instance($params);
|
||||||
|
}
|
||||||
|
}
|
@ -345,7 +345,7 @@ function assign_update_events($assign, $override = null) {
|
|||||||
unset($event->id);
|
unset($event->id);
|
||||||
}
|
}
|
||||||
$event->name = $eventname.' ('.get_string('duedate', 'assign').')';
|
$event->name = $eventname.' ('.get_string('duedate', 'assign').')';
|
||||||
calendar_event::create($event);
|
calendar_event::create($event, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1331,9 +1331,9 @@ class assign {
|
|||||||
// Now process the event.
|
// Now process the event.
|
||||||
if ($event->id) {
|
if ($event->id) {
|
||||||
$calendarevent = calendar_event::load($event->id);
|
$calendarevent = calendar_event::load($event->id);
|
||||||
$calendarevent->update($event);
|
$calendarevent->update($event, false);
|
||||||
} else {
|
} else {
|
||||||
calendar_event::create($event);
|
calendar_event::create($event, false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$DB->delete_records('event', array('modulename' => 'assign', 'instance' => $instance->id,
|
$DB->delete_records('event', array('modulename' => 'assign', 'instance' => $instance->id,
|
||||||
@ -1352,9 +1352,9 @@ class assign {
|
|||||||
// Now process the event.
|
// Now process the event.
|
||||||
if ($event->id) {
|
if ($event->id) {
|
||||||
$calendarevent = calendar_event::load($event->id);
|
$calendarevent = calendar_event::load($event->id);
|
||||||
$calendarevent->update($event);
|
$calendarevent->update($event, false);
|
||||||
} else {
|
} else {
|
||||||
calendar_event::create($event);
|
calendar_event::create($event, false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$DB->delete_records('event', array('modulename' => 'assign', 'instance' => $instance->id,
|
$DB->delete_records('event', array('modulename' => 'assign', 'instance' => $instance->id,
|
||||||
|
@ -0,0 +1,58 @@
|
|||||||
|
@mod @mod_assign
|
||||||
|
Feature: Assignment with no calendar capabilites
|
||||||
|
In order to allow work effectively
|
||||||
|
As a teacher
|
||||||
|
I need to be able to create assignments even when I cannot edit calendar events
|
||||||
|
|
||||||
|
Background:
|
||||||
|
Given the following "courses" exist:
|
||||||
|
| fullname | shortname | category | groupmode |
|
||||||
|
| Course 1 | C1 | 0 | 1 |
|
||||||
|
And the following "users" exist:
|
||||||
|
| username | firstname | lastname | email |
|
||||||
|
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||||
|
And the following "course enrolments" exist:
|
||||||
|
| user | course | role |
|
||||||
|
| teacher1 | C1 | editingteacher |
|
||||||
|
And I log in as "admin"
|
||||||
|
And I am on "Course 1" course homepage
|
||||||
|
And I navigate to "Users > Permissions" in current page administration
|
||||||
|
And I override the system permissions of "Teacher" role with:
|
||||||
|
| capability | permission |
|
||||||
|
| moodle/calendar:manageentries | Prohibit |
|
||||||
|
And I log out
|
||||||
|
|
||||||
|
Scenario: Editing an assignment
|
||||||
|
Given I log in as "admin"
|
||||||
|
And I am on "Course 1" course homepage with editing mode on
|
||||||
|
When I add a "Assignment" to section "1" and I fill the form with:
|
||||||
|
| Assignment name | Test assignment name |
|
||||||
|
| Description | Test assignment description |
|
||||||
|
| id_allowsubmissionsfromdate_enabled | 1 |
|
||||||
|
| id_allowsubmissionsfromdate_day | 1 |
|
||||||
|
| id_allowsubmissionsfromdate_month | 1 |
|
||||||
|
| id_allowsubmissionsfromdate_year | 2017 |
|
||||||
|
| id_duedate_enabled | 1 |
|
||||||
|
| id_duedate_day | 1 |
|
||||||
|
| id_duedate_month | 2 |
|
||||||
|
| id_duedate_year | 2017 |
|
||||||
|
| id_cutoffdate_enabled | 1 |
|
||||||
|
| id_cutoffdate_day | 2 |
|
||||||
|
| id_cutoffdate_month | 2 |
|
||||||
|
| id_cutoffdate_year | 2017 |
|
||||||
|
| id_gradingduedate_enabled | 1 |
|
||||||
|
| id_gradingduedate_day | 1 |
|
||||||
|
| id_gradingduedate_month | 3 |
|
||||||
|
| id_gradingduedate_year | 2017 |
|
||||||
|
And I log out
|
||||||
|
When I log in as "teacher1"
|
||||||
|
And I am on "Course 1" course homepage with editing mode on
|
||||||
|
And I follow "Test assignment name"
|
||||||
|
And I navigate to "Edit settings" in current page administration
|
||||||
|
And I set the following fields to these values:
|
||||||
|
| id_allowsubmissionsfromdate_year | 2018 |
|
||||||
|
| id_duedate_year | 2018 |
|
||||||
|
| id_cutoffdate_year | 2018 |
|
||||||
|
| id_gradingduedate_year | 2018 |
|
||||||
|
And I press "Save and return to course"
|
||||||
|
Then I should see "Test assignment name"
|
@ -1472,4 +1472,29 @@ class mod_assign_lib_testcase extends advanced_testcase {
|
|||||||
// is changed.
|
// is changed.
|
||||||
$this->assertNotEmpty($moduleupdatedevents);
|
$this->assertNotEmpty($moduleupdatedevents);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A user who does not have capabilities to add events to the calendar should be able to create an assignment.
|
||||||
|
*/
|
||||||
|
public function test_creation_with_no_calendar_capabilities() {
|
||||||
|
$this->resetAfterTest();
|
||||||
|
$course = self::getDataGenerator()->create_course();
|
||||||
|
$context = context_course::instance($course->id);
|
||||||
|
$user = self::getDataGenerator()->create_and_enrol($course, 'editingteacher');
|
||||||
|
$roleid = self::getDataGenerator()->create_role();
|
||||||
|
self::getDataGenerator()->role_assign($roleid, $user->id, $context->id);
|
||||||
|
assign_capability('moodle/calendar:manageentries', CAP_PROHIBIT, $roleid, $context, true);
|
||||||
|
$generator = self::getDataGenerator()->get_plugin_generator('mod_assign');
|
||||||
|
// Create an instance as a user without the calendar capabilities.
|
||||||
|
$this->setUser($user);
|
||||||
|
$time = time();
|
||||||
|
$params = array(
|
||||||
|
'course' => $course->id,
|
||||||
|
'allowsubmissionsfromdate' => $time,
|
||||||
|
'duedate' => $time + 500,
|
||||||
|
'cutoffdate' => $time + 600,
|
||||||
|
'gradingduedate' => $time + 700,
|
||||||
|
);
|
||||||
|
$generator->create_instance($params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,7 @@ function chat_add_instance($chat) {
|
|||||||
$event->timesort = $chat->chattime;
|
$event->timesort = $chat->chattime;
|
||||||
$event->timeduration = 0;
|
$event->timeduration = 0;
|
||||||
|
|
||||||
calendar_event::create($event);
|
calendar_event::create($event, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($chat->completionexpected)) {
|
if (!empty($chat->completionexpected)) {
|
||||||
@ -174,7 +174,7 @@ function chat_update_instance($chat) {
|
|||||||
$event->timesort = $chat->chattime;
|
$event->timesort = $chat->chattime;
|
||||||
|
|
||||||
$calendarevent = calendar_event::load($event->id);
|
$calendarevent = calendar_event::load($event->id);
|
||||||
$calendarevent->update($event);
|
$calendarevent->update($event, false);
|
||||||
} else {
|
} else {
|
||||||
// Do not publish this event, so delete it.
|
// Do not publish this event, so delete it.
|
||||||
$calendarevent = calendar_event::load($event->id);
|
$calendarevent = calendar_event::load($event->id);
|
||||||
@ -197,7 +197,7 @@ function chat_update_instance($chat) {
|
|||||||
$event->timesort = $chat->chattime;
|
$event->timesort = $chat->chattime;
|
||||||
$event->timeduration = 0;
|
$event->timeduration = 0;
|
||||||
|
|
||||||
calendar_event::create($event);
|
calendar_event::create($event, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -501,7 +501,7 @@ function chat_prepare_update_events($chat, $cm = null) {
|
|||||||
if ($event->id = $DB->get_field('event', 'id', array('modulename' => 'chat', 'instance' => $chat->id,
|
if ($event->id = $DB->get_field('event', 'id', array('modulename' => 'chat', 'instance' => $chat->id,
|
||||||
'eventtype' => CHAT_EVENT_TYPE_CHATTIME))) {
|
'eventtype' => CHAT_EVENT_TYPE_CHATTIME))) {
|
||||||
$calendarevent = calendar_event::load($event->id);
|
$calendarevent = calendar_event::load($event->id);
|
||||||
$calendarevent->update($event);
|
$calendarevent->update($event, false);
|
||||||
} else if ($chat->schedule > 0) {
|
} else if ($chat->schedule > 0) {
|
||||||
// The chat is scheduled and the event should be published.
|
// The chat is scheduled and the event should be published.
|
||||||
$event->courseid = $chat->course;
|
$event->courseid = $chat->course;
|
||||||
@ -512,7 +512,7 @@ function chat_prepare_update_events($chat, $cm = null) {
|
|||||||
$event->eventtype = CHAT_EVENT_TYPE_CHATTIME;
|
$event->eventtype = CHAT_EVENT_TYPE_CHATTIME;
|
||||||
$event->timeduration = 0;
|
$event->timeduration = 0;
|
||||||
$event->visible = $cm->visible;
|
$event->visible = $cm->visible;
|
||||||
calendar_event::create($event);
|
calendar_event::create($event, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
43
mod/chat/tests/behat/chat_no_calendar_capabilities.feature
Normal file
43
mod/chat/tests/behat/chat_no_calendar_capabilities.feature
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
@mod @mod_chat
|
||||||
|
Feature: Chat with no calendar capabilites
|
||||||
|
In order to allow work effectively
|
||||||
|
As a teacher
|
||||||
|
I need to be able to create chats even when I cannot edit calendar events
|
||||||
|
|
||||||
|
Background:
|
||||||
|
Given the following "courses" exist:
|
||||||
|
| fullname | shortname | category | groupmode |
|
||||||
|
| Course 1 | C1 | 0 | 1 |
|
||||||
|
And the following "users" exist:
|
||||||
|
| username | firstname | lastname | email |
|
||||||
|
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||||
|
And the following "course enrolments" exist:
|
||||||
|
| user | course | role |
|
||||||
|
| teacher1 | C1 | editingteacher |
|
||||||
|
And I log in as "admin"
|
||||||
|
And I am on "Course 1" course homepage
|
||||||
|
And I navigate to "Users > Permissions" in current page administration
|
||||||
|
And I override the system permissions of "Teacher" role with:
|
||||||
|
| capability | permission |
|
||||||
|
| moodle/calendar:manageentries | Prohibit |
|
||||||
|
And I log out
|
||||||
|
|
||||||
|
Scenario: Editing a chat
|
||||||
|
Given I log in as "admin"
|
||||||
|
And I am on "Course 1" course homepage with editing mode on
|
||||||
|
When I add a "Chat" to section "1" and I fill the form with:
|
||||||
|
| Name of this chat room | Test chat name |
|
||||||
|
| Description | Test chat description |
|
||||||
|
| Repeat/publish session times | No repeats - publish the specified time only |
|
||||||
|
| id_chattime_day | 1 |
|
||||||
|
| id_chattime_month | 1 |
|
||||||
|
| id_chattime_year | 2017 |
|
||||||
|
And I log out
|
||||||
|
When I log in as "teacher1"
|
||||||
|
And I am on "Course 1" course homepage with editing mode on
|
||||||
|
And I follow "Test chat name"
|
||||||
|
And I navigate to "Edit settings" in current page administration
|
||||||
|
And I set the following fields to these values:
|
||||||
|
| id_chattime_year | 2018 |
|
||||||
|
And I press "Save and return to course"
|
||||||
|
Then I should see "Test chat name"
|
@ -363,4 +363,25 @@ class mod_chat_lib_testcase extends advanced_testcase {
|
|||||||
|
|
||||||
return calendar_event::create($event);
|
return calendar_event::create($event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A user who does not have capabilities to add events to the calendar should be able to create an chat.
|
||||||
|
*/
|
||||||
|
public function test_creation_with_no_calendar_capabilities() {
|
||||||
|
$this->resetAfterTest();
|
||||||
|
$course = self::getDataGenerator()->create_course();
|
||||||
|
$context = context_course::instance($course->id);
|
||||||
|
$user = self::getDataGenerator()->create_and_enrol($course, 'editingteacher');
|
||||||
|
$roleid = self::getDataGenerator()->create_role();
|
||||||
|
self::getDataGenerator()->role_assign($roleid, $user->id, $context->id);
|
||||||
|
assign_capability('moodle/calendar:manageentries', CAP_PROHIBIT, $roleid, $context, true);
|
||||||
|
$generator = self::getDataGenerator()->get_plugin_generator('mod_chat');
|
||||||
|
// Create an instance as a user without the calendar capabilities.
|
||||||
|
$this->setUser($user);
|
||||||
|
$params = array(
|
||||||
|
'course' => $course->id,
|
||||||
|
'chattime' => time() + 500,
|
||||||
|
);
|
||||||
|
$generator->create_instance($params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ function choice_set_events($choice) {
|
|||||||
$event->visible = instance_is_visible('choice', $choice);
|
$event->visible = instance_is_visible('choice', $choice);
|
||||||
$event->timeduration = 0;
|
$event->timeduration = 0;
|
||||||
$calendarevent = calendar_event::load($event->id);
|
$calendarevent = calendar_event::load($event->id);
|
||||||
$calendarevent->update($event);
|
$calendarevent->update($event, false);
|
||||||
} else {
|
} else {
|
||||||
// Calendar event is on longer needed.
|
// Calendar event is on longer needed.
|
||||||
$calendarevent = calendar_event::load($event->id);
|
$calendarevent = calendar_event::load($event->id);
|
||||||
@ -78,7 +78,7 @@ function choice_set_events($choice) {
|
|||||||
$event->timesort = $choice->timeopen;
|
$event->timesort = $choice->timeopen;
|
||||||
$event->visible = instance_is_visible('choice', $choice);
|
$event->visible = instance_is_visible('choice', $choice);
|
||||||
$event->timeduration = 0;
|
$event->timeduration = 0;
|
||||||
calendar_event::create($event);
|
calendar_event::create($event, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ function choice_set_events($choice) {
|
|||||||
$event->visible = instance_is_visible('choice', $choice);
|
$event->visible = instance_is_visible('choice', $choice);
|
||||||
$event->timeduration = 0;
|
$event->timeduration = 0;
|
||||||
$calendarevent = calendar_event::load($event->id);
|
$calendarevent = calendar_event::load($event->id);
|
||||||
$calendarevent->update($event);
|
$calendarevent->update($event, false);
|
||||||
} else {
|
} else {
|
||||||
// Calendar event is on longer needed.
|
// Calendar event is on longer needed.
|
||||||
$calendarevent = calendar_event::load($event->id);
|
$calendarevent = calendar_event::load($event->id);
|
||||||
@ -117,7 +117,7 @@ function choice_set_events($choice) {
|
|||||||
$event->timesort = $choice->timeclose;
|
$event->timesort = $choice->timeclose;
|
||||||
$event->visible = instance_is_visible('choice', $choice);
|
$event->visible = instance_is_visible('choice', $choice);
|
||||||
$event->timeduration = 0;
|
$event->timeduration = 0;
|
||||||
calendar_event::create($event);
|
calendar_event::create($event, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,50 @@
|
|||||||
|
@mod @mod_choice
|
||||||
|
Feature: Choice with no calendar capabilites
|
||||||
|
In order to allow work effectively
|
||||||
|
As a teacher
|
||||||
|
I need to be able to create choices even when I cannot edit calendar events
|
||||||
|
|
||||||
|
Background:
|
||||||
|
Given the following "courses" exist:
|
||||||
|
| fullname | shortname | category | groupmode |
|
||||||
|
| Course 1 | C1 | 0 | 1 |
|
||||||
|
And the following "users" exist:
|
||||||
|
| username | firstname | lastname | email |
|
||||||
|
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||||
|
And the following "course enrolments" exist:
|
||||||
|
| user | course | role |
|
||||||
|
| teacher1 | C1 | editingteacher |
|
||||||
|
And I log in as "admin"
|
||||||
|
And I am on "Course 1" course homepage
|
||||||
|
And I navigate to "Users > Permissions" in current page administration
|
||||||
|
And I override the system permissions of "Teacher" role with:
|
||||||
|
| capability | permission |
|
||||||
|
| moodle/calendar:manageentries | Prohibit |
|
||||||
|
And I log out
|
||||||
|
|
||||||
|
Scenario: Editing a choice
|
||||||
|
Given I log in as "admin"
|
||||||
|
And I am on "Course 1" course homepage with editing mode on
|
||||||
|
When I add a "Choice" to section "1" and I fill the form with:
|
||||||
|
| Choice name | Test choice name |
|
||||||
|
| Description | Test choice description |
|
||||||
|
| option[0] | Option 1 |
|
||||||
|
| option[1] | Option 2 |
|
||||||
|
| id_timeopen_enabled | 1 |
|
||||||
|
| id_timeopen_day | 1 |
|
||||||
|
| id_timeopen_month | 1 |
|
||||||
|
| id_timeopen_year | 2017 |
|
||||||
|
| id_timeclose_enabled | 1 |
|
||||||
|
| id_timeclose_day | 1 |
|
||||||
|
| id_timeclose_month | 2 |
|
||||||
|
| id_timeclose_year | 2017 |
|
||||||
|
And I log out
|
||||||
|
When I log in as "teacher1"
|
||||||
|
And I am on "Course 1" course homepage with editing mode on
|
||||||
|
And I follow "Test choice name"
|
||||||
|
And I navigate to "Edit settings" in current page administration
|
||||||
|
And I set the following fields to these values:
|
||||||
|
| id_timeopen_year | 2018 |
|
||||||
|
| id_timeclose_year | 2018 |
|
||||||
|
And I press "Save and return to course"
|
||||||
|
Then I should see "Test choice name"
|
@ -979,4 +979,27 @@ class mod_choice_lib_testcase extends externallib_advanced_testcase {
|
|||||||
$this->expectException('moodle_exception');
|
$this->expectException('moodle_exception');
|
||||||
choice_user_submit_response($optionids[1], $choicewithoptions, $user2->id, $course, $cm);
|
choice_user_submit_response($optionids[1], $choicewithoptions, $user2->id, $course, $cm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A user who does not have capabilities to add events to the calendar should be able to create an choice.
|
||||||
|
*/
|
||||||
|
public function test_creation_with_no_calendar_capabilities() {
|
||||||
|
$this->resetAfterTest();
|
||||||
|
$course = self::getDataGenerator()->create_course();
|
||||||
|
$context = context_course::instance($course->id);
|
||||||
|
$user = self::getDataGenerator()->create_and_enrol($course, 'editingteacher');
|
||||||
|
$roleid = self::getDataGenerator()->create_role();
|
||||||
|
self::getDataGenerator()->role_assign($roleid, $user->id, $context->id);
|
||||||
|
assign_capability('moodle/calendar:manageentries', CAP_PROHIBIT, $roleid, $context, true);
|
||||||
|
$generator = self::getDataGenerator()->get_plugin_generator('mod_choice');
|
||||||
|
// Create an instance as a user without the calendar capabilities.
|
||||||
|
$this->setUser($user);
|
||||||
|
$time = time();
|
||||||
|
$params = array(
|
||||||
|
'course' => $course->id,
|
||||||
|
'timeopen' => $time + 200,
|
||||||
|
'timeclose' => $time + 500,
|
||||||
|
);
|
||||||
|
$generator->create_instance($params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -156,6 +156,7 @@ if ($rid) {
|
|||||||
|
|
||||||
$PAGE->set_title($data->name);
|
$PAGE->set_title($data->name);
|
||||||
$PAGE->set_heading($course->fullname);
|
$PAGE->set_heading($course->fullname);
|
||||||
|
$PAGE->force_settings_menu(true);
|
||||||
|
|
||||||
// Process incoming data for adding/updating records.
|
// Process incoming data for adding/updating records.
|
||||||
|
|
||||||
|
@ -84,6 +84,7 @@ if($mform->is_cancelled()) {
|
|||||||
// build header to match the rest of the UI
|
// build header to match the rest of the UI
|
||||||
$PAGE->set_title($data->name);
|
$PAGE->set_title($data->name);
|
||||||
$PAGE->set_heading($course->fullname);
|
$PAGE->set_heading($course->fullname);
|
||||||
|
$PAGE->force_settings_menu(true);
|
||||||
echo $OUTPUT->header();
|
echo $OUTPUT->header();
|
||||||
echo $OUTPUT->heading(format_string($data->name), 2);
|
echo $OUTPUT->heading(format_string($data->name), 2);
|
||||||
echo $OUTPUT->box(format_module_intro('data', $data, $cm->id), 'generalbox', 'intro');
|
echo $OUTPUT->box(format_module_intro('data', $data, $cm->id), 'generalbox', 'intro');
|
||||||
|
@ -241,6 +241,7 @@ foreach ($plugins as $plugin=>$fulldir){
|
|||||||
asort($menufield); //sort in alphabetical order
|
asort($menufield); //sort in alphabetical order
|
||||||
$PAGE->set_title(get_string('course') . ': ' . $course->fullname);
|
$PAGE->set_title(get_string('course') . ': ' . $course->fullname);
|
||||||
$PAGE->set_heading($course->fullname);
|
$PAGE->set_heading($course->fullname);
|
||||||
|
$PAGE->force_settings_menu(true);
|
||||||
|
|
||||||
$PAGE->set_pagetype('mod-data-field-' . $newtype);
|
$PAGE->set_pagetype('mod-data-field-' . $newtype);
|
||||||
if (($mode == 'new') && (!empty($newtype)) && confirm_sesskey()) { /// Adding a new field
|
if (($mode == 'new') && (!empty($newtype)) && confirm_sesskey()) { /// Adding a new field
|
||||||
|
@ -613,7 +613,7 @@ function data_set_events($data) {
|
|||||||
$event->visible = instance_is_visible('data', $data);
|
$event->visible = instance_is_visible('data', $data);
|
||||||
$event->timeduration = 0;
|
$event->timeduration = 0;
|
||||||
$calendarevent = calendar_event::load($event->id);
|
$calendarevent = calendar_event::load($event->id);
|
||||||
$calendarevent->update($event);
|
$calendarevent->update($event, false);
|
||||||
} else {
|
} else {
|
||||||
// Calendar event is on longer needed.
|
// Calendar event is on longer needed.
|
||||||
$calendarevent = calendar_event::load($event->id);
|
$calendarevent = calendar_event::load($event->id);
|
||||||
@ -633,7 +633,7 @@ function data_set_events($data) {
|
|||||||
$event->timesort = $data->timeavailablefrom;
|
$event->timesort = $data->timeavailablefrom;
|
||||||
$event->visible = instance_is_visible('data', $data);
|
$event->visible = instance_is_visible('data', $data);
|
||||||
$event->timeduration = 0;
|
$event->timeduration = 0;
|
||||||
calendar_event::create($event);
|
calendar_event::create($event, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -652,7 +652,7 @@ function data_set_events($data) {
|
|||||||
$event->visible = instance_is_visible('data', $data);
|
$event->visible = instance_is_visible('data', $data);
|
||||||
$event->timeduration = 0;
|
$event->timeduration = 0;
|
||||||
$calendarevent = calendar_event::load($event->id);
|
$calendarevent = calendar_event::load($event->id);
|
||||||
$calendarevent->update($event);
|
$calendarevent->update($event, false);
|
||||||
} else {
|
} else {
|
||||||
// Calendar event is on longer needed.
|
// Calendar event is on longer needed.
|
||||||
$calendarevent = calendar_event::load($event->id);
|
$calendarevent = calendar_event::load($event->id);
|
||||||
@ -672,7 +672,7 @@ function data_set_events($data) {
|
|||||||
$event->timesort = $data->timeavailableto;
|
$event->timesort = $data->timeavailableto;
|
||||||
$event->visible = instance_is_visible('data', $data);
|
$event->visible = instance_is_visible('data', $data);
|
||||||
$event->timeduration = 0;
|
$event->timeduration = 0;
|
||||||
calendar_event::create($event);
|
calendar_event::create($event, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,7 @@ require_capability('mod/data:managetemplates', $context);
|
|||||||
$PAGE->set_url(new moodle_url('/mod/data/preset.php', array('d'=>$data->id)));
|
$PAGE->set_url(new moodle_url('/mod/data/preset.php', array('d'=>$data->id)));
|
||||||
$PAGE->set_title(get_string('course') . ': ' . $course->fullname);
|
$PAGE->set_title(get_string('course') . ': ' . $course->fullname);
|
||||||
$PAGE->set_heading($course->fullname);
|
$PAGE->set_heading($course->fullname);
|
||||||
|
$PAGE->force_settings_menu(true);
|
||||||
|
|
||||||
// fill in missing properties needed for updating of instance
|
// fill in missing properties needed for updating of instance
|
||||||
$data->course = $cm->course;
|
$data->course = $cm->course;
|
||||||
|
@ -103,6 +103,7 @@ $PAGE->requires->js('/mod/data/data.js');
|
|||||||
$PAGE->set_title($data->name);
|
$PAGE->set_title($data->name);
|
||||||
$PAGE->set_heading($course->fullname);
|
$PAGE->set_heading($course->fullname);
|
||||||
$PAGE->set_pagelayout('admin');
|
$PAGE->set_pagelayout('admin');
|
||||||
|
$PAGE->force_settings_menu(true);
|
||||||
echo $OUTPUT->header();
|
echo $OUTPUT->header();
|
||||||
echo $OUTPUT->heading(format_string($data->name), 2);
|
echo $OUTPUT->heading(format_string($data->name), 2);
|
||||||
echo $OUTPUT->box(format_module_intro('data', $data, $cm->id), 'generalbox', 'intro');
|
echo $OUTPUT->box(format_module_intro('data', $data, $cm->id), 'generalbox', 'intro');
|
||||||
|
58
mod/data/tests/behat/data_no_calendar_capabilities.feature
Normal file
58
mod/data/tests/behat/data_no_calendar_capabilities.feature
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
@mod @mod_data
|
||||||
|
Feature: Database with no calendar capabilites
|
||||||
|
In order to allow work effectively
|
||||||
|
As a teacher
|
||||||
|
I need to be able to create databases even when I cannot edit calendar events
|
||||||
|
|
||||||
|
Background:
|
||||||
|
Given the following "courses" exist:
|
||||||
|
| fullname | shortname | category | groupmode |
|
||||||
|
| Course 1 | C1 | 0 | 1 |
|
||||||
|
And the following "users" exist:
|
||||||
|
| username | firstname | lastname | email |
|
||||||
|
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||||
|
And the following "course enrolments" exist:
|
||||||
|
| user | course | role |
|
||||||
|
| teacher1 | C1 | editingteacher |
|
||||||
|
And I log in as "admin"
|
||||||
|
And I am on "Course 1" course homepage
|
||||||
|
And I navigate to "Users > Permissions" in current page administration
|
||||||
|
And I override the system permissions of "Teacher" role with:
|
||||||
|
| capability | permission |
|
||||||
|
| moodle/calendar:manageentries | Prohibit |
|
||||||
|
And I log out
|
||||||
|
|
||||||
|
Scenario: Editing a database
|
||||||
|
Given I log in as "admin"
|
||||||
|
And I am on "Course 1" course homepage with editing mode on
|
||||||
|
When I add a "Database" to section "1" and I fill the form with:
|
||||||
|
| Name | Test database name |
|
||||||
|
| Description | Test database description |
|
||||||
|
| id_timeavailablefrom_enabled | 1 |
|
||||||
|
| id_timeavailablefrom_day | 1 |
|
||||||
|
| id_timeavailablefrom_month | 1 |
|
||||||
|
| id_timeavailablefrom_year | 2017 |
|
||||||
|
| id_timeavailableto_enabled | 1 |
|
||||||
|
| id_timeavailableto_day | 1 |
|
||||||
|
| id_timeavailableto_month | 4 |
|
||||||
|
| id_timeavailableto_year | 2017 |
|
||||||
|
| id_timeviewfrom_enabled | 1 |
|
||||||
|
| id_timeviewfrom_day | 1 |
|
||||||
|
| id_timeviewfrom_month | 3 |
|
||||||
|
| id_timeviewfrom_year | 2017 |
|
||||||
|
| id_timeviewto_enabled | 1 |
|
||||||
|
| id_timeviewto_day | 1 |
|
||||||
|
| id_timeviewto_month | 4 |
|
||||||
|
| id_timeviewto_year | 2017 |
|
||||||
|
And I log out
|
||||||
|
When I log in as "teacher1"
|
||||||
|
And I am on "Course 1" course homepage with editing mode on
|
||||||
|
And I follow "Test database name"
|
||||||
|
And I navigate to "Edit settings" in current page administration
|
||||||
|
And I set the following fields to these values:
|
||||||
|
| id_timeavailablefrom_year | 2018 |
|
||||||
|
| id_timeavailableto_year | 2018 |
|
||||||
|
| id_timeviewfrom_year | 2018 |
|
||||||
|
| id_timeviewto_year | 2018 |
|
||||||
|
And I press "Save and return to course"
|
||||||
|
Then I should see "Test database name"
|
@ -1772,4 +1772,29 @@ class mod_data_lib_testcase extends advanced_testcase {
|
|||||||
$this->assertNull($min);
|
$this->assertNull($min);
|
||||||
$this->assertNull($max);
|
$this->assertNull($max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A user who does not have capabilities to add events to the calendar should be able to create an database.
|
||||||
|
*/
|
||||||
|
public function test_creation_with_no_calendar_capabilities() {
|
||||||
|
$this->resetAfterTest();
|
||||||
|
$course = self::getDataGenerator()->create_course();
|
||||||
|
$context = context_course::instance($course->id);
|
||||||
|
$user = self::getDataGenerator()->create_and_enrol($course, 'editingteacher');
|
||||||
|
$roleid = self::getDataGenerator()->create_role();
|
||||||
|
self::getDataGenerator()->role_assign($roleid, $user->id, $context->id);
|
||||||
|
assign_capability('moodle/calendar:manageentries', CAP_PROHIBIT, $roleid, $context, true);
|
||||||
|
$generator = self::getDataGenerator()->get_plugin_generator('mod_data');
|
||||||
|
// Create an instance as a user without the calendar capabilities.
|
||||||
|
$this->setUser($user);
|
||||||
|
$time = time();
|
||||||
|
$params = array(
|
||||||
|
'course' => $course->id,
|
||||||
|
'timeavailablefrom' => $time + 200,
|
||||||
|
'timeavailableto' => $time + 2000,
|
||||||
|
'timeviewfrom' => $time + 400,
|
||||||
|
'timeviewto' => $time + 2000,
|
||||||
|
);
|
||||||
|
$generator->create_instance($params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -826,7 +826,7 @@ function feedback_set_events($feedback) {
|
|||||||
// Calendar event exists so update it.
|
// Calendar event exists so update it.
|
||||||
$event->id = $eventid;
|
$event->id = $eventid;
|
||||||
$calendarevent = calendar_event::load($event->id);
|
$calendarevent = calendar_event::load($event->id);
|
||||||
$calendarevent->update($event);
|
$calendarevent->update($event, false);
|
||||||
} else {
|
} else {
|
||||||
// Event doesn't exist so create one.
|
// Event doesn't exist so create one.
|
||||||
$event->courseid = $feedback->course;
|
$event->courseid = $feedback->course;
|
||||||
@ -835,7 +835,7 @@ function feedback_set_events($feedback) {
|
|||||||
$event->modulename = 'feedback';
|
$event->modulename = 'feedback';
|
||||||
$event->instance = $feedback->id;
|
$event->instance = $feedback->id;
|
||||||
$event->eventtype = FEEDBACK_EVENT_TYPE_OPEN;
|
$event->eventtype = FEEDBACK_EVENT_TYPE_OPEN;
|
||||||
calendar_event::create($event);
|
calendar_event::create($event, false);
|
||||||
}
|
}
|
||||||
} else if ($eventid) {
|
} else if ($eventid) {
|
||||||
// Calendar event is on longer needed.
|
// Calendar event is on longer needed.
|
||||||
@ -861,7 +861,7 @@ function feedback_set_events($feedback) {
|
|||||||
// Calendar event exists so update it.
|
// Calendar event exists so update it.
|
||||||
$event->id = $eventid;
|
$event->id = $eventid;
|
||||||
$calendarevent = calendar_event::load($event->id);
|
$calendarevent = calendar_event::load($event->id);
|
||||||
$calendarevent->update($event);
|
$calendarevent->update($event, false);
|
||||||
} else {
|
} else {
|
||||||
// Event doesn't exist so create one.
|
// Event doesn't exist so create one.
|
||||||
$event->courseid = $feedback->course;
|
$event->courseid = $feedback->course;
|
||||||
@ -869,7 +869,7 @@ function feedback_set_events($feedback) {
|
|||||||
$event->userid = 0;
|
$event->userid = 0;
|
||||||
$event->modulename = 'feedback';
|
$event->modulename = 'feedback';
|
||||||
$event->instance = $feedback->id;
|
$event->instance = $feedback->id;
|
||||||
calendar_event::create($event);
|
calendar_event::create($event, false);
|
||||||
}
|
}
|
||||||
} else if ($eventid) {
|
} else if ($eventid) {
|
||||||
// Calendar event is on longer needed.
|
// Calendar event is on longer needed.
|
||||||
|
@ -0,0 +1,48 @@
|
|||||||
|
@mod @mod_feedback
|
||||||
|
Feature: Feedback with no calendar capabilites
|
||||||
|
In order to allow work effectively
|
||||||
|
As a teacher
|
||||||
|
I need to be able to create feedbacks even when I cannot edit calendar events
|
||||||
|
|
||||||
|
Background:
|
||||||
|
Given the following "courses" exist:
|
||||||
|
| fullname | shortname | category | groupmode |
|
||||||
|
| Course 1 | C1 | 0 | 1 |
|
||||||
|
And the following "users" exist:
|
||||||
|
| username | firstname | lastname | email |
|
||||||
|
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||||
|
And the following "course enrolments" exist:
|
||||||
|
| user | course | role |
|
||||||
|
| teacher1 | C1 | editingteacher |
|
||||||
|
And I log in as "admin"
|
||||||
|
And I am on "Course 1" course homepage
|
||||||
|
And I navigate to "Users > Permissions" in current page administration
|
||||||
|
And I override the system permissions of "Teacher" role with:
|
||||||
|
| capability | permission |
|
||||||
|
| moodle/calendar:manageentries | Prohibit |
|
||||||
|
And I log out
|
||||||
|
|
||||||
|
Scenario: Editing a feedback
|
||||||
|
Given I log in as "admin"
|
||||||
|
And I am on "Course 1" course homepage with editing mode on
|
||||||
|
When I add a "Feedback" to section "1" and I fill the form with:
|
||||||
|
| Name | Test feedback name |
|
||||||
|
| Description | Test feedback description |
|
||||||
|
| id_timeopen_enabled | 1 |
|
||||||
|
| id_timeopen_day | 1 |
|
||||||
|
| id_timeopen_month | 1 |
|
||||||
|
| id_timeopen_year | 2017 |
|
||||||
|
| id_timeclose_enabled | 1 |
|
||||||
|
| id_timeclose_day | 1 |
|
||||||
|
| id_timeclose_month | 2 |
|
||||||
|
| id_timeclose_year | 2017 |
|
||||||
|
And I log out
|
||||||
|
When I log in as "teacher1"
|
||||||
|
And I am on "Course 1" course homepage with editing mode on
|
||||||
|
And I follow "Test feedback name"
|
||||||
|
And I navigate to "Edit settings" in current page administration
|
||||||
|
And I set the following fields to these values:
|
||||||
|
| id_timeopen_year | 2018 |
|
||||||
|
| id_timeclose_year | 2018 |
|
||||||
|
And I press "Save and return to course"
|
||||||
|
Then I should see "Test feedback name"
|
@ -852,4 +852,27 @@ class mod_feedback_lib_testcase extends advanced_testcase {
|
|||||||
// was successfully modified.
|
// was successfully modified.
|
||||||
$this->assertNotEmpty($moduleupdatedevents);
|
$this->assertNotEmpty($moduleupdatedevents);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A user who does not have capabilities to add events to the calendar should be able to create an feedback.
|
||||||
|
*/
|
||||||
|
public function test_creation_with_no_calendar_capabilities() {
|
||||||
|
$this->resetAfterTest();
|
||||||
|
$course = self::getDataGenerator()->create_course();
|
||||||
|
$context = context_course::instance($course->id);
|
||||||
|
$user = self::getDataGenerator()->create_and_enrol($course, 'editingteacher');
|
||||||
|
$roleid = self::getDataGenerator()->create_role();
|
||||||
|
self::getDataGenerator()->role_assign($roleid, $user->id, $context->id);
|
||||||
|
assign_capability('moodle/calendar:manageentries', CAP_PROHIBIT, $roleid, $context, true);
|
||||||
|
$generator = self::getDataGenerator()->get_plugin_generator('mod_feedback');
|
||||||
|
// Create an instance as a user without the calendar capabilities.
|
||||||
|
$this->setUser($user);
|
||||||
|
$time = time();
|
||||||
|
$params = array(
|
||||||
|
'course' => $course->id,
|
||||||
|
'timeopen' => $time + 200,
|
||||||
|
'timeclose' => $time + 2000,
|
||||||
|
);
|
||||||
|
$generator->create_instance($params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -217,7 +217,7 @@ function lesson_update_events($lesson, $override = null) {
|
|||||||
}
|
}
|
||||||
$event->name = get_string('lessoneventopens', 'lesson', $eventname);
|
$event->name = get_string('lessoneventopens', 'lesson', $eventname);
|
||||||
// The method calendar_event::create will reuse a db record if the id field is set.
|
// The method calendar_event::create will reuse a db record if the id field is set.
|
||||||
calendar_event::create($event);
|
calendar_event::create($event, false);
|
||||||
}
|
}
|
||||||
if ($deadline && $addclose) {
|
if ($deadline && $addclose) {
|
||||||
if ($oldevent = array_shift($oldevents)) {
|
if ($oldevent = array_shift($oldevents)) {
|
||||||
@ -236,7 +236,7 @@ function lesson_update_events($lesson, $override = null) {
|
|||||||
$event->priority = $closepriorities[$deadline];
|
$event->priority = $closepriorities[$deadline];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
calendar_event::create($event);
|
calendar_event::create($event, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,48 @@
|
|||||||
|
@mod @mod_lesson
|
||||||
|
Feature: Lesson with no calendar capabilites
|
||||||
|
In order to allow work effectively
|
||||||
|
As a teacher
|
||||||
|
I need to be able to create lessons even when I cannot edit calendar events
|
||||||
|
|
||||||
|
Background:
|
||||||
|
Given the following "courses" exist:
|
||||||
|
| fullname | shortname | category | groupmode |
|
||||||
|
| Course 1 | C1 | 0 | 1 |
|
||||||
|
And the following "users" exist:
|
||||||
|
| username | firstname | lastname | email |
|
||||||
|
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||||
|
And the following "course enrolments" exist:
|
||||||
|
| user | course | role |
|
||||||
|
| teacher1 | C1 | editingteacher |
|
||||||
|
And I log in as "admin"
|
||||||
|
And I am on "Course 1" course homepage
|
||||||
|
And I navigate to "Users > Permissions" in current page administration
|
||||||
|
And I override the system permissions of "Teacher" role with:
|
||||||
|
| capability | permission |
|
||||||
|
| moodle/calendar:manageentries | Prohibit |
|
||||||
|
And I log out
|
||||||
|
|
||||||
|
Scenario: Editing a lesson
|
||||||
|
Given I log in as "admin"
|
||||||
|
And I am on "Course 1" course homepage with editing mode on
|
||||||
|
When I add a "Lesson" to section "1" and I fill the form with:
|
||||||
|
| Name | Test lesson name |
|
||||||
|
| Description | Test lesson description |
|
||||||
|
| id_available_enabled | 1 |
|
||||||
|
| id_available_day | 1 |
|
||||||
|
| id_available_month | 1 |
|
||||||
|
| id_available_year | 2017 |
|
||||||
|
| id_deadline_enabled | 1 |
|
||||||
|
| id_deadline_day | 1 |
|
||||||
|
| id_deadline_month | 2 |
|
||||||
|
| id_deadline_year | 2017 |
|
||||||
|
And I log out
|
||||||
|
When I log in as "teacher1"
|
||||||
|
And I am on "Course 1" course homepage with editing mode on
|
||||||
|
And I follow "Test lesson name"
|
||||||
|
And I navigate to "Edit settings" in current page administration
|
||||||
|
And I set the following fields to these values:
|
||||||
|
| id_available_year | 2018 |
|
||||||
|
| id_deadline_year | 2018 |
|
||||||
|
And I press "Save and return to course"
|
||||||
|
Then I should see "Test lesson name"
|
@ -723,4 +723,27 @@ class mod_lesson_lib_testcase extends advanced_testcase {
|
|||||||
$this->assertNull($min);
|
$this->assertNull($min);
|
||||||
$this->assertNull($max);
|
$this->assertNull($max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A user who does not have capabilities to add events to the calendar should be able to create an lesson.
|
||||||
|
*/
|
||||||
|
public function test_creation_with_no_calendar_capabilities() {
|
||||||
|
$this->resetAfterTest();
|
||||||
|
$course = self::getDataGenerator()->create_course();
|
||||||
|
$context = context_course::instance($course->id);
|
||||||
|
$user = self::getDataGenerator()->create_and_enrol($course, 'editingteacher');
|
||||||
|
$roleid = self::getDataGenerator()->create_role();
|
||||||
|
self::getDataGenerator()->role_assign($roleid, $user->id, $context->id);
|
||||||
|
assign_capability('moodle/calendar:manageentries', CAP_PROHIBIT, $roleid, $context, true);
|
||||||
|
$generator = self::getDataGenerator()->get_plugin_generator('mod_lesson');
|
||||||
|
// Create an instance as a user without the calendar capabilities.
|
||||||
|
$this->setUser($user);
|
||||||
|
$time = time();
|
||||||
|
$params = array(
|
||||||
|
'course' => $course->id,
|
||||||
|
'available' => $time + 200,
|
||||||
|
'deadline' => $time + 2000,
|
||||||
|
);
|
||||||
|
$generator->create_instance($params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1340,7 +1340,7 @@ function quiz_update_events($quiz, $override = null) {
|
|||||||
}
|
}
|
||||||
$event->name = get_string('quizeventopens', 'quiz', $eventname);
|
$event->name = get_string('quizeventopens', 'quiz', $eventname);
|
||||||
// The method calendar_event::create will reuse a db record if the id field is set.
|
// The method calendar_event::create will reuse a db record if the id field is set.
|
||||||
calendar_event::create($event);
|
calendar_event::create($event, false);
|
||||||
}
|
}
|
||||||
if ($timeclose && $addclose) {
|
if ($timeclose && $addclose) {
|
||||||
if ($oldevent = array_shift($oldevents)) {
|
if ($oldevent = array_shift($oldevents)) {
|
||||||
@ -1359,7 +1359,7 @@ function quiz_update_events($quiz, $override = null) {
|
|||||||
$event->priority = $closepriorities[$timeclose];
|
$event->priority = $closepriorities[$timeclose];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
calendar_event::create($event);
|
calendar_event::create($event, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
48
mod/quiz/tests/behat/quiz_no_calendar_capabilities.feature
Normal file
48
mod/quiz/tests/behat/quiz_no_calendar_capabilities.feature
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
@mod @mod_quiz
|
||||||
|
Feature: Quiz with no calendar capabilites
|
||||||
|
In order to allow work effectively
|
||||||
|
As a teacher
|
||||||
|
I need to be able to create quiz even when I cannot edit calendar events
|
||||||
|
|
||||||
|
Background:
|
||||||
|
Given the following "courses" exist:
|
||||||
|
| fullname | shortname | category | groupmode |
|
||||||
|
| Course 1 | C1 | 0 | 1 |
|
||||||
|
And the following "users" exist:
|
||||||
|
| username | firstname | lastname | email |
|
||||||
|
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||||
|
And the following "course enrolments" exist:
|
||||||
|
| user | course | role |
|
||||||
|
| teacher1 | C1 | editingteacher |
|
||||||
|
And I log in as "admin"
|
||||||
|
And I am on "Course 1" course homepage
|
||||||
|
And I navigate to "Users > Permissions" in current page administration
|
||||||
|
And I override the system permissions of "Teacher" role with:
|
||||||
|
| capability | permission |
|
||||||
|
| moodle/calendar:manageentries | Prohibit |
|
||||||
|
And I log out
|
||||||
|
|
||||||
|
Scenario: Editing a quiz
|
||||||
|
Given I log in as "admin"
|
||||||
|
And I am on "Course 1" course homepage with editing mode on
|
||||||
|
When I add a "Quiz" to section "1" and I fill the form with:
|
||||||
|
| Name | Test quiz name |
|
||||||
|
| Description | Test quiz description |
|
||||||
|
| id_timeopen_enabled | 1 |
|
||||||
|
| id_timeopen_day | 1 |
|
||||||
|
| id_timeopen_month | 1 |
|
||||||
|
| id_timeopen_year | 2017 |
|
||||||
|
| id_timeclose_enabled | 1 |
|
||||||
|
| id_timeclose_day | 1 |
|
||||||
|
| id_timeclose_month | 2 |
|
||||||
|
| id_timeclose_year | 2017 |
|
||||||
|
And I log out
|
||||||
|
When I log in as "teacher1"
|
||||||
|
And I am on "Course 1" course homepage with editing mode on
|
||||||
|
And I follow "Test quiz name"
|
||||||
|
And I navigate to "Edit settings" in current page administration
|
||||||
|
And I set the following fields to these values:
|
||||||
|
| id_timeopen_year | 2018 |
|
||||||
|
| id_timeclose_year | 2018 |
|
||||||
|
And I press "Save and return to course"
|
||||||
|
Then I should see "Test quiz name"
|
@ -736,4 +736,27 @@ class mod_quiz_lib_testcase extends advanced_testcase {
|
|||||||
$this->assertEquals(mod_quiz_get_completion_active_rule_descriptions($moddefaults), $activeruledescriptions);
|
$this->assertEquals(mod_quiz_get_completion_active_rule_descriptions($moddefaults), $activeruledescriptions);
|
||||||
$this->assertEquals(mod_quiz_get_completion_active_rule_descriptions(new stdClass()), []);
|
$this->assertEquals(mod_quiz_get_completion_active_rule_descriptions(new stdClass()), []);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A user who does not have capabilities to add events to the calendar should be able to create a quiz.
|
||||||
|
*/
|
||||||
|
public function test_creation_with_no_calendar_capabilities() {
|
||||||
|
$this->resetAfterTest();
|
||||||
|
$course = self::getDataGenerator()->create_course();
|
||||||
|
$context = context_course::instance($course->id);
|
||||||
|
$user = self::getDataGenerator()->create_and_enrol($course, 'editingteacher');
|
||||||
|
$roleid = self::getDataGenerator()->create_role();
|
||||||
|
self::getDataGenerator()->role_assign($roleid, $user->id, $context->id);
|
||||||
|
assign_capability('moodle/calendar:manageentries', CAP_PROHIBIT, $roleid, $context, true);
|
||||||
|
$generator = self::getDataGenerator()->get_plugin_generator('mod_quiz');
|
||||||
|
// Create an instance as a user without the calendar capabilities.
|
||||||
|
$this->setUser($user);
|
||||||
|
$time = time();
|
||||||
|
$params = array(
|
||||||
|
'course' => $course->id,
|
||||||
|
'timeopen' => $time + 200,
|
||||||
|
'timeclose' => $time + 2000,
|
||||||
|
);
|
||||||
|
$generator->create_instance($params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2397,7 +2397,7 @@ function scorm_update_calendar(stdClass $scorm, $cmid) {
|
|||||||
$event->timeduration = 0;
|
$event->timeduration = 0;
|
||||||
|
|
||||||
$calendarevent = calendar_event::load($event->id);
|
$calendarevent = calendar_event::load($event->id);
|
||||||
$calendarevent->update($event);
|
$calendarevent->update($event, false);
|
||||||
} else {
|
} else {
|
||||||
// Calendar event is on longer needed.
|
// Calendar event is on longer needed.
|
||||||
$calendarevent = calendar_event::load($event->id);
|
$calendarevent = calendar_event::load($event->id);
|
||||||
@ -2418,7 +2418,7 @@ function scorm_update_calendar(stdClass $scorm, $cmid) {
|
|||||||
$event->visible = instance_is_visible('scorm', $scorm);
|
$event->visible = instance_is_visible('scorm', $scorm);
|
||||||
$event->timeduration = 0;
|
$event->timeduration = 0;
|
||||||
|
|
||||||
calendar_event::create($event);
|
calendar_event::create($event, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2438,7 +2438,7 @@ function scorm_update_calendar(stdClass $scorm, $cmid) {
|
|||||||
$event->timeduration = 0;
|
$event->timeduration = 0;
|
||||||
|
|
||||||
$calendarevent = calendar_event::load($event->id);
|
$calendarevent = calendar_event::load($event->id);
|
||||||
$calendarevent->update($event);
|
$calendarevent->update($event, false);
|
||||||
} else {
|
} else {
|
||||||
// Calendar event is on longer needed.
|
// Calendar event is on longer needed.
|
||||||
$calendarevent = calendar_event::load($event->id);
|
$calendarevent = calendar_event::load($event->id);
|
||||||
@ -2459,7 +2459,7 @@ function scorm_update_calendar(stdClass $scorm, $cmid) {
|
|||||||
$event->visible = instance_is_visible('scorm', $scorm);
|
$event->visible = instance_is_visible('scorm', $scorm);
|
||||||
$event->timeduration = 0;
|
$event->timeduration = 0;
|
||||||
|
|
||||||
calendar_event::create($event);
|
calendar_event::create($event, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
52
mod/scorm/tests/behat/scorm_no_calendar_capabilities.feature
Normal file
52
mod/scorm/tests/behat/scorm_no_calendar_capabilities.feature
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
@mod @mod_scorm
|
||||||
|
Feature: Scorm with no calendar capabilites
|
||||||
|
In order to allow work effectively
|
||||||
|
As a teacher
|
||||||
|
I need to be able to create SCORM activities even when I cannot edit calendar events
|
||||||
|
|
||||||
|
Background:
|
||||||
|
Given the following "courses" exist:
|
||||||
|
| fullname | shortname | category | groupmode |
|
||||||
|
| Course 1 | C1 | 0 | 1 |
|
||||||
|
And the following "users" exist:
|
||||||
|
| username | firstname | lastname | email |
|
||||||
|
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||||
|
And the following "course enrolments" exist:
|
||||||
|
| user | course | role |
|
||||||
|
| teacher1 | C1 | editingteacher |
|
||||||
|
And I log in as "admin"
|
||||||
|
And I am on "Course 1" course homepage
|
||||||
|
And I navigate to "Users > Permissions" in current page administration
|
||||||
|
And I override the system permissions of "Teacher" role with:
|
||||||
|
| capability | permission |
|
||||||
|
| moodle/calendar:manageentries | Prohibit |
|
||||||
|
And I log out
|
||||||
|
|
||||||
|
@javascript @_file_upload @_switch_iframe
|
||||||
|
Scenario: Editing a chat
|
||||||
|
Given I log in as "admin"
|
||||||
|
And I am on "Course 1" course homepage with editing mode on
|
||||||
|
When I add a "SCORM package" to section "1"
|
||||||
|
And I set the following fields to these values:
|
||||||
|
| Name | Test scorm name |
|
||||||
|
| Description | Test scorm description |
|
||||||
|
| id_timeopen_enabled | 1 |
|
||||||
|
| id_timeopen_day | 1 |
|
||||||
|
| id_timeopen_month | 1 |
|
||||||
|
| id_timeopen_year | 2017 |
|
||||||
|
| id_timeclose_enabled | 1 |
|
||||||
|
| id_timeclose_day | 1 |
|
||||||
|
| id_timeclose_month | 2 |
|
||||||
|
| id_timeclose_year | 2017 |
|
||||||
|
And I upload "mod/scorm/tests/packages/singlesco_scorm12.zip" file to "Package file" filemanager
|
||||||
|
And I click on "Save and display" "button"
|
||||||
|
And I log out
|
||||||
|
When I log in as "teacher1"
|
||||||
|
And I am on "Course 1" course homepage with editing mode on
|
||||||
|
And I follow "Test scorm name"
|
||||||
|
And I navigate to "Edit settings" in current page administration
|
||||||
|
And I set the following fields to these values:
|
||||||
|
| id_timeopen_year | 2018 |
|
||||||
|
| id_timeclose_year | 2018 |
|
||||||
|
And I press "Save and return to course"
|
||||||
|
Then I should see "Test scorm name"
|
@ -736,4 +736,27 @@ class mod_scorm_lib_testcase extends externallib_advanced_testcase {
|
|||||||
$this->assertNull($min);
|
$this->assertNull($min);
|
||||||
$this->assertNull($max);
|
$this->assertNull($max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A user who does not have capabilities to add events to the calendar should be able to create a SCORM.
|
||||||
|
*/
|
||||||
|
public function test_creation_with_no_calendar_capabilities() {
|
||||||
|
$this->resetAfterTest();
|
||||||
|
$course = self::getDataGenerator()->create_course();
|
||||||
|
$context = context_course::instance($course->id);
|
||||||
|
$user = self::getDataGenerator()->create_and_enrol($course, 'editingteacher');
|
||||||
|
$roleid = self::getDataGenerator()->create_role();
|
||||||
|
self::getDataGenerator()->role_assign($roleid, $user->id, $context->id);
|
||||||
|
assign_capability('moodle/calendar:manageentries', CAP_PROHIBIT, $roleid, $context, true);
|
||||||
|
$generator = self::getDataGenerator()->get_plugin_generator('mod_scorm');
|
||||||
|
// Create an instance as a user without the calendar capabilities.
|
||||||
|
$this->setUser($user);
|
||||||
|
$time = time();
|
||||||
|
$params = array(
|
||||||
|
'course' => $course->id,
|
||||||
|
'timeopen' => $time + 200,
|
||||||
|
'timeclose' => $time + 2000,
|
||||||
|
);
|
||||||
|
$generator->create_instance($params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user