use of org.alfresco.service.cmr.quickshare.QuickShareDTO in project alfresco-repository by Alfresco.
the class QuickShareServiceIntegrationTest method testWithCustomContentType.
/**
* Content types that extend cm:content should be shareable.
*
* See https://issues.alfresco.com/jira/browse/ALF-16274.
*/
@Test
public void testWithCustomContentType() {
ByteArrayInputStream modelStream = new ByteArrayInputStream(MODEL.getBytes());
temporaryModels.loadModel(modelStream);
QName sharableType = QName.createQName("{http://bugtestmodel}doc");
QName unsharableType = QName.createQName("{http://bugtestmodel}doc2");
final NodeRef sharableNode = testNodes.createNodeWithTextContent(userHome, "Quick Share Custom Type Sharable Test Node", sharableType, user1.getUsername(), "Quick Share Test Node Content");
Map<String, Object> metadata = getMetadata(sharableNode, user1);
assertTrue((Boolean) metadata.get("sharable"));
QuickShareDTO dto = share(sharableNode, user1.getUsername());
unshare(dto.getId(), user1.getUsername());
final NodeRef unsharableNode = testNodes.createNodeWithTextContent(userHome, "Quick Share Custom Type Unsharable Test Node", unsharableType, user1.getUsername(), "Quick Share Test Node Content");
metadata = getMetadata(unsharableNode, user1);
assertFalse((Boolean) metadata.get("sharable"));
boolean exceptionThrown = false;
try {
// Prior to fixing ALF-16274, this would throw an InvalidNodeRefException.
share(unsharableNode, user1.getUsername());
} catch (InvalidNodeRefException ex) {
exceptionThrown = true;
}
assertTrue("InvalidNodeRefException not thrown on trying to share an unsharable content type", exceptionThrown);
}
use of org.alfresco.service.cmr.quickshare.QuickShareDTO in project alfresco-repository by Alfresco.
the class QuickShareServiceIntegrationTest method testModifierAfterUnSharing.
/**
* Test for MNT-15654
* <p> The node is created and shared by user1. Then unshared by user2
* <p> The modifier should not change to user2 after unsharing.
*/
@Test
public void testModifierAfterUnSharing() {
AuthenticationUtil.runAs(new RunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
permissionService.setPermission(testNode, user2.getUsername(), PermissionService.CONSUMER, true);
return null;
}
}, user1.getUsername());
QuickShareDTO dto = share(testNode, user1.getUsername());
unshare(dto.getId(), user2.getUsername());
String modifier = AuthenticationUtil.runAsSystem(new RunAsWork<String>() {
@Override
public String doWork() throws Exception {
return (String) nodeService.getProperty(testNode, ContentModel.PROP_MODIFIER);
}
});
assertEquals("The modifier has changed after sharing.", user1.getUsername(), modifier);
}
use of org.alfresco.service.cmr.quickshare.QuickShareDTO in project alfresco-repository by Alfresco.
the class QuickShareServiceIntegrationTest method testDeleteAndRestoreSharedNode.
// MNT-16224, RA-1093
@Test
public void testDeleteAndRestoreSharedNode() {
// Share the test node
share(testNode, user1.getUsername());
AuthenticationUtil.runAsSystem(new RunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
assertTrue(nodeService.hasAspect(testNode, QuickShareModel.ASPECT_QSHARE));
return null;
}
});
// Delete and restore the shared node.
testNode = AuthenticationUtil.runAs(new RunAsWork<NodeRef>() {
@Override
public NodeRef doWork() throws Exception {
// Delete the shared node
nodeService.deleteNode(testNode);
// Check if the node has been archived
final NodeRef archivedNode = nodeArchiveService.getArchivedNode(testNode);
assertNotNull(archivedNode);
// Restore the deleted shared node from trashcan
RestoreNodeReport restoreNodeReport = nodeArchiveService.restoreArchivedNode(archivedNode);
assertNotNull(restoreNodeReport);
assertTrue(restoreNodeReport.getStatus() == RestoreStatus.SUCCESS);
NodeRef restoredNodeRef = restoreNodeReport.getRestoredNodeRef();
assertNotNull(restoredNodeRef);
return restoredNodeRef;
}
}, user1.getUsername());
// Check the restored node doesn't have the 'shared' aspect.
AuthenticationUtil.runAsSystem(new RunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
assertFalse(nodeService.hasAspect(testNode, QuickShareModel.ASPECT_QSHARE));
assertNull(nodeService.getProperty(testNode, QuickShareModel.PROP_QSHARE_SHAREDID));
assertNull(nodeService.getProperty(testNode, QuickShareModel.PROP_QSHARE_SHAREDBY));
return null;
}
});
/**
* Tests the scenario where the shared node has been deleted and restored before the fix (MNT-16224).
* In this scenario the user should be able to un-share the restored node.
*/
{
// Share the test node again
final QuickShareDTO dto = share(testNode, user1.getUsername());
// Delete only the sharedId without removing the 'shared' aspect!(The cause of MNT-16224 and RA-1093)
TenantUtil.runAsDefaultTenant(new TenantRunAsWork<Void>() {
public Void doWork() throws Exception {
attributeService.removeAttribute(".sharedIds", dto.getId());
return null;
}
});
// Check the 'shared' aspect does exist
AuthenticationUtil.runAsSystem(new RunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
assertTrue(nodeService.hasAspect(testNode, QuickShareModel.ASPECT_QSHARE));
return null;
}
});
try {
// Try to un-share the node even though the sharedId was deleted.
unshare(dto.getId(), user2.getUsername());
fail("user2 shouldn't be able to un-share the node.");
} catch (InvalidSharedIdException ex) {
// Expected
}
// Un-share the node even though the sharedId was deleted.
// This should succeed as the lookup will use TMDQ.
unshare(dto.getId(), user1.getUsername());
// Check the 'shared' aspect does not exist
AuthenticationUtil.runAsSystem(new RunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
assertFalse(nodeService.hasAspect(testNode, QuickShareModel.ASPECT_QSHARE));
return null;
}
});
}
}
use of org.alfresco.service.cmr.quickshare.QuickShareDTO in project alfresco-repository by Alfresco.
the class QuickShareServiceIntegrationTest method getMetadataFromShareId.
@Test
public void getMetadataFromShareId() {
QuickShareDTO dto = share(testNode, user1.getUsername());
Map<String, Object> metadata = quickShareService.getMetaData(dto.getId());
assertNotNull(metadata);
assertTrue(metadata.size() > 0);
}
use of org.alfresco.service.cmr.quickshare.QuickShareDTO in project alfresco-repository by Alfresco.
the class QuickShareServiceIntegrationTest method cloud928.
@Test
public void cloud928() {
final NodeRef node = testNodes.createNodeWithTextContent(userHome, "CLOUD-928 Test Node", ContentModel.TYPE_CONTENT, user1.getUsername(), "Quick Share Test Node Content");
QuickShareDTO dto = share(node, user1.getUsername());
attributeService.removeAttribute(QuickShareServiceImpl.ATTR_KEY_SHAREDIDS_ROOT, dto.getId());
AuthenticationUtil.runAs(new RunAsWork<Object>() {
@Override
public Object doWork() throws Exception {
nodeService.deleteNode(node);
return null;
}
}, user1.getUsername());
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
Assert.assertFalse(nodeService.exists(node));
}
Aggregations