From b02583be810776eae4fdec3ea81a690dd855637c Mon Sep 17 00:00:00 2001 From: Sara Arjona Date: Fri, 8 Mar 2019 09:30:46 +0100 Subject: [PATCH] MDL-65006 policy: avoid loop when no policies need to be agreeded Avoid an infinite loop when the user has no policies to agreed but the policyagreed = 0. --- .../policy/classes/output/page_agreedocs.php | 4 ++++ .../policy/tests/behat/acceptances.feature | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/admin/tool/policy/classes/output/page_agreedocs.php b/admin/tool/policy/classes/output/page_agreedocs.php index af6ebd61947..f149d52ccac 100644 --- a/admin/tool/policy/classes/output/page_agreedocs.php +++ b/admin/tool/policy/classes/output/page_agreedocs.php @@ -232,6 +232,10 @@ class page_agreedocs implements renderable, templatable { ]; redirect(new moodle_url('/admin/tool/policy/view.php', $urlparams)); } + } else { + // Update the policyagreed for the user to avoid infinite loop because there are no policies to-be-accepted. + api::update_policyagreed($userid); + $this->redirect_to_previous_url(); } } diff --git a/admin/tool/policy/tests/behat/acceptances.feature b/admin/tool/policy/tests/behat/acceptances.feature index 077477cdf63..f198cc90b66 100644 --- a/admin/tool/policy/tests/behat/acceptances.feature +++ b/admin/tool/policy/tests/behat/acceptances.feature @@ -292,3 +292,23 @@ Feature: Viewing acceptances reports and accepting on behalf of other users And I should see "2 of 2" in the "User One" "table_row" And "Consent given on behalf of user" "icon" should exist in the "User Two" "table_row" And I should see "2 of 2" in the "User Two" "table_row" + + Scenario: View acceptances made by users on their own after inactivating a policy + Given I log in as "user1" + And I should see "This site policy" + And I should not see "Course overview" + And I press "Next" + And I set the field "I agree to the This site policy" to "1" + And I press "Next" + And I should see "Course overview" + And I log out + And I log in as "admin" + And I navigate to "Users > Privacy and policies > Manage policies" in site administration + And I click on "Actions" "link_or_button" in the "This privacy policy" "table_row" + And I click on "Set status to \"Active\"" "link" in the "This privacy policy" "table_row" + And I press "Continue" + And I click on "Set status to \"Inactive\"" "link" in the "This privacy policy" "table_row" + And I press "Continue" + And I log out + When I log in as "user1" + Then I should see "Course overview"