From 6531013c44443392beba8c261c0d07c76be34c8b Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Wed, 8 Aug 2018 09:58:22 +0800 Subject: [PATCH 1/5] MDL-63094 tool_policy: Fix race condition in modal display The way in which the modal was displayed meant that there were no pending JS items, whilst the modal was rendered, causing random behat fails. This JS has been restructured to create the Modal and pass it a set of Promises for both the title, and body. --- amd/build/policyactions.min.js | 2 +- amd/src/policyactions.js | 74 ++++++++++++++++++++-------------- 2 files changed, 44 insertions(+), 32 deletions(-) diff --git a/amd/build/policyactions.min.js b/amd/build/policyactions.min.js index 9a87001..2e54773 100644 --- a/amd/build/policyactions.min.js +++ b/amd/build/policyactions.min.js @@ -1 +1 @@ -define(["jquery","core/ajax","core/notification","core/modal_factory","core/modal_events"],function(a,b,c,d,e){var f={VIEW_POLICY:'[data-action="view"]'},g=function(){this.registerEvents()};return g.prototype.registerEvents=function(){a(f.VIEW_POLICY).click(function(f){f.preventDefault();var g=a(this).data("versionid"),h=a(this).data("behalfid"),i={versionid:g,behalfid:h},j={methodname:"tool_policy_get_policy_version",args:i},k=b.call([j]),l="",m=d.types.DEFAULT;a.when(k[0]).then(function(a){return a.result.policy?(l=a.result.policy.name,a.result.policy.content):(c.addNotification({message:a.warnings[0].message,type:"error"}),!1)}).then(function(a){return 0!=a&&d.create({title:l,body:a,type:m,large:!0}).then(function(a){return a.getRoot().on(e.hidden,function(){a.destroy()}),a})}).done(function(a){a.show()}).fail(c.exception)})},{init:function(){return new g}}}); \ No newline at end of file +define(["jquery","core/ajax","core/notification","core/modal_factory","core/modal_events"],function(a,b,c,d,e){var f={VIEW_POLICY:'[data-action="view"]'},g=function(){this.registerEvents()};return g.prototype.registerEvents=function(){a(f.VIEW_POLICY).click(function(f){f.preventDefault();var g=a(this).data("versionid"),h=a(this).data("behalfid"),i={versionid:g,behalfid:h},j={methodname:"tool_policy_get_policy_version",args:i},k=a.Deferred(),l=a.Deferred(),m=d.create({title:k,body:l,large:!0}).then(function(a){return a.getRoot().on(e.hidden,function(){a.destroy()}),a}).then(function(a){return a.show(),a})["catch"](c.exception),n=b.call([j]);a.when(n[0]).then(function(a){if(a.result.policy)return k.resolve(a.result.policy.name),l.resolve(a.result.policy.content),a;throw new Error(a.warnings[0].message)})["catch"](function(a){return m.then(function(a){return a.hide(),a.destroy(),a})["catch"](c.exception),c.addNotification({message:a,type:"error"})})})},{init:function(){return new g}}}); \ No newline at end of file diff --git a/amd/src/policyactions.js b/amd/src/policyactions.js index ae70f48..b3de54a 100644 --- a/amd/src/policyactions.js +++ b/amd/src/policyactions.js @@ -65,43 +65,55 @@ function($, Ajax, Notification, ModalFactory, ModalEvents) { args: params }; + var modalTitle = $.Deferred(); + var modalBody = $.Deferred(); + + var modal = ModalFactory.create({ + title: modalTitle, + body: modalBody, + large: true + }) + .then(function(modal) { + // Handle hidden event. + modal.getRoot().on(ModalEvents.hidden, function() { + // Destroy when hidden. + modal.destroy(); + }); + + return modal; + }) + .then(function(modal) { + modal.show(); + + return modal; + }) + .catch(Notification.exception); + + // Make the request now that the modal is configured. var promises = Ajax.call([request]); - var modalTitle = ''; - var modalType = ModalFactory.types.DEFAULT; $.when(promises[0]).then(function(data) { if (data.result.policy) { - modalTitle = data.result.policy.name; - return data.result.policy.content; + modalTitle.resolve(data.result.policy.name); + modalBody.resolve(data.result.policy.content); + + return data; + } else { + throw new Error(data.warnings[0].message); } - // Fail. - Notification.addNotification({ - message: data.warnings[0].message, + }).catch(function(message) { + modal.then(function(modal) { + modal.hide(); + modal.destroy(); + + return modal; + }) + .catch(Notification.exception); + + return Notification.addNotification({ + message: message, type: 'error' }); - return false; - - }).then(function(html) { - if (html != false) { - return ModalFactory.create({ - title: modalTitle, - body: html, - type: modalType, - large: true - }).then(function(modal) { - // Handle hidden event. - modal.getRoot().on(ModalEvents.hidden, function() { - // Destroy when hidden. - modal.destroy(); - }); - - return modal; - }); - } - return false; - }).done(function(modal) { - // Show the modal. - modal.show(); - }).fail(Notification.exception); + }); }); }; From aa739212d6ed4877386881b702ec7a1fc17aa8dc Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Thu, 9 Aug 2018 14:10:59 +0800 Subject: [PATCH 2/5] MDL-63094 tool_policy: Fix the cookie banner to the bottom Floating banners cause issues with clickability in Behat as it is unable to understand that it cannot interact with the elements underneath the floating banner, or that it needs to scroll the page so that the required content is no longer beneath the floating banner. Changing the banner to be fixed to the bottom of the page during Behat runes is a reliable fix. --- styles.css | 4 ++++ tests/behat/consent.feature | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/styles.css b/styles.css index 5bebc1a..52bf795 100644 --- a/styles.css +++ b/styles.css @@ -10,6 +10,10 @@ z-index: 9999999; } +.behat-site .eupopup-container-bottom { + position: relative; +} + .eupopup-container-bottom { position: fixed; bottom: 0; diff --git a/tests/behat/consent.feature b/tests/behat/consent.feature index 482e6a1..492d6d8 100644 --- a/tests/behat/consent.feature +++ b/tests/behat/consent.feature @@ -460,7 +460,6 @@ Feature: User must accept policy managed by this plugin when logging in and sign | This privacy policy | 1 | | full text3 | short text3 | active | loggedin | | This guests policy | 0 | | full text4 | short text4 | active | guest | And I am on site homepage - And I change window size to "large" And I follow "Log in" When I press "Log in as a guest" Then I should see "If you continue browsing this website, you agree to our policies" From 6f590ef5beee41fb0fa36e2a4020db9ce06a25c8 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Thu, 30 Aug 2018 11:14:43 +0800 Subject: [PATCH 3/5] =?UTF-8?q?MDL-63094=20tool=5Fpolicy:=20Replace=20'?= =?UTF-8?q?=C3=97'=20with=20'.close'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This relates to MDL-59883, which was not backported to 33 and beyond. --- tests/behat/consent.feature | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/behat/consent.feature b/tests/behat/consent.feature index 492d6d8..ee52d88 100644 --- a/tests/behat/consent.feature +++ b/tests/behat/consent.feature @@ -472,11 +472,11 @@ Feature: User must accept policy managed by this plugin when logging in and sign # Confirm when clicking on the policy links, the policy content is displayed. When I click on "This site policy" "link" Then I should see "full text2" - And I click on "×" "button" + And I click on ".close" "css_element" And I should not see "full text2" When I click on "This guests policy" "link" Then I should see "full text4" - And I click on "×" "button" + And I click on ".close" "css_element" And I should not see "full text4" # Confirm when agreeing to policies the pop-up is no longer displayed. When I follow "Continue" From ba3ec3bc6c6cefce5c7d4a81dae8a4891321c88c Mon Sep 17 00:00:00 2001 From: Mihail Geshoski Date: Wed, 25 Jul 2018 15:50:41 +0800 Subject: [PATCH 4/5] MDL-62342 privacy: Use singular/plural form in labels --- classes/form/accept_policy.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/classes/form/accept_policy.php b/classes/form/accept_policy.php index f53af7a..3ff0daf 100644 --- a/classes/form/accept_policy.php +++ b/classes/form/accept_policy.php @@ -71,10 +71,12 @@ public function definition() { $mform->addElement('hidden', 'returnurl'); $mform->setType('returnurl', PARAM_LOCALURL); - - $mform->addElement('static', 'user', get_string('acceptanceusers', 'tool_policy'), join(', ', $usernames)); - $mform->addElement('static', 'policy', get_string('acceptancepolicies', 'tool_policy'), - join(', ', $versionnames)); + $useracceptancelabel = (count($usernames) > 1) ? get_string('acceptanceusers', 'tool_policy') : + get_string('user'); + $mform->addElement('static', 'user', $useracceptancelabel, join(', ', $usernames)); + $policyacceptancelabel = (count($versionnames) > 1) ? get_string('acceptancepolicies', 'tool_policy') : + get_string('policydochdrpolicy', 'tool_policy'); + $mform->addElement('static', 'policy', $policyacceptancelabel, join(', ', $versionnames)); if ($revoke) { $mform->addElement('static', 'ack', '', get_string('revokeacknowledgement', 'tool_policy')); From bde59b623798ccede87190ae53cd55cd8f80c5be Mon Sep 17 00:00:00 2001 From: Mihail Geshoski Date: Wed, 29 Aug 2018 11:48:55 +0800 Subject: [PATCH 5/5] MDL-62342 privacy: Fix strings used in the consent on behalf modal --- lang/en/tool_policy.php | 8 ++++---- tests/behat/acceptances.feature | 30 +++++++++++++++--------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lang/en/tool_policy.php b/lang/en/tool_policy.php index 3a75285..192cebb 100644 --- a/lang/en/tool_policy.php +++ b/lang/en/tool_policy.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); -$string['acceptanceacknowledgement'] = 'I acknowledge that I have received a request to give consent on behalf of user(s).'; +$string['acceptanceacknowledgement'] = 'I acknowledge that I have received a request to give consent on behalf of the above user(s).'; $string['acceptancecount'] = '{$a->agreedcount} of {$a->policiescount}'; $string['acceptancenote'] = 'Remarks'; $string['acceptancepolicies'] = 'Policies'; @@ -52,7 +52,7 @@ $string['agreepolicies'] = 'Please agree to the following policies'; $string['backtotop'] = 'Back to top'; $string['consentbulk'] = 'Consent'; -$string['consentdetails'] = 'Give consent on behalf of user'; +$string['consentdetails'] = 'Give consent on behalf of user(s)'; $string['consentpagetitle'] = 'Consent'; $string['contactdpo'] = 'For any questions about the policies please contact the privacy officer.'; $string['dataproc'] = 'Personal data processing'; @@ -77,7 +77,7 @@ $string['guestconsent:continue'] = 'Continue'; $string['guestconsentmessage'] = 'If you continue browsing this website, you agree to our policies:'; $string['iagree'] = 'I agree to the {$a}'; -$string['iagreetothepolicy'] = 'Give consent on behalf of user'; +$string['iagreetothepolicy'] = 'Give consent'; $string['inactivate'] = 'Set status to "Inactive"'; $string['inactivating'] = 'Inactivating a policy'; $string['inactivatingconfirm'] = '

You are about to inactivate policy \'{$a->name}\' version \'{$a->revision}\'.

'; @@ -158,7 +158,7 @@ $string['privacysettings'] = 'Privacy settings'; $string['readpolicy'] = 'Please read our {$a}'; $string['refertofullpolicytext'] = 'Please refer to the full {$a} if you would like to review the text.'; -$string['revokeacknowledgement'] = 'I acknowledge that I have received a request to withdraw consent on behalf of user(s).'; +$string['revokeacknowledgement'] = 'I acknowledge that I have received a request to withdraw consent on behalf of the above user(s).'; $string['revokedetails'] = 'Withdraw user consent'; $string['save'] = 'Save'; $string['saveasdraft'] = 'Save as draft'; diff --git a/tests/behat/acceptances.feature b/tests/behat/acceptances.feature index b8c6d6e..3d436d4 100644 --- a/tests/behat/acceptances.feature +++ b/tests/behat/acceptances.feature @@ -58,12 +58,12 @@ Feature: Viewing acceptances reports and accepting on behalf of other users And I navigate to "Users > Privacy and policies > Manage policies" in site administration And I click on "1 of 4 (25%)" "link" in the "This site policy" "table_row" And I click on "Consent not given" "link" in the "User One" "table_row" - Then I should see "Give consent on behalf of user" + Then I should see "Give consent" And I should see "User One" And I should see "This site policy" - And I should see "I acknowledge that I have received a request to give consent on behalf of user(s)." + And I should see "I acknowledge that I have received a request to give consent on behalf of the above user(s)." And I set the field "Remarks" to "Consent received from a parent" - And I press "Give consent on behalf of user" + And I press "Give consent" And "Consent given on behalf of user" "icon" should exist in the "User One" "table_row" And "Max Manager" "link" should exist in the "User One" "table_row" And "Consent received from a parent" "text" should exist in the "User One" "table_row" @@ -84,12 +84,12 @@ Feature: Viewing acceptances reports and accepting on behalf of other users And I navigate to "Users > Privacy and policies > Manage policies" in site administration And I click on "1 of 4 (25%)" "link" in the "This site policy" "table_row" And I click on "Consent not given" "link" in the "User One" "table_row" - Then I should see "Give consent on behalf of user" + Then I should see "Give consent" And I should see "User One" And I should see "This site policy" - And I should see "I acknowledge that I have received a request to give consent on behalf of user(s)." + And I should see "I acknowledge that I have received a request to give consent on behalf of the above user(s)." And I set the field "Remarks" to "Consent received from a parent" - And I press "Give consent on behalf of user" + And I press "Give consent" And "Consent given on behalf of user" "icon" should exist in the "User One" "table_row" And "Max Manager" "link" should exist in the "User One" "table_row" And "Consent received from a parent" "text" should exist in the "User One" "table_row" @@ -151,12 +151,12 @@ Feature: Viewing acceptances reports and accepting on behalf of other users And I press "Next" And I navigate to "Users > Privacy and policies > User agreements" in site administration And I click on "Consent not given; click to give consent on behalf of user for This site policy" "link" in the "User One" "table_row" - Then I should see "Give consent on behalf of user" + Then I should see "Give consent" And I should see "User One" And I should see "This site policy" - And I should see "I acknowledge that I have received a request to give consent on behalf of user(s)." + And I should see "I acknowledge that I have received a request to give consent on behalf of the above user(s)." And I set the field "Remarks" to "Consent received from a parent" - And I press "Give consent on behalf of user" + And I press "Give consent" And "Consent given on behalf of user" "icon" should exist in the "User One" "table_row" And "Consent not given; click to give consent on behalf of user for This privacy policy" "icon" should exist in the "User One" "table_row" And I click on "1 of 2" "link" in the "User One" "table_row" @@ -184,12 +184,12 @@ Feature: Viewing acceptances reports and accepting on behalf of other users And I press "Next" And I navigate to "Users > Privacy and policies > User agreements" in site administration And I click on "Consent not given; click to give consent on behalf of user for This site policy" "link" in the "User One" "table_row" - Then I should see "Give consent on behalf of user" + Then I should see "Give consent" And I should see "User One" And I should see "This site policy" - And I should see "I acknowledge that I have received a request to give consent on behalf of user(s)." + And I should see "I acknowledge that I have received a request to give consent on behalf of the above user(s)." And I set the field "Remarks" to "Consent received from a parent" - And I press "Give consent on behalf of user" + And I press "Give consent" And "Consent given on behalf of user" "icon" should exist in the "User One" "table_row" And "Consent not given; click to give consent on behalf of user for This privacy policy" "icon" should exist in the "User One" "table_row" And I click on "1 of 2" "link" in the "User One" "table_row" @@ -249,12 +249,12 @@ Feature: Viewing acceptances reports and accepting on behalf of other users And I navigate to "Users > Privacy and policies > Manage policies" in site administration And I click on "1 of 4 (25%)" "link" in the "This site policy" "table_row" And I click on "Consent not given" "link" in the "User One" "table_row" - Then I should see "Give consent on behalf of user" + Then I should see "Give consent" And I should see "User One" And I should see "This site policy" - And I should see "I acknowledge that I have received a request to give consent on behalf of user(s)." + And I should see "I acknowledge that I have received a request to give consent on behalf of the above user(s)." And I set the field "Remarks" to "Consent received from a parent" - And I press "Give consent on behalf of user" + And I press "Give consent" And "Consent given on behalf of user" "icon" should exist in the "User One" "table_row" And "Max Manager" "link" should not exist in the "User One" "table_row" And "Admin User" "link" should exist in the "User One" "table_row"