From e983ad767027c0f7783ba13d48a55f60075dbb89 Mon Sep 17 00:00:00 2001 From: Mikolaj Adamczyk Date: Tue, 18 Feb 2020 13:21:51 +0100 Subject: [PATCH] EZP-31310: Fixed VersionDraftConflict for content having multiple locations (#1237) --- .../VersionDraftConflictController.php | 19 ++++++++++++++++--- src/bundle/Resources/config/routing.yml | 3 ++- .../public/js/scripts/admin.location.view.js | 5 +++-- .../js/scripts/sidebar/btn/location.edit.js | 7 ++++++- .../content/tab/versions/table.html.twig | 2 +- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/bundle/Controller/Content/VersionDraftConflictController.php b/src/bundle/Controller/Content/VersionDraftConflictController.php index ea777affe3..ce2944d90f 100644 --- a/src/bundle/Controller/Content/VersionDraftConflictController.php +++ b/src/bundle/Controller/Content/VersionDraftConflictController.php @@ -60,16 +60,20 @@ public function __construct( /** * @param int $contentId * @param string $languageCode + * @param int|null $locationId * * @return Response * + * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException */ - public function draftHasNoConflictAction(int $contentId, string $languageCode): Response - { + public function draftHasNoConflictAction( + int $contentId, + string $languageCode, + ?int $locationId = null + ): Response { $content = $this->contentService->loadContent($contentId); - $location = $this->locationService->loadLocation($content->contentInfo->mainLocationId); $contentInfo = $content->contentInfo; try { @@ -89,6 +93,15 @@ public function draftHasNoConflictAction(int $contentId, string $languageCode): $versionsDataset = $this->datasetFactory->versions(); $versionsDataset->load($contentInfo); $conflictedDrafts = $versionsDataset->getConflictedDraftVersions($contentInfo->currentVersionNo, $languageCode); + $locationId = $locationId ?? $contentInfo->mainLocationId; + try { + $location = $this->locationService->loadLocation($locationId); + } catch (UnauthorizedException $e) { + // Will return list of locations user has *read* access to, or empty array if none + $availableLocations = $this->locationService->loadLocations($contentInfo); + // will return null if array of availableLocations is empty + $location = array_shift($availableLocations); + } $modalContent = $this->renderView('@ezdesign/content/modal_draft_conflict.html.twig', [ 'conflicted_drafts' => $conflictedDrafts, diff --git a/src/bundle/Resources/config/routing.yml b/src/bundle/Resources/config/routing.yml index af2279411a..111fa9a198 100644 --- a/src/bundle/Resources/config/routing.yml +++ b/src/bundle/Resources/config/routing.yml @@ -494,11 +494,12 @@ ezplatform.version.has_no_conflict: languageCode: ~ ezplatform.version_draft.has_no_conflict: - path: /version-draft/has-no-conflict/{contentId}/{languageCode} + path: /version-draft/has-no-conflict/{contentId}/{languageCode}/{locationId} options: expose: true defaults: _controller: 'EzPlatformAdminUiBundle:Content\VersionDraftConflict:draftHasNoConflict' + locationId: ~ # LocationView / Locations tab diff --git a/src/bundle/Resources/public/js/scripts/admin.location.view.js b/src/bundle/Resources/public/js/scripts/admin.location.view.js index df74ba720b..67232e4cca 100644 --- a/src/bundle/Resources/public/js/scripts/admin.location.view.js +++ b/src/bundle/Resources/public/js/scripts/admin.location.view.js @@ -20,10 +20,11 @@ }, currentLanguage: mfuContainer.dataset.currentLanguage, }; - const handleEditItem = (content) => { + const handleEditItem = (content, location) => { const contentId = content._id; + const locationId = location._id; const languageCode = content.mainLanguageCode; - const checkVersionDraftLink = Routing.generate('ezplatform.version_draft.has_no_conflict', { contentId, languageCode }); + const checkVersionDraftLink = Routing.generate('ezplatform.version_draft.has_no_conflict', { contentId, languageCode, locationId }); const submitVersionEditForm = () => { doc.querySelector('#form_subitems_content_edit_content_info').value = contentId; doc.querySelector(`#form_subitems_content_edit_language_${languageCode}`).checked = true; diff --git a/src/bundle/Resources/public/js/scripts/sidebar/btn/location.edit.js b/src/bundle/Resources/public/js/scripts/sidebar/btn/location.edit.js index b8e62d0bd5..b6eace3b70 100644 --- a/src/bundle/Resources/public/js/scripts/sidebar/btn/location.edit.js +++ b/src/bundle/Resources/public/js/scripts/sidebar/btn/location.edit.js @@ -4,6 +4,8 @@ const form = editActions.querySelector('form'); const contentIdInput = form.querySelector('#content_edit_content_info') || form.querySelector('#user_edit_content_info'); const contentId = contentIdInput.value; + const locationInput = form.querySelector('#content_edit_location') || form.querySelector('#user_edit_location'); + const locationId = locationInput.value; const resetRadioButtons = () => btns.forEach((btn) => { btn.checked = false; @@ -48,7 +50,10 @@ const changeHandler = (event) => { const checkedBtn = event.currentTarget; const languageCode = checkedBtn.value; - const checkVersionDraftLink = global.Routing.generate('ezplatform.version_draft.has_no_conflict', { contentId, languageCode }); + const checkVersionDraftLink = global.Routing.generate( + 'ezplatform.version_draft.has_no_conflict', + { contentId, languageCode, locationId } + ); fetch(checkVersionDraftLink, { credentials: 'same-origin', diff --git a/src/bundle/Resources/views/content/tab/versions/table.html.twig b/src/bundle/Resources/views/content/tab/versions/table.html.twig index 7ed9061a6f..36b0efa13c 100644 --- a/src/bundle/Resources/views/content/tab/versions/table.html.twig +++ b/src/bundle/Resources/views/content/tab/versions/table.html.twig @@ -36,7 +36,7 @@ 'contentId': version.contentInfo.id, 'versionNo': version.versionNo, 'language': version.initialLanguageCode, - 'locationId': location.id + 'locationId': location.id ?? null }) %}