Make WordPress Core

Ticket #43602: 43602.4.diff

File 43602.4.diff, 11.8 KB (added by allendav, 5 years ago)

Removed ajax-actions which was inadvertently included from 43637

  • src/wp-admin/includes/user.php

     
    709709 * @access private
    710710 */
    711711function _wp_personal_data_handle_actions() {
    712         if ( isset( $_POST['export_personal_data_email_retry'] ) ) { // WPCS: input var ok.
     712        if ( isset( $_POST['privacy_action_email_retry'] ) ) { // WPCS: input var ok.
    713713                check_admin_referer( 'bulk-privacy_requests' );
    714714
    715                 $request_id = absint( current( array_keys( (array) wp_unslash( $_POST['export_personal_data_email_retry'] ) ) ) ); // WPCS: input var ok, sanitization ok.
     715                $request_id = absint( current( array_keys( (array) wp_unslash( $_POST['privacy_action_email_retry'] ) ) ) ); // WPCS: input var ok, sanitization ok.
    716716                $result     = _wp_privacy_resend_request( $request_id );
    717717
    718718                if ( is_wp_error( $result ) ) {
    719719                        add_settings_error(
    720                                 'export_personal_data_email_retry',
    721                                 'export_personal_data_email_retry',
     720                                'privacy_action_email_retry',
     721                                'privacy_action_email_retry',
    722722                                $result->get_error_message(),
    723723                                'error'
    724724                        );
    725725                } else {
    726726                        add_settings_error(
    727                                 'export_personal_data_email_retry',
    728                                 'export_personal_data_email_retry',
     727                                'privacy_action_email_retry',
     728                                'privacy_action_email_retry',
    729729                                __( 'Confirmation request re-resent successfully.' ),
    730730                                'updated'
    731731                        );
     
    908908
    909909        _wp_personal_data_handle_actions();
    910910
     911        // "Borrow" xfn.js for now so we don't have to create new files.
     912        wp_enqueue_script( 'xfn' );
     913
    911914        $requests_table = new WP_Privacy_Data_Removal_Requests_Table( array(
    912915                'plural'   => 'privacy_requests',
    913916                'singular' => 'privacy_request',
    914917        ) );
     918
    915919        $requests_table->process_bulk_action();
    916920        $requests_table->prepare_items();
     921
    917922        ?>
    918923        <div class="wrap nosubsub">
    919924                <h1><?php esc_html_e( 'Remove Personal Data' ); ?></h1>
     
    13581363         * @return string
    13591364         */
    13601365        public function column_email( $item ) {
     1366                $exporters       = apply_filters( 'wp_privacy_personal_data_exporters', array() );
     1367                $exporters_count = count( $exporters );
     1368                $request_id      = $item['request_id'];
     1369                $nonce           = wp_create_nonce( 'wp-privacy-export-personal-data-' . $request_id );
     1370
     1371                $download_data_markup = '<div class="download_personal_data" data-exporters-count="' . esc_attr( $exporters_count ) . '" data-request-id="' . esc_attr( $request_id ) . '" data-nonce="' . esc_attr( $nonce ) . '">' .
     1372                        '<span class="download_personal_data_idle"><a href="#" >' . __( 'Download Personal Data' ) . '</a></span>' .
     1373                        '<span style="display:none" class="download_personal_data_processing" >' . __( 'Downloading Data...' ) . '</span>' .
     1374                        '<span style="display:none" class="download_personal_data_failed">' . __( 'Download Failed!' ) . ' <a href="#" >' . __( 'Retry' ) . '</a></span>';
     1375
    13611376                $row_actions = array(
    1362                         'download_data' => __( 'Download Personal Data' ),
     1377                        'download_data' => $download_data_markup,
    13631378                );
    13641379
    13651380                return sprintf( '%1$s %2$s', $item['email'], $this->row_actions( $row_actions ) );
     
    13831398                                // TODO Complete in follow on patch.
    13841399                                break;
    13851400                        case 'request-failed':
    1386                                 submit_button( __( 'Retry' ), 'secondary', 'export_personal_data_email_retry[' . $item['request_id'] . ']', false );
     1401                                submit_button( __( 'Retry' ), 'secondary', 'privacy_action_email_retry[' . $item['request_id'] . ']', false );
    13871402                                break;
    13881403                        case 'request-completed':
    13891404                                echo '<a href="' . esc_url( wp_nonce_url( add_query_arg( array(
     
    14281443         * @return string
    14291444         */
    14301445        public function column_email( $item ) {
    1431                 $row_actions = array(
    1432                         // TODO Complete in follow on patch.
    1433                         'remove_data' => __( 'Remove Personal Data' ),
    1434                 );
     1446                $row_actions = array();
    14351447
    1436                 // If we have a user ID, include a delete user action.
    1437                 if ( ! empty( $item['user_id'] ) ) {
    1438                         // TODO Complete in follow on patch.
    1439                         $row_actions['delete_user'] = __( 'Delete User' );
     1448                // Allow the administrator to "force remove" the personal data even if confirmation has not yet been received
     1449                $status = get_post_status( $item['request_id'] );
     1450                if ( 'request-confirmed' !== $status ) {
     1451                        $erasers       = apply_filters( 'wp_privacy_personal_data_erasers', array() );
     1452                        $erasers_count = count( $erasers );
     1453                        $request_id    = $item['request_id'];
     1454                        $nonce         = wp_create_nonce( 'wp-privacy-erase-personal-data-' . $request_id );
     1455
     1456                        $remove_data_markup = '<div class="remove_personal_data force_remove_personal_data" data-erasers-count="' . esc_attr( $erasers_count ) . '" data-request-id="' . esc_attr( $request_id ) . '" data-nonce="' . esc_attr( $nonce ) . '">' .
     1457                                '<span class="remove_personal_data_idle"><a href="#" >' . __( 'Force Remove Personal Data' ) . '</a></span>' .
     1458                                '<span style="display:none" class="remove_personal_data_processing" >' . __( 'Removing Data...' ) . '</span>' .
     1459                                '<span style="display:none" class="remove_personal_data_failed">' . __( 'Force Remove Failed!' ) . ' <a href="#" >' . __( 'Retry' ) . '</a></span>';
     1460
     1461                        $row_actions = array(
     1462                                'remove_data' => $remove_data_markup,
     1463                        );
    14401464                }
    14411465
    14421466                return sprintf( '%1$s %2$s', $item['email'], $this->row_actions( $row_actions ) );
     
    14501474         * @param array $item Item being shown.
    14511475         */
    14521476        public function column_next_steps( $item ) {
     1477                $status = get_post_status( $item['request_id'] );
     1478
     1479                switch ( $status ) {
     1480                        case 'request-pending':
     1481                                esc_html_e( 'Waiting for confirmation' );
     1482                                break;
     1483                        case 'request-confirmed':
     1484                                $erasers       = apply_filters( 'wp_privacy_personal_data_erasers', array() );
     1485                                $erasers_count = count( $erasers );
     1486                                $request_id    = $item['request_id'];
     1487                                $nonce         = wp_create_nonce( 'wp-privacy-erase-personal-data-' . $request_id );
     1488
     1489                                $remove_data_markup = '<div class="remove_personal_data" data-force-erase="1" data-erasers-count="' . esc_attr( $erasers_count ) . '" data-request-id="' . esc_attr( $request_id ) . '" data-nonce="' . esc_attr( $nonce ) . '">' .
     1490                                        '<span class="remove_personal_data_idle"><a class="button" href="#" >' . __( 'Remove Personal Data' ) . '</a></span>' .
     1491                                        '<span style="display:none" class="remove_personal_data_processing button updating-message" >' . __( 'Removing Data...' ) . '</span>' .
     1492                                        '<span style="display:none" class="remove_personal_data_failed">' . __( 'Removing Data Failed!' ) . ' <a class="button" href="#" >' . __( 'Retry' ) . '</a></span>';
     1493
     1494                                echo $remove_data_markup;
     1495                                break;
     1496                        case 'request-failed':
     1497                                submit_button( __( 'Retry' ), 'secondary', 'privacy_action_email_retry[' . $item['request_id'] . ']', false );
     1498                                break;
     1499                        case 'request-completed':
     1500                                echo '<a href="' . esc_url( wp_nonce_url( add_query_arg( array(
     1501                                        'action' => 'delete',
     1502                                        'request_id' => array( $item['request_id'] )
     1503                                ), admin_url( 'tools.php?page=remove_personal_data' ) ), 'bulk-privacy_requests' ) ) . '">' . esc_html__( 'Remove request' ) . '</a>';
     1504                                break;
     1505                }
    14531506        }
    14541507
    14551508}
  • src/wp-admin/js/xfn.js

     
    2020                $( '#link_rel' ).val( ( isMe ) ? 'me' : inputs.substr( 0,inputs.length - 1 ) );
    2121        });
    2222});
     23
     24// Privacy request action handling
     25
     26jQuery( document ).ready( function( $ ) {
     27        var strings = window.privacyToolsL10n || {};
     28
     29        function set_action_state( $action, state ) {
     30                $action.children().hide();
     31                $action.children( '.' + state ).show();
     32        }
     33
     34        function clearResultsAfterRow( $requestRow ) {
     35                if ( $requestRow.next().hasClass( 'request-results' ) ) {
     36                        $requestRow.next().remove();
     37                }
     38        }
     39
     40        function appendResultsAfterRow( $requestRow, classes, summaryMessage, additionalMessages ) {
     41                clearResultsAfterRow( $requestRow );
     42                if ( additionalMessages.length ) {
     43                        // TODO - render additionalMessages after the summaryMessage
     44                }
     45
     46                $requestRow.after( function() {
     47                        return '<tr class="request-results"><td colspan="5"><div class="notice inline notice-alt ' + classes + '"><p>' +
     48                                summaryMessage +
     49                                '</p></div></td></tr>';
     50                } );
     51        }
     52
     53        $( '.remove_personal_data a' ).click( function( event ) {
     54                event.preventDefault();
     55                event.stopPropagation();
     56
     57                var $this         = $( this );
     58                var $action       = $this.parents( '.remove_personal_data' );
     59                var $requestRow   = $this.parents( 'tr' );
     60                var requestID     = $action.data( 'request-id' );
     61                var nonce         = $action.data( 'nonce' );
     62                var erasersCount  = $action.data( 'erasers-count' );
     63
     64                var removedCount  = 0;
     65                var retainedCount = 0;
     66                var messages      = [];
     67
     68                $action.blur();
     69                clearResultsAfterRow( $requestRow );
     70
     71                function on_erasure_done_success() {
     72                        set_action_state( $action, 'remove_personal_data_idle' );
     73                        var summaryMessage = strings.noDataFound;
     74                        var classes = 'notice-success';
     75                        if ( 0 == removedCount ) {
     76                                if ( 0 == retainedCount ) {
     77                                        summaryMessage = strings.noDataFound;
     78                                } else {
     79                                        summaryMessage = strings.noneRemoved;
     80                                        classes = 'notice-warning';
     81                                }
     82                        } else {
     83                                if ( 0 == retainedCount ) {
     84                                        summaryMessage = strings.foundAndRemoved;
     85                                } else {
     86                                        summaryMessage = strings.someNotRemoved;
     87                                        classes = 'notice-warning';
     88                                }
     89                        }
     90                        appendResultsAfterRow( $requestRow, 'notice-success', summaryMessage, [] );
     91                }
     92
     93                function on_erasure_failure( textStatus, error ) {
     94                        set_action_state( $action, 'remove_personal_data_failed' );
     95                        appendResultsAfterRow( $requestRow, 'notice-error', strings.anErrorOccurred, [] );
     96                }
     97
     98                function do_next_erasure( eraserIndex, pageIndex ) {
     99                        $.ajax( {
     100                                url: ajaxurl,
     101                                data: {
     102                                        action: 'wp-privacy-erase-personal-data',
     103                                        eraser: eraserIndex,
     104                                        id: requestID,
     105                                        page: pageIndex,
     106                                        security: nonce,
     107                                },
     108                                method: 'post'
     109                        } ).done( function( response ) {
     110                                if ( ! response.success ) {
     111                                        on_erasure_failure( 'error', response.data );
     112                                        return;
     113                                }
     114                                var responseData = response.data;
     115                                if ( responseData.num_items_removed ) {
     116                                        removedCount += responseData.num_items_removed;
     117                                }
     118                                if ( responseData.num_items_retained ) {
     119                                        retainedCount += responseData.num_items_removed;
     120                                }
     121                                if ( responseData.messages ) {
     122                                        messages = messages.concat( responseData.messages );
     123                                }
     124                                if ( ! responseData.done ) {
     125                                        setTimeout( do_next_erasure( eraserIndex, pageIndex + 1 ) );
     126                                } else {
     127                                        if ( eraserIndex < erasersCount ) {
     128                                                setTimeout( do_next_erasure( eraserIndex + 1, 1 ) );
     129                                        } else {
     130                                                on_erasure_done_success();
     131                                        }
     132                                }
     133                        } ).fail( function( jqxhr, textStatus, error ) {
     134                                on_erasure_failure( textStatus, error );
     135                        } );
     136                }
     137
     138                // And now, let's begin
     139                set_action_state( $action, 'remove_personal_data_processing' );
     140
     141                do_next_erasure( 1, 1 );
     142        } )
     143} );
  • src/wp-includes/script-loader.php

     
    709709                );
    710710
    711711                $scripts->add( 'xfn', "/wp-admin/js/xfn$suffix.js", array( 'jquery' ), false, 1 );
     712                did_action( 'init' ) && $scripts->localize(
     713                        'xfn', 'privacyToolsL10n', array(
     714                                'noDataFound'     => __( 'No personal data was found for this user.' ),
     715                                'foundAndRemoved' => __( 'All of the personal data found for this user was removed.' ),
     716                                'noneRemoved'     => __( 'Personal data was found for this user but was not removed.' ),
     717                                'someNotRemoved'  => __( 'Personal data was found for this user but some of the personal data found was not removed.' ),
     718                                'anErrorOccurred' => __( 'An error occurred while attempting to find and remove personal data.' ),
     719                        )
     720                );
    712721
    713722                $scripts->add( 'postbox', "/wp-admin/js/postbox$suffix.js", array( 'jquery-ui-sortable' ), false, 1 );
    714723                did_action( 'init' ) && $scripts->localize(