[MNT-23550] Always disable behaviours to prevent unexpected modifier changes (#1898)

This commit is contained in:
tiagosalvado10
2023-05-03 20:34:37 +01:00
committed by GitHub
parent a177f391db
commit f83328f7b0
2 changed files with 67 additions and 14 deletions

View File

@@ -514,15 +514,11 @@ public class RenditionService2Impl implements RenditionService2, InitializingBea
NodeRef renditionNode = getRenditionNode(sourceNodeRef, renditionName);
boolean createRenditionNode = renditionNode == null;
boolean sourceHasAspectRenditioned = nodeService.hasAspect(sourceNodeRef, RenditionModel.ASPECT_RENDITIONED);
boolean sourceChanges = !sourceHasAspectRenditioned || createRenditionNode || transformInputStream == null;
try
{
if (sourceChanges)
{
ruleService.disableRuleType(RuleType.UPDATE);
behaviourFilter.disableBehaviour(sourceNodeRef, ContentModel.ASPECT_AUDITABLE);
behaviourFilter.disableBehaviour(sourceNodeRef, ContentModel.ASPECT_VERSIONABLE);
}
ruleService.disableRuleType(RuleType.UPDATE);
behaviourFilter.disableBehaviour(sourceNodeRef, ContentModel.ASPECT_AUDITABLE);
behaviourFilter.disableBehaviour(sourceNodeRef, ContentModel.ASPECT_VERSIONABLE);
// If they do not exist create the rendition association and the rendition node.
if (createRenditionNode)
@@ -592,12 +588,9 @@ public class RenditionService2Impl implements RenditionService2, InitializingBea
}
finally
{
if (sourceChanges)
{
behaviourFilter.enableBehaviour(sourceNodeRef, ContentModel.ASPECT_AUDITABLE);
behaviourFilter.enableBehaviour(sourceNodeRef, ContentModel.ASPECT_VERSIONABLE);
ruleService.enableRuleType(RuleType.UPDATE);
}
behaviourFilter.enableBehaviour(sourceNodeRef, ContentModel.ASPECT_AUDITABLE);
behaviourFilter.enableBehaviour(sourceNodeRef, ContentModel.ASPECT_VERSIONABLE);
ruleService.enableRuleType(RuleType.UPDATE);
}
return null;
}, false, true));

View File

@@ -30,6 +30,7 @@ import static org.junit.Assert.assertNotEquals;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.alfresco.model.ContentModel;
@@ -419,6 +420,65 @@ public class RenditionService2IntegrationTest extends AbstractRenditionIntegrati
assertTrue("New rendition content hash code was not generated", isValidRenditionContentHashCode(contentHashCode3));
}
@Test
public void testModifierAfterMultipleRenditionRequests() throws InterruptedException
{
String user1 = createRandomUser();
String user2 = createRandomUser();
List<NodeRef> nodes = new ArrayList<NodeRef>();
final int TOTAL_NODES = 10;
// Create nodes
for (int i = 0; i < TOTAL_NODES; i++)
{
NodeRef n = createSource(user1, "quick.jpg");
render(user1, n, DOC_LIB);
nodes.add(n);
}
// Ask rendition multiple times with 'user2'
for (int j = 0; j < 10; j++)
{
for (int i = 0; i < TOTAL_NODES; i++)
{
render(user2, nodes.get(i), DOC_LIB);
}
}
for (int i = 0; i < TOTAL_NODES; i++)
{
waitForRendition(user1, nodes.get(i), DOC_LIB, true);
}
// Check the modifier is still user1
assertEquals(TOTAL_NODES, countModifier(nodes, user1));
}
private int countModifier(List<NodeRef> nodes, String user)
{
int count = 0;
for (int i = 0; i < nodes.size(); i++)
{
count += compareModifier(nodes.get(i), user);
}
return count;
}
private int compareModifier(NodeRef nodeRef, String user)
{
int res = 0;
if (nodeRef != null && user != null)
{
String modifier = nodeService.getProperty(nodeRef, ContentModel.PROP_MODIFIER).toString();
if (user.equals(modifier))
{
res = 1;
}
}
return res;
}
/**
* @deprecated can be removed when we remove the original RenditionService
*/
@@ -622,4 +682,4 @@ public class RenditionService2IntegrationTest extends AbstractRenditionIntegrati
renditionService2.setEnabled(true);
}
}
}
}