Skip to content

Commit b0011e4

Browse files
tischsoiclserwatka
authored andcommitted
EZP-30128: Bulk delete - User account partially deleted (#197)
1 parent 1ee9f01 commit b0011e4

File tree

9 files changed

+61
-36
lines changed

9 files changed

+61
-36
lines changed

Resources/public/js/ContentTree.module.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Resources/public/js/MultiFileUpload.module.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Resources/public/js/SubItems.module.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Resources/public/js/SubItems.module.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Resources/public/js/UniversalDiscovery.module.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Resources/public/js/UniversalDiscovery.module.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Resources/translations/sub_items.en.xliff

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
<note>key: bulk_delete.error.message</note>
1313
</trans-unit>
1414
<trans-unit id="23c9d6861623cc0b2f5f454afa841f1e368123cc" resname="bulk_delete.error.modal.table_title">
15-
<source>Content item(s) cannot be sent to trash (%itemsCount%)</source>
16-
<target state="new">Content item(s) cannot be sent to trash (%itemsCount%)</target>
15+
<source>Content item(s) cannot be deleted (%itemsCount%)</source>
16+
<target state="new">Content item(s) cannot be deleted (%itemsCount%)</target>
1717
<note>key: bulk_delete.error.modal.table_title</note>
1818
</trans-unit>
1919
<trans-unit id="c1ffafa700d4b0ba80a626363f9dfe853571e080" resname="bulk_delete.error.more_info">
@@ -27,18 +27,18 @@
2727
<note>key: bulk_delete.popup.cancel</note>
2828
</trans-unit>
2929
<trans-unit id="a668a561527cc0e3e2c7952fbf300558d9d4f877" resname="bulk_delete.popup.confirm">
30-
<source>Send to trash</source>
31-
<target state="new">Send to trash</target>
30+
<source>Delete</source>
31+
<target state="new">Delete</target>
3232
<note>key: bulk_delete.popup.confirm</note>
3333
</trans-unit>
3434
<trans-unit id="02d93b03435046c6bcf08ce15ae7970f7ff8f746" resname="bulk_delete.popup.message">
35-
<source>Are you sure you want to send the selected content item(s) to trash?</source>
36-
<target state="new">Are you sure you want to send the selected content item(s) to trash?</target>
35+
<source>Are you sure you want to delete the selected content item(s)?</source>
36+
<target>Are you sure you want to delete the selected content item(s)?</target>
3737
<note>key: bulk_delete.popup.message</note>
3838
</trans-unit>
3939
<trans-unit id="684c07e2248d815e6eb6bc3f92d3cd49c6952cbe" resname="bulk_delete.success.message">
40-
<source>The selected content item(s) have been sent to trash</source>
41-
<target state="new">The selected content item(s) have been sent to trash</target>
40+
<source>The selected content item(s) have been deleted</source>
41+
<target state="new">The selected content item(s) have been deleted</target>
4242
<note>key: bulk_delete.success.message</note>
4343
</trans-unit>
4444
<trans-unit id="364a3498e021163497d9110380736b876beb326f" resname="bulk_move.error.message">

src/modules/sub-items/services/bulk.service.js

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,59 @@ const HEADERS_BULK = {
55
'Content-Type': 'application/vnd.ez.api.BulkOperation+json',
66
};
77
const TRASH_FAKE_LOCATION = '/api/ezp/v2/content/trash';
8+
const USER_ENDPOINT = '/api/ezp/v2/user/users';
89
const ENDPOINT_BULK = '/api/ezp/v2/bulk';
910

1011
export const bulkMoveLocations = (restInfo, locations, newLocationHref, callback) => {
11-
const requestBodyOperations = getBulkMoveRequestOperations(locations, newLocationHref);
12+
const requestBodyOperations = {};
13+
14+
locations.forEach((location) => {
15+
requestBodyOperations[location.id] = getBulkMoveRequestOperation(location, newLocationHref);
16+
});
1217

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

1621
export const bulkMoveLocationsToTrash = (restInfo, locations, callback) => {
22+
console.warn('[DEPRECATED] bulkMoveLocationsToTrash function is deprecated');
23+
console.warn('[DEPRECATED] it will be removed from ezplatform-admin-ui-modules 2.0');
24+
console.warn('[DEPRECATED] use bulkDeleteItems instead');
25+
1726
bulkMoveLocations(restInfo, locations, TRASH_FAKE_LOCATION, callback);
1827
};
1928

20-
const getBulkMoveRequestOperations = (locations, destination) => {
21-
const operations = {};
29+
export const bulkDeleteItems = (restInfo, items, contentTypesMap, callback) => {
30+
const locations = items.map(({ location }) => location);
31+
const requestBodyOperations = {};
2232

23-
locations.forEach((location) => {
24-
operations[location.id] = {
25-
uri: location._href,
26-
method: 'MOVE',
27-
headers: {
28-
Destination: destination,
29-
},
30-
};
33+
items.forEach(({ location, content }) => {
34+
const contentType = contentTypesMap[content.ContentType._href];
35+
const contentTypeIdentifier = contentType.identifier;
36+
const isUserContentItem = window.eZ.adminUiConfig.userContentTypes.includes(contentTypeIdentifier);
37+
38+
if (isUserContentItem) {
39+
requestBodyOperations[location.id] = getBulkDeleteUserRequestOperation(content);
40+
} else {
41+
requestBodyOperations[location.id] = getBulkMoveRequestOperation(location, TRASH_FAKE_LOCATION);
42+
}
3143
});
3244

33-
return operations;
45+
makeBulkRequest(restInfo, requestBodyOperations, processBulkResponse.bind(null, locations, callback));
3446
};
3547

48+
const getBulkDeleteUserRequestOperation = (content) => ({
49+
uri: `${USER_ENDPOINT}/${content._id}`,
50+
method: 'DELETE',
51+
});
52+
53+
const getBulkMoveRequestOperation = (location, destination) => ({
54+
uri: location._href,
55+
method: 'MOVE',
56+
headers: {
57+
Destination: destination,
58+
},
59+
});
60+
3661
const processBulkResponse = (locations, callback, response) => {
3762
const { operations } = response.BulkOperationResponse;
3863
const locationsMatches = Object.entries(operations).reduce(

src/modules/sub-items/sub.items.module.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Icon from '../common/icon/icon.js';
1212

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

1717
const ASCENDING_SORT_ORDER = 'ascending';
1818
const DESCENDING_SORT_ORDER = 'descending';
@@ -466,7 +466,7 @@ export default class SubItemsModule extends Component {
466466
/*@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',
467467
{},
468468
'sub_items'
469-
)
469+
),
470470
};
471471

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

545545
const { restInfo } = this.props;
546-
const { selectedItems } = this.state;
547-
const locationsToDelete = [...selectedItems.values()].map(({ location }) => location);
546+
const { selectedItems, contentTypesMap } = this.state;
547+
const itemsToDelete = [...selectedItems.values()];
548548

549-
bulkMoveLocationsToTrash(restInfo, locationsToDelete, this.afterBulkDelete.bind(this, selectedItems));
549+
bulkDeleteItems(restInfo, itemsToDelete, contentTypesMap, this.afterBulkDelete.bind(this, selectedItems));
550550
}
551551

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

562562
if (notDeletedLocations.length) {
563563
const modalTableTitle = Translator.trans(
564-
/*@Desc("Content item(s) cannot be sent to trash (%itemsCount%)")*/ 'bulk_delete.error.modal.table_title',
564+
/*@Desc("Content item(s) cannot be deleted (%itemsCount%)")*/ 'bulk_delete.error.modal.table_title',
565565
{
566566
itemsCount: notDeletedLocations.length,
567567
},
@@ -581,13 +581,13 @@ export default class SubItemsModule extends Component {
581581
/*@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',
582582
{},
583583
'sub_items'
584-
)
584+
),
585585
};
586586

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

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

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

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

0 commit comments

Comments
 (0)