From 64152010098a68ddae242a28aa18a3f4aecb7ed7 Mon Sep 17 00:00:00 2001 From: Mihail Geshoski Date: Fri, 10 Aug 2018 16:02:47 +0800 Subject: [PATCH 1/2] MDL-62341 privacy: Add link to previous page in viewall policies page --- admin/tool/policy/classes/output/page_viewalldoc.php | 10 ++++++++-- admin/tool/policy/lang/en/tool_policy.php | 1 + admin/tool/policy/lib.php | 6 +++--- admin/tool/policy/templates/page_viewalldoc.mustache | 8 ++++++++ admin/tool/policy/viewall.php | 4 +++- 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/admin/tool/policy/classes/output/page_viewalldoc.php b/admin/tool/policy/classes/output/page_viewalldoc.php index 66ea3aa25a7..801aac0c516 100644 --- a/admin/tool/policy/classes/output/page_viewalldoc.php +++ b/admin/tool/policy/classes/output/page_viewalldoc.php @@ -48,12 +48,15 @@ use tool_policy\policy_version; */ class page_viewalldoc implements renderable, templatable { + /** @var string Return url */ + private $returnurl; + /** * Prepare the page for rendering. * */ - public function __construct() { - + public function __construct($returnurl) { + $this->returnurl = $returnurl; $this->prepare_global_page_access(); $this->prepare_policies(); } @@ -99,6 +102,9 @@ class page_viewalldoc implements renderable, templatable { ]; $data->policies = array_values($this->policies); + if (!empty($this->returnurl)) { + $data->returnurl = $this->returnurl; + } array_walk($data->policies, function($item, $key) { $item->policytypestr = get_string('policydoctype'.$item->type, 'tool_policy'); diff --git a/admin/tool/policy/lang/en/tool_policy.php b/admin/tool/policy/lang/en/tool_policy.php index 3a752851900..8f2a1d5658d 100644 --- a/admin/tool/policy/lang/en/tool_policy.php +++ b/admin/tool/policy/lang/en/tool_policy.php @@ -50,6 +50,7 @@ $string['agreedyesonbehalfwithlinkall'] = 'Consent given on behalf of user; clic $string['agreedyeswithlink'] = 'Consent given; click to withdraw user consent for {$a}'; $string['agreedyeswithlinkall'] = 'Consent given; click to withdraw user consent for all policies'; $string['agreepolicies'] = 'Please agree to the following policies'; +$string['backtoprevious'] = 'Go back to previous page'; $string['backtotop'] = 'Back to top'; $string['consentbulk'] = 'Consent'; $string['consentdetails'] = 'Give consent on behalf of user'; diff --git a/admin/tool/policy/lib.php b/admin/tool/policy/lib.php index 62919d38b63..563254d814c 100644 --- a/admin/tool/policy/lib.php +++ b/admin/tool/policy/lib.php @@ -96,17 +96,17 @@ function tool_policy_before_standard_html_head() { /** * Callback to add footer elements. * - * @return str valid html footer content + * @return string HTML footer content */ function tool_policy_standard_footer_html() { - global $CFG; + global $CFG, $PAGE; $output = ''; if (!empty($CFG->sitepolicyhandler) && $CFG->sitepolicyhandler == 'tool_policy') { $policies = api::get_current_versions_ids(); if (!empty($policies)) { - $url = (new moodle_url('/admin/tool/policy/viewall.php'))->out(); + $url = new moodle_url('/admin/tool/policy/viewall.php', ['returnurl' => $PAGE->url]); $output .= html_writer::link($url, get_string('userpolicysettings', 'tool_policy')); $output = html_writer::div($output, 'policiesfooter'); } diff --git a/admin/tool/policy/templates/page_viewalldoc.mustache b/admin/tool/policy/templates/page_viewalldoc.mustache index 2f9df36e0a5..3e4664c1a0a 100644 --- a/admin/tool/policy/templates/page_viewalldoc.mustache +++ b/admin/tool/policy/templates/page_viewalldoc.mustache @@ -26,10 +26,12 @@ - Context variables required for this template: + * returnurl - url to the previous page * policies - policy array Example context (json): { + "returnurl": "#", "policies": [ { "id": "2", @@ -51,6 +53,12 @@ } }} +{{#returnurl}} +
+ {{# str }} backtoprevious, tool_policy {{/ str }} +
+{{/returnurl}} +

{{# str }} listactivepolicies, tool_policy {{/ str }}

diff --git a/admin/tool/policy/viewall.php b/admin/tool/policy/viewall.php index 9f5528cb057..e1f3f60cc43 100644 --- a/admin/tool/policy/viewall.php +++ b/admin/tool/policy/viewall.php @@ -34,7 +34,9 @@ define('NO_SITEPOLICY_CHECK', true); // @codingStandardsIgnoreLine See the {@link page_viewalldoc} for the access control checks. require(__DIR__.'/../../../config.php'); -$viewallpage = new page_viewalldoc(); +$returnurl = optional_param('returnurl', '', PARAM_LOCALURL); // A return URL. + +$viewallpage = new page_viewalldoc($returnurl); $output = $PAGE->get_renderer('tool_policy'); From 0af0d1d7f6e5040659edf42334d0700e9d0f55b9 Mon Sep 17 00:00:00 2001 From: Mihail Geshoski Date: Fri, 10 Aug 2018 16:03:14 +0800 Subject: [PATCH 2/2] MDL-62341 privacy: Add behat test --- .../policy/tests/behat/managepolicies.feature | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/admin/tool/policy/tests/behat/managepolicies.feature b/admin/tool/policy/tests/behat/managepolicies.feature index f25bd4dc12e..4db68e33663 100644 --- a/admin/tool/policy/tests/behat/managepolicies.feature +++ b/admin/tool/policy/tests/behat/managepolicies.feature @@ -256,3 +256,21 @@ Feature: Manage policies | Policy1 Site policy, All users | Inactive | v1 | 1 of 4 (25%) | And I should not see "v2" And I log out + + Scenario: Current user can go back to previous page in List of active policies page + Given the following policies exist: + | Name | Revision | Content | Summary | Status | + | Policy1 | v1 | full text2 | short text2 | active | + And I log in as "user1" + And I press "Next" + And I set the field "I agree to the Policy1" to "1" + And I press "Next" + And I follow "Preferences" in the user menu + And I should see "Preferences" + And I should see "Policies" + # User should see a redirect back to previous page link. + And I click on "Policies" "link" + And I should see "List of active policies" + And I should see "Go back to previous page" + When I click on "Go back to previous page" "link" + Then I should see "Preferences"