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 d1f4585 commit f5680bb
Showing 1 changed file with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@

import org.exoplatform.container.PortalContainer;
import org.exoplatform.services.cms.impl.Utils;
import org.exoplatform.services.jcr.core.ExtendedSession;
import org.exoplatform.services.jcr.core.ExtendedNode;

import org.exoplatform.services.security.ConversationState;
import org.gatein.common.text.EntityEncoder;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.simple.JSONObject;

import org.exoplatform.addons.chat.listener.ServerBootstrap;
import org.exoplatform.chat.services.ChatService;
import org.exoplatform.commons.utils.CommonsUtils;
Expand Down Expand Up @@ -244,24 +246,22 @@ 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);

Space space = spaceService_.getSpaceByDisplayName(roomFullName);
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 f5680bb

Please sign in to comment.