Search in sources :

Example 86 with DocumentModel

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

the class GroupChangesTestSuite method testGroupChangesOnSyncRootChild.

/**
 * Tests changes on a group that has access to a child of a synchronization root.
 */
@Test
public void testGroupChangesOnSyncRootChild() throws Exception {
    DocumentModel child;
    try {
        DocumentModel syncRoot = session.createDocument(session.createDocumentModel("/", "syncRoot", "Folder"));
        child = session.createDocument(session.createDocumentModel("/syncRoot", "child", "Folder"));
        log.trace("Grant ReadWrite to group1 on syncRoot");
        setPermissions(syncRoot, new ACE("group1", SecurityConstants.READ_WRITE));
        log.trace("Block inheritance on child");
        setPermissions(child, ACE.BLOCK);
        log.trace("Grant ReadWrite to group2 on child");
        setPermissions(child, new ACE("group2", SecurityConstants.READ_WRITE));
        nuxeoDriveManager.registerSynchronizationRoot(userSession.getPrincipal(), syncRoot, userSession);
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        List<FileSystemItemChange> changes = getChanges(userSession.getPrincipal());
        // Folder creation and sync root registration events
        assertEquals(3, changes.size());
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    testGroupChanges(child, "defaultFileSystemItemFactory", "group2", false);
}
Also used : ACE(org.nuxeo.ecm.core.api.security.ACE) FileSystemItemChange(org.nuxeo.drive.service.FileSystemItemChange) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test)

Example 87 with DocumentModel

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

the class GroupChangesTestSuite method testGroupChangesOnSyncRoot.

/**
 * Tests changes on a group that has access to a synchronization root.
 */
@Test
public void testGroupChangesOnSyncRoot() throws Exception {
    DocumentModel syncRoot;
    try {
        syncRoot = session.createDocument(session.createDocumentModel("/", "syncRoot", "Folder"));
        log.trace("Grant ReadWrite to group1 on syncRoot");
        setPermissions(syncRoot, new ACE("group1", SecurityConstants.READ_WRITE));
        nuxeoDriveManager.registerSynchronizationRoot(userSession.getPrincipal(), syncRoot, userSession);
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        List<FileSystemItemChange> changes = getChanges(userSession.getPrincipal());
        // Sync root creation and registration events
        assertEquals(2, changes.size());
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    testGroupChanges(syncRoot, "defaultSyncRootFolderItemFactory", "group1", false);
}
Also used : ACE(org.nuxeo.ecm.core.api.security.ACE) FileSystemItemChange(org.nuxeo.drive.service.FileSystemItemChange) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test)

Example 88 with DocumentModel

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

the class TestNuxeoDriveManager method testOtherUsersSyncRootFSItemId.

@Test
public void testOtherUsersSyncRootFSItemId() {
    log.trace("Register a workspace as a sync root for user1");
    nuxeoDriveManager.registerSynchronizationRoot(user1Session.getPrincipal(), workspace_2, user1Session);
    log.trace("Create a test folder in sync root");
    DocumentModel testFolder = user1Session.createDocument(user1Session.createDocumentModel(workspace_2.getPathAsString(), "testFolder", "Folder"));
    log.trace("Register test folder as a sync root for user2");
    nuxeoDriveManager.registerSynchronizationRoot(user2Session.getPrincipal(), testFolder, user2Session);
    log.trace("Check FileSystemItem id for user1");
    assertEquals("defaultFileSystemItemFactory#test#" + testFolder.getId(), fileSystemItemAdapterService.getFileSystemItem(testFolder).getId());
    log.trace("Check FileSystemItem id for user2");
    DocumentModel testFolderUser2 = user2Session.getDocument(testFolder.getRef());
    assertEquals("defaultSyncRootFolderItemFactory#test#" + testFolderUser2.getId(), fileSystemItemAdapterService.getFileSystemItem(testFolderUser2).getId());
    log.trace("Check FileSystemItem id for user1 relaxing sync root constraint");
    String fsItemIdUser1 = fileSystemItemAdapterService.getFileSystemItem(testFolder, false, true).getId();
    assertEquals("test#" + testFolder.getId(), fsItemIdUser1);
    log.trace("Check FileSystemItem id for user2 relaxing sync root constraint");
    String fsItemIdUser2 = fileSystemItemAdapterService.getFileSystemItem(testFolderUser2, false, true).getId();
    assertEquals(fsItemIdUser1, fsItemIdUser2);
}
Also used : DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test)

Example 89 with DocumentModel

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

the class AuditChangeFinderClusteringEnabledTestSuite method testClusteringEnabled.

@Test
public void testClusteringEnabled() throws Exception {
    List<FileSystemItemChange> changes;
    DocumentModel file1;
    DocumentModel file2;
    try {
        // No sync roots
        changes = getChanges();
        assertNotNull(changes);
        assertTrue(changes.isEmpty());
        log.trace("Register a sync root and create a document inside it");
        nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), folder1, session);
        file1 = session.createDocumentModel("/folder1", "file1", "File");
        file1.setPropertyValue("file:content", new StringBlob("The file content"));
        file1 = session.createDocument(file1);
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        // NXP-22284: Cannot expect to have no changes if the clustering delay is not expired since waiting for
        // async completion has an unknown duration
        // Wait for (2 * clustering delay + 1 second) then check changes, expecting at least 2:
        // - documentCreated for file1
        // - rootRegistered for folder1
        // The documentCreated event for folder1 might have already been "swallowed" by the first call to
        // #getChanges() if the test initialization takes too much time, sometimes happens with an Oracle database
        Thread.sleep(3000);
        changes = getChanges();
        assertTrue(changes.size() >= 2);
        Set<SimpleFileSystemItemChange> expectedChanges = new HashSet<>();
        expectedChanges.add(new SimpleFileSystemItemChange(file1.getId(), "documentCreated", "test", "defaultFileSystemItemFactory#test#" + file1.getId(), "file1"));
        expectedChanges.add(new SimpleFileSystemItemChange(folder1.getId(), "rootRegistered", "test", "defaultSyncRootFolderItemFactory#test#" + folder1.getId(), "folder1"));
        expectedChanges.add(new SimpleFileSystemItemChange(folder1.getId(), "documentCreated", "test", "defaultSyncRootFolderItemFactory#test#" + folder1.getId(), "folder1"));
        assertTrue(CollectionUtils.isSubCollection(toSimpleFileSystemItemChanges(changes), expectedChanges));
        log.trace("Update existing document and create a new one");
        file1.setPropertyValue("dc:description", "Upated description");
        session.saveDocument(file1);
        file2 = session.createDocumentModel("/folder1", "file2", "File");
        file2.setPropertyValue("file:content", new StringBlob("The second file content"));
        file2 = session.createDocument(file2);
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    // NXP-22284: Cannot expect to have no changes if the clustering delay is not expired since waiting for
    // async completion has an unknown duration
    // Wait for (2 * clustering delay + 1 second) then check changes, expecting 2:
    // - documentCreated for file2
    // - documentModified for file1
    Thread.sleep(3000);
    changes = getChanges();
    assertEquals(2, changes.size());
    Set<SimpleFileSystemItemChange> expectedChanges = new HashSet<>();
    expectedChanges.add(new SimpleFileSystemItemChange(file2.getId(), "documentCreated", "test", "defaultFileSystemItemFactory#test#" + file2.getId(), "file2"));
    expectedChanges.add(new SimpleFileSystemItemChange(file1.getId(), "documentModified", "test", "defaultFileSystemItemFactory#test#" + file1.getId(), "file1"));
    assertTrue(CollectionUtils.isEqualCollection(expectedChanges, toSimpleFileSystemItemChanges(changes)));
}
Also used : StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) FileSystemItemChange(org.nuxeo.drive.service.FileSystemItemChange) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 90 with DocumentModel

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

the class DefaultFileSystemItemFactoryFixture method testGetFileSystemItem.

@Test
public void testGetFileSystemItem() throws Exception {
    // ------------------------------------------------------
    // Check downloadable FileSystemItems
    // ------------------------------------------------------
    // File
    assertTrue(defaultFileSystemItemFactory.isFileSystemItem(file));
    FileSystemItem fsItem = defaultFileSystemItemFactory.getFileSystemItem(file);
    assertNotNull(fsItem);
    assertTrue(fsItem instanceof FileItem);
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId(), fsItem.getId());
    assertEquals(syncRootItemId, fsItem.getParentId());
    assertEquals("Joe.odt", fsItem.getName());
    assertFalse(fsItem.isFolder());
    assertEquals("Administrator", fsItem.getCreator());
    assertEquals("Administrator", fsItem.getLastContributor());
    Blob fileItemBlob = ((FileItem) fsItem).getBlob();
    assertEquals("Joe.odt", fileItemBlob.getFilename());
    assertEquals("Content of Joe's file.", fileItemBlob.getString());
    // Note
    assertTrue(defaultFileSystemItemFactory.isFileSystemItem(note));
    fsItem = defaultFileSystemItemFactory.getFileSystemItem(note);
    assertNotNull(fsItem);
    assertTrue(fsItem instanceof FileItem);
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + note.getId(), fsItem.getId());
    assertEquals(syncRootItemId, fsItem.getParentId());
    assertEquals("aNote.txt", fsItem.getName());
    assertFalse(fsItem.isFolder());
    assertEquals("Administrator", fsItem.getCreator());
    assertEquals("Administrator", fsItem.getLastContributor());
    fileItemBlob = ((FileItem) fsItem).getBlob();
    assertEquals("aNote.txt", fileItemBlob.getFilename());
    assertEquals("Content of Bob's note.", fileItemBlob.getString());
    // Custom doc type with the "file" schema
    assertTrue(defaultFileSystemItemFactory.isFileSystemItem(custom));
    fsItem = defaultFileSystemItemFactory.getFileSystemItem(custom);
    assertNotNull(fsItem);
    assertTrue(fsItem instanceof FileItem);
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + custom.getId(), fsItem.getId());
    assertEquals(syncRootItemId, fsItem.getParentId());
    assertEquals("Bonnie's file.odt", fsItem.getName());
    assertFalse(fsItem.isFolder());
    assertEquals("Administrator", fsItem.getCreator());
    assertEquals("Administrator", fsItem.getLastContributor());
    fileItemBlob = ((FileItem) fsItem).getBlob();
    assertEquals("Bonnie's file.odt", fileItemBlob.getFilename());
    assertEquals("Content of Bonnie's file.", fileItemBlob.getString());
    // File without a blob => not adaptable as a FileSystemItem
    file.setPropertyValue("file:content", null);
    file = session.saveDocument(file);
    assertFalse(defaultFileSystemItemFactory.isFileSystemItem(file));
    fsItem = defaultFileSystemItemFactory.getFileSystemItem(file);
    assertNull(fsItem);
    // Deleted file => not adaptable as a FileSystemItem
    custom.followTransition("delete");
    assertFalse(defaultFileSystemItemFactory.isFileSystemItem(custom));
    assertNull(defaultFileSystemItemFactory.getFileSystemItem(custom));
    // Deleted file with explicit "includeDeleted" => adaptable as a
    // FileSystemItem
    assertTrue(defaultFileSystemItemFactory.isFileSystemItem(custom, true));
    fsItem = defaultFileSystemItemFactory.getFileSystemItem(custom, true);
    assertNotNull(fsItem);
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + custom.getId(), fsItem.getId());
    assertEquals("Bonnie's file.odt", fsItem.getName());
    // Version
    // Note is now automatically versioned at each save
    assertEquals("0.1", note.getVersionLabel());
    note.checkOut();
    DocumentRef versionRef = session.checkIn(note.getRef(), VersioningOption.MINOR, null);
    DocumentModel version = session.getDocument(versionRef);
    assertFalse(defaultFileSystemItemFactory.isFileSystemItem(version));
    // Proxy
    DocumentModel proxy = session.createProxy(note.getRef(), folder.getRef());
    assertTrue(defaultFileSystemItemFactory.isFileSystemItem(proxy));
    // HiddenInNavigation
    note.addFacet("HiddenInNavigation");
    assertFalse(defaultFileSystemItemFactory.isFileSystemItem(note));
    note.removeFacet("HiddenInNavigation");
    // ------------------------------------------------------
    // Check folderish FileSystemItems
    // ------------------------------------------------------
    // Folder
    assertTrue(defaultFileSystemItemFactory.isFileSystemItem(folder));
    fsItem = defaultFileSystemItemFactory.getFileSystemItem(folder);
    assertNotNull(fsItem);
    assertTrue(fsItem instanceof FolderItem);
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), fsItem.getId());
    assertEquals(syncRootItemId, fsItem.getParentId());
    assertEquals("Jack's folder", fsItem.getName());
    assertTrue(fsItem.isFolder());
    assertEquals("Administrator", fsItem.getCreator());
    assertEquals("Administrator", fsItem.getLastContributor());
    FolderItem folderItem = (FolderItem) fsItem;
    List<FileSystemItem> children = folderItem.getChildren();
    assertNotNull(children);
    assertEquals(0, children.size());
    assertTrue(folderItem.getCanScrollDescendants());
    ScrollFileSystemItemList descendants = folderItem.scrollDescendants(null, 10, 1000);
    assertNotNull(descendants);
    assertNotNull(descendants.getScrollId());
    assertEquals(0, descendants.size());
    // FolderishFile => adaptable as a FolderItem since the default
    // FileSystemItem factory gives precedence to the Folderish facet
    assertTrue(defaultFileSystemItemFactory.isFileSystemItem(folderishFile));
    fsItem = defaultFileSystemItemFactory.getFileSystemItem(folderishFile);
    assertNotNull(fsItem);
    assertTrue(fsItem instanceof FolderItem);
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folderishFile.getId(), fsItem.getId());
    assertEquals(syncRootItemId, fsItem.getParentId());
    assertEquals("Sarah's folderish file", fsItem.getName());
    assertTrue(fsItem.isFolder());
    assertEquals("Administrator", fsItem.getCreator());
    assertEquals("Administrator", fsItem.getLastContributor());
    // ------------------------------------------------------
    // Check not downloadable nor folderish
    // ------------------------------------------------------
    assertFalse(defaultFileSystemItemFactory.isFileSystemItem(notAFileSystemItem));
    fsItem = defaultFileSystemItemFactory.getFileSystemItem(notAFileSystemItem);
    assertNull(fsItem);
    // -------------------------------------------------------------
    // Check #getFileSystemItem(DocumentModel doc, FolderItem parentItem)
    // -------------------------------------------------------------
    FolderItem syncRootSystemItem = (FolderItem) fileSystemItemAdapterService.getFileSystemItemFactoryForId(syncRootItemId).getFileSystemItemById(syncRootItemId, principal);
    fsItem = defaultFileSystemItemFactory.getFileSystemItem(note, syncRootSystemItem);
    assertEquals(syncRootItemId, fsItem.getParentId());
    // Passing a null parent will force a null parentId
    fsItem = defaultFileSystemItemFactory.getFileSystemItem(note, null);
    assertNull(fsItem.getParentId());
    // ------------------------------------------------------------------
    // Check FileSystemItem#getCanRename and FileSystemItem#getCanDelete
    // ------------------------------------------------------------------
    // As Administrator
    fsItem = defaultFileSystemItemFactory.getFileSystemItem(note);
    assertTrue(fsItem.getCanRename());
    assertTrue(fsItem.getCanDelete());
    // As a user with READ permission
    DocumentModel rootDoc = session.getRootDocument();
    setPermission(rootDoc, "joe", SecurityConstants.READ, true);
    // Under Oracle, the READ ACL optims are not visible from the joe
    // session while the transaction has not been committed.
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    try (CloseableCoreSession joeSession = coreFeature.openCoreSession("joe")) {
        nuxeoDriveManager.registerSynchronizationRoot(joeSession.getPrincipal(), syncRootFolder, session);
        note = joeSession.getDocument(note.getRef());
        fsItem = defaultFileSystemItemFactory.getFileSystemItem(note);
        assertFalse(fsItem.getCanRename());
        assertFalse(fsItem.getCanDelete());
        // As a user with WRITE permission
        setPermission(rootDoc, "joe", SecurityConstants.WRITE, true);
        fsItem = defaultFileSystemItemFactory.getFileSystemItem(note);
        assertTrue(fsItem.getCanRename());
        assertTrue(fsItem.getCanDelete());
    }
    resetPermissions(rootDoc, "joe");
}
Also used : ScrollFileSystemItemList(org.nuxeo.drive.adapter.ScrollFileSystemItemList) FileItem(org.nuxeo.drive.adapter.FileItem) StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) Blob(org.nuxeo.ecm.core.api.Blob) FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) FolderItem(org.nuxeo.drive.adapter.FolderItem) DocumentRef(org.nuxeo.ecm.core.api.DocumentRef) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test)

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