Merge branch 'MDL-80973-master' of https://github.com/jleyva/moodle

This commit is contained in:
Huong Nguyen
2024-05-30 10:37:42 +07:00
2 changed files with 10 additions and 2 deletions
+3 -1
View File
@@ -1034,7 +1034,9 @@ class api {
}
}
if ($user->policyagreed != $allresponded) {
// MDL-80973: At this point, the policyagreed value in DB could be 0 but $user->policyagreed could be 1 (as it was copied from $USER).
// So we need to ensure that the value in DB is set true if all policies were responded.
if ($user->policyagreed != $allresponded || $allresponded) {
$user->policyagreed = $allresponded;
$DB->set_field('user', 'policyagreed', $allresponded, ['id' => $user->id]);
}
+7 -1
View File
@@ -579,7 +579,7 @@ class api_test extends \advanced_testcase {
* Test that accepting policy updates 'policyagreed'
*/
public function test_accept_policies() {
global $DB;
global $DB, $USER;
$this->resetAfterTest();
$this->setAdminUser();
@@ -623,6 +623,12 @@ class api_test extends \advanced_testcase {
api::accept_policies([$policy3->id]);
$this->assertEquals(1, $DB->get_field('user', 'policyagreed', ['id' => $user2->id]));
// Ensure policies are always accepted when all are responded regardless the $USER->policyagreed value.
$USER->policyagreed = 1;
$DB->set_field('user', 'policyagreed', 0, ['id' => $user2->id]);
api::accept_policies([$policy3->id]);
$this->assertEquals(1, $DB->get_field('user', 'policyagreed', ['id' => $user2->id]));
}
/**