mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
Merge branch 'MDL-52974-master' of git://github.com/jleyva/moodle
This commit is contained in:
commit
05b0f579ca
@ -1275,6 +1275,7 @@ $services = array(
|
||||
'core_user_get_users_by_field',
|
||||
'core_user_add_user_private_files',
|
||||
'mod_assign_view_grading_table',
|
||||
'mod_assign_view_submission_status',
|
||||
'mod_scorm_view_scorm',
|
||||
'mod_scorm_get_scorm_scoes',
|
||||
'mod_scorm_get_scorm_user_data',
|
||||
|
@ -155,4 +155,12 @@ $functions = array(
|
||||
'capabilities' => 'mod/assign:view, mod/assign:viewgrades'
|
||||
),
|
||||
|
||||
'mod_assign_view_submission_status' => array(
|
||||
'classname' => 'mod_assign_external',
|
||||
'methodname' => 'view_submission_status',
|
||||
'classpath' => 'mod/assign/externallib.php',
|
||||
'description' => 'Trigger the submission status viewed event.',
|
||||
'type' => 'write',
|
||||
'capabilities' => 'mod/assign:view'
|
||||
),
|
||||
);
|
||||
|
@ -2122,4 +2122,66 @@ class mod_assign_external extends external_api {
|
||||
)
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Describes the parameters for view_submission_status.
|
||||
*
|
||||
* @return external_external_function_parameters
|
||||
* @since Moodle 3.1
|
||||
*/
|
||||
public static function view_submission_status_parameters() {
|
||||
return new external_function_parameters (
|
||||
array(
|
||||
'assignid' => new external_value(PARAM_INT, 'assign instance id'),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger the submission status viewed event.
|
||||
*
|
||||
* @param int $assignid assign instance id
|
||||
* @return array of warnings and status result
|
||||
* @since Moodle 3.1
|
||||
*/
|
||||
public static function view_submission_status($assignid) {
|
||||
global $DB;
|
||||
|
||||
$warnings = array();
|
||||
$params = array(
|
||||
'assignid' => $assignid,
|
||||
);
|
||||
$params = self::validate_parameters(self::view_submission_status_parameters(), $params);
|
||||
|
||||
// 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);
|
||||
// Please, note that is not required to check mod/assign:view because is done by validate_context->require_login.
|
||||
self::validate_context($context);
|
||||
|
||||
$assign = new assign($context, $cm, $course);
|
||||
\mod_assign\event\submission_status_viewed::create_from_assign($assign)->trigger();
|
||||
|
||||
$result = array();
|
||||
$result['status'] = true;
|
||||
$result['warnings'] = $warnings;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes the view_submission_status return value.
|
||||
*
|
||||
* @return external_single_structure
|
||||
* @since Moodle 3.1
|
||||
*/
|
||||
public static function view_submission_status_returns() {
|
||||
return new external_single_structure(
|
||||
array(
|
||||
'status' => new external_value(PARAM_BOOL, 'status: true if success'),
|
||||
'warnings' => new external_warnings(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1600,4 +1600,73 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
$this->assertEquals(VALUE_OPTIONAL, $parameters->keys['plugindata']->keys['assignfeedbackcomments_editor']->required);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test test_view_submission_status
|
||||
*/
|
||||
public function test_view_submission_status() {
|
||||
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_submission_status(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_submission_status($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.
|
||||
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
|
||||
$this->getDataGenerator()->enrol_user($user->id, $course->id, $studentrole->id);
|
||||
|
||||
// Trigger and capture the event.
|
||||
$sink = $this->redirectEvents();
|
||||
|
||||
$result = mod_assign_external::view_submission_status($assign->id);
|
||||
$result = external_api::clean_returnvalue(mod_assign_external::view_submission_status_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\submission_status_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, $studentrole->id, $context->id);
|
||||
accesslib_clear_all_caches_for_unit_testing();
|
||||
course_modinfo::clear_instance_cache();
|
||||
|
||||
try {
|
||||
mod_assign_external::view_submission_status($assign->id);
|
||||
$this->fail('Exception expected due to missing capability.');
|
||||
} catch (moodle_exception $e) {
|
||||
$this->assertEquals('requireloginerror', $e->errorcode);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,6 +25,6 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->component = 'mod_assign'; // Full name of the plugin (used for diagnostics).
|
||||
$plugin->version = 2015111600; // The current module version (Date: YYYYMMDDXX).
|
||||
$plugin->version = 2015111601; // The current module version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2015111000; // Requires this Moodle version.
|
||||
$plugin->cron = 60;
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$version = 2016030100.00; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
$version = 2016030101.00; // 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