Skip to content

Commit

Permalink
MDL-54098 external: Remove usage of require_login and $PAGE->set_context
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederic Massart committed May 9, 2016
1 parent 1e72daa commit 67ee103
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 15 deletions.
4 changes: 1 addition & 3 deletions enrol/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -651,9 +651,7 @@ public static function get_course_enrolment_methods($courseid) {
global $DB;

$params = self::validate_parameters(self::get_course_enrolment_methods_parameters(), array('courseid' => $courseid));

// Note that we can't use validate_context because the user is not enrolled in the course.
require_login(null, false, null, false, true);
self::validate_context(context_system::instance());

$course = $DB->get_record('course', array('id' => $params['courseid']), '*', MUST_EXIST);
$context = context_course::instance($course->id);
Expand Down
2 changes: 1 addition & 1 deletion enrol/guest/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static function get_instance_info($instanceid) {
throw new moodle_exception('invaliddata', 'error');
}

require_login(null, false, null, false, true);
self::validate_context(context_system::instance());
$enrolinstance = $DB->get_record('enrol', array('id' => $params['instanceid']), '*', MUST_EXIST);

$course = $DB->get_record('course', array('id' => $enrolinstance->courseid), '*', MUST_EXIST);
Expand Down
6 changes: 2 additions & 4 deletions enrol/self/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ public static function get_instance_info($instanceid) {
throw new moodle_exception('invaliddata', 'error');
}

// Note that we can't use validate_context because the user is not enrolled in the course.
require_login(null, false, null, false, true);
self::validate_context(context_system::instance());

$enrolinstance = $DB->get_record('enrol', array('id' => $params['instanceid']), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $enrolinstance->courseid), '*', MUST_EXIST);
Expand Down Expand Up @@ -146,8 +145,7 @@ public static function enrol_user($courseid, $password = '', $instanceid = 0) {

$course = get_course($params['courseid']);
$context = context_course::instance($course->id);
// Note that we can't use validate_context because the user is not enrolled in the course.
require_login(null, false, null, false, true);
self::validate_context(context_system::instance());

if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $context)) {
throw new moodle_exception('coursehidden');
Expand Down
1 change: 0 additions & 1 deletion mod/lti/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,6 @@ public static function get_tool_types($toolproxyid) {
$context = context_system::instance();

self::validate_context($context);
$PAGE->set_context($context);
require_capability('moodle/site:config', $context);

if (!empty($toolproxyid)) {
Expand Down
4 changes: 1 addition & 3 deletions question/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ public static function update_flag($qubaid, $questionid, $qaid, $slot, $checksum
);

$warnings = array();

// Check user is logged in.
require_login(null, false, null, false, true);
self::validate_context(context_system::instance());

// The checksum will be checked to provide security flagging other users questions.
question_flags::update_flag($params['qubaid'], $params['questionid'], $params['qaid'], $params['slot'], $params['checksum'],
Expand Down
5 changes: 2 additions & 3 deletions tag/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ public static function get_tags($tags) {
// Validate and normalize parameters.
$tags = self::validate_parameters(self::get_tags_parameters(), array('tags' => $tags));

require_login(null, false, null, false, true);

$systemcontext = context_system::instance();
self::validate_context($systemcontext);

$canmanage = has_capability('moodle/tag:manage', $systemcontext);
$canedit = has_capability('moodle/tag:edit', $systemcontext);

Expand Down Expand Up @@ -300,7 +300,6 @@ public static function get_tagindex($params) {

// Login to the course / module if applicable.
$context = $params['ctx'] ? context::instance_by_id($params['ctx']) : context_system::instance();
require_login(null, false, null, false, true);
self::validate_context($context);

$tag = core_tag_tag::get_by_name($params['tc'], $params['tag'], '*', MUST_EXIST);
Expand Down

0 comments on commit 67ee103

Please sign in to comment.