Skip to content

Commit

Permalink
fix: Document - wrong creator for chat attachment  - EXO-73182
Browse files Browse the repository at this point in the history
Prior to this fix, attachments uploaded to chat conversation are created by System session,

This commit change that to use the current user session to create attachments.
  • Loading branch information
mkrout committed Nov 4, 2024
1 parent 8eee13c commit bf5bc8c
Showing 1 changed file with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import javax.ws.rs.core.SecurityContext;

import org.apache.commons.lang3.StringUtils;
import org.exoplatform.services.jcr.core.ExtendedNode;
import org.exoplatform.services.jcr.core.ExtendedSession;
import org.exoplatform.services.security.ConversationState;
import org.gatein.common.text.EntityEncoder;
import org.json.JSONArray;
Expand Down Expand Up @@ -259,26 +261,25 @@ private Node storeFile(UploadResource uploadResource,
SessionProvider sessionProvider = new SessionProvider(ConversationState.getCurrent());
sessionProvider.setCurrentRepository(currentRepository);
sessionProvider.setCurrentWorkspace(workspaceName);
Node homeNode;
Session session = sessionProvider.getSession(workspaceName, currentRepository);
Node docNode;
if (isPrivateContext) {
Node userNode = nodeHierarchyCreator_.getUserNode(sessionProvider, remoteUser);
homeNode = userNode.getNode("Private");
SessionProvider systemSessionProvider = sessionProviderService_.getSystemSessionProvider(null); // Need system session to get the User root node
Node userNode = nodeHierarchyCreator_.getUserNode(systemSessionProvider, remoteUser);
docNode = userNode.getNode("Private/Documents");
docNode = ((ExtendedSession) session).getNodeByIdentifier(((ExtendedNode) docNode).getIdentifier()); // Get the user private documents node using the user session, to use it as creator.
} else {
Session session = sessionProvider.getSession(workspaceName, currentRepository);

String roomJSONObject = ServerBootstrap.getRoom(remoteUser, token, roomId);
org.json.JSONObject room = new org.json.JSONObject(roomJSONObject);
Space space = spaceService_.getSpaceByPrettyName(room.get("prettyName").toString());
String groupPath = nodeHierarchyCreator_.getJcrPath(BasePath.CMS_GROUPS_PATH);
String spaceParentPath = groupPath + space.getGroupId();
if (!session.itemExists(spaceParentPath)) {
throw new IllegalStateException("Root node of space '" + spaceParentPath + "' doesn't exist");
String spaceDocumentsPath = groupPath + space.getGroupId() + "/Documents";
if (!session.itemExists(spaceDocumentsPath )) {
throw new IllegalStateException("Documents node of space '" + spaceDocumentsPath + "' doesn't exist");
}
homeNode = (Node) session.getItem(spaceParentPath);
docNode = (Node) session.getItem(spaceDocumentsPath);
}

Node docNode = homeNode.getNode("Documents");

int suffix = 1;
while (docNode.hasNode(filename)) {
filename = filename.contains(".") ? filename.replace(".", "-" + suffix + ".") : filename + "-" + suffix;
Expand Down

0 comments on commit bf5bc8c

Please sign in to comment.