From b957460b7b8fb41358f52b5a215b8178aecd7683 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 27 Mar 2019 19:41:01 +0000 Subject: [PATCH] Privacy: Ensure the privacy data erase fulfillment email is sent in the locale of the user whose data is being erased (or the site's default locale if they are not a registered user) when the administrator fulfilling the request uses a different locale. Props desrosj, birgire, garrett-eclipse. Fixes #44721. git-svn-id: https://develop.svn.wordpress.org/trunk@45039 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/user.php | 13 ++ tests/phpunit/data/languages/de_DE.mo | Bin 699 -> 777 bytes tests/phpunit/data/languages/de_DE.po | 11 +- tests/phpunit/data/languages/es_ES.mo | Bin 855 -> 939 bytes tests/phpunit/data/languages/es_ES.po | 11 +- ...vacySendErasureFulfillmentNotification.php | 169 +++++++++++++++++- 6 files changed, 197 insertions(+), 7 deletions(-) diff --git a/src/wp-includes/user.php b/src/wp-includes/user.php index 752b92dcde..6b7a974dbb 100644 --- a/src/wp-includes/user.php +++ b/src/wp-includes/user.php @@ -3140,6 +3140,15 @@ function _wp_privacy_send_erasure_fulfillment_notification( $request_id ) { return; } + // Localize message content for user; fallback to site default for visitors. + if ( ! empty( $request->user_id ) ) { + $locale = get_user_locale( $request->user_id ); + } else { + $locale = get_locale(); + } + + $switched_locale = switch_to_locale( $locale ); + /** * Filters the recipient of the data erasure fulfillment notification. * @@ -3250,6 +3259,10 @@ All at ###SITENAME### $email_sent = wp_mail( $user_email, $subject, $content ); + if ( $switched_locale ) { + restore_previous_locale(); + } + if ( $email_sent ) { update_post_meta( $request_id, '_wp_user_notified', true ); } diff --git a/tests/phpunit/data/languages/de_DE.mo b/tests/phpunit/data/languages/de_DE.mo index b65a14e19c98eb3c4294921179ff799e95d444c2..3698ce3fda3e65a3b6db942142c49644de9ccf51 100644 GIT binary patch delta 318 zcmdnZ+R0XbPl#nI0}yZku?!H$05LZZ&jDf(I03}GKztI2rGfZ55X%AaXCM{^Vj)I| zxEhpp0@6Z2@i-uD48(;%EC%E+Wny5E2hw|hG)Vs)AkE6a;KuM9$N;KgU}T2S%s?85 z7+9fvAd`U&h}nS{;#NJmXw~9a1=pg);?km2g`m{J($wM-1-H_i zw9K5G)Rc*jN_j1H4UBb-%oU7`tc=Vjr!dZEG@8u9q{3{fXEa%xsYw@Xg3sY?#mO0o mrD-KaiRlW7rN!x~X@~b@6qPWfr0Tl3GUzbqG31mKF#rIt&oih1 delta 241 zcmeBV+s#^kPl#nI0}!wSu?!H005LZZ_W&^n>;Ph3Al?bY(m;G1h=qapF_ixuN((bG zFbDzJ`as$kh@F5~49G8IVqlO5(!D^M6-ciI(m*MO%@Ep*VJncq3>4T7l>joq3PCi; zQ6K=60t1jb79eJucvNq)5Mv3ig|2~xuA#Alp{13f<>bkX^BD~%8#Adeo9J0ij$&%! TOG(vrab?h9&|}CcDPjNsOk^8{ diff --git a/tests/phpunit/data/languages/de_DE.po b/tests/phpunit/data/languages/de_DE.po index 4d66b76c10..c3ff771d5e 100644 --- a/tests/phpunit/data/languages/de_DE.po +++ b/tests/phpunit/data/languages/de_DE.po @@ -2,13 +2,13 @@ # This file is distributed under the same license as the 4.9.x package. msgid "" msgstr "" -"PO-Revision-Date: 2018-08-13 19:19+0300\n" +"PO-Revision-Date: 2019-03-27 22:27+0300\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Poedit 2.1.1\n" -"Project-Id-Version: Development (4.9.x)\n" +"X-Generator: Poedit 2.2.1\n" +"Project-Id-Version: Development (5.2.x)\n" "Language: de_DE\n" "POT-Creation-Date: \n" "Last-Translator: \n" @@ -48,3 +48,8 @@ msgstr "Jetzt %s aktualisieren" #: wp-includes/user.php:3445 msgid "[%1$s] Confirm Action: %2$s" msgstr "[%1$s] Aktion bestätigen: %2$s" + +#. translators: %s: Site name. +#: wp-includes/user.php:3175 +msgid "[%s] Erasure Request Fulfilled" +msgstr "[%s] Löschauftrag ausgeführt" diff --git a/tests/phpunit/data/languages/es_ES.mo b/tests/phpunit/data/languages/es_ES.mo index d4c5767eafdbf2e2d7ed13638bbe72dfefc68f20..3fe721e0018eb94dba6696bfb16c297d9e68a9a3 100644 GIT binary patch delta 314 zcmcc4wwk^Eo)F7a1|Z-7Vi_Qg0b*_-o&&@nZ~};JfcPX33jr}3BLjmpkd_3}azNS? z$`66k1wb04t_MgP1Mz$y_5t!QGchoT18D_jAO_MFKw5=?!Hppj$N(8w2c&s`^ei9^ zL=4M;1W+#+fcPK>0?mK}b|8xdh}nRcb>h|nxoFkmSOwRj#NyJTRE40_!qU{@5(T%? zoV3iGoYa)bDvXJ|mbwPUx<=*-Mn+af=94Ee&Sx~5Y{aC(Y^rB8Ig;t33fPF?{G80> i%#zX+g_KlX{N0Em5n{3T2b4B|lgBal`A(wxi?eOf@8hk?P2!41d&B8Fff0n`HqAU?=J zKs|8424t}SF)K)9;?aW1A&d#U7Puser->create_and_get( + array( + 'user_email' => self::$requester_email, + 'role' => 'subscriber', + ) + ); + self::$admin_user = $factory->user->create_and_get( + array( + 'user_email' => 'admin@local.dev', + 'role' => 'administrator', + ) + ); + + self::$request_id = wp_create_user_request( self::$requester_email, 'remove_personal_data' ); wp_update_post( array( 'ID' => self::$request_id, @@ -69,6 +100,7 @@ class Tests_Privacy_WpPrivacySendErasureFulfillmentNotification extends WP_UnitT */ public function tearDown() { reset_phpmailer_instance(); + restore_previous_locale(); parent::tearDown(); } @@ -276,4 +308,139 @@ class Tests_Privacy_WpPrivacySendErasureFulfillmentNotification extends WP_UnitT $this->assertFalse( metadata_exists( 'post', self::$request_id, '_wp_user_notified' ) ); } + /** + * The function should respect the user locale settings when the site uses the default locale. + * + * @since 5.2.0 + * @ticket 44721 + * @group l10n + */ + public function test_should_send_fulfillment_email_in_user_locale() { + update_user_meta( self::$request_user->ID, 'locale', 'es_ES' ); + + _wp_privacy_send_erasure_fulfillment_notification( self::$request_id ); + $mailer = tests_retrieve_phpmailer_instance(); + + $this->assertContains( 'Solicitud de borrado completada', $mailer->get_sent()->subject ); + } + + /** + * The function should respect the user locale settings when the site does not use en_US, the administrator + * uses the site's default locale, and the user has a different locale. + * + * @since 5.2.0 + * @ticket 44721 + * @group l10n + */ + public function test_should_send_fulfillment_email_in_user_locale_when_site_is_not_en_us() { + update_option( 'WPLANG', 'es_ES' ); + switch_to_locale( 'es_ES' ); + + update_user_meta( self::$request_user->ID, 'locale', 'de_DE' ); + wp_set_current_user( self::$admin_user->ID ); + + _wp_privacy_send_erasure_fulfillment_notification( self::$request_id ); + $mailer = tests_retrieve_phpmailer_instance(); + + $this->assertContains( 'Löschauftrag ausgeführt', $mailer->get_sent()->subject ); + } + + /** + * The function should respect the user locale settings when the site is not en_US, the administrator + * has a different selected locale, and the user uses the site's default locale. + * + * @since 5.2.0 + * @ticket 44721 + * @group l10n + */ + public function test_should_send_fulfillment_email_in_user_locale_when_admin_and_site_have_different_locales() { + update_option( 'WPLANG', 'es_ES' ); + switch_to_locale( 'es_ES' ); + + update_user_meta( self::$admin_user->ID, 'locale', 'de_DE' ); + wp_set_current_user( self::$admin_user->ID ); + + _wp_privacy_send_erasure_fulfillment_notification( self::$request_id ); + $mailer = tests_retrieve_phpmailer_instance(); + + $this->assertContains( 'Solicitud de borrado completada', $mailer->get_sent()->subject ); + } + + /** + * The function should respect the user locale settings when the site is not en_US and both the + * administrator and the user use different locales. + * + * @since 5.2.0 + * @ticket 44721 + * @group l10n + */ + public function test_should_send_fulfillment_email_in_user_locale_when_both_have_different_locales_than_site() { + update_option( 'WPLANG', 'es_ES' ); + switch_to_locale( 'es_ES' ); + + update_user_meta( self::$admin_user->ID, 'locale', 'en_US' ); + update_user_meta( self::$request_user->ID, 'locale', 'de_DE' ); + + wp_set_current_user( self::$admin_user->ID ); + + _wp_privacy_send_erasure_fulfillment_notification( self::$request_id ); + $mailer = tests_retrieve_phpmailer_instance(); + + $this->assertContains( 'Löschauftrag ausgeführt', $mailer->get_sent()->subject ); + } + + /** + * The function should respect the site's locale when the request is for an unregistered user and the + * administrator does not use the site's locale. + * + * @since 5.2.0 + * @ticket 44721 + * @group l10n + */ + public function test_should_send_fulfillment_email_in_site_locale() { + update_user_meta( self::$admin_user->ID, 'locale', 'es_ES' ); + wp_set_current_user( self::$admin_user->ID ); + + $request_id = wp_create_user_request( 'erase-user-not-registered@example.com', 'remove_personal_data' ); + wp_update_post( + array( + 'ID' => $request_id, + 'post_status' => 'request-completed', + ) + ); + + _wp_privacy_send_erasure_fulfillment_notification( $request_id ); + $mailer = tests_retrieve_phpmailer_instance(); + + $this->assertContains( 'Erasure Request Fulfilled', $mailer->get_sent()->subject ); + } + + /** + * The function should respect the site's locale when it is not en_US, the request is for an + * unregistered user, and the administrator does not use the site's default locale. + * + * @since 5.2.0 + * @ticket 44721 + * @group l10n + */ + public function test_should_send_fulfillment_email_in_site_locale_when_not_en_us_and_admin_has_different_locale() { + update_option( 'WPLANG', 'es_ES' ); + switch_to_locale( 'es_ES' ); + + update_user_meta( self::$admin_user->ID, 'locale', 'de_DE' ); + wp_set_current_user( self::$admin_user->ID ); + + $request_id = wp_create_user_request( 'erase-user-not-registered@example.com', 'remove_personal_data' ); + wp_update_post( + array( + 'ID' => $request_id, + 'post_status' => 'request-completed', + ) + ); + + _wp_privacy_send_erasure_fulfillment_notification( $request_id ); + $mailer = tests_retrieve_phpmailer_instance(); + + $this->assertContains( 'Solicitud de borrado completada', $mailer->get_sent()->subject ); + } }