diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/ContentSectionApplication.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/ContentSectionApplication.java index 1e1b4afc3..34170509a 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/ContentSectionApplication.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/ContentSectionApplication.java @@ -74,6 +74,7 @@ public class ContentSectionApplication extends Application { classes.add(DocumentWorkflowController.class); classes.addAll(getAuthoringSteps()); + classes.addAll(getAuthoringStepResources()); classes.add(IsAuthenticatedFilter.class); @@ -88,5 +89,13 @@ public class ContentSectionApplication extends Application { .filter(stepsValidator::validateAuthoringStep) .collect(Collectors.toSet()); } + + private Set> getAuthoringStepResources() { + return authoringSteps + .stream() + .map(MvcAuthoringSteps::getResourceClasses) + .flatMap(Set::stream) + .collect(Collectors.toSet()); + } } 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 df43c40a7..0cde3b3b9 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 @@ -20,6 +20,7 @@ package org.librecms.ui.contentsections.documents; import org.librecms.ui.contenttypes.MvcArticlePropertiesStep; import org.librecms.ui.contenttypes.MvcArticleTextBodyStep; +import org.librecms.ui.contenttypes.MvcArticleTextBodyStepResources; import java.util.HashSet; import java.util.Set; @@ -46,4 +47,12 @@ public class CmsMvcAuthoringSteps implements MvcAuthoringSteps { return classes; } + @Override + public Set> getResourceClasses() { + final Set> classes = new HashSet<>(); + classes.add(MvcArticleTextBodyStepResources.class); + + return classes; + } + } diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/MvcAuthoringStep.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/MvcAuthoringStep.java index d585fecf8..32c7b599e 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/MvcAuthoringStep.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/MvcAuthoringStep.java @@ -32,6 +32,12 @@ import javax.ws.rs.Path; */ public interface MvcAuthoringStep { + /** + * Returns the class implementing the step. This method is used by CCM is to + * get the correct class instead of a CDI proxy. + * + * @return The class implementing the step. + */ Class getStepClass(); ContentSection getContentSection() throws ContentSectionNotFoundException; @@ -52,7 +58,9 @@ public interface MvcAuthoringStep { * admin priviliges for the content section of the item. * * - * @return {@code true} if the current user can edit the document/item, {@false} otherwise. + * @return {@code true} if the current user can edit the document/item, { + * + * @false} otherwise. */ boolean getCanEdit(); @@ -88,7 +96,7 @@ public interface MvcAuthoringStep { DocumentNotFoundException; String getStepPath(); - + /** * Builds the redirect path of the authoring step.This path is most often * used to implement the redirect after post pattern. diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/MvcAuthoringSteps.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/MvcAuthoringSteps.java index fc5042267..e079c5017 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/MvcAuthoringSteps.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/documents/MvcAuthoringSteps.java @@ -18,6 +18,7 @@ */ package org.librecms.ui.contentsections.documents; +import java.util.Collections; import java.util.Set; /** @@ -33,9 +34,14 @@ public interface MvcAuthoringSteps { = "sectionIdentifier"; public static final String DOCUMENT_PATH_PATH_PARAM_NAME = "documentPath"; - - public static final String DOCUMENT_PATH_PATH_PARAM = DOCUMENT_PATH_PATH_PARAM_NAME + ":(.+)?"; + + public static final String DOCUMENT_PATH_PATH_PARAM + = DOCUMENT_PATH_PATH_PARAM_NAME + ":(.+)?"; Set> getClasses(); + default Set> getResourceClasses() { + return Collections.emptySet(); + } + } diff --git a/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticleTextBodyStep.java b/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticleTextBodyStep.java index cc0726bf9..b174489bc 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticleTextBodyStep.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticleTextBodyStep.java @@ -226,38 +226,38 @@ public class MvcArticleTextBodyStep extends AbstractMvcAuthoringStep { } } - @GET -// @Path("/{locale}/@view") - @Path("/variants/{locale}") - @Transactional(Transactional.TxType.REQUIRED) - public String viewTextValue( - @PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM) - final String sectionIdentifier, - @PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME) - final String documentPath, - @PathParam("locale") final String localeParam - ) { - try { - init(); - } catch (ContentSectionNotFoundException ex) { - return ex.showErrorMessage(); - } catch (DocumentNotFoundException ex) { - return ex.showErrorMessage(); - } - - if (itemPermissionChecker.canEditItem(getArticle())) { - selectedLocale = new Locale(localeParam).toString(); - -// return "org/librecms/ui/contenttypes/article/article-text/view.xhtml"; - return getTextValues().get(localeParam); - } else { - return documentUi.showAccessDenied( - getContentSection(), - getArticle(), - articleMessageBundle.getMessage("article.edit.denied") - ); - } - } +// @GET +//// @Path("/{locale}/@view") +// @Path("/variants/{locale}") +// @Transactional(Transactional.TxType.REQUIRED) +// public String viewTextValue( +// @PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM) +// final String sectionIdentifier, +// @PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME) +// final String documentPath, +// @PathParam("locale") final String localeParam +// ) { +// try { +// init(); +// } catch (ContentSectionNotFoundException ex) { +// return ex.showErrorMessage(); +// } catch (DocumentNotFoundException ex) { +// return ex.showErrorMessage(); +// } +// +// if (itemPermissionChecker.canEditItem(getArticle())) { +// selectedLocale = new Locale(localeParam).toString(); +// +//// return "org/librecms/ui/contenttypes/article/article-text/view.xhtml"; +// return getTextValues().get(localeParam); +// } else { +// return documentUi.showAccessDenied( +// getContentSection(), +// getArticle(), +// articleMessageBundle.getMessage("article.edit.denied") +// ); +// } +// } @GET diff --git a/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticleTextBodyStepResources.java b/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticleTextBodyStepResources.java new file mode 100644 index 000000000..1443ffde7 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/ui/contenttypes/MvcArticleTextBodyStepResources.java @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2021 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.librecms.ui.contenttypes; + +import org.librecms.contentsection.ContentItem; +import org.librecms.contentsection.ContentItemRepository; +import org.librecms.contentsection.ContentSection; +import org.librecms.contenttypes.Article; +import org.librecms.ui.contentsections.ContentSectionsUi; +import org.librecms.ui.contentsections.ItemPermissionChecker; +import org.librecms.ui.contentsections.documents.MvcAuthoringSteps; + +import java.util.Locale; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.transaction.Transactional; +import javax.ws.rs.ForbiddenException; +import javax.ws.rs.GET; +import javax.ws.rs.NotFoundException; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; + +/** + * + * @author Jens Pelzetter + */ +@RequestScoped +@Path(MvcAuthoringSteps.PATH_PREFIX + "article-text-resources") +public class MvcArticleTextBodyStepResources { + + /** + * Used for retrieving and saving the article. + */ + @Inject + private ContentItemRepository itemRepo; + + @Inject + private ContentSectionsUi sectionsUi; + + @Inject + private ItemPermissionChecker itemPermissionChecker; + + @GET +// @Path("/{locale}/@view") + @Path("/variants/{locale}") + @Transactional(Transactional.TxType.REQUIRED) + public String viewTextValue( + @PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM) + final String sectionIdentifier, + @PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME) + final String documentPathParam, + @PathParam("locale") final String localeParam + ) { +// try { +// init(); +// } catch (ContentSectionNotFoundException ex) { +// return ex.showErrorMessage(); +// } catch (DocumentNotFoundException ex) { +// return ex.showErrorMessage(); +// } + + final ContentSection contentSection = sectionsUi + .findContentSection(sectionIdentifier) + .orElseThrow( + () -> new NotFoundException() + ); + + final ContentItem document = itemRepo + .findByPath(contentSection, documentPathParam) + .orElseThrow( + () -> new NotFoundException() + ); + + if (!(document instanceof Article)) { + throw new NotFoundException(); + } + + final Article article = (Article) document; + if (itemPermissionChecker.canEditItem(article)) { + return article.getText().getValue(new Locale(localeParam)); + } else { + throw new ForbiddenException(); + } + } + +} diff --git a/ccm-cms/src/main/resources/META-INF/resources/components/librecms/cmsEditor.xhtml b/ccm-cms/src/main/resources/META-INF/resources/components/librecms/cmsEditor.xhtml index f3a1a3856..0d2776dd6 100644 --- a/ccm-cms/src/main/resources/META-INF/resources/components/librecms/cmsEditor.xhtml +++ b/ccm-cms/src/main/resources/META-INF/resources/components/librecms/cmsEditor.xhtml @@ -217,7 +217,7 @@ @@ -354,6 +354,7 @@