Skip to content

Commit

Permalink
EZP-30128: Bulk delete - User account partially deleted (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
tischsoic authored and lserwatka committed Jul 16, 2019
1 parent 1ee9f01 commit b0011e4
Showing 9 changed files with 61 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Resources/public/js/ContentTree.module.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Resources/public/js/MultiFileUpload.module.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Resources/public/js/SubItems.module.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Resources/public/js/SubItems.module.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Resources/public/js/UniversalDiscovery.module.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Resources/public/js/UniversalDiscovery.module.js.map

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions Resources/translations/sub_items.en.xliff
Original file line number Diff line number Diff line change
@@ -12,8 +12,8 @@
<note>key: bulk_delete.error.message</note>
</trans-unit>
<trans-unit id="23c9d6861623cc0b2f5f454afa841f1e368123cc" resname="bulk_delete.error.modal.table_title">
<source>Content item(s) cannot be sent to trash (%itemsCount%)</source>
<target state="new">Content item(s) cannot be sent to trash (%itemsCount%)</target>
<source>Content item(s) cannot be deleted (%itemsCount%)</source>
<target state="new">Content item(s) cannot be deleted (%itemsCount%)</target>
<note>key: bulk_delete.error.modal.table_title</note>
</trans-unit>
<trans-unit id="c1ffafa700d4b0ba80a626363f9dfe853571e080" resname="bulk_delete.error.more_info">
@@ -27,18 +27,18 @@
<note>key: bulk_delete.popup.cancel</note>
</trans-unit>
<trans-unit id="a668a561527cc0e3e2c7952fbf300558d9d4f877" resname="bulk_delete.popup.confirm">
<source>Send to trash</source>
<target state="new">Send to trash</target>
<source>Delete</source>
<target state="new">Delete</target>
<note>key: bulk_delete.popup.confirm</note>
</trans-unit>
<trans-unit id="02d93b03435046c6bcf08ce15ae7970f7ff8f746" resname="bulk_delete.popup.message">
<source>Are you sure you want to send the selected content item(s) to trash?</source>
<target state="new">Are you sure you want to send the selected content item(s) to trash?</target>
<source>Are you sure you want to delete the selected content item(s)?</source>
<target>Are you sure you want to delete the selected content item(s)?</target>
<note>key: bulk_delete.popup.message</note>
</trans-unit>
<trans-unit id="684c07e2248d815e6eb6bc3f92d3cd49c6952cbe" resname="bulk_delete.success.message">
<source>The selected content item(s) have been sent to trash</source>
<target state="new">The selected content item(s) have been sent to trash</target>
<source>The selected content item(s) have been deleted</source>
<target state="new">The selected content item(s) have been deleted</target>
<note>key: bulk_delete.success.message</note>
</trans-unit>
<trans-unit id="364a3498e021163497d9110380736b876beb326f" resname="bulk_move.error.message">
49 changes: 37 additions & 12 deletions src/modules/sub-items/services/bulk.service.js
Original file line number Diff line number Diff line change
@@ -5,34 +5,59 @@ const HEADERS_BULK = {
'Content-Type': 'application/vnd.ez.api.BulkOperation+json',
};
const TRASH_FAKE_LOCATION = '/api/ezp/v2/content/trash';
const USER_ENDPOINT = '/api/ezp/v2/user/users';
const ENDPOINT_BULK = '/api/ezp/v2/bulk';

export const bulkMoveLocations = (restInfo, locations, newLocationHref, callback) => {
const requestBodyOperations = getBulkMoveRequestOperations(locations, newLocationHref);
const requestBodyOperations = {};

locations.forEach((location) => {
requestBodyOperations[location.id] = getBulkMoveRequestOperation(location, newLocationHref);
});

makeBulkRequest(restInfo, requestBodyOperations, processBulkResponse.bind(null, locations, callback));
};

export const bulkMoveLocationsToTrash = (restInfo, locations, callback) => {
console.warn('[DEPRECATED] bulkMoveLocationsToTrash function is deprecated');
console.warn('[DEPRECATED] it will be removed from ezplatform-admin-ui-modules 2.0');
console.warn('[DEPRECATED] use bulkDeleteItems instead');

bulkMoveLocations(restInfo, locations, TRASH_FAKE_LOCATION, callback);
};

const getBulkMoveRequestOperations = (locations, destination) => {
const operations = {};
export const bulkDeleteItems = (restInfo, items, contentTypesMap, callback) => {
const locations = items.map(({ location }) => location);
const requestBodyOperations = {};

locations.forEach((location) => {
operations[location.id] = {
uri: location._href,
method: 'MOVE',
headers: {
Destination: destination,
},
};
items.forEach(({ location, content }) => {
const contentType = contentTypesMap[content.ContentType._href];
const contentTypeIdentifier = contentType.identifier;
const isUserContentItem = window.eZ.adminUiConfig.userContentTypes.includes(contentTypeIdentifier);

if (isUserContentItem) {
requestBodyOperations[location.id] = getBulkDeleteUserRequestOperation(content);
} else {
requestBodyOperations[location.id] = getBulkMoveRequestOperation(location, TRASH_FAKE_LOCATION);
}
});

return operations;
makeBulkRequest(restInfo, requestBodyOperations, processBulkResponse.bind(null, locations, callback));
};

const getBulkDeleteUserRequestOperation = (content) => ({
uri: `${USER_ENDPOINT}/${content._id}`,
method: 'DELETE',
});

const getBulkMoveRequestOperation = (location, destination) => ({
uri: location._href,
method: 'MOVE',
headers: {
Destination: destination,
},
});

const processBulkResponse = (locations, callback, response) => {
const { operations } = response.BulkOperationResponse;
const locationsMatches = Object.entries(operations).reduce(
20 changes: 10 additions & 10 deletions src/modules/sub-items/sub.items.module.js
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ import Icon from '../common/icon/icon.js';

import deepClone from '../common/helpers/deep.clone.helper.js';
import { updateLocationPriority, loadLocation, loadContentInfo, loadContentType, loadContentTypes } from './services/sub.items.service';
import { bulkMoveLocations, bulkMoveLocationsToTrash } from './services/bulk.service.js';
import { bulkMoveLocations, bulkDeleteItems } from './services/bulk.service.js';

const ASCENDING_SORT_ORDER = 'ascending';
const DESCENDING_SORT_ORDER = 'descending';
@@ -466,7 +466,7 @@ export default class SubItemsModule extends Component {
/*@Desc("<u><a class='ez-notification-btn ez-notification-btn--show-modal'>Click here for more information.</a></u><br>")*/ 'bulk_move.error.more_info',
{},
'sub_items'
)
),
};

this.handleBulkOperationFailedNotification(selectedItems, notMovedLocations, modalTableTitle, notificationMessage, rawPlaceholdersMap);
@@ -543,10 +543,10 @@ export default class SubItemsModule extends Component {
this.toggleBulkOperationStatusState(true);

const { restInfo } = this.props;
const { selectedItems } = this.state;
const locationsToDelete = [...selectedItems.values()].map(({ location }) => location);
const { selectedItems, contentTypesMap } = this.state;
const itemsToDelete = [...selectedItems.values()];

bulkMoveLocationsToTrash(restInfo, locationsToDelete, this.afterBulkDelete.bind(this, selectedItems));
bulkDeleteItems(restInfo, itemsToDelete, contentTypesMap, this.afterBulkDelete.bind(this, selectedItems));
}

afterBulkDelete(selectedItems, deletedLocations, notDeletedLocations) {
@@ -561,7 +561,7 @@ export default class SubItemsModule extends Component {

if (notDeletedLocations.length) {
const modalTableTitle = Translator.trans(
/*@Desc("Content item(s) cannot be sent to trash (%itemsCount%)")*/ 'bulk_delete.error.modal.table_title',
/*@Desc("Content item(s) cannot be deleted (%itemsCount%)")*/ 'bulk_delete.error.modal.table_title',
{
itemsCount: notDeletedLocations.length,
},
@@ -581,13 +581,13 @@ export default class SubItemsModule extends Component {
/*@Desc("<u><a class='ez-notification-btn ez-notification-btn--show-modal'>Click here for more information.</a></u><br>")*/ 'bulk_delete.error.more_info',
{},
'sub_items'
)
),
};

this.handleBulkOperationFailedNotification(selectedItems, notDeletedLocations, modalTableTitle, message, rawPlaceholdersMap);
} else {
const message = Translator.trans(
/*@Desc("The selected content item(s) have been sent to trash")*/ 'bulk_delete.success.message',
/*@Desc("The selected content item(s) have been deleted")*/ 'bulk_delete.success.message',
{},
'sub_items'
);
@@ -653,7 +653,7 @@ export default class SubItemsModule extends Component {

renderConfirmationPopupFooter() {
const cancelLabel = Translator.trans(/*@Desc("Cancel")*/ 'bulk_delete.popup.cancel', {}, 'sub_items');
const confirmLabel = Translator.trans(/*@Desc("Send to trash")*/ 'bulk_delete.popup.confirm', {}, 'sub_items');
const confirmLabel = Translator.trans(/*@Desc("Delete")*/ 'bulk_delete.popup.confirm', {}, 'sub_items');

return (
<Fragment>
@@ -679,7 +679,7 @@ export default class SubItemsModule extends Component {
}

const confirmationMessage = Translator.trans(
/*@Desc("Are you sure you want to send the selected content item(s) to trash?")*/ 'bulk_delete.popup.message',
/*@Desc("Are you sure you want to delete the selected content item(s)?")*/ 'bulk_delete.popup.message',
{},
'sub_items'
);

0 comments on commit b0011e4

Please sign in to comment.