From 6f026f99a7e4ec24d628942568f53db4994e9c8e Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Tue, 21 Dec 2021 20:55:12 +0100 Subject: [PATCH] Some bugfixes --- .../DocumentFolderController.java | 80 ++++++++++-- .../documents/CmsMvcAuthoringSteps.java | 6 +- .../documents/DocumentController.java | 59 ++++++++- .../mpa/MpaSectionsStepModel.java | 3 + .../documentfolder/documentfolder.xhtml | 32 ++++- ...erties.xhtml => mpa-basicproperties.xhtml} | 0 .../ui/contenttypes/mpa/mpa-sections.xhtml | 119 ++++++++++-------- .../org/librecms/CmsAdminMessages.properties | 9 ++ .../librecms/CmsAdminMessages_de.properties | 9 ++ .../ui/contenttypes/ArticleBundle.properties | 2 +- .../contenttypes/ArticleBundle_de.properties | 2 +- .../ui/contenttypes/MpaStepsBundle.properties | 1 + .../contenttypes/MpaStepsBundle_de.properties | 1 + 13 files changed, 251 insertions(+), 72 deletions(-) rename ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contenttypes/mpa/{mpa-basic-properties.xhtml => mpa-basicproperties.xhtml} (100%) diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/DocumentFolderController.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/DocumentFolderController.java index 55f4a1375..ea5c58630 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/DocumentFolderController.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/DocumentFolderController.java @@ -55,8 +55,6 @@ import java.util.List; import java.util.Locale; import java.util.Objects; import java.util.Optional; -import java.util.SortedMap; -import java.util.TreeMap; import java.util.TreeSet; import java.util.stream.Collectors; @@ -736,6 +734,74 @@ public class DocumentFolderController { ); } + /** + * Deletes an empty folder. + * + * @param sectionIdentifier The identifier of the content section + * @param folderPath The path of the folder. + * + * @return A redirect to the parent folder. + */ + @POST + @Path("/@delete/{folderPath:(.+)?}") + @AuthorizationRequired + @Transactional(Transactional.TxType.REQUIRED) + public String deleteFolder( + @PathParam("sectionIdentifier") final String sectionIdentifier, + @PathParam("folderPath") final String folderPath + ) { + final Optional sectionResult = sectionsUi + .findContentSection(sectionIdentifier); + if (!sectionResult.isPresent()) { + return sectionsUi.showContentSectionNotFound(sectionIdentifier); + } + + final ContentSection section = sectionResult.get(); + if (!itemPermissionChecker.canEditItems(section)) { + return sectionsUi.showAccessDenied( + "sectionidentifier", sectionIdentifier + ); + } + + final Folder folder; + final Optional folderResult = folderRepo + .findByPath( + section, + folderPath, + FolderType.DOCUMENTS_FOLDER + ); + if (folderResult.isPresent()) { + folder = folderResult.get(); + + documentFolderModel.setBreadcrumbs(buildBreadcrumbs(folderPath)); + } else { + return showDocumentFolderNotFound(section, folderPath); + } + + if (!itemPermissionChecker.canDeleteItems(folder)) { + return sectionsUi.showAccessDenied( + "sectionidentifier", sectionIdentifier, + "folderPath", folderPath + ); + } + + final String parentFolderPath = Optional + .ofNullable(folder.getParentFolder()) + .map(folderManager::getFolderPath) + .orElse(""); + + if (folderManager.folderIsDeletable(folder) + == FolderManager.FolderIsDeletable.YES) { + folderManager.deleteFolder(folder); + } + + return String.format( + "redirect:/%s/documentfolders/%s", + sectionIdentifier, + parentFolderPath + ); + } + /** * A helper method for building the breadcrumb trail of a folder. * @@ -799,11 +865,11 @@ public class DocumentFolderController { row.setFolderPath( folderManager .getFolderPath(folder) -// .substring( -// folderManager -// .getFolderPath(section.getRootDocumentsFolder()) -// .length() -// ) + // .substring( + // folderManager + // .getFolderPath(section.getRootDocumentsFolder()) + // .length() + // ) ); row.setLanguages(Collections.emptySortedSet()); row.setLastEditPublished(false); diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/CmsMvcAuthoringSteps.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/CmsMvcAuthoringSteps.java index 5285892b0..ee4742a13 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/CmsMvcAuthoringSteps.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/CmsMvcAuthoringSteps.java @@ -25,6 +25,8 @@ import org.librecms.ui.contentsections.documents.relatedinfo.RelatedInfoStepServ import org.librecms.ui.contenttypes.article.MvcArticlePropertiesStep; import org.librecms.ui.contenttypes.article.MvcArticleTextBodyStep; import org.librecms.ui.contenttypes.article.MvcArticleTextBodyStepResources; +import org.librecms.ui.contenttypes.mpa.MvcMpaPropertiesStep; +import org.librecms.ui.contenttypes.mpa.MvcMpaSectionsStep; import java.util.Set; @@ -46,7 +48,9 @@ public class CmsMvcAuthoringSteps implements MvcAuthoringSteps { PublishStep.class, RelatedInfoStep.class, MvcArticlePropertiesStep.class, - MvcArticleTextBodyStep.class + MvcArticleTextBodyStep.class, + MvcMpaPropertiesStep.class, + MvcMpaSectionsStep.class ); } diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/DocumentController.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/DocumentController.java index 5aa021902..1d165edce 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/DocumentController.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/DocumentController.java @@ -26,6 +26,7 @@ import org.librecms.contentsection.ContentItemManager; import org.librecms.contentsection.ContentItemRepository; import org.librecms.contentsection.ContentSection; import org.librecms.contentsection.Folder; +import org.librecms.contentsection.FolderManager; import org.librecms.contentsection.FolderRepository; import org.librecms.contentsection.FolderType; import org.librecms.contentsection.privileges.ItemPrivileges; @@ -99,6 +100,9 @@ public class DocumentController { @Inject private DocumentUi documentUi; + @Inject + private FolderManager folderManager; + /** * {@link FolderRepository} instance for retrieving folders. */ @@ -766,6 +770,57 @@ public class DocumentController { ); } + /** + * Deletes a document. + * + * @param sectionIdentifier + * @param documentPath + * + * @return A redirect to the folder of the document. + */ + @POST + @Path("/{documentPath:(.+)?}/@delete") + @AuthorizationRequired + @Transactional(Transactional.TxType.REQUIRED) + public String deleteDocument( + @PathParam("sectionIdentifier") final String sectionIdentifier, + @PathParam("documentPath") final String documentPath + ) { + final Optional sectionResult = sectionsUi + .findContentSection(sectionIdentifier); + if (!sectionResult.isPresent()) { + return sectionsUi.showContentSectionNotFound(sectionIdentifier); + } + final ContentSection section = sectionResult.get(); + final Optional itemResult = itemRepo + .findByPath(section, documentPath); + if (!itemResult.isPresent()) { + return documentUi.showDocumentNotFound(section, documentPath); + } + final ContentItem item = itemResult.get(); + if (!permissionChecker.isPermitted(ItemPrivileges.DELETE, item)) { + return sectionsUi.showAccessDenied( + "sectionIdentifier", sectionIdentifier, + "documentPath", documentPath + ); + } + + final String folderPath = itemManager + .getItemFolder(item) + .map(folderManager::getFolderPath) + .orElse(""); + + if (!itemManager.isLive(item)) { + itemRepo.delete(item); + } + + return String.format( + "redirect:/%s/documentfolders/%s", + sectionIdentifier, + folderPath + ); + } + /** * Helper method for reading the authoring steps for the current content * item. @@ -814,7 +869,7 @@ public class DocumentController { .replace( String.format( "/{%s}", - MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM + MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM ), itemManager.getItemPath(item) ); @@ -905,7 +960,7 @@ public class DocumentController { * Helper method for showing the "document type not available" page if the * requested document type is not available for the current content section. * - * @param section The content section. + * @param section The content section. * @param documentType The folder path. * * @return The template of the "document type not found" page. diff --git a/ccm-cms/src/main/java/org/librecms/ui/contenttypes/mpa/MpaSectionsStepModel.java b/ccm-cms/src/main/java/org/librecms/ui/contenttypes/mpa/MpaSectionsStepModel.java index d8cb7ef2b..e640e9a75 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contenttypes/mpa/MpaSectionsStepModel.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contenttypes/mpa/MpaSectionsStepModel.java @@ -63,4 +63,7 @@ public class MpaSectionsStepModel { this.sections = new ArrayList<>(sections); } + public boolean getSectionsEmpty() { + return sections.isEmpty(); + } } diff --git a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/documentfolder/documentfolder.xhtml b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/documentfolder/documentfolder.xhtml index da746e34d..186f7178a 100644 --- a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/documentfolder/documentfolder.xhtml +++ b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/documentfolder/documentfolder.xhtml @@ -382,11 +382,33 @@ - + + + + + + + + + diff --git a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contenttypes/mpa/mpa-basic-properties.xhtml b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contenttypes/mpa/mpa-basicproperties.xhtml similarity index 100% rename from ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contenttypes/mpa/mpa-basic-properties.xhtml rename to ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contenttypes/mpa/mpa-basicproperties.xhtml diff --git a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contenttypes/mpa/mpa-sections.xhtml b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contenttypes/mpa/mpa-sections.xhtml index 8c91a4f21..46645c238 100644 --- a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contenttypes/mpa/mpa-sections.xhtml +++ b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contenttypes/mpa/mpa-sections.xhtml @@ -11,7 +11,7 @@ value="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documents/#{CmsSelectedDocumentModel.itemPath}/@mpa-sections" /> -

#{CmsMpaMessageBundle.getMessage('sectionsstep.header', CmsMpaSectionsStep.articleTitle)}

+

#{CmsMpaMessageBundle.getMessage('sectionsstep.header', [CmsMpaSectionsStep.articleTitle])}

@@ -95,60 +95,69 @@
- - - - - - - - - - - - - - - - - - - -
#{CmsMpaMessageBundle['sectionsstep.sections.section.title']}#{CmsMpaMessageBundle['sectionsstep.sections.text']}#{CmsMpaMessageBundle['sectionsstep.sections.pagebreak']}#{CmsMpaMessageBundle['sectionsstep.sections.actions']}
- - #{section.title} - - #{section.textPreview} - - - - #{CmsMpaMessageBundle['sectionsstep.sections.section.pagebreak.yes']} - - - #{CmsMpaMessageBundle['sectionsstep.sections.section.pagebreak.no']} - - - - - - - #{CmsMpaMessageBundle['sectionsstep.sections.section.show_details']} - - - - -
+ + +

+ #{CmsMpaMessageBundle['sectionsstep.sections.empty']} +

+
+ + + + + + + + + + + + + + + + + + + + +
#{CmsMpaMessageBundle['sectionsstep.sections.section.title']}#{CmsMpaMessageBundle['sectionsstep.sections.text']}#{CmsMpaMessageBundle['sectionsstep.sections.pagebreak']}#{CmsMpaMessageBundle['sectionsstep.sections.actions']}
+ + #{section.title} + + #{section.textPreview} + + + + #{CmsMpaMessageBundle['sectionsstep.sections.section.pagebreak.yes']} + + + #{CmsMpaMessageBundle['sectionsstep.sections.section.pagebreak.no']} + + + + + + + #{CmsMpaMessageBundle['sectionsstep.sections.section.show_details']} + + + + +
+
+
diff --git a/ccm-cms/src/main/resources/org/librecms/CmsAdminMessages.properties b/ccm-cms/src/main/resources/org/librecms/CmsAdminMessages.properties index 20e1dfdef..b67a70e2d 100644 --- a/ccm-cms/src/main/resources/org/librecms/CmsAdminMessages.properties +++ b/ccm-cms/src/main/resources/org/librecms/CmsAdminMessages.properties @@ -1014,3 +1014,12 @@ contentsection.document.authoring.workflow.none=No workflow assigned contentsection.document.authoring.workflow.change_workflow.title=Assign workflow contentsection.document.authoring.workflow.change_workflow.submit=Assign workflow contentsection.document.authoring.workflow.change_workflow.close=Cancel +contentsection.documentfolder.actions.delete.cancel=Cancel +contentsection.documentfolder.actions.delete.confirm=Delete folder +contentsection.documentfolder.actions.delete.dialog.title=Confirm deletion of folder +contentsection.documentfolder.actions.delete.dialog.message=Are you sure to delete the folder {0}? +contentsection.documentfolder.actions.delete_item.button.label=Delete document +contentsection.documentfolder.actions.delete_item.cancel=Cancel +contentsection.documentfolder.actions.delete_item.confirm=Delete document +contentsection.documentfolder.actions.delete_item.dialog.title=Confirm deletation of document +contentsection.documentfolder.actions.delete_item.dialog.message=Are you sure to delete the document {0}/{1}? diff --git a/ccm-cms/src/main/resources/org/librecms/CmsAdminMessages_de.properties b/ccm-cms/src/main/resources/org/librecms/CmsAdminMessages_de.properties index cfb748a31..6fde16669 100644 --- a/ccm-cms/src/main/resources/org/librecms/CmsAdminMessages_de.properties +++ b/ccm-cms/src/main/resources/org/librecms/CmsAdminMessages_de.properties @@ -1015,3 +1015,12 @@ contentsection.document.authoring.workflow.none=Kein Arbeitsablauf zugewiesen contentsection.document.authoring.workflow.change_workflow.title=Arbeitsablauf zuweisen contentsection.document.authoring.workflow.change_workflow.submit=Arbeitsablauf zuweisen contentsection.document.authoring.workflow.change_workflow.close=Abbrechen +contentsection.documentfolder.actions.delete.cancel=Abbrechen +contentsection.documentfolder.actions.delete.confirm=Ordner l\u00f6schen +contentsection.documentfolder.actions.delete.dialog.title=L\u00f6schen des Ordners best\u00e4tigen +contentsection.documentfolder.actions.delete.dialog.message=Are you sure to delete the folder {0}? +contentsection.documentfolder.actions.delete_item.button.label=Dokument l\u00f6schen +contentsection.documentfolder.actions.delete_item.cancel=Abbrechen +contentsection.documentfolder.actions.delete_item.confirm=Dokument l\u00f6schen +contentsection.documentfolder.actions.delete_item.dialog.title=L\u00f6schen des Dokumentes best\u00e4tigen +contentsection.documentfolder.actions.delete_item.dialog.message=Sind Sie sicher, dass Sie das Dokument {0}/{1} l\u00f6schen wollen? diff --git a/ccm-cms/src/main/resources/org/librecms/ui/contenttypes/ArticleBundle.properties b/ccm-cms/src/main/resources/org/librecms/ui/contenttypes/ArticleBundle.properties index 8acb8367f..36ea3bf9d 100644 --- a/ccm-cms/src/main/resources/org/librecms/ui/contenttypes/ArticleBundle.properties +++ b/ccm-cms/src/main/resources/org/librecms/ui/contenttypes/ArticleBundle.properties @@ -90,7 +90,7 @@ textstep.languages.th.language=Language textstep.languages.th.actions=Actions textstep.languages.none=No texts available textstep.header.edit=Edit text for locale {0} -textstep.header.view=Text for locale {0} +textstep.header.view=Text of Article {0} for locale {1} textstep.back=Back to available languages text.editor.add_variant=Add language text.editor.add.locale.help=The language of the new variant. diff --git a/ccm-cms/src/main/resources/org/librecms/ui/contenttypes/ArticleBundle_de.properties b/ccm-cms/src/main/resources/org/librecms/ui/contenttypes/ArticleBundle_de.properties index 0cf3ba34f..f981a3a3d 100644 --- a/ccm-cms/src/main/resources/org/librecms/ui/contenttypes/ArticleBundle_de.properties +++ b/ccm-cms/src/main/resources/org/librecms/ui/contenttypes/ArticleBundle_de.properties @@ -90,7 +90,7 @@ textstep.languages.th.language=Sprache textstep.languages.th.actions=Aktionen textstep.languages.none=Keine Texte vorhandenen textstep.header.edit=Text f\u00fcr Sprache {0} bearbeiten -textstep.header.view=Text f\u00fcr Sprache {0} +textstep.header.view=Text des Artikels {0} f\u00fcr Sprache {1} textstep.back=Zur\u00fcck zur Liste der verf\u00fcgbaren Sprachen text.editor.add_variant=Sprache hinzuf\u00fcgen text.editor.add.locale.help=Die Sprache der neuen Variante. diff --git a/ccm-cms/src/main/resources/org/librecms/ui/contenttypes/MpaStepsBundle.properties b/ccm-cms/src/main/resources/org/librecms/ui/contenttypes/MpaStepsBundle.properties index 0b368f3ca..068b697cf 100644 --- a/ccm-cms/src/main/resources/org/librecms/ui/contenttypes/MpaStepsBundle.properties +++ b/ccm-cms/src/main/resources/org/librecms/ui/contenttypes/MpaStepsBundle.properties @@ -113,3 +113,4 @@ sectionstep.textstep.back=Back sectionstep.textstep.header.edit=Edit text for locale {2} of section {1} of multipart article {0} sectionstep.textstep.text.editor.header=Text authoringsteps.sections.label=Sections +sectionsstep.sections.empty=This multipart article has no sections yet. diff --git a/ccm-cms/src/main/resources/org/librecms/ui/contenttypes/MpaStepsBundle_de.properties b/ccm-cms/src/main/resources/org/librecms/ui/contenttypes/MpaStepsBundle_de.properties index 6447017ea..70c2a0c61 100644 --- a/ccm-cms/src/main/resources/org/librecms/ui/contenttypes/MpaStepsBundle_de.properties +++ b/ccm-cms/src/main/resources/org/librecms/ui/contenttypes/MpaStepsBundle_de.properties @@ -113,3 +113,4 @@ sectionstep.textstep.back=Zur\u00fcck sectionstep.textstep.header.edit=Text f\u00fcr Sprache {2} des Abschnitts {1} des mehrteiligen Artikels {0} bearbeiten sectionstep.textstep.text.editor.header=Text authoringsteps.sections.label=Abschnitte +sectionsstep.sections.empty=Diese mehrteilige Artikel hat noch keine Abschnitte.