You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by dk...@apache.org on 2018/01/31 21:39:29 UTC

[sling-whiteboard] branch master updated: Adding a filter to enable 'unpublished' pages and the ability to view / edit the root of the taxonomy

This is an automated email from the ASF dual-hosted git repository.

dklco pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 1514176  Adding a filter to enable 'unpublished' pages and the ability to view / edit the root of the taxonomy
1514176 is described below

commit 1514176c258d0f3ca9e5e274d80aaa7d4e10d463
Author: Dan Klco <da...@gmail.com>
AuthorDate: Wed Jan 31 16:39:20 2018 -0500

    Adding a filter to enable 'unpublished' pages and the ability to view / edit the root of the taxonomy
---
 .../java/org/apache/sling/cms/CMSConstants.java    | 37 +++++++---
 .../sling/cms/core/filters/PublishFilter.java      | 85 ++++++++++++++++++++++
 cms/ui/pom.xml                                     |  1 +
 .../resources/SLING-INF/nodetypes/nodetypes.cnd    | 31 +++++---
 .../jcr_root/etc/taxonomy/jcr:content.json         |  4 +
 .../cms/contentbreadcrumb/contentbreadcrumb.jsp    | 12 +--
 .../components/cms/pagetemplate/edit.json          |  2 +-
 .../libs/sling-cms/content/file/upload.json        |  2 +-
 .../libs/sling-cms/content/site/content.json       | 62 +---------------
 .../libs/sling-cms/content/taxonomy/list.json      |  5 +-
 10 files changed, 147 insertions(+), 94 deletions(-)

diff --git a/cms/core/src/main/java/org/apache/sling/cms/CMSConstants.java b/cms/core/src/main/java/org/apache/sling/cms/CMSConstants.java
index 664dc06..17866ce 100644
--- a/cms/core/src/main/java/org/apache/sling/cms/CMSConstants.java
+++ b/cms/core/src/main/java/org/apache/sling/cms/CMSConstants.java
@@ -22,10 +22,9 @@ package org.apache.sling.cms;
 public class CMSConstants {
 
 	/**
-	 * Private constructor to prevent instantiation of class.
+	 * The Request attribute for whether or not editing is enabled
 	 */
-	private CMSConstants() {
-	}
+	public static final String ATTR_EDIT_ENABLED = "cmsEditEnabled";
 
 	/**
 	 * Content path.
@@ -38,14 +37,19 @@ public class CMSConstants {
 	public static final String NAMESPACE = "sling";
 
 	/**
-	 * Description attribute name
+	 * Component node type.
 	 */
-	public static final String PN_DESCRIPTION = "jcr:description";
+	public static final String NT_COMPONENT = NAMESPACE + ":Component";
 
 	/**
-	 * Title attribute name
+	 * File node type
 	 */
-	public static final String PN_TITLE = "jcr:title";
+	public static final String NT_FILE = NAMESPACE + ":File";
+
+	/**
+	 * Page node type.
+	 */
+	public static final String NT_PAGE = NAMESPACE + ":Page";
 
 	/**
 	 * Site node type.
@@ -53,13 +57,24 @@ public class CMSConstants {
 	public static final String NT_SITE = NAMESPACE + ":Site";
 
 	/**
-	 * Page node type.
+	 * Description attribute name
 	 */
-	public static final String NT_PAGE = NAMESPACE + ":Page";
+	public static final String PN_DESCRIPTION = "jcr:description";
 
 	/**
-	 * Component node type.
+	 * Published flag property
 	 */
-	public static final String NT_COMPONENT = NAMESPACE + ":Component";
+	public static final String PN_PUBLISHED = "published";
+
+	/**
+	 * Title attribute name
+	 */
+	public static final String PN_TITLE = "jcr:title";
+
+	/**
+	 * Private constructor to prevent instantiation of class.
+	 */
+	private CMSConstants() {
+	}
 
 }
\ No newline at end of file
diff --git a/cms/core/src/main/java/org/apache/sling/cms/core/filters/PublishFilter.java b/cms/core/src/main/java/org/apache/sling/cms/core/filters/PublishFilter.java
new file mode 100644
index 0000000..b34cce2
--- /dev/null
+++ b/cms/core/src/main/java/org/apache/sling/cms/core/filters/PublishFilter.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.cms.core.filters;
+
+import java.io.IOException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.lang.ArrayUtils;
+import org.apache.felix.scr.annotations.sling.SlingFilter;
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.cms.CMSConstants;
+import org.apache.sling.jcr.resource.JcrResourceConstants;
+
+@SlingFilter(order = Integer.MAX_VALUE)
+public class PublishFilter implements Filter {
+
+	public static final String[] PUBLISHABLE_TYPES = new String[] { CMSConstants.NT_FILE, CMSConstants.NT_PAGE,
+			JcrResourceConstants.NT_SLING_FOLDER, JcrResourceConstants.NT_SLING_ORDERED_FOLDER };
+
+	public static final String[] VALID_METHODS = new String[] { "GET", "HEAD" };
+
+	@Override
+	public void init(FilterConfig filterConfig) throws ServletException {
+	}
+
+	@Override
+	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
+			throws IOException, ServletException {
+		if (request instanceof SlingHttpServletRequest) {
+			SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request;
+			if (ArrayUtils.contains(VALID_METHODS, slingRequest.getMethod())) {
+				Object editEnabled = slingRequest.getAttribute(CMSConstants.ATTR_EDIT_ENABLED);
+				if (!"true".equals(editEnabled)) {
+					Resource publishable = findPublishableParent(slingRequest.getResource());
+					if (publishable != null && publishable.getChild(JcrConstants.JCR_CONTENT) != null) {
+						if (!(publishable.getChild(JcrConstants.JCR_CONTENT).getValueMap()
+								.get(CMSConstants.PN_PUBLISHED, true))) {
+							((HttpServletResponse) response).sendError(404);
+							return;
+						}
+					}
+				}
+			}
+		}
+		chain.doFilter(request, response);
+	}
+
+	private Resource findPublishableParent(Resource resource) {
+		String type = resource.getValueMap().get(JcrConstants.JCR_PRIMARYTYPE, String.class);
+		if (ArrayUtils.contains(PUBLISHABLE_TYPES, type)) {
+			return resource;
+		} else if (resource.getParent() != null) {
+			return findPublishableParent(resource.getParent());
+		}
+		return null;
+	}
+
+	@Override
+	public void destroy() {
+	}
+
+}
diff --git a/cms/ui/pom.xml b/cms/ui/pom.xml
index edb41f4..9234445 100644
--- a/cms/ui/pom.xml
+++ b/cms/ui/pom.xml
@@ -38,6 +38,7 @@
                         <Sling-Nodetypes>SLING-INF/nodetypes/nodetypes.cnd</Sling-Nodetypes>
                         <Sling-Initial-Content>
                         	jcr_root/apps/reference;overwrite:=true;uninstall:=true;path:=/apps/reference,
+                            jcr_root/etc/taxonomy;overwrite:=false;uninstall:=true;path:=/etc/taxonomy,
                             jcr_root/libs/sling-cms;overwrite:=true;uninstall:=true;path:=/libs/sling-cms,
                             jcr_root/etc/clientlibs/sling-cms;overwrite:=true;uninstall:=true;path:=/etc/clientlibs/sling-cms
                         </Sling-Initial-Content>
diff --git a/cms/ui/src/main/resources/SLING-INF/nodetypes/nodetypes.cnd b/cms/ui/src/main/resources/SLING-INF/nodetypes/nodetypes.cnd
index 3de2f55..c70284b 100644
--- a/cms/ui/src/main/resources/SLING-INF/nodetypes/nodetypes.cnd
+++ b/cms/ui/src/main/resources/SLING-INF/nodetypes/nodetypes.cnd
@@ -22,17 +22,11 @@
 //	-  http://jackrabbit.apache.org/node-type-notation.html
 
 <sling = 'http://www.sling.apache.org/sling/1.0'>
+	
 
-[sling:Site] > nt:hierarchyNode
-	orderable
-	- sling:config (string)
-	- sling:created (date)
-	- sling:createdBy (string)
-	- jcr:lastModified (date)
-	- jcr:lastModifiedBy (string)
+[sling:Component] > nt:unstructured
+	- componentType (string)
 	- jcr:title (string)
-	- jcr:description (string)
-	+ * (nt:base) = nt:base version
 	
 [sling:Config] > nt:hierarchyNode
 	orderable
@@ -43,6 +37,14 @@
 	- jcr:lastModifiedBy (string)
 	- jcr:title (string)
 	+ * (nt:unstructured) = nt:unstructured version
+	
+[sling:File] > nt:file
+	 - * (undefined) copy
+	 + jcr:content (sling:FileContent) = sling:FileContent copy primary autocreated
+	
+[sling:FileContent] > nt:resource
+	- * (undefined) copy
+	- * (undefined) copy multiple
 
 [sling:Page] > nt:hierarchyNode
 	orderable
@@ -50,9 +52,16 @@
 	+ jcr:content (nt:unstructured) = nt:unstructured copy primary
 	+ * (nt:base) = nt:base version
 
-[sling:Component] > nt:unstructured
-	- componentType (string)
+[sling:Site] > nt:hierarchyNode
+	orderable
+	- sling:config (string)
+	- sling:created (date)
+	- sling:createdBy (string)
+	- jcr:lastModified (date)
+	- jcr:lastModifiedBy (string)
 	- jcr:title (string)
+	- jcr:description (string)
+	+ * (nt:base) = nt:base version
 
 [sling:Taxonomy] > nt:hierarchyNode
 	orderable
diff --git a/cms/ui/src/main/resources/jcr_root/etc/taxonomy/jcr:content.json b/cms/ui/src/main/resources/jcr_root/etc/taxonomy/jcr:content.json
new file mode 100644
index 0000000..26d6e7e
--- /dev/null
+++ b/cms/ui/src/main/resources/jcr_root/etc/taxonomy/jcr:content.json
@@ -0,0 +1,4 @@
+{
+	"jcr:primaryType": "nt:unstructured",
+	"jcr:title": "Taxonomy"
+}
\ No newline at end of file
diff --git a/cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/contentbreadcrumb/contentbreadcrumb.jsp b/cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/contentbreadcrumb/contentbreadcrumb.jsp
index 2080bd2..5a6c606 100644
--- a/cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/contentbreadcrumb/contentbreadcrumb.jsp
+++ b/cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/contentbreadcrumb/contentbreadcrumb.jsp
@@ -17,25 +17,25 @@
  * under the License.
  */ --%>
  <%@include file="/libs/sling-cms/global.jsp"%>
-<sling:getParent resource="${slingRequest.requestPathInfo.suffixResource}" var="site" level="${resource.valueMap.depth}" />
+<sling:getParent resource="${slingRequest.requestPathInfo.suffixResource}" var="root" level="${resource.valueMap.depth}" />
 <ul class="Breadcrumb">
 	<li class="Breadcrumb-Item">
-		<a href="${resource.valueMap.prefix}${site.path}">
-			<sling:encode value="${site.valueMap['jcr:title']}" mode="HTML" />
+		<a href="${resource.valueMap.prefix}${root.path}">
+			<sling:encode value="${root.valueMap['jcr:title'] != null ? root.valueMap['jcr:title'] : root.valueMap['jcr:content/jcr:title']}" mode="HTML" />
 		</a>
 	</li>
 	<c:if test="${site.path != slingRequest.requestPathInfo.suffix && site.path != slingRequest.requestPathInfo.suffixResource.parent.path}">
 		<c:forEach var="parent" items="${sling:getParents(slingRequest.requestPathInfo.suffixResource,(resource.valueMap.depth + 1))}">
 			<li class="Breadcrumb-Item">
 				<a href="${resource.valueMap.prefix}${parent.path}">
-					<sling:encode value="${parent.valueMap[resource.valueMap.titleProp]}" default="${parent.name}" mode="HTML" />
+					<sling:encode value="${parent.valueMap['jcr:title'] != null ? parent.valueMap['jcr:title'] : parent.valueMap['jcr:content/jcr:title']}" default="${parent.name}" mode="HTML" />
 				</a>
 			</li>
 		</c:forEach>
 	</c:if>
-	<c:if test="${site.path != slingRequest.requestPathInfo.suffix}">
+	<c:if test="${root.path != slingRequest.requestPathInfo.suffix}">
 		<li class="Breadcrumb-Item">
-			<sling:encode value="${slingRequest.requestPathInfo.suffixResource.valueMap[resource.valueMap.titleProp]}" default="${slingRequest.requestPathInfo.suffix}" mode="HTML" />
+			<sling:encode value="${slingRequest.requestPathInfo.suffixResource.valueMap['jcr:title'] != null ? slingRequest.requestPathInfo.suffixResource.valueMap['jcr:title'] : slingRequest.requestPathInfo.suffixResource.valueMap['jcr:content/jcr:title']}" default="${slingRequest.requestPathInfo.suffix}" mode="HTML" />
 		</li>
 	</c:if>
 </ul>
\ No newline at end of file
diff --git a/cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/pagetemplate/edit.json b/cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/pagetemplate/edit.json
index 3cc8559..d9b39c3 100644
--- a/cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/pagetemplate/edit.json
+++ b/cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/pagetemplate/edit.json
@@ -33,7 +33,7 @@
 		"template": {
 			"jcr:primaryType": "nt:unstructured",
 			"sling:resourceType": "sling-cms/components/editor/fields/textarea",
-			"defaultValue":"{\r\n  \"jcr:primaryType\": \"sling:Page\",\r\n  \"jcr:content\": {\r\n    \"jcr:primaryType\": \"nt:unstructured\",\r\n    \"jcr:title\": \"{{title}}\",\r\n    \"sling:template\": \"{{template}}\",\r\n    \"sling:resourceType\": \"references\/components\/pages\/base\"\r\n  }\r\n}",
+			"defaultValue": "{\r\n  \"jcr:primaryType\": \"sling:Page\",\r\n  \"jcr:content\": {\r\n    \"jcr:primaryType\": \"nt:unstructured\",\r\n    \"jcr:title\": \"{{title}}\",\r\n    \"sling:template\": \"{{template}}\",\r\n    \"sling:resourceType\": \"reference\/components\/pages\/base\",\r\n    \"published\": false\r\n  }\r\n}",
 			"label": "Template",
 			"name": "template",
 			"required": true
diff --git a/cms/ui/src/main/resources/jcr_root/libs/sling-cms/content/file/upload.json b/cms/ui/src/main/resources/jcr_root/libs/sling-cms/content/file/upload.json
index 111c1e3..1723c34 100644
--- a/cms/ui/src/main/resources/jcr_root/libs/sling-cms/content/file/upload.json
+++ b/cms/ui/src/main/resources/jcr_root/libs/sling-cms/content/file/upload.json
@@ -30,7 +30,7 @@
 						"jcr:primaryType": "nt:unstructured",
 						"sling:resourceType": "sling-cms/components/editor/fields/hidden",
 						"name": "*@TypeHint",
-						"value": "nt:file"
+						"value": "sling:File"
 					}
 				}
 			}
diff --git a/cms/ui/src/main/resources/jcr_root/libs/sling-cms/content/site/content.json b/cms/ui/src/main/resources/jcr_root/libs/sling-cms/content/site/content.json
index d4f0b21..be13965 100644
--- a/cms/ui/src/main/resources/jcr_root/libs/sling-cms/content/site/content.json
+++ b/cms/ui/src/main/resources/jcr_root/libs/sling-cms/content/site/content.json
@@ -136,7 +136,7 @@
 							}
 						}
 					},
-					"nt:file":{
+					"sling:File":{
 						"jcr:primaryType": "nt:unstructured",
 						"columns": {
 							"jcr:primaryType": "nt:unstructured",
@@ -316,66 +316,6 @@
 								}
 							}
 						}
-					},
-					"nt:folder":{
-						"jcr:primaryType": "nt:unstructured",
-						"columns": {
-							"jcr:primaryType": "nt:unstructured",
-							"name": {
-								"jcr:primaryType": "nt:unstructured",
-								"link": true,
-								"type": "Name"
-							},
-							"title": {
-								"jcr:primaryType": "nt:unstructured",
-								"link": false,
-								"type": "Name"
-							},
-							"publish": {
-								"jcr:primaryType": "nt:unstructured",
-								"type": "Publish"
-							},
-							"type": {
-								"jcr:primaryType": "nt:unstructured",
-								"value": "Folder",
-								"type": "Static"
-							},
-							"lastModified": {
-								"jcr:primaryType": "nt:unstructured",
-								"property": "jcr:content/jcr:lastModified",
-								"type": "Date"
-							},
-							"lastModifiedBy": {
-								"jcr:primaryType": "nt:unstructured",
-								"property": "jcr:content/jcr:lastModifiedBy",
-								"type": "String"
-							},
-							"actions": {
-								"jcr:primaryType": "nt:unstructured",
-								"type": "Actions",
-								"edit": {
-									"jcr:primaryType": "nt:unstructured",
-									"modal": true,
-									"title": "Edit Folder",
-									"text": "&#x270f;",
-									"prefix": "/cms/folder/edit.html"
-								},
-								"movecopy": {
-									"jcr:primaryType": "nt:unstructured",
-									"modal": true,
-									"title": "Move / Copy Folder",
-									"text": "&#x21c6;",
-									"prefix": "/cms/shared/movecopy.html"
-								},
-								"delete": {
-									"jcr:primaryType": "nt:unstructured",
-									"title": "Delete Folder",
-									"text": "&times;",
-									"prefix": "/cms/shared/delete.html",
-									"modal": true
-								}
-							}
-						}
 					}
 				}
 			}
diff --git a/cms/ui/src/main/resources/jcr_root/libs/sling-cms/content/taxonomy/list.json b/cms/ui/src/main/resources/jcr_root/libs/sling-cms/content/taxonomy/list.json
index 0e4589f..cb81efc 100644
--- a/cms/ui/src/main/resources/jcr_root/libs/sling-cms/content/taxonomy/list.json
+++ b/cms/ui/src/main/resources/jcr_root/libs/sling-cms/content/taxonomy/list.json
@@ -21,9 +21,8 @@
 			"contentbreadcrumb": {
 				"jcr:primaryType": "nt:unstructured",
 				"sling:resourceType": "sling-cms/components/cms/contentbreadcrumb",
-				"depth": 3,
-				"prefix": "/cms/taxonomy/list.html",
-				"titleProp": "jcr:title"
+				"depth": 2,
+				"prefix": "/cms/taxonomy/list.html"
 			},
 			"contenttable": {
 				"jcr:primaryType": "nt:unstructured",

-- 
To stop receiving notification emails like this one, please contact
dklco@apache.org.