mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
Merge branch 'MDL-49796-master' of git://github.com/jleyva/moodle
This commit is contained in:
commit
82b9551f2d
@ -2063,7 +2063,7 @@ class core_course_external extends external_api {
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulate the view.php web interface page, logging events, completion, etc...
|
||||
* Trigger the course viewed event.
|
||||
*
|
||||
* @param int $courseid id of course
|
||||
* @param int $sectionnumber sectionnumber (0, 1, 2...)
|
||||
|
@ -1139,6 +1139,7 @@ $services = array(
|
||||
'mod_url_view_url',
|
||||
'core_user_get_users_by_field',
|
||||
'core_user_add_user_private_files',
|
||||
'mod_assign_view_grading_table',
|
||||
),
|
||||
'enabled' => 0,
|
||||
'restrictedusers' => 0,
|
||||
|
@ -144,6 +144,15 @@ $functions = array(
|
||||
'classpath' => 'mod/assign/externallib.php',
|
||||
'description' => 'Reveal the identities for a blind marking assignment',
|
||||
'type' => 'write'
|
||||
)
|
||||
),
|
||||
|
||||
'mod_assign_view_grading_table' => array(
|
||||
'classname' => 'mod_assign_external',
|
||||
'methodname' => 'view_grading_table',
|
||||
'classpath' => 'mod/assign/externallib.php',
|
||||
'description' => 'Trigger the grading_table_viewed event.',
|
||||
'type' => 'write',
|
||||
'capabilities' => 'mod/assign:view, mod/assign:viewgrades'
|
||||
),
|
||||
|
||||
);
|
||||
|
@ -2050,4 +2050,70 @@ class mod_assign_external extends external_api {
|
||||
public static function copy_previous_attempt_returns() {
|
||||
return new external_warnings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
*
|
||||
* @return external_function_parameters
|
||||
* @since Moodle 3.0
|
||||
*/
|
||||
public static function view_grading_table_parameters() {
|
||||
return new external_function_parameters(
|
||||
array(
|
||||
'assignid' => new external_value(PARAM_INT, 'assign instance id')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger the grading_table_viewed event.
|
||||
*
|
||||
* @param int $assignid the assign instance id
|
||||
* @return array of warnings and status result
|
||||
* @since Moodle 3.0
|
||||
* @throws moodle_exception
|
||||
*/
|
||||
public static function view_grading_table($assignid) {
|
||||
global $DB, $CFG;
|
||||
require_once($CFG->dirroot . "/mod/assign/locallib.php");
|
||||
|
||||
$params = self::validate_parameters(self::view_grading_table_parameters(),
|
||||
array(
|
||||
'assignid' => $assignid
|
||||
));
|
||||
$warnings = array();
|
||||
|
||||
// Request and permission validation.
|
||||
$assign = $DB->get_record('assign', array('id' => $params['assignid']), 'id', MUST_EXIST);
|
||||
list($course, $cm) = get_course_and_cm_from_instance($assign, 'assign');
|
||||
|
||||
$context = context_module::instance($cm->id);
|
||||
self::validate_context($context);
|
||||
|
||||
require_capability('mod/assign:view', $context);
|
||||
|
||||
$assign = new assign($context, null, null);
|
||||
$assign->require_view_grades();
|
||||
\mod_assign\event\grading_table_viewed::create_from_assign($assign)->trigger();
|
||||
|
||||
$result = array();
|
||||
$result['status'] = true;
|
||||
$result['warnings'] = $warnings;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method result value
|
||||
*
|
||||
* @return external_description
|
||||
* @since Moodle 3.0
|
||||
*/
|
||||
public static function view_grading_table_returns() {
|
||||
return new external_single_structure(
|
||||
array(
|
||||
'status' => new external_value(PARAM_BOOL, 'status: true if success'),
|
||||
'warnings' => new external_warnings()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1486,4 +1486,73 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
$this->assertEquals($USER->id, $updateduserflag->allocatedmarker);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test view_grading_table
|
||||
*/
|
||||
public function test_view_grading_table() {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
$this->setAdminUser();
|
||||
// Setup test data.
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$assign = $this->getDataGenerator()->create_module('assign', array('course' => $course->id));
|
||||
$context = context_module::instance($assign->cmid);
|
||||
$cm = get_coursemodule_from_instance('assign', $assign->id);
|
||||
|
||||
// Test invalid instance id.
|
||||
try {
|
||||
mod_assign_external::view_grading_table(0);
|
||||
$this->fail('Exception expected due to invalid mod_assign instance id.');
|
||||
} catch (moodle_exception $e) {
|
||||
$this->assertEquals('invalidrecord', $e->errorcode);
|
||||
}
|
||||
|
||||
// Test not-enrolled user.
|
||||
$user = self::getDataGenerator()->create_user();
|
||||
$this->setUser($user);
|
||||
try {
|
||||
mod_assign_external::view_grading_table($assign->id);
|
||||
$this->fail('Exception expected due to not enrolled user.');
|
||||
} catch (moodle_exception $e) {
|
||||
$this->assertEquals('requireloginerror', $e->errorcode);
|
||||
}
|
||||
|
||||
// Test user with full capabilities.
|
||||
$teacherrole = $DB->get_record('role', array('shortname' => 'teacher'));
|
||||
$this->getDataGenerator()->enrol_user($user->id, $course->id, $teacherrole->id);
|
||||
|
||||
// Trigger and capture the event.
|
||||
$sink = $this->redirectEvents();
|
||||
|
||||
$result = mod_assign_external::view_grading_table($assign->id);
|
||||
$result = external_api::clean_returnvalue(mod_assign_external::view_grading_table_returns(), $result);
|
||||
|
||||
$events = $sink->get_events();
|
||||
$this->assertCount(1, $events);
|
||||
$event = array_shift($events);
|
||||
|
||||
// Checking that the event contains the expected values.
|
||||
$this->assertInstanceOf('\mod_assign\event\grading_table_viewed', $event);
|
||||
$this->assertEquals($context, $event->get_context());
|
||||
$moodleurl = new \moodle_url('/mod/assign/view.php', array('id' => $cm->id));
|
||||
$this->assertEquals($moodleurl, $event->get_url());
|
||||
$this->assertEventContextNotUsed($event);
|
||||
$this->assertNotEmpty($event->get_name());
|
||||
|
||||
// Test user with no capabilities.
|
||||
// We need a explicit prohibit since this capability is only defined in authenticated user and guest roles.
|
||||
assign_capability('mod/assign:view', CAP_PROHIBIT, $teacherrole->id, $context->id);
|
||||
accesslib_clear_all_caches_for_unit_testing();
|
||||
|
||||
try {
|
||||
mod_assign_external::view_grading_table($assign->id);
|
||||
$this->fail('Exception expected due to missing capability.');
|
||||
} catch (moodle_exception $e) {
|
||||
$this->assertEquals('nopermissions', $e->errorcode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,6 +25,6 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->component = 'mod_assign'; // Full name of the plugin (used for diagnostics).
|
||||
$plugin->version = 2015051100; // The current module version (Date: YYYYMMDDXX).
|
||||
$plugin->version = 2015051101; // The current module version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2015050500; // Requires this Moodle version.
|
||||
$plugin->cron = 60;
|
||||
|
@ -68,7 +68,7 @@ $functions = array(
|
||||
'classname' => 'mod_forum_external',
|
||||
'methodname' => 'view_forum',
|
||||
'classpath' => 'mod/forum/externallib.php',
|
||||
'description' => 'Simulate the view.php web interface page: trigger events, completion, etc...',
|
||||
'description' => 'Trigger the course module viewed event and update the module completion status.',
|
||||
'type' => 'write',
|
||||
'capabilities' => 'mod/forum:viewdiscussion'
|
||||
),
|
||||
@ -77,7 +77,7 @@ $functions = array(
|
||||
'classname' => 'mod_forum_external',
|
||||
'methodname' => 'view_forum_discussion',
|
||||
'classpath' => 'mod/forum/externallib.php',
|
||||
'description' => 'Simulate the forum/discuss.php web interface page: trigger events, completion, etc...',
|
||||
'description' => 'Trigger the forum discussion viewed event.',
|
||||
'type' => 'write',
|
||||
'capabilities' => 'mod/forum:viewdiscussion'
|
||||
),
|
||||
|
@ -848,7 +848,7 @@ class mod_forum_external extends external_api {
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulate the forum/view.php web interface page: trigger events, completion, etc...
|
||||
* Trigger the course module viewed event and update the module completion status.
|
||||
*
|
||||
* @param int $forumid the forum instance id
|
||||
* @return array of warnings and status result
|
||||
@ -913,7 +913,7 @@ class mod_forum_external extends external_api {
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulate the forum/discuss.php web interface page: trigger events
|
||||
* Trigger the discussion viewed event.
|
||||
*
|
||||
* @param int $discussionid the discussion id
|
||||
* @return array of warnings and status result
|
||||
|
@ -54,7 +54,7 @@ class mod_url_external extends external_api {
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulate the url/view.php web interface page: trigger events, completion, etc...
|
||||
* Trigger the course module viewed event and update the module completion status.
|
||||
*
|
||||
* @param int $urlid the url instance id
|
||||
* @return array of warnings and status result
|
||||
|
@ -31,7 +31,7 @@ $functions = array(
|
||||
'mod_url_view_url' => array(
|
||||
'classname' => 'mod_url_external',
|
||||
'methodname' => 'view_url',
|
||||
'description' => 'Simulate the view.php web interface url: trigger events, completion, etc...',
|
||||
'description' => 'Trigger the course module viewed event and update the module completion status.',
|
||||
'type' => 'write',
|
||||
'capabilities' => 'mod/url:view'
|
||||
),
|
||||
|
@ -1258,7 +1258,7 @@ class core_user_external extends external_api {
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulate the /user/index.php web interface page triggering events
|
||||
* Trigger the user_list_viewed event.
|
||||
*
|
||||
* @param int $courseid id of course
|
||||
* @return array of warnings and status result
|
||||
@ -1334,7 +1334,7 @@ class core_user_external extends external_api {
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulate the /user/index.php and /user/profile.php web interface page triggering events
|
||||
* Trigger the user profile viewed event.
|
||||
*
|
||||
* @param int $userid id of user
|
||||
* @param int $courseid id of course
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$version = 2015071100.00; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
$version = 2015071100.01; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
// RR = release increments - 00 in DEV branches.
|
||||
// .XX = incremental changes.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user