Search in sources :

Example 91 with DocumentModel

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

the class DefaultFileSystemItemFactoryFixture method testSection.

@Test
public void testSection() {
    // Check that a Section is adaptable as a FileSystemItem by the
    // defaultSyncRootFolderItemFactory
    DocumentModel section = session.createDocument(session.createDocumentModel("/", "sectionSyncRoot", "Section"));
    nuxeoDriveManager.registerSynchronizationRoot(principal, section, session);
    FileSystemItemFactory defaultSyncRootFolderItemFactory = ((FileSystemItemAdapterServiceImpl) fileSystemItemAdapterService).getFileSystemItemFactory("defaultSyncRootFolderItemFactory");
    FolderItem sectionItem = (FolderItem) defaultSyncRootFolderItemFactory.getFileSystemItem(section);
    assertNotNull(sectionItem);
    assertFalse(sectionItem.getCanCreateChild());
    assertFalse(sectionItem.getCanRename());
    assertTrue(sectionItem.getCanDelete());
    // Publish documents in the Section and check its children
    session.publishDocument(file, section);
    session.publishDocument(note, section);
    session.save();
    List<FileSystemItem> children = sectionItem.getChildren();
    assertEquals(2, children.size());
    FileSystemItem child = children.get(0);
    assertFalse(child.getCanRename());
    assertFalse(child.getCanDelete());
}
Also used : DefaultFileSystemItemFactory(org.nuxeo.drive.service.impl.DefaultFileSystemItemFactory) FileSystemItemFactory(org.nuxeo.drive.service.FileSystemItemFactory) FolderItem(org.nuxeo.drive.adapter.FolderItem) FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) FileSystemItemAdapterServiceImpl(org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test)

Example 92 with DocumentModel

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

the class TestDefaultTopLevelFolderItemFactory method testFileSystemItemFactory.

@Test
public void testFileSystemItemFactory() {
    // #getName()
    assertEquals("org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory", defaultTopLevelFolderItemFactory.getName());
    // #setName(String name)
    defaultTopLevelFolderItemFactory.setName("testName");
    assertEquals("testName", defaultTopLevelFolderItemFactory.getName());
    defaultTopLevelFolderItemFactory.setName("org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory");
    // #isFileSystemItem(DocumentModel doc)
    DocumentModel fakeDoc = DocumentModelFactory.createDocumentModel("File");
    assertFalse(defaultTopLevelFolderItemFactory.isFileSystemItem(fakeDoc));
    // #getFileSystemItem(DocumentModel doc)
    assertNull(defaultTopLevelFolderItemFactory.getFileSystemItem(fakeDoc));
    // #canHandleFileSystemItemId(String id)
    assertTrue(defaultTopLevelFolderItemFactory.canHandleFileSystemItemId("org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory#"));
    assertFalse(defaultTopLevelFolderItemFactory.canHandleFileSystemItemId("org.nuxeo.drive.service.impl.DefaultFileSystemItemFactory#"));
    // #exists(String id, Principal principal)
    assertTrue(defaultTopLevelFolderItemFactory.exists("org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory#", session.getPrincipal()));
    try {
        defaultTopLevelFolderItemFactory.exists("testId", session.getPrincipal());
        fail("Should be unsupported.");
    } catch (UnsupportedOperationException e) {
        assertEquals("Cannot check if a file system item exists for an id that cannot be handled from factory org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory.", e.getMessage());
    }
    // #getFileSystemItemById(String id, Principal principal)
    FileSystemItem topLevelFolderItem = defaultTopLevelFolderItemFactory.getFileSystemItemById("org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory#", session.getPrincipal());
    assertNotNull(topLevelFolderItem);
    assertTrue(topLevelFolderItem instanceof DefaultTopLevelFolderItem);
    assertNull(topLevelFolderItem.getParentId());
    assertEquals("Nuxeo Drive", topLevelFolderItem.getName());
    try {
        defaultTopLevelFolderItemFactory.getFileSystemItemById("testId", session.getPrincipal());
        fail("Should be unsupported.");
    } catch (UnsupportedOperationException e) {
        assertEquals("Cannot get the file system item for an id that cannot be handled from factory org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory.", e.getMessage());
    }
    // #getFileSystemItemById(String id, String parentId, Principal
    // principal)
    topLevelFolderItem = defaultTopLevelFolderItemFactory.getFileSystemItemById("org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory#", null, session.getPrincipal());
    assertTrue(topLevelFolderItem instanceof DefaultTopLevelFolderItem);
}
Also used : FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) DefaultTopLevelFolderItem(org.nuxeo.drive.adapter.impl.DefaultTopLevelFolderItem) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test)

Example 93 with DocumentModel

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

the class TestFileSystemItemManagerService method testReadOperations.

@Test
public void testReadOperations() throws Exception {
    // ------------------------------------------------------
    // Check #getTopLevelFolder
    // ------------------------------------------------------
    List<FileSystemItem> topLevelChildren = fileSystemItemManagerService.getTopLevelFolder(principal).getChildren();
    assertNotNull(topLevelChildren);
    assertEquals(2, topLevelChildren.size());
    FileSystemItem childFsItem = topLevelChildren.get(0);
    assertTrue(childFsItem instanceof DefaultSyncRootFolderItem);
    assertEquals("defaultSyncRootFolderItemFactory#test#" + syncRoot1.getId(), childFsItem.getId());
    assertTrue(childFsItem.getParentId().endsWith("DefaultTopLevelFolderItemFactory#"));
    assertEquals("syncRoot1", childFsItem.getName());
    childFsItem = topLevelChildren.get(1);
    assertTrue(childFsItem instanceof DefaultSyncRootFolderItem);
    assertEquals("defaultSyncRootFolderItemFactory#test#" + syncRoot2.getId(), childFsItem.getId());
    assertTrue(childFsItem.getParentId().endsWith("DefaultTopLevelFolderItemFactory#"));
    assertEquals("syncRoot2", childFsItem.getName());
    // ------------------------------------------------------
    // Check #exists
    // ------------------------------------------------------
    // Non existent doc id
    assertFalse(fileSystemItemManagerService.exists(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + "nonExistentId", principal));
    // File
    assertTrue(fileSystemItemManagerService.exists(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId(), principal));
    // Not adaptable as a FileSystemItem
    assertFalse(fileSystemItemManagerService.exists(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + notAFileSystemItem.getId(), principal));
    // Deleted
    custom.followTransition("delete");
    assertFalse(fileSystemItemManagerService.exists(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + custom.getId(), principal));
    // ------------------------------------------------------------
    // Check #getFileSystemItemById(String id, Principal principal)
    // ------------------------------------------------------------
    // Folder
    FileSystemItem fsItem = fileSystemItemManagerService.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), principal);
    assertNotNull(fsItem);
    assertTrue(fsItem instanceof FolderItem);
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), fsItem.getId());
    String expectedSyncRoot1Id = DEFAULT_SYNC_ROOT_ITEM_ID_PREFIX + syncRoot1.getId();
    assertEquals(expectedSyncRoot1Id, fsItem.getParentId());
    assertEquals("Jack's folder", fsItem.getName());
    assertTrue(fsItem.isFolder());
    assertTrue(fsItem.getCanRename());
    assertTrue(fsItem.getCanDelete());
    assertTrue(((FolderItem) fsItem).getCanCreateChild());
    List<FileSystemItem> children = ((FolderItem) fsItem).getChildren();
    assertNotNull(children);
    assertEquals(4, children.size());
    // File
    fsItem = fileSystemItemManagerService.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId(), principal);
    assertNotNull(fsItem);
    assertTrue(fsItem instanceof FileItem);
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId(), fsItem.getId());
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), fsItem.getParentId());
    assertEquals("Joe.odt", fsItem.getName());
    assertFalse(fsItem.isFolder());
    assertTrue(fsItem.getCanRename());
    assertTrue(fsItem.getCanDelete());
    FileItem fileFsItem = (FileItem) fsItem;
    assertTrue(fileFsItem.getCanUpdate());
    assertEquals("nxfile/test/" + file.getId() + "/blobholder:0/Joe.odt", fileFsItem.getDownloadURL());
    assertEquals("MD5", fileFsItem.getDigestAlgorithm());
    assertEquals(file.getAdapter(BlobHolder.class).getBlob().getDigest(), fileFsItem.getDigest());
    Blob fileItemBlob = fileFsItem.getBlob();
    assertEquals("Joe.odt", fileItemBlob.getFilename());
    assertEquals("Content of Joe's file.", fileItemBlob.getString());
    // FolderishFile
    fsItem = fileSystemItemManagerService.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folderishFile.getId(), principal);
    assertNotNull(fsItem);
    assertTrue(fsItem instanceof FolderItem);
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folderishFile.getId(), fsItem.getId());
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), fsItem.getParentId());
    assertEquals("Sarah's folderish file", fsItem.getName());
    assertTrue(fsItem.isFolder());
    assertTrue(fsItem.getCanRename());
    assertTrue(fsItem.getCanDelete());
    assertTrue(((FolderItem) fsItem).getCanCreateChild());
    assertTrue(((FolderItem) fsItem).getChildren().isEmpty());
    // Not adaptable as a FileSystemItem
    fsItem = fileSystemItemManagerService.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + notAFileSystemItem.getId(), principal);
    assertNull(fsItem);
    // Deleted
    assertNull(fileSystemItemManagerService.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + custom.getId(), principal));
    // Sub folder
    fsItem = fileSystemItemManagerService.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + subFolder.getId(), principal);
    assertNotNull(fsItem);
    assertTrue(fsItem instanceof FolderItem);
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + subFolder.getId(), fsItem.getId());
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), fsItem.getParentId());
    assertEquals("Tony's sub folder", fsItem.getName());
    assertTrue(fsItem.isFolder());
    assertTrue(fsItem.getCanRename());
    assertTrue(fsItem.getCanDelete());
    assertTrue(((FolderItem) fsItem).getCanCreateChild());
    assertTrue(((FolderItem) fsItem).getChildren().isEmpty());
    // -------------------------------------------------------------------
    // Check #getFileSystemItemById(String id, String parentId, Principal
    // principal)
    // -------------------------------------------------------------------
    fsItem = fileSystemItemManagerService.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId(), DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), principal);
    assertTrue(fsItem instanceof FileItem);
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId(), fsItem.getId());
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), fsItem.getParentId());
    // ------------------------------------------------------
    // Check #getChildren
    // ------------------------------------------------------
    // Need to flush VCS cache for the session used in DocumentBackedFolderItem#getChildren() to be aware of changes
    // in the current session
    session.save();
    children = fileSystemItemManagerService.getChildren(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), principal);
    assertNotNull(children);
    assertEquals(4, children.size());
    // Ordered
    checkChildren(children, folder.getId(), file.getId(), note.getId(), folderishFile.getId(), subFolder.getId(), true);
    children = fileSystemItemManagerService.getChildren(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + subFolder.getId(), principal);
    assertTrue(children.isEmpty());
    // ------------------------------------------------------
    // Check #scrollDescendants
    // ------------------------------------------------------
    // Need to flush VCS cache for the session used in DocumentBackedFolderItem#scrollDescendants to be aware of
    // changes in the current session
    session.save();
    FolderItem folderItem = (FolderItem) fileSystemItemManagerService.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), principal);
    assertTrue(folderItem.getCanScrollDescendants());
    // Scroll through all descendants in one breath
    ScrollFileSystemItemList folderDescendants = fileSystemItemManagerService.scrollDescendants(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), principal, null, 10, 1000);
    assertNotNull(folderDescendants);
    assertNotNull(folderDescendants.getScrollId());
    assertEquals(4, folderDescendants.size());
    // Order is not determined
    checkChildren(folderDescendants, folder.getId(), file.getId(), note.getId(), folderishFile.getId(), subFolder.getId(), false);
    // Scroll through descendants in several steps
    folderDescendants.clear();
    ScrollFileSystemItemList descendantsBatch;
    int batchSize = 2;
    String scrollId = null;
    while (!(descendantsBatch = folderItem.scrollDescendants(scrollId, batchSize, 1000)).isEmpty()) {
        assertTrue(descendantsBatch.size() > 0);
        scrollId = descendantsBatch.getScrollId();
        folderDescendants.addAll(descendantsBatch);
    }
    assertEquals(4, folderDescendants.size());
    // Order is not determined
    checkChildren(folderDescendants, folder.getId(), file.getId(), note.getId(), folderishFile.getId(), subFolder.getId(), false);
    folderDescendants = fileSystemItemManagerService.scrollDescendants(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + subFolder.getId(), principal, null, 10, 1000);
    assertTrue(folderDescendants.isEmpty());
    // ------------------------------------------------------
    // Check #canMove
    // ------------------------------------------------------
    // Not allowed to move a file system item to a non FolderItem
    String srcFsItemId = DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + note.getId();
    String destFsItemId = DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId();
    assertFalse(fileSystemItemManagerService.canMove(srcFsItemId, destFsItemId, principal));
    // Not allowed to move a file system item if no REMOVE permission on the
    // source backing doc
    Principal joePrincipal = new NuxeoPrincipalImpl("joe");
    DocumentModel rootDoc = session.getRootDocument();
    setPermission(rootDoc, "joe", SecurityConstants.READ, true);
    nuxeoDriveManager.registerSynchronizationRoot(joePrincipal, syncRoot1, session);
    // Under Oracle, the READ ACL optims are not visible from the joe
    // session while the transaction has not been committed.
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    destFsItemId = DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + subFolder.getId();
    assertFalse(fileSystemItemManagerService.canMove(srcFsItemId, destFsItemId, joePrincipal));
    // Not allowed to move a file system item if no ADD_CHILDREN permission
    // on the destination backing doc
    setPermission(folder, "joe", SecurityConstants.WRITE, true);
    setPermission(subFolder, "joe", SecurityConstants.READ, true);
    setPermission(subFolder, SecurityConstants.ADMINISTRATOR, SecurityConstants.EVERYTHING, true);
    setPermission(subFolder, SecurityConstants.EVERYONE, SecurityConstants.EVERYTHING, false);
    assertFalse(fileSystemItemManagerService.canMove(srcFsItemId, destFsItemId, joePrincipal));
    // OK: REMOVE permission on the source backing doc + REMOVE_CHILDREN
    // permission on its parent + ADD_CHILDREN permission on the destination
    // backing doc
    resetPermissions(subFolder, SecurityConstants.EVERYONE);
    resetPermissions(subFolder, "joe");
    setPermission(subFolder, "joe", SecurityConstants.WRITE, true);
    assertTrue(fileSystemItemManagerService.canMove(srcFsItemId, destFsItemId, joePrincipal));
    // Reset permissions
    resetPermissions(rootDoc, "joe");
    resetPermissions(folder, "joe");
    resetPermissions(subFolder, "joe");
}
Also used : ScrollFileSystemItemList(org.nuxeo.drive.adapter.ScrollFileSystemItemList) StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) Blob(org.nuxeo.ecm.core.api.Blob) DefaultSyncRootFolderItem(org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) FileItem(org.nuxeo.drive.adapter.FileItem) NuxeoPrincipalImpl(org.nuxeo.ecm.platform.usermanager.NuxeoPrincipalImpl) FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) DefaultSyncRootFolderItem(org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem) FolderItem(org.nuxeo.drive.adapter.FolderItem) BlobHolder(org.nuxeo.ecm.core.api.blobholder.BlobHolder) Principal(java.security.Principal) Test(org.junit.Test)

Example 94 with DocumentModel

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

the class NuxeoDriveSetupIntegrationTests method createTestUsers.

protected String createTestUsers(String[] testUserNames) {
    StringBuilder testUserCredentials = new StringBuilder();
    UserManager userManager = Framework.getService(UserManager.class);
    DirectoryService directoryService = Framework.getService(DirectoryService.class);
    String userSchemaName = userManager.getUserSchemaName();
    String userNameField = directoryService.getDirectoryIdField(userManager.getUserDirectoryName());
    String passwordField = directoryService.getDirectoryPasswordField(userManager.getUserDirectoryName());
    for (int i = 0; i < testUserNames.length; i++) {
        String testUserName = testUserNames[i];
        // Generate random password
        String testUserPassword = UUID.randomUUID().toString().substring(0, 6);
        // Create test user
        DocumentModel testUserModel = userManager.getBareUserModel();
        testUserModel.setProperty(userSchemaName, userNameField, testUserName);
        testUserModel.setProperty(userSchemaName, passwordField, testUserPassword);
        if (useMembersGroup) {
            testUserModel.setProperty(userSchemaName, "groups", new String[] { "members" });
        }
        userManager.createUser(testUserModel);
        // Append test user's credentials
        testUserCredentials.append(testUserName);
        testUserCredentials.append(":");
        testUserCredentials.append(testUserPassword);
        if (i < testUserNames.length - 1) {
            testUserCredentials.append(",");
        }
    }
    return testUserCredentials.toString();
}
Also used : UserManager(org.nuxeo.ecm.platform.usermanager.UserManager) DirectoryService(org.nuxeo.ecm.directory.api.DirectoryService) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 95 with DocumentModel

use of org.nuxeo.ecm.core.api.DocumentModel 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)

Aggregations

DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)128 Test (org.junit.Test)58 StringBlob (org.nuxeo.ecm.core.api.impl.blob.StringBlob)26 CloseableCoreSession (org.nuxeo.ecm.core.api.CloseableCoreSession)25 FileSystemItemChange (org.nuxeo.drive.service.FileSystemItemChange)24 FileSystemItem (org.nuxeo.drive.adapter.FileSystemItem)22 PathRef (org.nuxeo.ecm.core.api.PathRef)21 IdRef (org.nuxeo.ecm.core.api.IdRef)18 HashSet (java.util.HashSet)17 Blob (org.nuxeo.ecm.core.api.Blob)17 DocumentRef (org.nuxeo.ecm.core.api.DocumentRef)17 ArrayList (java.util.ArrayList)16 FolderItem (org.nuxeo.drive.adapter.FolderItem)14 NuxeoException (org.nuxeo.ecm.core.api.NuxeoException)11 Principal (java.security.Principal)10 ACE (org.nuxeo.ecm.core.api.security.ACE)10 NuxeoDriveManager (org.nuxeo.drive.service.NuxeoDriveManager)9 FileItem (org.nuxeo.drive.adapter.FileItem)8 BlobHolder (org.nuxeo.ecm.core.api.blobholder.BlobHolder)8 HashMap (java.util.HashMap)7