Search in sources :

Example 96 with DocumentModel

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

the class TestNuxeoDriveManager method testResetSyncRootsOnCopy.

@Test
public void testResetSyncRootsOnCopy() {
    nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), folder_1_1, session);
    // Copy a sync root
    DocumentModel copy = session.copy(folder_1_1.getRef(), workspace_2.getRef(), null);
    txFeature.nextTransaction();
    assertFalse(nuxeoDriveManager.isSynchronizationRoot(session.getPrincipal(), copy));
    nuxeoDriveManager.invalidateSynchronizationRootsCache(session.getPrincipal().getName());
    // Copy a folder containing a sync root
    copy = session.copy(workspace_1.getRef(), workspace_2.getRef(), null);
    txFeature.nextTransaction();
    assertFalse(nuxeoDriveManager.isSynchronizationRoot(session.getPrincipal(), session.getDocument(new PathRef(copy.getPathAsString() + "/" + folder_1_1.getName()))));
}
Also used : PathRef(org.nuxeo.ecm.core.api.PathRef) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test)

Example 97 with DocumentModel

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

the class TestNuxeoDriveManager method testSyncRootChildWhenBlockingInheritance.

@Test
public void testSyncRootChildWhenBlockingInheritance() {
    // Create a folder_2_1_1, as a child of folder_2_1
    DocumentModel folder_2_1_1 = session.createDocument(session.createDocumentModel("/default-domain/workspaces/workspace-2/folder-2-1", "folder_2-1-1", "Folder"));
    // Make user1 register workspace-2, should have no effect on child
    // folder-2-1
    // and on folder_2_1_1
    nuxeoDriveManager.registerSynchronizationRoot(user1Session.getPrincipal(), workspace_2, user1Session);
    folder_2_1 = session.getDocument(new PathRef("/default-domain/workspaces/workspace-2/folder-2-1"));
    assertTrue(isUserSubscribed("user1", workspace_2));
    assertFalse(isUserSubscribed("user1", folder_2_1));
    assertFalse(isUserSubscribed("user1", folder_2_1_1));
    // Block permissions inheritance on folder_2_1
    ACP acp = folder_2_1.getACP();
    ACL localACL = acp.getOrCreateACL(ACL.LOCAL_ACL);
    List<ACE> aceList = new ArrayList<>();
    aceList.addAll(Arrays.asList(localACL.getACEs()));
    localACL.clear();
    aceList.add(new ACE(SecurityConstants.EVERYONE, SecurityConstants.EVERYTHING, false));
    localACL.addAll(aceList);
    folder_2_1.setACP(acp, true);
    folder_2_1 = session.saveDocument(folder_2_1);
    // Check that the user1 has no longer access to folder_2_1
    assertFalse(session.hasPermission(Framework.getService(UserManager.class).getPrincipal("user1"), folder_2_1_1.getRef(), SecurityConstants.READ_WRITE));
    // Give permission READ_WRITE to user1 on folder_2_1_1 and make it sync
    // root
    acp = folder_2_1_1.getACP();
    localACL = acp.getOrCreateACL(ACL.LOCAL_ACL);
    localACL.add(new ACE("user1", SecurityConstants.READ_WRITE, true));
    folder_2_1_1.setACP(acp, true);
    folder_2_1_1 = session.saveDocument(folder_2_1_1);
    assertTrue(session.hasPermission(Framework.getService(UserManager.class).getPrincipal("user1"), folder_2_1_1.getRef(), SecurityConstants.READ_WRITE));
    nuxeoDriveManager.registerSynchronizationRoot(user1Session.getPrincipal(), folder_2_1_1, user1Session);
    assertTrue(isUserSubscribed("user1", workspace_2));
    assertFalse(isUserSubscribed("user1", folder_2_1));
    assertTrue(isUserSubscribed("user1", folder_2_1_1));
    Principal user1 = user1Session.getPrincipal();
    checkRootsCount(user1, 2);
}
Also used : ACE(org.nuxeo.ecm.core.api.security.ACE) PathRef(org.nuxeo.ecm.core.api.PathRef) UserManager(org.nuxeo.ecm.platform.usermanager.UserManager) ArrayList(java.util.ArrayList) ACL(org.nuxeo.ecm.core.api.security.ACL) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) ACP(org.nuxeo.ecm.core.api.security.ACP) Principal(java.security.Principal) Test(org.junit.Test)

Example 98 with DocumentModel

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

the class TestNuxeoDriveManager method testResetSyncRootsOnVersioning.

@Test
public void testResetSyncRootsOnVersioning() {
    nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), workspace_1, session);
    DocumentRef syncRootVersionRef = session.checkIn(workspace_1.getRef(), VersioningOption.MAJOR, null);
    txFeature.nextTransaction();
    DocumentModel syncRootVersion = session.getDocument(syncRootVersionRef);
    assertFalse(nuxeoDriveManager.isSynchronizationRoot(session.getPrincipal(), syncRootVersion));
}
Also used : DocumentRef(org.nuxeo.ecm.core.api.DocumentRef) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test)

Example 99 with DocumentModel

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

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

the class TestDriveVersioning method testAutomaticVersioning.

@Test
@Deploy({ "org.nuxeo.drive.core:OSGI-INF/test-nuxeodrive-versioning-file-policy-not-drive-contrib.xml" })
public void testAutomaticVersioning() throws Exception {
    FileItem fileItem = (FileItem) defaultFileSystemItemFactory.getFileSystemItem(file);
    // 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);
        file = joeSession.getDocument(file.getRef());
        fileItem = (FileItem) defaultFileSystemItemFactory.getFileSystemItem(file);
        assertFalse(fileItem.getCanUpdate());
        // As a user with WRITE permission
        setPermission(rootDoc, "joe", SecurityConstants.WRITE, true);
        fileItem = (FileItem) defaultFileSystemItemFactory.getFileSystemItem(file);
        assertTrue(fileItem.getCanUpdate());
        // Re-fetch file with Administrator session
        file = session.getDocument(file.getRef());
        fileItem = (FileItem) defaultFileSystemItemFactory.getFileSystemItem(file);
        // ------------------------------------------------------
        // FileItem#getBlob
        // ------------------------------------------------------
        Blob fileItemBlob = fileItem.getBlob();
        assertEquals("Joe.odt", fileItemBlob.getFilename());
        assertEquals("Content of Joe's file.", fileItemBlob.getString());
        // Check initial version
        // A version with a minor increment is automatically created during creation for all File documents
        // by the "version-file" policy (automatic versioning),
        // see test-nuxeodrive-versioning-file-policy-not-drive-contrib.xml
        assertEquals("0.1", file.getVersionLabel());
        // ------------------------------------------------------
        // 1. Change without delay
        // ------------------------------------------------------
        Blob newBlob = new StringBlob("This is a new file.");
        newBlob.setFilename("New blob.txt");
        ensureJustModified(file, session);
        fileItem.setBlob(newBlob);
        file = session.getDocument(file.getRef());
        Blob updatedBlob = (Blob) file.getPropertyValue("file:content");
        assertEquals("New blob.txt", updatedBlob.getFilename());
        assertEquals("This is a new file.", updatedBlob.getString());
        // Check versioning => should not be versioned since same contributor,
        // last modification was done before the versioning delay
        // and the "drive-force-versioning" policy prevents automatic versioning
        // from performing a minor increment,
        // see test-nuxeodrive-versioning-file-policy-not-drive-contrib.xml
        // Should be checked out since not previously checked out
        assertEquals("0.1+", file.getVersionLabel());
        // ------------------------------------------------------
        // 2. Change with delay
        // ------------------------------------------------------
        // Wait for versioning delay
        Thread.sleep(VERSIONING_DELAY);
        newBlob.setFilename("File name modified.txt");
        fileItem.setBlob(newBlob);
        file = session.getDocument(file.getRef());
        updatedBlob = (Blob) file.getPropertyValue("file:content");
        assertEquals("File name modified.txt", updatedBlob.getFilename());
        // Check versioning => should be versioned with a major increment by the "versioning-delay" policy
        // since last modification was done after the versioning delay
        // and a minor increment by the "version-file" policy
        // Should not be checked out since the "version-file" policy is not applied before update
        assertEquals("1.1", file.getVersionLabel());
        List<DocumentModel> fileVersions = session.getVersions(file.getRef());
        assertEquals(3, fileVersions.size());
        DocumentModel firstMinorFileVersion = fileVersions.get(0);
        Blob versionedBlob = (Blob) firstMinorFileVersion.getPropertyValue("file:content");
        assertEquals("Joe.odt", versionedBlob.getFilename());
        DocumentModel lastMajorFileVersion = fileVersions.get(1);
        versionedBlob = (Blob) lastMajorFileVersion.getPropertyValue("file:content");
        assertEquals("New blob.txt", versionedBlob.getFilename());
        DocumentModel lastFileVersion = fileVersions.get(2);
        versionedBlob = (Blob) lastFileVersion.getPropertyValue("file:content");
        assertEquals("File name modified.txt", versionedBlob.getFilename());
        // ------------------------------------------------------
        // 3. Change with delay
        // ------------------------------------------------------
        // Wait for versioning delay
        Thread.sleep(VERSIONING_DELAY);
        newBlob.setFilename("File name modified again.txt");
        fileItem.setBlob(newBlob);
        file = session.getDocument(file.getRef());
        updatedBlob = (Blob) file.getPropertyValue("file:content");
        assertEquals("File name modified again.txt", updatedBlob.getFilename());
        // Check versioning => no major increment by the "versioning-delay" policy
        // because the document is already checked in,
        // but versioned with a minor increment because of the "version-file" policy
        // Should not be checked out since the "version-file" policy is not applied before update
        assertEquals("1.2", file.getVersionLabel());
        fileVersions = session.getVersions(file.getRef());
        assertEquals(4, fileVersions.size());
        lastFileVersion = fileVersions.get(3);
        versionedBlob = (Blob) lastFileVersion.getPropertyValue("file:content");
        assertEquals("File name modified again.txt", versionedBlob.getFilename());
        // ------------------------------------------------------
        // 4. Change without delay
        // ------------------------------------------------------
        newBlob.setFilename("File name modified again as new draft.txt");
        ensureJustModified(file, session);
        fileItem.setBlob(newBlob);
        file = session.getDocument(file.getRef());
        updatedBlob = (Blob) file.getPropertyValue("file:content");
        assertEquals("File name modified again as new draft.txt", updatedBlob.getFilename());
        // Check versioning => should not be versioned since same contributor,
        // last modification was done before the versioning delay
        // and the "drive-force-versioning" policy prevents automatic versioning
        // from performing a minor increment,
        // see test-nuxeodrive-versioning-file-policy-not-drive-contrib.xml
        // Should be checked out since not previously checked out
        assertEquals("1.2+", file.getVersionLabel());
        fileVersions = session.getVersions(file.getRef());
        assertEquals(4, fileVersions.size());
        lastFileVersion = fileVersions.get(3);
        versionedBlob = (Blob) lastFileVersion.getPropertyValue("file:content");
        assertEquals("File name modified again.txt", versionedBlob.getFilename());
        // ------------------------------------------------------
        // 5. Change without delay with another user
        // ------------------------------------------------------
        file = joeSession.getDocument(file.getRef());
        fileItem = (FileItem) defaultFileSystemItemFactory.getFileSystemItem(file);
        newBlob.setFilename("File name modified by Joe.txt");
        fileItem.setBlob(newBlob);
        // Re-fetch file with Administrator session
        file = session.getDocument(file.getRef());
        updatedBlob = (Blob) file.getPropertyValue("file:content");
        assertEquals("File name modified by Joe.txt", updatedBlob.getFilename());
        // Check versioning => should be versioned with a major increment by the "collaborative-save" policy
        // since updated by a different contributor
        // and a minor increment by the "version-file" policy
        // Should not be checked out since the "version-file" policy is not applied before update
        assertEquals("2.1", file.getVersionLabel());
        fileVersions = session.getVersions(file.getRef());
        assertEquals(6, fileVersions.size());
        lastMajorFileVersion = fileVersions.get(4);
        versionedBlob = (Blob) lastMajorFileVersion.getPropertyValue("file:content");
        assertEquals("File name modified again as new draft.txt", versionedBlob.getFilename());
        lastFileVersion = fileVersions.get(5);
        versionedBlob = (Blob) lastFileVersion.getPropertyValue("file:content");
        assertEquals("File name modified by Joe.txt", versionedBlob.getFilename());
        // ------------------------------------------------------
        // 6. Change with delay with the same user
        // ------------------------------------------------------
        // Wait for versioning delay
        Thread.sleep(VERSIONING_DELAY);
        file = joeSession.getDocument(file.getRef());
        fileItem = (FileItem) defaultFileSystemItemFactory.getFileSystemItem(file);
        newBlob.setFilename("File name modified by Joe again.txt");
        fileItem.setBlob(newBlob);
        // Re-fetch file with Administrator session
        file = session.getDocument(file.getRef());
        updatedBlob = (Blob) file.getPropertyValue("file:content");
        assertEquals("File name modified by Joe again.txt", updatedBlob.getFilename());
        // Check versioning => no major increment by the "versioning-delay" policy
        // because the document is already checked in,
        // but versioned with a minor increment because of the "version-file" policy
        // Should not be checked out since the "version-file" policy is not applied before update
        assertEquals("2.2", file.getVersionLabel());
        fileVersions = session.getVersions(file.getRef());
        assertEquals(7, fileVersions.size());
        lastFileVersion = fileVersions.get(6);
        versionedBlob = (Blob) lastFileVersion.getPropertyValue("file:content");
        assertEquals("File name modified by Joe again.txt", versionedBlob.getFilename());
    }
    resetPermissions(rootDoc, "joe");
}
Also used : FileItem(org.nuxeo.drive.adapter.FileItem) StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) Blob(org.nuxeo.ecm.core.api.Blob) StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) 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