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 667fce760..38c693e67 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 @@ -23,7 +23,6 @@ import org.librecms.contentsection.ContentItemRepository; import org.librecms.contentsection.ContentSection; import org.librecms.contentsection.ContentSectionRepository; import org.librecms.contentsection.ContentType; -import org.librecms.contentsection.ContentTypeManager; import org.librecms.contentsection.ContentTypeRepository; import org.librecms.contentsection.DocumentFolderEntry; import org.librecms.contentsection.Folder; @@ -58,7 +57,6 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.QueryParam; -import org.librecms.ui.CmsAdminMessages; import javax.ws.rs.FormParam; import javax.ws.rs.POST; @@ -518,6 +516,70 @@ public class DocumentFolderController { ); } + @POST + @Path("/@rename/{folderPath:(.+)?}") + @AuthorizationRequired + @Transactional(Transactional.TxType.REQUIRED) + public String renameFolder( + @PathParam("sectionIdentifier") final String sectionIdentifier, + @PathParam("folderPath") final String folderPath, + @FormParam("folderName") final String folderName + ) { + final Optional sectionResult = retrieveContentSection( + sectionIdentifier + ); + if (!sectionResult.isPresent()) { + models.put("sectionIdentifier", sectionIdentifier); + return "org/librecms/ui/contentsection/contentsection-not-found.xhtml"; + } + + final ContentSection section = sectionResult.get(); + if (!permissionChecker.isPermitted( + ItemPrivileges.EDIT, section.getRootDocumentsFolder() + )) { + models.put("sectionidentifier", sectionIdentifier); + return "org/librecms/ui/contentsection/access-denied.xhtml"; + } + + final Folder folder; + final Optional folderResult = folderRepo + .findByPath( + section, + folderPath, + FolderType.DOCUMENTS_FOLDER + ); + if (folderResult.isPresent()) { + folder = folderResult.get(); + + documentFolderModel.setBreadcrumbs(buildBreadcrumbs(folderPath)); + } else { + models.put("contentSection", section.getLabel()); + models.put("folderPath", folderPath); + return "org/librecms/ui/contentsection/documentfolder/documentfolder-not-found.xhtml"; + } + + if (!permissionChecker.isPermitted(ItemPrivileges.EDIT, folder)) { + models.put("sectionidentifier", sectionIdentifier); + models.put("folderPath", folderPath); + return "org/librecms/ui/contentsection/access-denied.xhtml"; + } + + folder.setName(folderName); + folderRepo.save(folder); + + final String[] folderPathTokens = folderPath.split("/"); + final String returnFolderPath = String.join( + "/", + Arrays.copyOf(folderPathTokens, folderPathTokens.length - 1) + ); + + return String.format( + "redirect:/%s/documentfolders/%s", + sectionIdentifier, + returnFolderPath + ); + } + private Optional retrieveContentSection( final String sectionIdentifier ) { 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 3d26f2ecb..20179d6a4 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 @@ -315,10 +315,10 @@ name="folderName" pattern="^([a-zA-Z0-9-_]*)$" type="text" - value="" /> + value="#{row.name}" /> - #{CmsAdminMessages['contentsection.documentfolder.new_subfolder.name.help']} + #{CmsAdminMessages['contentsection.documentfolder.rename_folder.name.help']} diff --git a/ccm-cms/src/main/resources/org/librecms/CmsAdminMessages.properties b/ccm-cms/src/main/resources/org/librecms/CmsAdminMessages.properties index 4c4bee82e..ebeb60eb9 100644 --- a/ccm-cms/src/main/resources/org/librecms/CmsAdminMessages.properties +++ b/ccm-cms/src/main/resources/org/librecms/CmsAdminMessages.properties @@ -58,7 +58,7 @@ contentsection.categories.title=Categories & Page Trees contentsection.configuration.title=Configuration contentsection.documentfolder.new_subfolder_dialog.title=Create new subfolder contentsection.documentfolder.new_subfolder.name.label=Name -contentsection.documentfolder.new_subfolder.name.help=The new name of the subfolder. May only contain the letters a to z and A to Z, numbers, the dash and the underscore +contentsection.documentfolder.new_subfolder.name.help=The name of the new subfolder. May only contain the letters a to z and A to Z, numbers, the dash and the underscore contentsection.documentfolder.new_subfolder_dialog.submit=Create new subfolder contentsection.documentfolder.new_subfolder_dialog.close=Cancel contentsection.documentfolders.root.title=Documents @@ -90,7 +90,8 @@ contentsection.documentfolder.permissions.dialog.close=Cancel contentsection.documentfolder.permissions.dialog.submit=Apply changed permissions contentsection.documentfolder.permissions.dialog.granted_by_inheritence=Granted by inhertitence contentsections.role.not_found=Role {0} not found -contentsection.documentfolder.rename_folder_dialog.title=Rename folder {0} +contentsection.documentfolder.rename_folder_dialog.title=Rename folder /{0} contentsection.documentfolder.rename_folder_dialog.close=Cancel contentsection.documentfolder.rename_folder_dialog.save=Rename folder contentsection.documentfolder.rename_folder.name.label=Name +contentsection.documentfolder.rename_folder.name.help=The new name of the folder. May only contain the letters a to z and A to Z, numbers, the dash and the underscore 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 9b818862f..595b13317 100644 --- a/ccm-cms/src/main/resources/org/librecms/CmsAdminMessages_de.properties +++ b/ccm-cms/src/main/resources/org/librecms/CmsAdminMessages_de.properties @@ -90,7 +90,8 @@ contentsection.documentfolder.permissions.dialog.close=Abbrechen contentsection.documentfolder.permissions.dialog.submit=Berechtigungen anwenden contentsection.documentfolder.permissions.dialog.granted_by_inheritence=Durch \u00fcbergeordnetes Objekt gew\u00e4hrt contentsections.role.not_found=Rolle {0} nicht gefunden -contentsection.documentfolder.rename_folder_dialog.title=Order {0} umbenennen +contentsection.documentfolder.rename_folder_dialog.title=Order /{0} umbenennen contentsection.documentfolder.rename_folder_dialog.close=Abbrechen contentsection.documentfolder.rename_folder_dialog.save=Ordner umbenennen contentsection.documentfolder.rename_folder.name.label=Name +contentsection.documentfolder.rename_folder.name.help=Der neue Name des Ordners. Darf nur die Buchstaben a bis z und A bis Z, Ziffern, den Bindestrich und den Unterstrich enthalten.