Commit e7325bfd authored by Bert Leunis's avatar Bert Leunis

HSTTWO-4238 use channel root path as default for the picker root path

If the tag attribute rootPath is not available and the @JcrPath annotation of the component parameter is not given, use the channel root path as fallback/default for the picker root path. This prevents that the picker dialog allows the user to pick documents from outside the channel's content folder.

In case this IS actuallly wanted, then the rootPath attribute could be configured with something like '/content/documents' to allow for this.

Due to the fact that now in many more cases the pickerRootPath by default is provided, a number of unit tests had to be extended to cover this.
parent 70e61a37
......@@ -138,7 +138,6 @@ public class HstManageContentTag extends TagSupport {
log.error("Exception while checking rootPath parameter.", e);
return EVAL_PAGE;
}
final String componentValue = getComponentValue(requestContext, isRelativePathParameter);
try {
......@@ -152,6 +151,11 @@ public class HstManageContentTag extends TagSupport {
}
}
private String getChannelRootPath() {
final ResolvedMount resolvedMount = RequestContextProvider.get().getResolvedMount();
return resolvedMount.getMount().getContentPath();
}
private String checkRootPath(final HstRequestContext requestContext) throws RepositoryException {
if (rootPath == null) {
return null;
......@@ -196,9 +200,7 @@ public class HstManageContentTag extends TagSupport {
final String componentValue = window.getParameter(prefixedParameterName);
if (componentValue != null && isRelativePathParameter) {
final ResolvedMount resolvedMount = requestContext.getResolvedMount();
final String contentRoot = resolvedMount.getMount().getContentPath();
return contentRoot + "/" + componentValue;
return getChannelRootPath() + "/" + componentValue;
}
return componentValue;
}
......@@ -242,7 +244,7 @@ public class HstManageContentTag extends TagSupport {
}
private Map<String, Object> getAttributeMap(final String documentId, final String componentValue, final JcrPath jcrPath,
final boolean isRelativePathParameter, final String absoluteRootPath) {
final boolean isRelativePathParameter, final String absoluteRootPath) {
final Map<String, Object> result = new LinkedHashMap<>();
writeToMap(result, ChannelManagerConstants.HST_TYPE, "MANAGE_CONTENT_LINK");
writeToMap(result, "uuid", documentId);
......@@ -260,7 +262,7 @@ public class HstManageContentTag extends TagSupport {
writeToMap(result, "pickerConfiguration", jcrPath.pickerConfiguration());
writeToMap(result, "pickerInitialPath", jcrPath.pickerInitialPath());
writeToMap(result, "pickerRemembersLastVisited", Boolean.toString(jcrPath.pickerRemembersLastVisited()));
writeToMap(result, "pickerRootPath", absoluteRootPath != null ? absoluteRootPath : jcrPath.pickerRootPath());
writeToMap(result, "pickerRootPath", getFirstNonBlankString(absoluteRootPath, jcrPath.pickerRootPath(), getChannelRootPath()));
final String nodeTypes = Arrays.stream(jcrPath.pickerSelectableNodeTypes()).collect(Collectors.joining(","));
writeToMap(result, "pickerSelectableNodeTypes", nodeTypes);
......@@ -275,6 +277,16 @@ public class HstManageContentTag extends TagSupport {
}
}
/**
* Get the first String that is not blank from a number of Strings.
*
* @param strings variable list of Strings
* @return first non-null and not empty String or null if all are blank
*/
private String getFirstNonBlankString(final String ... strings) {
return Arrays.stream(strings).filter(StringUtils::isNotBlank).findFirst().orElse(null);
}
/*
* when a currentNode is of type hippo:handle, we return this node, else we check the parent, until we are at the jcr root node.
* When we hit the jcr root node, we return null;
......
......@@ -230,6 +230,14 @@ public class HstManageContentTagTest {
tag.setTemplateQuery("new-document");
tag.setParameterName("absPath");
final ResolvedMount resolvedMount = createMock(ResolvedMount.class);
final Mount mount = createMock(Mount.class);
expect(resolvedMount.getMount()).andReturn(mount).anyTimes();
expect(mount.getContentPath()).andReturn("/my/channel/path").anyTimes();
hstRequestContext.setResolvedMount(resolvedMount);
replay(resolvedMount, mount);
assertThat(tag.doEndTag(), is(EVAL_PAGE));
assertThat(response.getContentAsString(), is("<!-- {"
......@@ -238,7 +246,8 @@ public class HstManageContentTagTest {
+ "\"parameterName\":\"absPath\","
+ "\"parameterValueIsRelativePath\":\"false\","
+ "\"pickerConfiguration\":\"cms-pickers/documents\","
+ "\"pickerRemembersLastVisited\":\"true\""
+ "\"pickerRemembersLastVisited\":\"true\","
+ "\"pickerRootPath\":\"/my/channel/path\""
+ "} -->"));
}
......@@ -247,6 +256,14 @@ public class HstManageContentTagTest {
tag.setTemplateQuery("new-document");
tag.setParameterName("relPath");
final ResolvedMount resolvedMount = createMock(ResolvedMount.class);
final Mount mount = createMock(Mount.class);
expect(resolvedMount.getMount()).andReturn(mount).anyTimes();
expect(mount.getContentPath()).andReturn("/my/channel/path").anyTimes();
hstRequestContext.setResolvedMount(resolvedMount);
replay(resolvedMount, mount);
assertThat(tag.doEndTag(), is(EVAL_PAGE));
assertThat(response.getContentAsString(), is("<!-- {"
......@@ -255,7 +272,8 @@ public class HstManageContentTagTest {
+ "\"parameterName\":\"relPath\","
+ "\"parameterValueIsRelativePath\":\"true\","
+ "\"pickerConfiguration\":\"cms-pickers/documents\","
+ "\"pickerRemembersLastVisited\":\"true\""
+ "\"pickerRemembersLastVisited\":\"true\","
+ "\"pickerRootPath\":\"/my/channel/path\""
+ "} -->"));
}
......@@ -316,7 +334,14 @@ public class HstManageContentTagTest {
final MockNode root = MockNode.root();
final MockNode handle = root.addNode("document", HippoNodeType.NT_HANDLE);
expect(document.getNode()).andReturn(handle);
replay(document);
final ResolvedMount resolvedMount = createMock(ResolvedMount.class);
final Mount mount = createMock(Mount.class);
expect(resolvedMount.getMount()).andReturn(mount).anyTimes();
expect(mount.getContentPath()).andReturn("/my/channel/path").anyTimes();
hstRequestContext.setResolvedMount(resolvedMount);
replay(document, resolvedMount, mount);
assertThat(tag.doEndTag(), is(EVAL_PAGE));
......@@ -327,7 +352,8 @@ public class HstManageContentTagTest {
+ "\"parameterValueIsRelativePath\":\"false\","
+ "\"parameterValue\":\"/absolute/path\","
+ "\"pickerConfiguration\":\"cms-pickers/documents\","
+ "\"pickerRemembersLastVisited\":\"true\""
+ "\"pickerRemembersLastVisited\":\"true\","
+ "\"pickerRootPath\":\"/my/channel/path\""
+ "} -->"));
}
......@@ -360,7 +386,8 @@ public class HstManageContentTagTest {
+ "\"parameterValueIsRelativePath\":\"true\","
+ "\"parameterValue\":\"/mount/path/relative/path\","
+ "\"pickerConfiguration\":\"cms-pickers/documents\","
+ "\"pickerRemembersLastVisited\":\"true\""
+ "\"pickerRemembersLastVisited\":\"true\","
+ "\"pickerRootPath\":\"/mount/path\""
+ "} -->"));
}
......@@ -377,7 +404,14 @@ public class HstManageContentTagTest {
final MockNode root = MockNode.root();
final MockNode handle = root.addNode("document", HippoNodeType.NT_HANDLE);
expect(document.getNode()).andReturn(handle);
replay(document);
final ResolvedMount resolvedMount = createMock(ResolvedMount.class);
final Mount mount = createMock(Mount.class);
expect(resolvedMount.getMount()).andReturn(mount).anyTimes();
expect(mount.getContentPath()).andReturn("/my/channel/path").anyTimes();
hstRequestContext.setResolvedMount(resolvedMount);
replay(document, resolvedMount, mount);
assertThat(tag.doEndTag(), is(EVAL_PAGE));
......@@ -388,7 +422,8 @@ public class HstManageContentTagTest {
+ "\"parameterValueIsRelativePath\":\"false\","
+ "\"parameterValue\":\"/absolute/path\","
+ "\"pickerConfiguration\":\"cms-pickers/documents\","
+ "\"pickerRemembersLastVisited\":\"true\""
+ "\"pickerRemembersLastVisited\":\"true\","
+ "\"pickerRootPath\":\"/my/channel/path\""
+ "} -->"));
}
......@@ -404,7 +439,14 @@ public class HstManageContentTagTest {
final MockNode root = MockNode.root();
final MockNode handle = root.addNode("document", HippoNodeType.NT_HANDLE);
expect(document.getNode()).andReturn(handle);
replay(document);
final ResolvedMount resolvedMount = createMock(ResolvedMount.class);
final Mount mount = createMock(Mount.class);
expect(resolvedMount.getMount()).andReturn(mount).anyTimes();
expect(mount.getContentPath()).andReturn("/my/channel/path").anyTimes();
hstRequestContext.setResolvedMount(resolvedMount);
replay(document, resolvedMount, mount);
assertThat(tag.doEndTag(), is(EVAL_PAGE));
......@@ -415,7 +457,8 @@ public class HstManageContentTagTest {
+ "\"parameterValueIsRelativePath\":\"false\","
+ "\"parameterValue\":\"/absolute/path\","
+ "\"pickerConfiguration\":\"cms-pickers/documents\","
+ "\"pickerRemembersLastVisited\":\"true\""
+ "\"pickerRemembersLastVisited\":\"true\","
+ "\"pickerRootPath\":\"/my/channel/path\""
+ "} -->"));
}
......@@ -423,6 +466,14 @@ public class HstManageContentTagTest {
public void pickerConfiguration() throws Exception {
tag.setParameterName("pickerPath");
final ResolvedMount resolvedMount = createMock(ResolvedMount.class);
final Mount mount = createMock(Mount.class);
expect(resolvedMount.getMount()).andReturn(mount).anyTimes();
expect(mount.getContentPath()).andReturn("/my/channel/path").anyTimes();
hstRequestContext.setResolvedMount(resolvedMount);
replay(resolvedMount, mount);
assertThat(tag.doEndTag(), is(EVAL_PAGE));
assertThat(response.getContentAsString(), is("<!-- {"
......@@ -604,7 +655,13 @@ public class HstManageContentTagTest {
expect(folderNode.isNodeType(HippoStdNodeType.NT_DIRECTORY)).andReturn(true);
expect(jcrSession.getNode("/my/channel/path/relative/path")).andReturn(folderNode);
replay(jcrSession, folderNode);
final ResolvedMount resolvedMount = createMock(ResolvedMount.class);
final Mount mount = createMock(Mount.class);
expect(resolvedMount.getMount()).andReturn(mount).anyTimes();
expect(mount.getContentPath()).andReturn("/my/channel/path").anyTimes();
hstRequestContext.setResolvedMount(resolvedMount);
replay(jcrSession, folderNode, resolvedMount, mount);
assertThat(tag.doEndTag(), is(EVAL_PAGE));
assertThat(response.getContentAsString(), is("<!-- {"
......@@ -623,11 +680,13 @@ public class HstManageContentTagTest {
tag.setParameterName("docPathParameter");
window.setComponent(new TestComponentWithoutPickerRootPath());
Session jcrSession = createMock(Session.class);
hstRequestContext.setSession(jcrSession);
hstRequestContext.setSiteContentBasePath("my/channel/path");
final ResolvedMount resolvedMount = createMock(ResolvedMount.class);
final Mount mount = createMock(Mount.class);
expect(resolvedMount.getMount()).andReturn(mount).anyTimes();
expect(mount.getContentPath()).andReturn("/my/channel/path").anyTimes();
hstRequestContext.setResolvedMount(resolvedMount);
replay(jcrSession);
replay(resolvedMount, mount);
assertThat(tag.doEndTag(), is(EVAL_PAGE));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment