2019-05-26 22:50:53 +02:00
|
|
|
/**
|
|
|
|
* Interactions used by the User Privacy tools in WordPress.
|
|
|
|
*
|
|
|
|
* @output wp-admin/js/privacy-tools.js
|
|
|
|
*/
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Privacy request action handling.
|
2019-05-26 22:50:53 +02:00
|
|
|
jQuery( document ).ready( function( $ ) {
|
2020-07-02 13:11:06 +02:00
|
|
|
var __ = wp.i18n.__,
|
2020-06-30 15:56:03 +02:00
|
|
|
copiedNoticeTimeout;
|
2019-05-26 22:50:53 +02:00
|
|
|
|
|
|
|
function setActionState( $action, state ) {
|
2019-06-05 01:40:55 +02:00
|
|
|
$action.children().addClass( 'hidden' );
|
|
|
|
$action.children( '.' + state ).removeClass( 'hidden' );
|
2019-05-26 22:50:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function clearResultsAfterRow( $requestRow ) {
|
|
|
|
$requestRow.removeClass( 'has-request-results' );
|
|
|
|
|
|
|
|
if ( $requestRow.next().hasClass( 'request-results' ) ) {
|
|
|
|
$requestRow.next().remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function appendResultsAfterRow( $requestRow, classes, summaryMessage, additionalMessages ) {
|
|
|
|
var itemList = '',
|
|
|
|
resultRowClasses = 'request-results';
|
|
|
|
|
|
|
|
clearResultsAfterRow( $requestRow );
|
|
|
|
|
|
|
|
if ( additionalMessages.length ) {
|
|
|
|
$.each( additionalMessages, function( index, value ) {
|
|
|
|
itemList = itemList + '<li>' + value + '</li>';
|
|
|
|
});
|
|
|
|
itemList = '<ul>' + itemList + '</ul>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$requestRow.addClass( 'has-request-results' );
|
|
|
|
|
|
|
|
if ( $requestRow.hasClass( 'status-request-confirmed' ) ) {
|
|
|
|
resultRowClasses = resultRowClasses + ' status-request-confirmed';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $requestRow.hasClass( 'status-request-failed' ) ) {
|
|
|
|
resultRowClasses = resultRowClasses + ' status-request-failed';
|
|
|
|
}
|
|
|
|
|
|
|
|
$requestRow.after( function() {
|
|
|
|
return '<tr class="' + resultRowClasses + '"><th colspan="5">' +
|
|
|
|
'<div class="notice inline notice-alt ' + classes + '">' +
|
|
|
|
'<p>' + summaryMessage + '</p>' +
|
|
|
|
itemList +
|
|
|
|
'</div>' +
|
|
|
|
'</td>' +
|
|
|
|
'</tr>';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$( '.export-personal-data-handle' ).click( function( event ) {
|
|
|
|
var $this = $( this ),
|
|
|
|
$action = $this.parents( '.export-personal-data' ),
|
|
|
|
$requestRow = $this.parents( 'tr' ),
|
2020-02-10 22:38:08 +01:00
|
|
|
$progress = $requestRow.find( '.export-progress' ),
|
2020-03-01 00:45:07 +01:00
|
|
|
$rowActions = $this.parents( '.row-actions' ),
|
2019-05-26 22:50:53 +02:00
|
|
|
requestID = $action.data( 'request-id' ),
|
|
|
|
nonce = $action.data( 'nonce' ),
|
|
|
|
exportersCount = $action.data( 'exporters-count' ),
|
|
|
|
sendAsEmail = $action.data( 'send-as-email' ) ? true : false;
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
|
2020-03-01 00:45:07 +01:00
|
|
|
$rowActions.addClass( 'processing' );
|
|
|
|
|
2019-05-26 22:50:53 +02:00
|
|
|
$action.blur();
|
|
|
|
clearResultsAfterRow( $requestRow );
|
2020-02-10 21:19:05 +01:00
|
|
|
setExportProgress( 0 );
|
2019-05-26 22:50:53 +02:00
|
|
|
|
|
|
|
function onExportDoneSuccess( zipUrl ) {
|
2020-07-02 13:11:06 +02:00
|
|
|
var summaryMessage = __( 'The personal data export link for this user was sent.' );
|
2019-10-06 08:56:02 +02:00
|
|
|
|
2019-05-26 22:50:53 +02:00
|
|
|
setActionState( $action, 'export-personal-data-success' );
|
2019-10-06 08:56:02 +02:00
|
|
|
|
|
|
|
appendResultsAfterRow( $requestRow, 'notice-success', summaryMessage, [] );
|
2020-02-10 21:19:05 +01:00
|
|
|
|
2019-05-26 22:50:53 +02:00
|
|
|
if ( 'undefined' !== typeof zipUrl ) {
|
|
|
|
window.location = zipUrl;
|
|
|
|
} else if ( ! sendAsEmail ) {
|
2020-07-02 13:11:06 +02:00
|
|
|
onExportFailure( __( 'No personal data export file was generated.' ) );
|
2019-05-26 22:50:53 +02:00
|
|
|
}
|
2020-03-01 00:45:07 +01:00
|
|
|
|
2020-06-30 15:56:03 +02:00
|
|
|
setTimeout( function() { $rowActions.removeClass( 'processing' ); }, 500 );
|
2019-05-26 22:50:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onExportFailure( errorMessage ) {
|
2020-07-02 13:11:06 +02:00
|
|
|
var summaryMessage = __( 'An error occurred while attempting to export personal data.' );
|
|
|
|
|
2019-05-26 22:50:53 +02:00
|
|
|
setActionState( $action, 'export-personal-data-failed' );
|
2020-07-02 13:11:06 +02:00
|
|
|
|
2019-05-26 22:50:53 +02:00
|
|
|
if ( errorMessage ) {
|
2020-07-02 13:11:06 +02:00
|
|
|
appendResultsAfterRow( $requestRow, 'notice-error', summaryMessage, [ errorMessage ] );
|
2019-05-26 22:50:53 +02:00
|
|
|
}
|
2020-03-01 00:45:07 +01:00
|
|
|
|
2020-06-30 15:56:03 +02:00
|
|
|
setTimeout( function() { $rowActions.removeClass( 'processing' ); }, 500 );
|
2019-05-26 22:50:53 +02:00
|
|
|
}
|
|
|
|
|
2020-02-10 21:19:05 +01:00
|
|
|
function setExportProgress( exporterIndex ) {
|
2020-06-30 15:56:03 +02:00
|
|
|
var progress = ( exportersCount > 0 ? exporterIndex / exportersCount : 0 ),
|
|
|
|
progressString = Math.round( progress * 100 ).toString() + '%';
|
|
|
|
|
2020-02-10 21:19:05 +01:00
|
|
|
$progress.html( progressString );
|
|
|
|
}
|
|
|
|
|
2019-05-26 22:50:53 +02:00
|
|
|
function doNextExport( exporterIndex, pageIndex ) {
|
|
|
|
$.ajax(
|
|
|
|
{
|
|
|
|
url: window.ajaxurl,
|
|
|
|
data: {
|
|
|
|
action: 'wp-privacy-export-personal-data',
|
|
|
|
exporter: exporterIndex,
|
|
|
|
id: requestID,
|
|
|
|
page: pageIndex,
|
|
|
|
security: nonce,
|
|
|
|
sendAsEmail: sendAsEmail
|
|
|
|
},
|
|
|
|
method: 'post'
|
|
|
|
}
|
|
|
|
).done( function( response ) {
|
|
|
|
var responseData = response.data;
|
|
|
|
|
|
|
|
if ( ! response.success ) {
|
2020-01-29 01:45:18 +01:00
|
|
|
// e.g. invalid request ID.
|
2020-06-30 15:56:03 +02:00
|
|
|
setTimeout( function() { onExportFailure( response.data ); }, 500 );
|
2019-05-26 22:50:53 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! responseData.done ) {
|
|
|
|
setTimeout( doNextExport( exporterIndex, pageIndex + 1 ) );
|
|
|
|
} else {
|
2020-03-01 00:45:07 +01:00
|
|
|
setExportProgress( exporterIndex );
|
2019-05-26 22:50:53 +02:00
|
|
|
if ( exporterIndex < exportersCount ) {
|
|
|
|
setTimeout( doNextExport( exporterIndex + 1, 1 ) );
|
|
|
|
} else {
|
2020-06-30 15:56:03 +02:00
|
|
|
setTimeout( function() { onExportDoneSuccess( responseData.url ); }, 500 );
|
2019-05-26 22:50:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}).fail( function( jqxhr, textStatus, error ) {
|
2020-01-29 01:45:18 +01:00
|
|
|
// e.g. Nonce failure.
|
2020-06-30 15:56:03 +02:00
|
|
|
setTimeout( function() { onExportFailure( error ); }, 500 );
|
2019-05-26 22:50:53 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// And now, let's begin.
|
2019-05-26 22:50:53 +02:00
|
|
|
setActionState( $action, 'export-personal-data-processing' );
|
|
|
|
doNextExport( 1, 1 );
|
|
|
|
});
|
|
|
|
|
|
|
|
$( '.remove-personal-data-handle' ).click( function( event ) {
|
|
|
|
var $this = $( this ),
|
|
|
|
$action = $this.parents( '.remove-personal-data' ),
|
|
|
|
$requestRow = $this.parents( 'tr' ),
|
2020-02-10 22:38:08 +01:00
|
|
|
$progress = $requestRow.find( '.erasure-progress' ),
|
2020-03-01 00:45:07 +01:00
|
|
|
$rowActions = $this.parents( '.row-actions' ),
|
2019-05-26 22:50:53 +02:00
|
|
|
requestID = $action.data( 'request-id' ),
|
|
|
|
nonce = $action.data( 'nonce' ),
|
|
|
|
erasersCount = $action.data( 'erasers-count' ),
|
|
|
|
hasRemoved = false,
|
|
|
|
hasRetained = false,
|
|
|
|
messages = [];
|
|
|
|
|
2020-03-01 00:45:07 +01:00
|
|
|
event.preventDefault();
|
2019-05-26 22:50:53 +02:00
|
|
|
event.stopPropagation();
|
|
|
|
|
2020-03-01 00:45:07 +01:00
|
|
|
$rowActions.addClass( 'processing' );
|
|
|
|
|
2019-05-26 22:50:53 +02:00
|
|
|
$action.blur();
|
|
|
|
clearResultsAfterRow( $requestRow );
|
2020-02-10 21:19:05 +01:00
|
|
|
setErasureProgress( 0 );
|
2019-05-26 22:50:53 +02:00
|
|
|
|
|
|
|
function onErasureDoneSuccess() {
|
2020-07-02 13:11:06 +02:00
|
|
|
var summaryMessage = __( 'No personal data was found for this user.' ),
|
2020-06-30 15:56:03 +02:00
|
|
|
classes = 'notice-success';
|
2019-05-26 22:50:53 +02:00
|
|
|
|
2019-09-23 21:13:58 +02:00
|
|
|
setActionState( $action, 'remove-personal-data-success' );
|
2019-05-26 22:50:53 +02:00
|
|
|
|
|
|
|
if ( false === hasRemoved ) {
|
|
|
|
if ( false === hasRetained ) {
|
2020-07-02 13:11:06 +02:00
|
|
|
summaryMessage = __( 'No personal data was found for this user.' );
|
2019-05-26 22:50:53 +02:00
|
|
|
} else {
|
2020-07-02 13:11:06 +02:00
|
|
|
summaryMessage = __( 'Personal data was found for this user but was not erased.' );
|
2019-05-26 22:50:53 +02:00
|
|
|
classes = 'notice-warning';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ( false === hasRetained ) {
|
2020-07-02 13:11:06 +02:00
|
|
|
summaryMessage = __( 'All of the personal data found for this user was erased.' );
|
2019-05-26 22:50:53 +02:00
|
|
|
} else {
|
2020-07-02 13:11:06 +02:00
|
|
|
summaryMessage = __( 'Personal data was found for this user but some of the personal data found was not erased.' );
|
2019-05-26 22:50:53 +02:00
|
|
|
classes = 'notice-warning';
|
|
|
|
}
|
|
|
|
}
|
2019-10-06 08:56:02 +02:00
|
|
|
appendResultsAfterRow( $requestRow, classes, summaryMessage, messages );
|
2020-03-01 00:45:07 +01:00
|
|
|
|
2020-06-30 15:56:03 +02:00
|
|
|
setTimeout( function() { $rowActions.removeClass( 'processing' ); }, 500 );
|
2019-05-26 22:50:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onErasureFailure() {
|
2020-07-02 13:11:06 +02:00
|
|
|
var summaryMessage = __( 'An error occurred while attempting to find and erase personal data.' );
|
|
|
|
|
2019-05-26 22:50:53 +02:00
|
|
|
setActionState( $action, 'remove-personal-data-failed' );
|
2020-07-02 13:11:06 +02:00
|
|
|
|
|
|
|
appendResultsAfterRow( $requestRow, 'notice-error', summaryMessage, [] );
|
2020-03-01 00:45:07 +01:00
|
|
|
|
2020-06-30 15:56:03 +02:00
|
|
|
setTimeout( function() { $rowActions.removeClass( 'processing' ); }, 500 );
|
2019-05-26 22:50:53 +02:00
|
|
|
}
|
|
|
|
|
2020-02-10 21:19:05 +01:00
|
|
|
function setErasureProgress( eraserIndex ) {
|
2020-06-30 15:56:03 +02:00
|
|
|
var progress = ( erasersCount > 0 ? eraserIndex / erasersCount : 0 ),
|
|
|
|
progressString = Math.round( progress * 100 ).toString() + '%';
|
|
|
|
|
2020-02-10 21:19:05 +01:00
|
|
|
$progress.html( progressString );
|
|
|
|
}
|
|
|
|
|
2019-05-26 22:50:53 +02:00
|
|
|
function doNextErasure( eraserIndex, pageIndex ) {
|
|
|
|
$.ajax({
|
|
|
|
url: window.ajaxurl,
|
|
|
|
data: {
|
|
|
|
action: 'wp-privacy-erase-personal-data',
|
|
|
|
eraser: eraserIndex,
|
|
|
|
id: requestID,
|
|
|
|
page: pageIndex,
|
|
|
|
security: nonce
|
|
|
|
},
|
|
|
|
method: 'post'
|
|
|
|
}).done( function( response ) {
|
|
|
|
var responseData = response.data;
|
|
|
|
|
|
|
|
if ( ! response.success ) {
|
2020-06-30 15:56:03 +02:00
|
|
|
setTimeout( function() { onErasureFailure(); }, 500 );
|
2019-05-26 22:50:53 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( responseData.items_removed ) {
|
|
|
|
hasRemoved = hasRemoved || responseData.items_removed;
|
|
|
|
}
|
|
|
|
if ( responseData.items_retained ) {
|
|
|
|
hasRetained = hasRetained || responseData.items_retained;
|
|
|
|
}
|
|
|
|
if ( responseData.messages ) {
|
|
|
|
messages = messages.concat( responseData.messages );
|
|
|
|
}
|
|
|
|
if ( ! responseData.done ) {
|
|
|
|
setTimeout( doNextErasure( eraserIndex, pageIndex + 1 ) );
|
|
|
|
} else {
|
2020-03-01 00:45:07 +01:00
|
|
|
setErasureProgress( eraserIndex );
|
2019-05-26 22:50:53 +02:00
|
|
|
if ( eraserIndex < erasersCount ) {
|
|
|
|
setTimeout( doNextErasure( eraserIndex + 1, 1 ) );
|
|
|
|
} else {
|
2020-06-30 15:56:03 +02:00
|
|
|
setTimeout( function() { onErasureDoneSuccess(); }, 500 );
|
2019-05-26 22:50:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}).fail( function() {
|
2020-06-30 15:56:03 +02:00
|
|
|
setTimeout( function() { onErasureFailure(); }, 500 );
|
2019-05-26 22:50:53 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// And now, let's begin.
|
2019-05-26 22:50:53 +02:00
|
|
|
setActionState( $action, 'remove-personal-data-processing' );
|
|
|
|
|
|
|
|
doNextErasure( 1, 1 );
|
|
|
|
});
|
|
|
|
|
2020-04-12 16:26:11 +02:00
|
|
|
// Privacy Policy page, copy action.
|
2019-05-26 22:50:53 +02:00
|
|
|
$( document ).on( 'click', function( event ) {
|
2020-04-12 16:26:11 +02:00
|
|
|
var $parent,
|
|
|
|
$container,
|
|
|
|
range,
|
|
|
|
$target = $( event.target ),
|
|
|
|
copiedNotice = $target.siblings( '.success' );
|
2019-05-26 22:50:53 +02:00
|
|
|
|
2020-06-30 15:56:03 +02:00
|
|
|
clearTimeout( copiedNoticeTimeout );
|
|
|
|
|
2019-05-26 22:50:53 +02:00
|
|
|
if ( $target.is( 'button.privacy-text-copy' ) ) {
|
|
|
|
$parent = $target.parent().parent();
|
|
|
|
$container = $parent.find( 'div.wp-suggested-text' );
|
|
|
|
|
|
|
|
if ( ! $container.length ) {
|
|
|
|
$container = $parent.find( 'div.policy-text' );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $container.length ) {
|
|
|
|
try {
|
2020-03-03 18:51:05 +01:00
|
|
|
var documentPosition = document.documentElement.scrollTop,
|
|
|
|
bodyPosition = document.body.scrollTop;
|
|
|
|
|
2020-04-12 16:26:11 +02:00
|
|
|
// Setup copy.
|
2019-05-26 22:50:53 +02:00
|
|
|
window.getSelection().removeAllRanges();
|
2020-04-12 16:26:11 +02:00
|
|
|
|
|
|
|
// Hide tutorial content to remove from copied content.
|
2019-05-26 22:50:53 +02:00
|
|
|
range = document.createRange();
|
|
|
|
$container.addClass( 'hide-privacy-policy-tutorial' );
|
|
|
|
|
2020-04-12 16:26:11 +02:00
|
|
|
// Copy action.
|
2019-05-26 22:50:53 +02:00
|
|
|
range.selectNodeContents( $container[0] );
|
|
|
|
window.getSelection().addRange( range );
|
|
|
|
document.execCommand( 'copy' );
|
|
|
|
|
2020-04-12 16:26:11 +02:00
|
|
|
// Reset section.
|
2019-05-26 22:50:53 +02:00
|
|
|
$container.removeClass( 'hide-privacy-policy-tutorial' );
|
|
|
|
window.getSelection().removeAllRanges();
|
2020-03-03 18:51:05 +01:00
|
|
|
|
2020-04-12 16:26:11 +02:00
|
|
|
// Return scroll position - see #49540.
|
2020-03-03 18:51:05 +01:00
|
|
|
if ( documentPosition > 0 && documentPosition !== document.documentElement.scrollTop ) {
|
|
|
|
document.documentElement.scrollTop = documentPosition;
|
|
|
|
} else if ( bodyPosition > 0 && bodyPosition !== document.body.scrollTop ) {
|
|
|
|
document.body.scrollTop = bodyPosition;
|
|
|
|
}
|
2020-04-12 16:26:11 +02:00
|
|
|
|
|
|
|
// Display and speak notice to indicate action complete.
|
|
|
|
copiedNotice.addClass( 'visible' );
|
|
|
|
wp.a11y.speak( __( 'The section has been copied to your clipboard.' ) );
|
|
|
|
|
|
|
|
// Delay notice dismissal.
|
2020-06-30 15:56:03 +02:00
|
|
|
copiedNoticeTimeout = setTimeout( function() {
|
|
|
|
copiedNotice.removeClass( 'visible' );
|
|
|
|
}, 3000 );
|
2019-05-26 22:50:53 +02:00
|
|
|
} catch ( er ) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|