Skip to content

Commit

Permalink
fix: [BUG] - Bad redirection for shared document notification - EXO-7…
Browse files Browse the repository at this point in the history
…7137

Prior to this fix, Notifications generated dor shered filkes redirect to the space home page. This fix changes the notifications url to use the new space permalinks.
  • Loading branch information
mkrout authored Mar 4, 2025
1 parent 10f7e0c commit c2d8ebc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
*/
package org.exoplatform.documents.notification.utils;

import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;

import org.exoplatform.commons.utils.CommonsUtils;
import org.exoplatform.documents.rest.util.EntityBuilder;
import org.exoplatform.services.jcr.core.ExtendedNode;
Expand All @@ -28,10 +32,6 @@
import org.exoplatform.social.core.space.model.Space;
import org.exoplatform.social.core.space.spi.SpaceService;

import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;

public class NotificationUtils {

public static final String JCR_CONTENT = "jcr:content";
Expand All @@ -44,10 +44,9 @@ public static String getDocumentLink(Node node, SpaceService spaceService, Ident
StringBuilder stringBuilder = new StringBuilder();
Identity identity = EntityBuilder.getOwnerIdentityFromNodePath(node.getPath(), identityManager, spaceService);
Space space = spaceService.getSpaceByPrettyName(identity.getRemoteId());
String groupId = space.getGroupId().replace("/", ":");
String domain = CommonsUtils.getCurrentDomain();
stringBuilder.append(domain).append("/").append(LinkProvider.getPortalName(null)).append("/");
stringBuilder.append("g/").append(groupId).append("/").append(space.getPrettyName());
stringBuilder.append("s/").append(space.getId());
if (node.hasNode(JCR_CONTENT)) {
stringBuilder.append("/documents?documentPreviewId=");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.*;

import javax.jcr.*;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Value;

import org.exoplatform.services.jcr.impl.core.SessionImpl;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -24,8 +24,8 @@
import org.exoplatform.commons.utils.CommonsUtils;
import org.exoplatform.documents.rest.util.EntityBuilder;
import org.exoplatform.services.jcr.core.ExtendedNode;
import org.exoplatform.services.jcr.core.ExtendedSession;
import org.exoplatform.services.jcr.impl.core.NodeImpl;
import org.exoplatform.services.jcr.impl.core.SessionImpl;
import org.exoplatform.social.core.identity.model.Identity;
import org.exoplatform.social.core.identity.model.Profile;
import org.exoplatform.social.core.identity.provider.OrganizationIdentityProvider;
Expand Down Expand Up @@ -67,8 +67,9 @@ public void setUp() throws Exception {
public void getDocumentLink() throws RepositoryException {
Identity identity = mock(Identity.class);
Space space = new Space();
space.setGroupId("/spaces/spacex");
space.setId("1");
space.setPrettyName("spacex");
space.setGroupId("/spaces/spacex");
when(identity.getRemoteId()).thenReturn("spacex");
Node node = Mockito.mock(ExtendedNode.class);
when(((ExtendedNode) node).getIdentifier()).thenReturn("123");
Expand All @@ -78,7 +79,7 @@ public void getDocumentLink() throws RepositoryException {
ENTITY_BUILDER.when(() -> EntityBuilder.getOwnerIdentityFromNodePath(any(), any(), any())).thenReturn(identity);

String link = NotificationUtils.getDocumentLink(node, spaceService, identityManager);
assertEquals("http://domain/portal/g/:spaces:spacex/spacex/documents?documentPreviewId=123", link);
assertEquals("http://domain/portal/s/1/documents?documentPreviewId=123", link);
}

@Test
Expand Down

0 comments on commit c2d8ebc

Please sign in to comment.