diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/ContentSectionController.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/ContentSectionController.java new file mode 100644 index 000000000..9a55bd453 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/ContentSectionController.java @@ -0,0 +1,54 @@ +package org.librecms.ui.contentsections; + +import org.libreccm.security.AuthorizationRequired; + +import java.net.URI; +import java.net.URISyntaxException; + +import javax.inject.Inject; +import javax.mvc.Controller; +import javax.servlet.http.HttpServletRequest; +import javax.transaction.Transactional; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Response; + +/** + * + * @author Jens Pelzetter + */ +@Controller +@Path("/") +public class ContentSectionController { + + @Inject + private HttpServletRequest request; + + @GET + @Path("/") + @AuthorizationRequired + @Transactional(Transactional.TxType.REQUIRED) + public Response redirectToContentSectionsList() { + try { + return Response + .seeOther( + new URI( + request.getScheme(), + "", + request.getServerName(), + request.getServerPort(), + String.format( + "%s/@cms/contentsections", + request.getContextPath() + ), + "", + "" + ) + ).build(); + } catch (URISyntaxException ex) { + throw new WebApplicationException(ex); + } + } + +} 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 46ba9464b..a201c8262 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 @@ -5,6 +5,8 @@ */ package org.librecms.ui.contentsections; +import com.arsdigita.cms.ui.folder.FolderPath; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.libreccm.api.Identifier; @@ -56,6 +58,9 @@ import javax.ws.rs.QueryParam; import org.librecms.ui.CmsAdminMessages; +import javax.ws.rs.FormParam; +import javax.ws.rs.POST; + /** * * @author Jens Pelzetter @@ -65,7 +70,8 @@ import org.librecms.ui.CmsAdminMessages; @Path("/{sectionIdentifier}/documentfolders") public class DocumentFolderController { - private static final Logger LOGGER = LogManager.getLogger(DocumentFolderController.class + private static final Logger LOGGER = LogManager.getLogger( + DocumentFolderController.class ); @Inject @@ -127,7 +133,7 @@ public class DocumentFolderController { sectionIdentifier, "", filterTerm, firstResult, maxResults ); } - + @GET @Path("/{folderPath:(.+)?}") @AuthorizationRequired @@ -254,6 +260,13 @@ public class DocumentFolderController { System.currentTimeMillis() - rowsStart ); + documentFolderModel.setPath(folderPath); + documentFolderModel.setCanCreateSubFolders( + permissionChecker.isPermitted( + ItemPrivileges.CREATE_NEW, folder + ) + ); + return "org/librecms/ui/contentsection/documentfolder/documentfolder.xhtml"; } else { models.put("sectionidentifier", sectionIdentifier); @@ -359,6 +372,89 @@ public class DocumentFolderController { } } + @POST + @Path("/") + @AuthorizationRequired + @Transactional(Transactional.TxType.REQUIRED) + public String newSubFolder( + @PathParam("sectionIdentifier") final String sectionIdentifier, + @FormParam("folderName") final String folderName + ) { + return newSubFolder( + sectionIdentifier, "", folderName + ); + } + + @POST + @Path("/{parentFolderPath:(.+)?}") + @AuthorizationRequired + @Transactional(Transactional.TxType.REQUIRED) + public String newSubFolder( + @PathParam("sectionIdentifier") final String sectionIdentifier, + @PathParam("parentFolderPath") final String parentFolderPath, + @FormParam("folderName") final String folderName + ) { + final Identifier identifier = identifierParser.parseIdentifier( + sectionIdentifier + ); + final Optional sectionResult; + switch (identifier.getType()) { + case ID: + sectionResult = sectionRepo.findById( + Long.parseLong(identifier.getIdentifier()) + ); + break; + case UUID: + sectionResult = sectionRepo.findByUuid(identifier + .getIdentifier()); + break; + default: + sectionResult = sectionRepo.findByLabel(identifier + .getIdentifier()); + break; + } + + if (sectionResult.isPresent()) { + final ContentSection section = sectionResult.get(); + + final Folder parentFolder; + if (parentFolderPath.isEmpty()) { + parentFolder = section.getRootDocumentsFolder(); + } else { + final Optional parentFolderResult = folderRepo + .findByPath(section, parentFolderPath, + FolderType.DOCUMENTS_FOLDER); + if (parentFolderResult.isPresent()) { + parentFolder = parentFolderResult.get(); + } else { + models.put("contentSection", section.getLabel()); + models.put("folderPath", parentFolderPath); + return "org/librecms/ui/contentsection/documentfolder/documentfolder-not-found.xhtml"; + } + } + + if (permissionChecker.isPermitted( + ItemPrivileges.CREATE_NEW, parentFolder + )) { + folderManager.createFolder(folderName, parentFolder); + + return String.format( + "redirect:/%s/documentfolders/%s", + sectionIdentifier, + parentFolderPath + ); + } else { + models.put("sectionidentifier", sectionIdentifier); + models.put("folderPath", parentFolderPath); + return "org/librecms/ui/contentsection/access-denied.xhtml"; + } + + } else { + models.put("sectionIdentifier", sectionIdentifier); + return "org/librecms/ui/contentsection/contentsection-not-found.xhtml"; + } + } + private List buildFolderTree( final ContentSection section, final Folder currentFolder ) { diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/DocumentFolderModel.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/DocumentFolderModel.java index 5a96b6a2a..c44cedfa6 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/DocumentFolderModel.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/DocumentFolderModel.java @@ -31,6 +31,11 @@ public class DocumentFolderModel { private List breadcrumbs; + private String path; + + private boolean canCreateSubFolders; + + public long getCount() { return count; } @@ -43,7 +48,6 @@ public class DocumentFolderModel { return firstResult; } - protected void setFirstResult(final int firstResult) { this.firstResult = firstResult; } @@ -71,8 +75,7 @@ public class DocumentFolderModel { protected void setRows(final List rows) { this.rows = new ArrayList<>(rows); } - - + public List getBreadcrumbs() { return Collections.unmodifiableList(breadcrumbs); } @@ -83,4 +86,20 @@ public class DocumentFolderModel { this.breadcrumbs = new ArrayList<>(breadcrumbs); } + public String getPath() { + return path; + } + + protected void setPath(final String path) { + this.path = path; + } + + public boolean isCanCreateSubFolders() { + return canCreateSubFolders; + } + + protected void setCanCreateSubFolders(final boolean canCreateSubFolders) { + this.canCreateSubFolders = canCreateSubFolders; + } + } 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 a9fce8df7..b8de4e3a0 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 @@ -5,7 +5,7 @@ xmlns:cms="http://xmlns.jcp.org/jsf/composite/components/cms" xmlns:libreccm="http://xmlns.jcp.org/jsf/composite/components/libreccm" xmlns:ui="http://xmlns.jcp.org/jsf/facelets"> - + @@ -49,30 +49,34 @@ - - - #{CmsAdminMessages['contentsection.documentfolders.searchbox.label']} - - - - - - - #{CmsAdminMessages['contentsection.documentfolders.searchbox.submit']} - + + + #{CmsAdminMessages['contentsection.documentfolders.searchbox.label']} + + + + + + + #{CmsAdminMessages['contentsection.documentfolders.searchbox.submit']} + + + #{CmsAdminMessages["contentsection.documentfolders.root.title"]} + + @@ -81,56 +85,7 @@ value="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documentfolders" /> - - - - @@ -149,7 +104,7 @@ - + #{CmsAdminMessages['contentsection.documentfolder.filter.submit']} @@ -159,10 +114,66 @@ ${CmsAdminMessages.getMessage("contentsection.documentfolder.pageof", [DocumentFolderModel.currentPage, DocumentFolderModel.numberOfPages])} - + #{CmsAdminMessages['contentsection.documentfolder.add_subfolder']} + + + + + + #{CmsAdminMessages['contentsection.documentfolder.new_subfolder_dialog.title']} + + + × + + + + + + #{CmsAdminMessages['contentsection.documentfolder.new_subfolder.name.label']} + + + + #{CmsAdminMessages['contentsection.documentfolder.new_subfolder.name.help']} + + + + + + + #{CmsAdminMessages['contentsection.documentfolder.add_document']} diff --git a/ccm-cms/src/main/resources/org/librecms/CmsAdminMessages.properties b/ccm-cms/src/main/resources/org/librecms/CmsAdminMessages.properties index c23720707..ba57726cd 100644 --- a/ccm-cms/src/main/resources/org/librecms/CmsAdminMessages.properties +++ b/ccm-cms/src/main/resources/org/librecms/CmsAdminMessages.properties @@ -44,7 +44,7 @@ contentsection.documentfolder.pagination.next_page=Next page contentsection.not_found=No content section identifed by {0} available. contentsection.accessdenied=Your are not permitted to access content section {0}. contentsection.documentfolder.types.folder=Folder -contentsection.documentfolder.pageof=Page {0} of {1}. +contentsection.documentfolder.pageof=Page {0} of {1} contentsection.documentfolder.add_document=Create document contentsection.documentfolder.add_subfolder=Add subfolder contentsection.documentfolder.filter.label=Filter documents @@ -53,6 +53,12 @@ contentsections.documentfolder.not_found=Not folder with path {1} found in conte contentsection.not_found.title=Content Section not found contentsection.documentfolders.searchbox.label=Search in document folders contentsection.documentfolders.searchbox.submit=Search -contentsection.assetsfolders.title=Media & Data +contentsection.assetfolders.title=Media & Data contentsection.categories.title=Categories & Page Trees -contentsection.categories.configuration=Configuration +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_dialog.submit=Create new subfolder +contentsection.documentfolder.new_subfolder_dialog.close=Cancel +contentsection.documentfolders.root.title=Documents 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 99581e4b7..454420e45 100644 --- a/ccm-cms/src/main/resources/org/librecms/CmsAdminMessages_de.properties +++ b/ccm-cms/src/main/resources/org/librecms/CmsAdminMessages_de.properties @@ -44,7 +44,7 @@ contentsection.documentfolder.pagination.next_page=Eine Seite weiter contentsection.not_found=Keine Content Section mit dem Identifier {0} gefunden. contentsection.accessdenied=Sind sind nicht berechtigt auf die Content Section {0} zuzugreifen. contentsection.documentfolder.types.folder=Ordner -contentsection.documentfolder.pageof=Seite {0} von {1}. +contentsection.documentfolder.pageof=Seite {0} von {1} contentsection.documentfolder.add_document=Neues Dokument erstellen contentsection.documentfolder.add_subfolder=Unterordner erstellen contentsection.documentfolder.filter.label=Dokumente filtern @@ -53,6 +53,12 @@ contentsections.documentfolder.not_found=Es wurde kein Ordner mit dem Pfad {1} i contentsection.not_found.title=Content Section nicht gefunden contentsection.documentfolders.searchbox.label=In Dokument-Ordnern suchen contentsection.documentfolders.searchbox.submit=Suchen -contentsection.assetsfolders.title=Media & Data +contentsection.assetfolders.title=Media & Data contentsection.categories.title=Kategorien & Seitenb\u00e4ume -contentsection.categories.configuration=Konfiguration +contentsection.configuration.title=Konfiguration +contentsection.documentfolder.new_subfolder_dialog.title=Neuen Unterordner erstellen +contentsection.documentfolder.new_subfolder.name.label=Name +contentsection.documentfolder.new_subfolder.name.help=Der Name des neuen Ordners. Darf nur die Buchstaben a bis z und A bis Z, Ziffern, den Bindestrich und den Unterstrich enthalten. +contentsection.documentfolder.new_subfolder_dialog.submit=Neuen Ordner anlegen +contentsection.documentfolder.new_subfolder_dialog.close=Abbrechen +contentsection.documentfolders.root.title=Dokumente