Search in sources :

Example 6 with QuickShareDTO

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);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) QuickShareDTO(org.alfresco.service.cmr.quickshare.QuickShareDTO) ByteArrayInputStream(java.io.ByteArrayInputStream) QName(org.alfresco.service.namespace.QName) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) Test(org.junit.Test)

Example 7 with QuickShareDTO

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);
}
Also used : QuickShareDTO(org.alfresco.service.cmr.quickshare.QuickShareDTO) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) InvalidSharedIdException(org.alfresco.service.cmr.quickshare.InvalidSharedIdException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) Test(org.junit.Test)

Example 8 with QuickShareDTO

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;
            }
        });
    }
}
Also used : RestoreNodeReport(org.alfresco.repo.node.archive.RestoreNodeReport) NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidSharedIdException(org.alfresco.service.cmr.quickshare.InvalidSharedIdException) QuickShareDTO(org.alfresco.service.cmr.quickshare.QuickShareDTO) RunAsWork(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork) TenantRunAsWork(org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork) TenantRunAsWork(org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) InvalidSharedIdException(org.alfresco.service.cmr.quickshare.InvalidSharedIdException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) Test(org.junit.Test)

Example 9 with QuickShareDTO

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);
}
Also used : QuickShareDTO(org.alfresco.service.cmr.quickshare.QuickShareDTO) Test(org.junit.Test)

Example 10 with QuickShareDTO

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));
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) QuickShareDTO(org.alfresco.service.cmr.quickshare.QuickShareDTO) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) InvalidSharedIdException(org.alfresco.service.cmr.quickshare.InvalidSharedIdException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) Test(org.junit.Test)

Aggregations

QuickShareDTO (org.alfresco.service.cmr.quickshare.QuickShareDTO)10 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)8 NodeRef (org.alfresco.service.cmr.repository.NodeRef)7 Test (org.junit.Test)7 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)6 InvalidSharedIdException (org.alfresco.service.cmr.quickshare.InvalidSharedIdException)5 HashMap (java.util.HashMap)2 RestoreNodeReport (org.alfresco.repo.node.archive.RestoreNodeReport)2 QName (org.alfresco.service.namespace.QName)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 ClientAppNotFoundException (org.alfresco.repo.client.config.ClientAppNotFoundException)1 QuickShareLinkExpiryActionException (org.alfresco.repo.quickshare.QuickShareLinkExpiryActionException)1 RunAsWork (org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork)1 TenantRunAsWork (org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork)1 QuickShareLink (org.alfresco.rest.api.model.QuickShareLink)1 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)1 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)1