Skip to content

Commit

Permalink
MDL-68632 quizaccess_seb: Limit privacy queriyes to the quiz module
Browse files Browse the repository at this point in the history
Without this, joins are performed against the course_modules table purely on
the instance id - other modules can share this ID, resulting in incorrect
contexts being pulled in.
  • Loading branch information
aolley committed Jun 12, 2020
1 parent aa6830e commit 9db6c36
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 8 additions & 1 deletion mod/quiz/accessrule/seb/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@ public static function get_contexts_for_userid(int $userid): contextlist {
$sql = "SELECT c.id
FROM {quizaccess_seb_quizsettings} qs
JOIN {course_modules} cm ON cm.instance = qs.quizid
JOIN {modules} m ON cm.module = m.id AND m.name = :modulename
JOIN {context} c ON c.instanceid = cm.id AND c.contextlevel = :context
WHERE qs.usermodified = :userid
GROUP BY c.id";

$params = [
'context' => CONTEXT_MODULE,
'modulename' => 'quiz',
'userid' => $userid
];

Expand All @@ -108,6 +110,7 @@ public static function get_contexts_for_userid(int $userid): contextlist {
FROM {quizaccess_seb_template} tem
JOIN {quizaccess_seb_quizsettings} qs ON qs.templateid = tem.id
JOIN {course_modules} cm ON cm.instance = qs.quizid
JOIN {modules} m ON cm.module = m.id AND m.name = :modulename
JOIN {context} c ON c.instanceid = cm.id AND c.contextlevel = :context
WHERE qs.usermodified = :userid
GROUP BY c.id";
Expand Down Expand Up @@ -139,6 +142,7 @@ public static function export_user_data(approved_contextlist $contextlist) {
}

list($insql, $params) = $DB->get_in_or_equal($cmids, SQL_PARAMS_NAMED);
$params['modulename'] = 'quiz';

// SEB quiz settings.
$sql = "SELECT qs.id as id,
Expand All @@ -148,6 +152,7 @@ public static function export_user_data(approved_contextlist $contextlist) {
qs.timemodified as timemodified
FROM {quizaccess_seb_quizsettings} qs
JOIN {course_modules} cm ON cm.instance = qs.quizid
JOIN {modules} m ON cm.module = m.id AND m.name = :modulename
WHERE cm.id {$insql}";

$quizsettingslist = $DB->get_records_sql($sql, $params);
Expand Down Expand Up @@ -180,6 +185,7 @@ public static function export_user_data(approved_contextlist $contextlist) {
FROM {quizaccess_seb_template} tem
JOIN {quizaccess_seb_quizsettings} qs ON qs.templateid = tem.id
JOIN {course_modules} cm ON cm.instance = qs.quizid
JOIN {modules} m ON cm.module = m.id AND m.name = :modulename
WHERE cm.id {$insql}";

$templatesettingslist = $DB->get_records_sql($sql, $params);
Expand Down Expand Up @@ -262,8 +268,9 @@ public static function get_users_in_context(userlist $userlist) {
$sql = "SELECT qs.usermodified AS userid
FROM {quizaccess_seb_quizsettings} qs
JOIN {course_modules} cm ON cm.instance = qs.quizid
JOIN {modules} m ON cm.module = m.id AND m.name = ?
WHERE cm.id = ?";
$params = [$context->instanceid];
$params = ['quiz', $context->instanceid];
$userlist->add_from_sql('userid', $sql, $params);
}

Expand Down
5 changes: 5 additions & 0 deletions mod/quiz/accessrule/seb/tests/privacy_provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ public function test_export_user_data() {

$context = context_module::instance($this->quiz->cmid);

// Add another course_module of a differenty type - doing this lets us
// test that the data exporter is correctly limiting its selection to
// the quiz and not anything with the same instance id.
$this->getDataGenerator()->create_module('label', array('course' => $this->course->id));

$contextlist = provider::get_contexts_for_userid($this->user->id);
$approvedcontextlist = new approved_contextlist(
$this->user,
Expand Down

0 comments on commit 9db6c36

Please sign in to comment.