Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ensure Case-Insensitive file existence check -EXO-66043 #2195

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>ecms</artifactId>
<groupId>org.exoplatform.ecms</groupId>
<version>6.5.x-SNAPSHOT</version>
<version>6.5.x-maintenance-SNAPSHOT</version>
</parent>
<artifactId>ecms-apps</artifactId>
<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion apps/portlet-administration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>ecms-apps</artifactId>
<groupId>org.exoplatform.ecms</groupId>
<version>6.5.x-SNAPSHOT</version>
<version>6.5.x-maintenance-SNAPSHOT</version>
</parent>
<artifactId>ecms-apps-portlet-administration</artifactId>
<packaging>war</packaging>
Expand Down
4 changes: 1 addition & 3 deletions apps/portlet-clouddrives/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/portlet-clouddrives/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<parent>
<artifactId>ecms-apps</artifactId>
<groupId>org.exoplatform.ecms</groupId>
<version>6.5.x-SNAPSHOT</version>
<version>6.5.x-maintenance-SNAPSHOT</version>
</parent>
<artifactId>ecms-apps-portlet-clouddrives</artifactId>
<packaging>war</packaging>
Expand Down
2 changes: 1 addition & 1 deletion apps/portlet-documents/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<parent>
<artifactId>ecms-apps</artifactId>
<groupId>org.exoplatform.ecms</groupId>
<version>6.5.x-SNAPSHOT</version>
<version>6.5.x-maintenance-SNAPSHOT</version>
</parent>
<artifactId>ecms-apps-portlet-documents</artifactId>
<packaging>war</packaging>
Expand Down
4 changes: 1 addition & 3 deletions apps/portlet-editors/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/portlet-editors/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<parent>
<artifactId>ecms-apps</artifactId>
<groupId>org.exoplatform.ecms</groupId>
<version>6.5.x-SNAPSHOT</version>
<version>6.5.x-maintenance-SNAPSHOT</version>
</parent>
<artifactId>ecms-apps-portlet-editors</artifactId>
<packaging>war</packaging>
Expand Down
2 changes: 1 addition & 1 deletion apps/portlet-explorer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>ecms-apps</artifactId>
<groupId>org.exoplatform.ecms</groupId>
<version>6.5.x-SNAPSHOT</version>
<version>6.5.x-maintenance-SNAPSHOT</version>
</parent>
<artifactId>ecms-apps-portlet-explorer</artifactId>
<packaging>war</packaging>
Expand Down
2 changes: 1 addition & 1 deletion apps/portlet-presentation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>ecms-apps</artifactId>
<groupId>org.exoplatform.ecms</groupId>
<version>6.5.x-SNAPSHOT</version>
<version>6.5.x-maintenance-SNAPSHOT</version>
</parent>
<artifactId>ecms-apps-portlet-presentation</artifactId>
<packaging>war</packaging>
Expand Down
2 changes: 1 addition & 1 deletion apps/portlet-search/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>ecms-apps</artifactId>
<groupId>org.exoplatform.ecms</groupId>
<version>6.5.x-SNAPSHOT</version>
<version>6.5.x-maintenance-SNAPSHOT</version>
</parent>
<artifactId>ecms-apps-portlet-search</artifactId>
<packaging>war</packaging>
Expand Down
2 changes: 1 addition & 1 deletion apps/portlet-seo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>ecms-apps</artifactId>
<groupId>org.exoplatform.ecms</groupId>
<version>6.5.x-SNAPSHOT</version>
<version>6.5.x-maintenance-SNAPSHOT</version>
</parent>
<artifactId>ecms-apps-portlet-seo</artifactId>
<packaging>war</packaging>
Expand Down
2 changes: 1 addition & 1 deletion apps/portlet-transferrules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<parent>
<artifactId>ecms-apps</artifactId>
<groupId>org.exoplatform.ecms</groupId>
<version>6.5.x-SNAPSHOT</version>
<version>6.5.x-maintenance-SNAPSHOT</version>
</parent>
<artifactId>ecms-apps-portlet-transferrules</artifactId>
<packaging>war</packaging>
Expand Down
2 changes: 1 addition & 1 deletion apps/resources-wcm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>ecms-apps</artifactId>
<groupId>org.exoplatform.ecms</groupId>
<version>6.5.x-SNAPSHOT</version>
<version>6.5.x-maintenance-SNAPSHOT</version>
</parent>
<artifactId>ecms-apps-resources-wcm</artifactId>
<packaging>war</packaging>
Expand Down
16 changes: 3 additions & 13 deletions core/connector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<parent>
<artifactId>ecms-core</artifactId>
<groupId>org.exoplatform.ecms</groupId>
<version>6.5.x-SNAPSHOT</version>
<version>6.5.x-maintenance-SNAPSHOT</version>
</parent>
<artifactId>ecms-core-connector</artifactId>
<packaging>jar</packaging>
<name>eXo PLF:: ECMS Connector</name>
<description>eXo ECMS REST Services</description>
<properties>
<exo.test.coverage.ratio>0.0</exo.test.coverage.ratio>
<exo.test.coverage.ratio>0.10</exo.test.coverage.ratio>
</properties>
<dependencies>
<!--swagger-->
Expand Down Expand Up @@ -204,17 +204,7 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<artifactId>mockito-inline</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import org.apache.commons.lang.StringUtils;
import org.exoplatform.services.cms.drives.impl.ManageDriveServiceImpl;
import org.exoplatform.services.jcr.core.ExtendedNode;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

Expand Down Expand Up @@ -650,25 +652,61 @@ private Element createFileElement(Document document,
return file;
}

/**
* This function gets or creates the folder where the files will be stored
* @param driveName the name of the selected JCR drive
* @param workspaceName The name of the JCR workspace
* @param currentFolder The folder where the files will be stored
* for spaces, the currentFolder will be created directly under the Documents folder of the space.
* If the currentFolder param is preceded with 'DRIVE_ROOT_NODE' then currentFolder will be created under the root folder of the space
* @return Node object representing the parent folder where the files will be uploaded
* @throws Exception
*/
private Node getNode(String driveName, String workspaceName, String currentFolder) throws Exception {
return getNode(driveName, workspaceName, currentFolder, false);
}


/**
* This function gets or creates the folder where the files will be stored
* @param driveName the name of the selected JCR drive
* @param workspaceName The name of the JCR workspace
* @param currentFolder The folder where the files will be stored
* for spaces, the currentFolder will be created directly under the Documents folder of the space.
* If the currentFolder param is preceded with 'DRIVE_ROOT_NODE' then currentFolder will be created under the root folder of the space
* @param isSystem use system session if true
* @return Node object representing the parent folder where the files will be uploaded
* @throws Exception
*/
private Node getNode(String driveName, String workspaceName, String currentFolder, boolean isSystem) throws Exception {
Session session;
if (isSystem) {
session = getSystemSession(workspaceName);
} else {
session = getSession(workspaceName);
}
String driveHomePath = manageDriveService.getDriveByName(Text.escapeIllegalJcrChars(driveName)).getHomePath();
DriveData driveData = manageDriveService.getDriveByName(Text.escapeIllegalJcrChars(driveName));
String driveHomePath = driveData.getHomePath();
String userId = ConversationState.getCurrent().getIdentity().getUserId();
String drivePath = Utils.getPersonalDrivePath(driveHomePath, userId);
Node node = (Node) session.getItem(Text.escapeIllegalJcrChars(drivePath));
if (StringUtils.isEmpty(currentFolder)) {
return node;
}
for (String folder : currentFolder.split("/")) {
// Check if we store the file under Documents folder or under the root folder of the space
if(driveName.startsWith(".spaces.") && currentFolder.startsWith("DRIVE_ROOT_NODE")) {
String driveRootPath = driveHomePath;
if(driveHomePath.contains("/Documents")) {
driveRootPath = driveHomePath.substring(0, driveHomePath.indexOf("/Documents"));
}
// Need system session to create the folder if it does not exist
SessionProvider sessionProvider = SessionProvider.createSystemProvider();
Session systemSession = sessionProvider.getSession(workspaceName, getCurrentRepository());
node = (Node) systemSession.getItem(Text.escapeIllegalJcrChars(driveRootPath));
currentFolder = currentFolder.substring("DRIVE_ROOT_NODE/".length());
}

List<String> foldersNames = Arrays.stream(currentFolder.split("/")).filter(item -> !item.isEmpty()).toList().stream().toList();
for (String folder : foldersNames) {
String cleanFolderName = org.exoplatform.services.jcr.util.Text.escapeIllegalJcrChars(org.exoplatform.services.cms.impl.Utils.cleanString(folder));
if (node.hasNode(folder)) {
node = node.getNode(folder);
Expand All @@ -683,6 +721,16 @@ private Node getNode(String driveName, String workspaceName, String currentFolde
newNode.addMixin(NodetypeConstant.EXO_RSS_ENABLE);
}
newNode.setProperty(NodetypeConstant.EXO_TITLE, org.exoplatform.services.cms.impl.Utils.cleanDocumentTitle(folder));

// Update permissions
if (newNode.canAddMixin("exo:privilegeable")) {
newNode.addMixin("exo:privilegeable");
}
String groupId = driveData.getParameters().get(ManageDriveServiceImpl.DRIVE_PARAMATER_GROUP_ID);
if(StringUtils.isNotBlank(groupId) && groupId.startsWith("/spaces/")) {
((ExtendedNode) newNode).setPermission(groupId, new String[]{PermissionType.READ, PermissionType.ADD_NODE, PermissionType.SET_PROPERTY});
}

node.save();
node = newNode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

import javax.jcr.ItemExistsException;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.RepositoryException;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.CacheControl;
Expand Down Expand Up @@ -306,13 +307,21 @@ public Response checkExistence(Node parent, String fileName) throws Exception {
fileName = fileName.replaceAll(FILE_DECODE_REGEX, "%25");
fileName = URLDecoder.decode(fileName,"UTF-8");
fileName = fileName.replaceAll(FILE_DECODE_REGEX, "-");
Node existNode = null;
if (parent.hasNodes()) {
NodeIterator iterator = parent.getNodes();
while (iterator.hasNext()) {
Node childNode = iterator.nextNode();
if (childNode.getName().equalsIgnoreCase(fileName)) {
existNode = childNode;
break;
}
}
}
Element rootElement = fileExistence.createElement(
parent.hasNode(fileName) ? "Existed" : "NotExisted");
if(parent.hasNode(fileName)){
Node existNode = parent.getNode(fileName);
if(existNode.isNodeType(NodetypeConstant.MIX_VERSIONABLE)){
existNode !=null ? "Existed" : "NotExisted");
if(existNode != null && existNode.isNodeType(NodetypeConstant.MIX_VERSIONABLE)){
rootElement.appendChild(fileExistence.createElement("Versioned"));
}
}
if(parent.isNodeType(NodetypeConstant.NT_FILE) &&
resolver.getMimeType(parent.getName()).equals(resolver.getMimeType(fileName))){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.exoplatform.commons.testing.ConfigTestCase;
//import org.exoplatform.wcm.connector.authoring.TestCopyContentFile;
//import org.exoplatform.wcm.connector.authoring.TestLifecycleConnector;
import org.exoplatform.ecm.connector.platform.ManageDocumentServiceTest;
import org.exoplatform.wcm.connector.collaboration.TestDownloadConnector;
import org.exoplatform.wcm.connector.collaboration.TestFavoriteRESTService;
import org.exoplatform.wcm.connector.collaboration.TestOpenInOfficeConnector;
Expand Down Expand Up @@ -47,7 +48,8 @@
TestDownloadConnector.class,
TestOpenInOfficeConnector.class,
TestThumbnailRESTService.class,
TestFavoriteRESTService.class
TestFavoriteRESTService.class,
ManageDocumentServiceTest.class
})
@ConfigTestCase(BaseConnectorTestCase.class)
public class BaseConnectorTestSuite extends BaseExoContainerTestSuite {
Expand Down
Loading