Ticket #44133: 44133.10.diff
File 44133.10.diff, 12.8 KB (added by , 6 years ago) |
---|
-
src/wp-admin/includes/admin-filters.php
135 135 // Privacy hooks 136 136 add_filter( 'wp_privacy_personal_data_erasure_page', 'wp_privacy_process_personal_data_erasure_page', 10, 5 ); 137 137 add_filter( 'wp_privacy_personal_data_export_page', 'wp_privacy_process_personal_data_export_page', 10, 7 ); 138 add_action( 'wp_privacy_personal_data_export_file', 'wp_privacy_generate_personal_data_export_file', 10 );138 add_action( 'wp_privacy_personal_data_export_file', 'wp_privacy_generate_personal_data_export_file', 10, 3 ); 139 139 add_action( 'wp_privacy_personal_data_erased', '_wp_privacy_send_erasure_fulfillment_notification', 10 ); 140 140 141 141 // Privacy policy text changes check. -
src/wp-admin/includes/file.php
2155 2155 * Generate the personal data export file. 2156 2156 * 2157 2157 * @since 4.9.6 2158 * @since 5.2.0 Added the $request parameter. 2159 * @since 5.2.0 Added the $has_export_data parameter. 2158 2160 * 2159 * @param int $request_id The export request ID. 2161 * @param int $request_id The export request ID. 2162 * 2163 * @param WP_User_Request $request The export request. 2164 * @param bool $has_export_data Wether there is personal data to export. 2160 2165 */ 2161 function wp_privacy_generate_personal_data_export_file( $request_id ) {2166 function wp_privacy_generate_personal_data_export_file( $request_id, $request, $has_export_data ) { 2162 2167 if ( ! class_exists( 'ZipArchive' ) ) { 2163 2168 wp_send_json_error( __( 'Unable to generate export file. ZipArchive not available.' ) ); 2164 2169 } 2165 2170 2166 // Get the request data. 2167 $request = wp_get_user_request_data( $request_id ); 2171 if ( ! $request ) { 2172 // Get the request data. 2173 $request = wp_get_user_request_data( $request_id ); 2174 } 2168 2175 2169 2176 if ( ! $request || 'export_personal_data' !== $request->action_name ) { 2170 2177 wp_send_json_error( __( 'Invalid request ID when generating export file.' ) ); … … 2274 2281 fwrite( $file, wp_privacy_generate_personal_data_export_group_html( $group_data ) ); 2275 2282 } 2276 2283 2284 if ( ! $has_export_data ) { 2285 fwrite( $file, '<strong>' . esc_html__( 'No personal data found.' ) . '</strong>' ); 2286 } 2287 2277 2288 fwrite( $file, "</body>\n" ); 2278 2289 2279 2290 // Close HTML. … … 2340 2351 /** 2341 2352 * Send an email to the user with a link to the personal data export file 2342 2353 * 2354 * The link to the export file is only included in the email content when there 2355 * is personal data to export. 2356 * 2343 2357 * @since 4.9.6 2358 * @since 5.2.0 Added the $has_export_data parameter. 2344 2359 * 2345 * @param int $request_id The request ID for this personal data export. 2360 * @param int $request_id The request ID for this personal data export. 2361 * @param bool $has_export_data Whether there is personal data to export. 2362 * 2346 2363 * @return true|WP_Error True on success or `WP_Error` on failure. 2347 2364 */ 2348 function wp_privacy_send_personal_data_export_email( $request_id ) {2365 function wp_privacy_send_personal_data_export_email( $request_id, $has_export_data = true ) { 2349 2366 // Get the request data. 2350 2367 $request = wp_get_user_request_data( $request_id ); 2351 2368 … … 2358 2375 $expiration_date = date_i18n( get_option( 'date_format' ), time() + $expiration ); 2359 2376 2360 2377 /* translators: Do not translate EXPIRATION, LINK, SITENAME, SITEURL: those are placeholders. */ 2361 $email_text = __(2362 'Howdy,2378 if ( $has_export_data ) { 2379 $email_text = __( 'Howdy, 2363 2380 2364 2381 Your request for an export of personal data has been completed. You may 2365 2382 download your personal data by clicking on the link below. For privacy … … 2370 2387 2371 2388 Regards, 2372 2389 All at ###SITENAME### 2373 ###SITEURL###' 2374 ); 2390 ###SITEURL###' ); 2375 2391 2376 /** 2377 * Filters the text of the email sent with a personal data export file. 2378 * 2379 * The following strings have a special meaning and will get replaced dynamically: 2380 * ###EXPIRATION### The date when the URL will be automatically deleted. 2381 * ###LINK### URL of the personal data export file for the user. 2382 * ###SITENAME### The name of the site. 2383 * ###SITEURL### The URL to the site. 2384 * 2385 * @since 4.9.6 2386 * 2387 * @param string $email_text Text in the email. 2388 * @param int $request_id The request ID for this personal data export. 2389 */ 2390 $content = apply_filters( 'wp_privacy_personal_data_email_content', $email_text, $request_id ); 2392 /** 2393 * Filters the text of the email sent when personal data exists to export. 2394 * 2395 * The following strings have a special meaning and will get replaced dynamically: 2396 * ###EXPIRATION### The date when the URL will be automatically deleted. 2397 * ###LINK### URL of the personal data export file for the user. 2398 * ###SITENAME### The name of the site. 2399 * ###SITEURL### The URL to the site. 2400 * 2401 * @since 4.9.6 2402 * @since 5.3.0 $has_export_data argument added. 2403 * 2404 * @param string $email_text Text in the email. 2405 * @param int $request_id The request ID for this personal data export. 2406 * @param bool $has_export_data Whether there is personal data to export. 2407 */ 2408 $content = apply_filters( 'wp_privacy_personal_data_email_content', $email_text, $request_id, $has_export_data ); 2409 } else { 2410 /* translators: Do not translate EXPIRATION, LINK, SITENAME, SITEURL: those are placeholders. */ 2411 $email_text = __( 'Howdy, 2412 Your request for an export of personal data has been completed. 2391 2413 2414 ###SITENAME### has identified no personal data associated with this email address. 2415 2416 You may download your personal data by clicking on the link below. For privacy 2417 and security, we will automatically delete the file on ###EXPIRATION###, 2418 so please download it before then. 2419 2420 ###LINK### 2421 2422 Regards, 2423 All at ###SITENAME### 2424 ###SITEURL###' ); 2425 2426 /** 2427 * Filters the text of the email sent when no personal data exists to export. 2428 * 2429 * The following strings have a special meaning and will get replaced dynamically: 2430 * ###EXPIRATION### The date when the URL will be automatically deleted. 2431 * ###LINK### URL of the personal data export file for the user. 2432 * ###SITENAME### The name of the site. 2433 * ###SITEURL### The URL to the site. 2434 * 2435 * @since 5.3.0 2436 * 2437 * @param string $email_text Text in the email. 2438 * @param int $request_id The request ID for this personal data export. 2439 * @param bool $has_export_data Whether there is personal data to export. 2440 */ 2441 $content = apply_filters( 'wp_privacy_personal_data_email_content_no_data', $email_text, $request_id, $has_export_data ); 2442 } 2443 2392 2444 $email_address = $request->email; 2393 2445 $export_file_url = get_post_meta( $request_id, '_export_file_url', true ); 2394 2446 $site_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); … … 2396 2448 2397 2449 $content = str_replace( '###EXPIRATION###', $expiration_date, $content ); 2398 2450 $content = str_replace( '###LINK###', esc_url_raw( $export_file_url ), $content ); 2399 $content = str_replace( '###EMAIL###', $email_address, $content );2400 2451 $content = str_replace( '###SITENAME###', $site_name, $content ); 2401 2452 $content = str_replace( '###SITEURL###', esc_url_raw( $site_url ), $content ); 2402 2453 … … 2508 2559 delete_post_meta( $request_id, '_export_data_raw' ); 2509 2560 update_post_meta( $request_id, '_export_data_grouped', $groups ); 2510 2561 2562 $has_export_data = ! empty( $groups ); 2563 2511 2564 /** 2512 2565 * Generate the export file from the collected, grouped personal data. 2513 2566 * 2514 2567 * @since 4.9.6 2568 * @since 5.3.0 Added the $request parameter. 2569 * @since 5.3.0 Added the $has_export_data parameter. 2515 2570 * 2516 * @param int $request_id The export request ID. 2571 * @param int $request_id The export request ID. 2572 * @param WP_User_Request $request The export request. 2573 * @param bool $has_export_data Whether there is personal data to export. 2517 2574 */ 2518 do_action( 'wp_privacy_personal_data_export_file', $request_id );2575 do_action( 'wp_privacy_personal_data_export_file', $request_id, $request, $has_export_data ); 2519 2576 2520 2577 // Clear the grouped data now that it is no longer needed. 2521 2578 delete_post_meta( $request_id, '_export_data_grouped' ); 2522 2579 2523 2580 // If the destination is email, send it now. 2524 2581 if ( $send_as_email ) { 2525 $mail_success = wp_privacy_send_personal_data_export_email( $request_id );2582 $mail_success = wp_privacy_send_personal_data_export_email( $request_id, $has_export_data ); 2526 2583 if ( is_wp_error( $mail_success ) ) { 2527 2584 wp_send_json_error( $mail_success->get_error_message() ); 2528 2585 } -
tests/phpunit/tests/privacy/wpPrivacyGeneratePersonalDataExportFile.php
26 26 protected static $export_request_id; 27 27 28 28 /** 29 * An Export Request 30 * 31 * @since 5.3.0 32 * 33 * @var int $export_request 34 */ 35 protected static $export_request; 36 37 /** 29 38 * The full path to the export file for the current test method. 30 39 * 31 40 * @since 5.2.0 … … 52 61 */ 53 62 public static function wpSetUpBeforeClass( $factory ) { 54 63 self::$export_request_id = wp_create_user_request( 'export-requester@example.com', 'export_personal_data' ); 64 self::$export_request = wp_get_user_request_data( self::$export_request_id ); 55 65 update_post_meta( self::$export_request_id, '_export_data_grouped', array() ); 56 66 self::$exports_dir = wp_privacy_exports_dir(); 57 67 } … … 162 172 */ 163 173 public function test_rejects_remove_requests() { 164 174 $request_id = wp_create_user_request( 'removal-requester@example.com', 'remove_personal_data' ); 175 $request = wp_get_user_request_data( $request_id ); 165 176 166 177 $this->setExpectedException( 'WPDieException' ); 167 178 $this->expectOutputString( '{"success":false,"data":"Invalid request ID when generating export file."}' ); 168 wp_privacy_generate_personal_data_export_file( $request_id );179 wp_privacy_generate_personal_data_export_file( $request_id, $request, false ); 169 180 } 170 181 171 182 /** … … 176 187 public function test_invalid_request_id() { 177 188 $this->setExpectedException( 'WPDieException' ); 178 189 $this->expectOutputString( '{"success":false,"data":"Invalid request ID when generating export file."}' ); 179 wp_privacy_generate_personal_data_export_file( 123456789 );190 wp_privacy_generate_personal_data_export_file( 123456789, null, false ); 180 191 } 181 192 182 193 /** … … 194 205 ) 195 206 ); 196 207 208 $request = wp_get_user_request_data( $request_id ); 209 197 210 $this->setExpectedException( 'WPDieException' ); 198 211 $this->expectOutputString( '{"success":false,"data":"Invalid email address when generating export file."}' ); 199 wp_privacy_generate_personal_data_export_file( $request_id );212 wp_privacy_generate_personal_data_export_file( $request_id, $request, false ); 200 213 } 201 214 202 215 /** … … 210 223 211 224 $this->setExpectedException( 'WPDieException' ); 212 225 $this->expectOutputString( '{"success":false,"data":"Unable to create export folder."}' ); 213 wp_privacy_generate_personal_data_export_file( self::$export_request_id );226 wp_privacy_generate_personal_data_export_file( self::$export_request_id, self::$export_request, false ); 214 227 } 215 228 216 229 /** 217 230 * Test that an index.html file can be added to the export directory. 218 231 * 219 232 * @ticket 44233 233 * @ticket 44133 Supplied new params for request and has_export_data 220 234 */ 221 235 public function test_creates_index_in_export_folder() { 222 236 $this->expectOutputString( '' ); 223 wp_privacy_generate_personal_data_export_file( self::$export_request_id );237 wp_privacy_generate_personal_data_export_file( self::$export_request_id, self::$export_request, false ); 224 238 225 239 $this->assertTrue( file_exists( self::$exports_dir . 'index.html' ) ); 226 240 } … … 229 243 * Test that an export file is successfully created. 230 244 * 231 245 * @ticket 44233 246 * @ticket 44133 Supplied new params for request and has_export_data 232 247 */ 233 248 public function test_can_succeed() { 234 wp_privacy_generate_personal_data_export_file( self::$export_request_id );249 wp_privacy_generate_personal_data_export_file( self::$export_request_id, self::$export_request, false ); 235 250 236 251 $this->assertTrue( file_exists( $this->export_file_name ) ); 237 252 } … … 240 255 * Test the export file has all the expected parts. 241 256 * 242 257 * @ticket 44233 258 * @ticket 44133 Supplied new params for request and has_export_data 243 259 */ 244 260 public function test_contents() { 245 261 $this->expectOutputString( '' ); 246 wp_privacy_generate_personal_data_export_file( self::$export_request_id );262 wp_privacy_generate_personal_data_export_file( self::$export_request_id, self::$export_request, false ); 247 263 $this->assertTrue( file_exists( $this->export_file_name ) ); 248 264 249 265 $report_dir = trailingslashit( self::$exports_dir . 'test_contents' );