From 2b85015b83c26c663d1ca90ed212c52a735b17f1 Mon Sep 17 00:00:00 2001 From: Mihail Geshoski Date: Thu, 30 Aug 2018 13:48:00 +0800 Subject: [PATCH 1/2] MDL-63109 privacy: Fix the initialisation of the policy acceptance modal --- .../tool/policy/amd/build/acceptmodal.min.js | 2 +- admin/tool/policy/amd/src/acceptmodal.js | 36 +++++++++++++------ .../tool/policy/classes/acceptances_table.php | 6 ++-- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/admin/tool/policy/amd/build/acceptmodal.min.js b/admin/tool/policy/amd/build/acceptmodal.min.js index da1432a14a3..020e5bf4204 100644 --- a/admin/tool/policy/amd/build/acceptmodal.min.js +++ b/admin/tool/policy/amd/build/acceptmodal.min.js @@ -1 +1 @@ -define(["jquery","core/str","core/modal_factory","core/modal_events","core/notification","core/fragment","core/ajax","core/yui"],function(a,b,c,d,e,f,g,h){"use strict";var i=function(a){this.contextid=a,this.init()};return i.prototype.modal=null,i.prototype.contextid=-1,i.prototype.stringKeys=[{key:"consentdetails",component:"tool_policy"},{key:"iagreetothepolicy",component:"tool_policy"},{key:"selectusersforconsent",component:"tool_policy"},{key:"ok"},{key:"revokedetails",component:"tool_policy"},{key:"irevokethepolicy",component:"tool_policy"}],i.prototype.init=function(){var c=a("a[data-action=acceptmodal]");c.on("click",function(b){b.preventDefault();var c=a(b.currentTarget).attr("href"),d=c.slice(c.indexOf("?")+1);this.showFormModal(d)}.bind(this)),c=a("form[data-action=acceptmodal]"),c.on("submit",function(d){if(d.preventDefault(),a(d.currentTarget).find('input[type=checkbox][name="userids[]"]:checked').length){var f=a(d.currentTarget).serialize();this.showFormModal(f,c)}else b.get_strings(this.stringKeys).done(function(a){e.alert("",a[2],a[3])})}.bind(this))},i.prototype.showFormModal=function(a,d){for(var f,g=a.split("&"),h=0;h new \moodle_url('/admin/tool/policy/accept.php'), 'data-action' => 'acceptmodal']); + ['action' => new \moodle_url('/admin/tool/policy/accept.php')]); echo \html_writer::empty_tag('input', ['type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()]); echo \html_writer::empty_tag('input', ['type' => 'hidden', 'name' => 'returnurl', 'value' => $this->get_return_url()]); @@ -433,8 +433,8 @@ class acceptances_table extends \table_sql { public function wrap_html_finish() { global $PAGE; if ($this->canagreeany) { - echo \html_writer::empty_tag('input', ['type' => 'submit', - 'value' => get_string('consentbulk', 'tool_policy'), 'class' => 'btn btn-primary']); + echo \html_writer::empty_tag('input', ['type' => 'submit', 'data-action' => 'acceptmodal', + 'value' => get_string('consentbulk', 'tool_policy'), 'class' => 'btn btn-primary m-t-1']); $PAGE->requires->js_call_amd('tool_policy/acceptmodal', 'getInstance', [\context_system::instance()->id]); } echo "\n"; From 85de6d525d33e16448336c7f12584d88601442ae Mon Sep 17 00:00:00 2001 From: Mihail Geshoski Date: Tue, 18 Sep 2018 15:06:23 +0800 Subject: [PATCH 2/2] MDL-63109 privacy: Add behat tests --- .../policy/tests/behat/acceptances.feature | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/admin/tool/policy/tests/behat/acceptances.feature b/admin/tool/policy/tests/behat/acceptances.feature index 3d436d441ca..23198daf919 100644 --- a/admin/tool/policy/tests/behat/acceptances.feature +++ b/admin/tool/policy/tests/behat/acceptances.feature @@ -260,3 +260,37 @@ Feature: Viewing acceptances reports and accepting on behalf of other users And "Admin User" "link" should exist in the "User One" "table_row" And "Consent received from a parent" "text" should exist in the "User One" "table_row" And "Consent not given" "icon" should exist in the "User Two" "table_row" + + @javascript + Scenario: Bulk agree on behalf of another users as a manager, multiple policies, javascript on + Given I log in as "admin" + And I navigate to "Users > Privacy and policies > Manage policies" in site administration + And I open the action menu in "This privacy policy" "table_row" + And I click on "Set status to \"Active\"" "link" in the "This privacy policy" "table_row" + And I press "Activate" + And I set the following system permissions of "Manager" role: + | capability | permission | + | tool/policy:acceptbehalf | Allow | + And I log out + When I log in as "manager" + And I press "Next" + And I press "Next" + And I set the field "I agree to the This site policy" to "1" + And I set the field "I agree to the This privacy policy" to "1" + And I press "Next" + And I navigate to "Users > Privacy and policies > User agreements" in site administration + And I click on "Select" "checkbox" in the "User One" "table_row" + And I press "Consent" + And I should see "Give consent on behalf of user(s)" + And I should see "One" + And I press "Cancel" + And I should not see "Give consent on behalf of user(s)" + And I click on "Select" "checkbox" in the "User Two" "table_row" + And I press "Consent" + And I should see "Give consent on behalf of user(s)" + And I should see "User One, User Two" + When I press "Give consent" + Then "Consent given on behalf of user" "icon" should exist in the "User One" "table_row" + 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"