Search in sources :

Example 26 with IdRef

use of org.nuxeo.ecm.core.api.IdRef in project nuxeo-drive-server by nuxeo.

the class TestPermissionHierarchyFileSystemChanges method testAdaptableUnregisteredSyncRootChange.

/**
 * When an unregistered synchronization root can still be adapted as a FileSystemItem, for example in the case of
 * the "My Docs" virtual folder in the permission based hierarchy implementation, checks that the related
 * {@link FileSystemItemChange} computed by the {@link AuditChangeFinder} contains a null {@code fileSystemItem}
 * attribute, see https://jira.nuxeo.com/browse/NXP-16478.
 */
@Test
public void testAdaptableUnregisteredSyncRootChange() throws InterruptedException {
    commitAndWaitForAsyncCompletion();
    lastEventLogId = nuxeoDriveManager.getChangeFinder().getUpperBound();
    // user1
    try {
        nuxeoDriveManager.registerSynchronizationRoot(session1.getPrincipal(), userWorkspace1, session1);
        assertTrue(nuxeoDriveManager.getSynchronizationRootReferences(session1).contains(new IdRef(userWorkspace1.getId())));
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    // Check file system item change
    try {
        List<FileSystemItemChange> changes = getChanges(principal1);
        assertEquals(1, changes.size());
        FileSystemItemChange change = changes.get(0);
        assertEquals(userWorkspace1ItemId, change.getFileSystemItemId());
        assertEquals("My Docs", change.getFileSystemItemName());
        assertNotNull(change.getFileSystemItem());
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    // user1
    try {
        nuxeoDriveManager.unregisterSynchronizationRoot(session1.getPrincipal(), userWorkspace1, session1);
        assertFalse(nuxeoDriveManager.getSynchronizationRootReferences(session1).contains(new IdRef(userWorkspace1.getId())));
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    // Check file system item change
    try {
        List<FileSystemItemChange> changes = getChanges(principal1);
        assertEquals(1, changes.size());
        FileSystemItemChange change = changes.get(0);
        assertEquals("test#" + userWorkspace1.getId(), change.getFileSystemItemId());
        assertNull(change.getFileSystemItemName());
        assertNull(change.getFileSystemItem());
    } finally {
        commitAndWaitForAsyncCompletion();
    }
}
Also used : FileSystemItemChange(org.nuxeo.drive.service.FileSystemItemChange) IdRef(org.nuxeo.ecm.core.api.IdRef) Test(org.junit.Test)

Example 27 with IdRef

use of org.nuxeo.ecm.core.api.IdRef in project nuxeo-drive-server by nuxeo.

the class TestPermissionHierarchyFileSystemChanges method testRootlessItems.

/**
 * Tests the rootless file system items, typically:
 * <ul>
 * <li>A folder registered as a synchronization root but that is not adaptable as a {@link FileSystemItem}. For
 * example if it is handled by the {@link PermissionSyncRootFactory} and
 * {@link PermissionSyncRootFactory#isFileSystemItem(DocumentModel, boolean)} returns {@code false} because of the
 * missing required permission.</li>
 * <li>A file created in such a folder.</li>
 * <li>A file created in a folder registered as a synchronization root on which the user doesn't have Read
 * access.</li>
 * </ul>
 * For the test, the required permission for a folder to be adapted by the {@link PermissionSyncRootFactory} is
 * Everything.
 *
 * <pre>
 * Server side hierarchy for the test
 * ==================================
 *
 * /user1 (user workspace)
 *   |-- user1Folder1       (registered as a synchronization root with Everything permission for user2)
 *   |-- user1Folder2       (registered as a synchronization root with ReadWrite permission only for user2)
 *   |     |-- user1File1
 *   |     |-- user1File2
 * </pre>
 */
@Test
@Deploy("org.nuxeo.drive.operations.test:OSGI-INF/test-nuxeodrive-hierarchy-permission-adapter-contrib.xml")
public void testRootlessItems() throws Exception {
    commitAndWaitForAsyncCompletion();
    DocumentModel user1Folder1;
    DocumentModel user1Folder2;
    DocumentModel user1File2;
    try {
        // Populate user1's personal workspace
        user1Folder1 = createFolder(session1, userWorkspace1.getPathAsString(), "user1Folder1", "Folder");
        user1Folder2 = createFolder(session1, userWorkspace1.getPathAsString(), "user1Folder2", "Folder");
        session1.save();
        setPermission(session1, user1Folder1, "user2", SecurityConstants.EVERYTHING, true);
        setPermission(session1, user1Folder2, "user2", SecurityConstants.READ_WRITE, true);
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    lastEventLogId = nuxeoDriveManager.getChangeFinder().getUpperBound();
    // so appears in the file system changes
    try {
        nuxeoDriveManager.registerSynchronizationRoot(session2.getPrincipal(), user1Folder1, session2);
        assertTrue(nuxeoDriveManager.getSynchronizationRootReferences(session2).contains(new IdRef(user1Folder1.getId())));
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        List<FileSystemItemChange> changes = getChanges(principal2);
        assertEquals(1, changes.size());
        FileSystemItemChange change = changes.get(0);
        assertEquals(SYNC_ROOT_ID_PREFIX + user1Folder1.getId(), change.getFileSystemItemId());
        assertEquals("user1Folder1", change.getFileSystemItemName());
        assertNotNull(change.getFileSystemItem());
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    // adaptable so doesn't appear in the file system changes
    try {
        nuxeoDriveManager.registerSynchronizationRoot(session2.getPrincipal(), user1Folder2, session2);
        assertTrue(nuxeoDriveManager.getSynchronizationRootReferences(session2).contains(new IdRef(user1Folder2.getId())));
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        List<FileSystemItemChange> changes = getChanges(principal2);
        assertTrue(changes.isEmpty());
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    // the file system changes
    try {
        createFile(session1, user1Folder2.getPathAsString(), "user1File1", "File", "user1File1.txt", CONTENT_PREFIX + "user1File1");
        session1.save();
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        List<FileSystemItemChange> changes = getChanges(principal2);
        assertTrue(changes.isEmpty());
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    // the file system changes
    try {
        resetPermissions(session1, user1Folder2.getRef(), "user2");
        user1File2 = createFile(session1, user1Folder2.getPathAsString(), "user1File2", "File", "user1File2.txt", CONTENT_PREFIX + "user1File2");
        setPermission(session1, user1File2, "user2", SecurityConstants.READ, true);
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        // Security updates
        List<FileSystemItemChange> changes = getChanges(principal2);
        assertEquals(2, changes.size());
        FileSystemItemChange change = changes.get(0);
        assertEquals("securityUpdated", change.getEventId());
        assertEquals("test#" + user1File2.getId(), change.getFileSystemItemId());
        assertNull(change.getFileSystemItemName());
        // Not adaptable as a FileSystemItem since parent is not
        assertNull(change.getFileSystemItem());
        change = changes.get(1);
        assertEquals("securityUpdated", change.getEventId());
        assertEquals("test#" + user1Folder2.getId(), change.getFileSystemItemId());
        assertNull(change.getFileSystemItemName());
        // Not adaptable as a FileSystemItem since no Read permission
        assertNull(change.getFileSystemItem());
    } finally {
        commitAndWaitForAsyncCompletion();
    }
}
Also used : FileSystemItemChange(org.nuxeo.drive.service.FileSystemItemChange) IdRef(org.nuxeo.ecm.core.api.IdRef) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test) Deploy(org.nuxeo.runtime.test.runner.Deploy)

Example 28 with IdRef

use of org.nuxeo.ecm.core.api.IdRef in project nuxeo-drive-server by nuxeo.

the class TestPermissionHierarchyFileSystemChanges method getChanges.

protected List<FileSystemItemChange> getChanges(Principal principal) throws InterruptedException {
    FileSystemChangeSummary changeSummary = nuxeoDriveManager.getChangeSummaryIntegerBounds(principal, Collections.<String, Set<IdRef>>emptyMap(), lastEventLogId);
    assertNotNull(changeSummary);
    lastEventLogId = changeSummary.getUpperBound();
    return changeSummary.getFileSystemChanges();
}
Also used : FileSystemChangeSummary(org.nuxeo.drive.service.FileSystemChangeSummary) IdRef(org.nuxeo.ecm.core.api.IdRef)

Example 29 with IdRef

use of org.nuxeo.ecm.core.api.IdRef in project nuxeo-drive-server by nuxeo.

the class TestNuxeoDriveManager method testSyncRootsWithPathInclusion.

@Test
public void testSyncRootsWithPathInclusion() {
    Principal user1Principal = user1Session.getPrincipal();
    // Create 2 folders with path inclusion:
    // /default-domain/folder1 includes /default-domain/folder
    DocumentModel folder = session.createDocument(session.createDocumentModel("/default-domain/workspaces", "folder", "Folder"));
    DocumentModel folder1 = session.createDocument(session.createDocumentModel("/default-domain/workspaces", "folder1", "Folder"));
    setPermissions(folder, new ACE("members", SecurityConstants.READ_WRITE));
    setPermissions(folder1, new ACE("members", SecurityConstants.READ_WRITE));
    // Register folder as a synchronization root
    nuxeoDriveManager.registerSynchronizationRoot(user1Principal, folder, user1Session);
    // Register folder1 as a synchronization root
    nuxeoDriveManager.registerSynchronizationRoot(user1Principal, folder1, user1Session);
    // Check there are 2 synchronization roots
    Set<IdRef> syncRootrefs = nuxeoDriveManager.getSynchronizationRootReferences(user1Session);
    assertEquals(2, syncRootrefs.size());
    assertTrue(syncRootrefs.contains(folder.getRef()));
    assertTrue(syncRootrefs.contains(folder1.getRef()));
}
Also used : ACE(org.nuxeo.ecm.core.api.security.ACE) IdRef(org.nuxeo.ecm.core.api.IdRef) Principal(java.security.Principal) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test)

Example 30 with IdRef

use of org.nuxeo.ecm.core.api.IdRef in project nuxeo-drive-server by nuxeo.

the class TestFileSystemItemOperations method testDelete.

@Test
public void testDelete() throws Exception {
    // ------------------------------------------------------
    // Delete file in sync root: should trash it
    // ------------------------------------------------------
    clientSession.newRequest(NuxeoDriveDelete.ID).set("id", DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file1.getId()).execute();
    // Need to flush VCS cache to be aware of changes in the session used by the file system item
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    DocumentModel deletedFileDoc = session.getDocument(new IdRef(file1.getId()));
    assertTrue(deletedFileDoc.isTrashed());
    // ------------------------------------------------------
    // Delete sync root: should unregister it
    // ------------------------------------------------------
    clientSession.newRequest(NuxeoDriveDelete.ID).set("id", SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot2.getId()).execute();
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    assertFalse(nuxeoDriveManager.getSynchronizationRootReferences(session).contains(new IdRef(syncRoot2.getId())));
    // ------------------------------------------------------
    try {
        clientSession.newRequest(NuxeoDriveDelete.ID).set("id", fileSystemItemAdapterService.getTopLevelFolderItemFactory().getTopLevelFolderItem(session.getPrincipal()).getId()).execute();
        fail("Top level folder item deletion should be unsupported.");
    } catch (Exception e) {
        assertEquals("Failed to invoke operation: NuxeoDrive.Delete", e.getMessage());
    }
}
Also used : IdRef(org.nuxeo.ecm.core.api.IdRef) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test)

Aggregations

IdRef (org.nuxeo.ecm.core.api.IdRef)31 DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)18 Test (org.junit.Test)13 NuxeoDriveManager (org.nuxeo.drive.service.NuxeoDriveManager)8 SynchronizationRoots (org.nuxeo.drive.service.SynchronizationRoots)8 ArrayList (java.util.ArrayList)7 FileSystemItem (org.nuxeo.drive.adapter.FileSystemItem)7 FileSystemItemChange (org.nuxeo.drive.service.FileSystemItemChange)7 CloseableCoreSession (org.nuxeo.ecm.core.api.CloseableCoreSession)7 DocumentRef (org.nuxeo.ecm.core.api.DocumentRef)6 DocumentModelList (org.nuxeo.ecm.core.api.DocumentModelList)4 Principal (java.security.Principal)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 FolderItem (org.nuxeo.drive.adapter.FolderItem)3 DefaultSyncRootFolderItem (org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem)3 DocumentBackedFileItem (org.nuxeo.drive.adapter.impl.DocumentBackedFileItem)3 FileSystemChangeSummary (org.nuxeo.drive.service.FileSystemChangeSummary)3 Blob (org.nuxeo.ecm.automation.client.model.Blob)3