Skip to content

Commit

Permalink
Merge branch 'MDL-80973-403' of https://github.com/jleyva/moodle into…
Browse files Browse the repository at this point in the history
… MOODLE_403_STABLE
  • Loading branch information
HuongNV13 committed May 30, 2024
2 parents 9459034 + 770947d commit 5b39c49
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion admin/tool/policy/classes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,9 @@ public static function update_policyagreed($user = null) {
}
}

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]);
}
Expand Down
8 changes: 7 additions & 1 deletion admin/tool/policy/tests/api_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ public function test_fix_revision_values() {
* Test that accepting policy updates 'policyagreed'
*/
public function test_accept_policies() {
global $DB;
global $DB, $USER;
$this->resetAfterTest();
$this->setAdminUser();

Expand Down Expand Up @@ -623,6 +623,12 @@ public function test_accept_policies() {

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]));
}

/**
Expand Down

0 comments on commit 5b39c49

Please sign in to comment.