Search in sources :

Example 1 with Repository

use of org.alfresco.repo.model.Repository in project alfresco-repository by Alfresco.

the class DownloadServiceIntegrationTest method deleteBeforeDateAsNormalUserFromAllSysDownloadFolders.

// see MNT-20212
@Test
public void deleteBeforeDateAsNormalUserFromAllSysDownloadFolders() throws InterruptedException {
    String randomUsername = createRandomUser();
    NamespaceService namespaceService = APP_CONTEXT_INIT.getApplicationContext().getBean("namespaceService", NamespaceService.class);
    Repository repositoryHelper = APP_CONTEXT_INIT.getApplicationContext().getBean("repositoryHelper", Repository.class);
    FileFolderService fileFolderService = APP_CONTEXT_INIT.getApplicationContext().getBean("fileFolderService", FileFolderService.class);
    // this value should be similar to whatever is set in the properties files for:
    // system.downloads_container.childname=sys:downloads
    final String nodeName = "sys:downloads";
    QName container = QName.createQName(nodeName, namespaceService);
    final NodeRef problematicDuplicateSystemDownloadNode = createProblematicDuplicateSystemNode(container, NODE_SERVICE, repositoryHelper);
    try {
        // add "downloads_container"
        assertNotEquals(problematicDuplicateSystemDownloadNode.getId(), nodeName);
        // downloads_container is taken from the downloadsSpace.xml uuid setting
        assertNotEquals(problematicDuplicateSystemDownloadNode.getId(), "downloads_container");
        Authentication previousAuth = AuthenticationUtil.getFullAuthentication();
        AuthenticationUtil.setFullyAuthenticatedUser(randomUsername);
        NodeRef beforeNodeRef;
        NodeRef afterNodeRef;
        Date beforeTime;
        try {
            beforeNodeRef = DOWNLOAD_SERVICE.createDownload(new NodeRef[] { level1Folder1 }, true);
            testNodes.addNodeRef(beforeNodeRef);
            waitForDownload(beforeNodeRef);
            beforeTime = new Date();
            afterNodeRef = DOWNLOAD_SERVICE.createDownload(new NodeRef[] { level1Folder2 }, true);
            testNodes.addNodeRef(afterNodeRef);
            waitForDownload(afterNodeRef);
        } finally {
            // assuming previous authentication is the system user
            AuthenticationUtil.setFullAuthentication(previousAuth);
        }
        moveDownloadedFileToProblematicFolder(fileFolderService, problematicDuplicateSystemDownloadNode, beforeNodeRef);
        deleteDownloadsAndCheckParameters(beforeNodeRef, afterNodeRef, beforeTime);
    } finally {
        cleanProblematicFolder(problematicDuplicateSystemDownloadNode);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Repository(org.alfresco.repo.model.Repository) NamespaceService(org.alfresco.service.namespace.NamespaceService) QName(org.alfresco.service.namespace.QName) Authentication(net.sf.acegisecurity.Authentication) FileFolderService(org.alfresco.service.cmr.model.FileFolderService) Date(java.util.Date) Test(org.junit.Test)

Example 2 with Repository

use of org.alfresco.repo.model.Repository in project alfresco-repository by Alfresco.

the class ScriptNodeTest method testConvertMultiplePropertyForActivitiScriptNode.

/**
 *  MNT-16053: Conversion for property with multiple=true, on an Activiti script node, fails.
 */
@Test
public void testConvertMultiplePropertyForActivitiScriptNode() {
    ArrayList<String> numbers = new ArrayList<>();
    numbers.add("Phone #1");
    numbers.add("Phone #2");
    Repository repositoryHelper = (Repository) APP_CONTEXT_INIT.getApplicationContext().getBean("repositoryHelper");
    NodeRef companyHome = repositoryHelper.getCompanyHome();
    ActivitiScriptNode scriptNode = new ActivitiScriptNode(companyHome, SERVICE_REGISTRY);
    try {
        // Do a conversion of a multiple property (this is a residual property, but it doesn't matter, the conversion code is the same, regardless of the property being in the model or not).
        scriptNode.getValueConverter().convertValueForScript(QName.createQName("cm:phonenumbers"), numbers);
    } catch (Exception e) {
        fail("Converting multiple property for Activiti script fails with " + e);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Repository(org.alfresco.repo.model.Repository) ActivitiScriptNode(org.alfresco.repo.workflow.activiti.ActivitiScriptNode) ArrayList(java.util.ArrayList) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) ScriptException(org.alfresco.scripts.ScriptException) Test(org.junit.Test)

Example 3 with Repository

use of org.alfresco.repo.model.Repository in project alfresco-repository by Alfresco.

the class ScriptNodeTest method createTestContent.

/**
 * Create test content, can be versionable.
 * @param versionable boolean
 */
private void createTestContent(boolean versionable) {
    Repository repositoryHelper = (Repository) APP_CONTEXT_INIT.getApplicationContext().getBean("repositoryHelper");
    NodeRef companyHome = repositoryHelper.getCompanyHome();
    // Create some test content
    testNode = testNodes.createQuickFile(MimetypeMap.MIMETYPE_TEXT_PLAIN, companyHome, "userOnesDoc", TEST_USER1.getUsername(), versionable);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Repository(org.alfresco.repo.model.Repository)

Example 4 with Repository

use of org.alfresco.repo.model.Repository in project alfresco-repository by Alfresco.

the class ScriptNodeTest method testCreateRemoveAssociation.

/**
 * Test associations related script api, after the permissions checks have been pushed to the NodeService level (MNT-20833).
 */
@Test
public void testCreateRemoveAssociation() throws Exception {
    Repository repositoryHelper = (Repository) APP_CONTEXT_INIT.getApplicationContext().getBean("repositoryHelper");
    NodeRef companyHome = repositoryHelper.getCompanyHome();
    AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE_NAME);
    NodeRef newNode1 = testNodes.createNode(companyHome, "theTestFolder", ContentModel.TYPE_FOLDER, AuthenticationUtil.getFullyAuthenticatedUser());
    NodeRef newNode2 = testNodes.createNode(companyHome, "theTestContent", ContentModel.TYPE_CONTENT, AuthenticationUtil.getFullyAuthenticatedUser());
    // Give USER_TWO READ permission similar to the Consumer role
    PERMISSION_SERVICE.setPermission(newNode1, USER_TWO_NAME, PermissionService.READ, true);
    PERMISSION_SERVICE.setPermission(newNode2, USER_TWO_NAME, PermissionService.READ, true);
    AuthenticationUtil.setFullyAuthenticatedUser(USER_TWO_NAME);
    ScriptNode sourceScriptNode = SEARCH_SCRIPT.findNode(newNode1);
    assertNotNull(sourceScriptNode);
    ScriptNode targetScriptNode = SEARCH_SCRIPT.findNode(newNode2);
    assertNotNull(targetScriptNode);
    // Create associations
    String assocType = "cm:contains";
    try {
        sourceScriptNode.createAssociation(targetScriptNode, assocType);
        fail("Creating associations without write permission on source is not allowed.");
    } catch (AccessDeniedException ade) {
    // expected
    }
    // Give USER_TWO WRITE permission to be able to successfully create an association from sourceScriptNode to targetScriptNode
    AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE_NAME);
    PERMISSION_SERVICE.setPermission(newNode1, USER_TWO_NAME, PermissionService.WRITE, true);
    AuthenticationUtil.setFullyAuthenticatedUser(USER_TWO_NAME);
    assertTrue(sourceScriptNode.hasPermission(PermissionService.WRITE_PROPERTIES));
    assertNotNull(sourceScriptNode.createAssociation(targetScriptNode, assocType));
    // Remove associations
    try {
        sourceScriptNode.removeAssociation(targetScriptNode, assocType);
        fail("Removing associations without delete permission on source is not allowed.");
    } catch (AccessDeniedException ade) {
    // expected
    }
    // Give USER_TWO DELETE permission to be able to successfully remove an association from sourceScriptNode to targetScriptNode
    AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE_NAME);
    PERMISSION_SERVICE.setPermission(newNode1, USER_TWO_NAME, PermissionService.DELETE, true);
    AuthenticationUtil.setFullyAuthenticatedUser(USER_TWO_NAME);
    sourceScriptNode.removeAssociation(targetScriptNode, assocType);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Repository(org.alfresco.repo.model.Repository) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) ActivitiScriptNode(org.alfresco.repo.workflow.activiti.ActivitiScriptNode) Test(org.junit.Test)

Example 5 with Repository

use of org.alfresco.repo.model.Repository in project alfresco-repository by Alfresco.

the class InviteSenderTest method mockRepository.

/**
 * Mocks up a Repository that will return the inviter as the current user.
 *
 * @return Repository
 */
private Repository mockRepository() {
    Repository repository = mock(Repository.class);
    when(repository.getPerson()).thenReturn(inviter.node);
    return repository;
}
Also used : Repository(org.alfresco.repo.model.Repository)

Aggregations

Repository (org.alfresco.repo.model.Repository)24 NodeRef (org.alfresco.service.cmr.repository.NodeRef)10 Before (org.junit.Before)6 Test (org.junit.Test)6 ActivitiScriptNode (org.alfresco.repo.workflow.activiti.ActivitiScriptNode)5 NodeService (org.alfresco.service.cmr.repository.NodeService)4 BeforeClass (org.junit.BeforeClass)4 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)3 ServiceRegistry (org.alfresco.service.ServiceRegistry)3 ContentService (org.alfresco.service.cmr.repository.ContentService)3 PersonService (org.alfresco.service.cmr.security.PersonService)3 QName (org.alfresco.service.namespace.QName)3 ScriptContentData (org.alfresco.repo.jscript.ScriptNode.ScriptContentData)2 AuthenticationComponent (org.alfresco.repo.security.authentication.AuthenticationComponent)2 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)2 ScriptException (org.alfresco.scripts.ScriptException)2 FileFolderService (org.alfresco.service.cmr.model.FileFolderService)2 ContentData (org.alfresco.service.cmr.repository.ContentData)2 MutableAuthenticationService (org.alfresco.service.cmr.security.MutableAuthenticationService)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1