Search in sources :

Example 1 with FolderItem

use of org.nuxeo.drive.adapter.FolderItem in project nuxeo-drive-server by nuxeo.

the class DefaultFileSystemItemFactoryFixture method testLockedDocument.

@Test
public void testLockedDocument() {
    setPermission(syncRootFolder, "joe", SecurityConstants.READ_WRITE, true);
    setPermission(syncRootFolder, "jack", SecurityConstants.READ_WRITE, true);
    try (CloseableCoreSession joeSession = coreFeature.openCoreSession("joe")) {
        nuxeoDriveManager.registerSynchronizationRoot(joeSession.getPrincipal(), syncRootFolder, joeSession);
        DocumentModel joeFile = joeSession.getDocument(file.getRef());
        log.trace("Check readonly flags on an unlocked document");
        FileSystemItem fsItem = defaultFileSystemItemFactory.getFileSystemItem(joeFile);
        assertTrue(fsItem.getCanRename());
        assertTrue(fsItem.getCanDelete());
        assertTrue(((FileItem) fsItem).getCanUpdate());
        assertNull(fsItem.getLockInfo());
        log.trace("Check readonly flags on an document locked by the current user");
        joeSession.setLock(joeFile.getRef());
        // Re-fetch document to clear lock info
        joeFile = joeSession.getDocument(file.getRef());
        fsItem = defaultFileSystemItemFactory.getFileSystemItem(joeFile);
        assertTrue(fsItem.getCanRename());
        assertTrue(fsItem.getCanDelete());
        assertTrue(((FileItem) fsItem).getCanUpdate());
        Lock lockInfo = fsItem.getLockInfo();
        assertNotNull(lockInfo);
        assertEquals("joe", lockInfo.getOwner());
        assertNotNull(lockInfo.getCreated());
        // Check that the lock info is not fetched for FileSystemItem
        // adaptation when calling getChildren or
        // scrollDescendants
        FileSystemItemFactory defaultSyncRootFolderItemFactory = ((FileSystemItemAdapterServiceImpl) fileSystemItemAdapterService).getFileSystemItemFactory("defaultSyncRootFolderItemFactory");
        FolderItem syncRootFolderItem = (FolderItem) defaultSyncRootFolderItemFactory.getFileSystemItem(syncRootFolder);
        List<FileSystemItem> children = syncRootFolderItem.getChildren();
        assertEquals(5, children.size());
        for (FileSystemItem child : children) {
            assertNull(child.getLockInfo());
        }
        children = syncRootFolderItem.scrollDescendants(null, 10, 1000);
        assertEquals(5, children.size());
        for (FileSystemItem child : children) {
            assertNull(child.getLockInfo());
        }
        try (CloseableCoreSession jackSession = coreFeature.openCoreSession("jack")) {
            nuxeoDriveManager.registerSynchronizationRoot(jackSession.getPrincipal(), syncRootFolder, jackSession);
            DocumentModel jackFile = jackSession.getDocument(file.getRef());
            log.trace("Check readonly flags for a non administrator on a document locked by another user");
            fsItem = defaultFileSystemItemFactory.getFileSystemItem(jackFile);
            assertFalse(fsItem.getCanRename());
            assertFalse(fsItem.getCanDelete());
            assertFalse(((FileItem) fsItem).getCanUpdate());
            lockInfo = fsItem.getLockInfo();
            assertNotNull(lockInfo);
            assertEquals("joe", lockInfo.getOwner());
            assertNotNull(lockInfo.getCreated());
            log.trace("Check readonly flags for an administrator on a document locked by another user");
            fsItem = defaultFileSystemItemFactory.getFileSystemItem(file);
            assertTrue(fsItem.getCanRename());
            assertTrue(fsItem.getCanDelete());
            assertTrue(((FileItem) fsItem).getCanUpdate());
            lockInfo = fsItem.getLockInfo();
            assertNotNull(lockInfo);
            assertEquals("joe", lockInfo.getOwner());
            assertNotNull(lockInfo.getCreated());
            log.trace("Check readonly flags for a non administrator on an unlocked document");
            joeSession.removeLock(joeFile.getRef());
            // Re-fetch document to clear lock info
            jackFile = jackSession.getDocument(file.getRef());
            fsItem = defaultFileSystemItemFactory.getFileSystemItem(jackFile);
            assertTrue(fsItem.getCanRename());
            assertTrue(fsItem.getCanDelete());
            assertTrue(((FileItem) fsItem).getCanUpdate());
            assertNull(fsItem.getLockInfo());
        }
    }
    resetPermissions(syncRootFolder, "jack");
    resetPermissions(syncRootFolder, "joe");
}
Also used : FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) DefaultFileSystemItemFactory(org.nuxeo.drive.service.impl.DefaultFileSystemItemFactory) FileSystemItemFactory(org.nuxeo.drive.service.FileSystemItemFactory) FolderItem(org.nuxeo.drive.adapter.FolderItem) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) FileSystemItemAdapterServiceImpl(org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Lock(org.nuxeo.ecm.core.api.Lock) Test(org.junit.Test)

Example 2 with FolderItem

use of org.nuxeo.drive.adapter.FolderItem in project nuxeo-drive-server by nuxeo.

the class DefaultFileSystemItemFactoryFixture method testScrollDescendantsIncludingCollections.

@Test
public void testScrollDescendantsIncludingCollections() {
    log.trace("Add a document to a new collection \"testCollection\" created in \"/default-domain/UserWorkspaces/Administrator/Collections\"");
    collectionManager.addToNewCollection("testCollection", null, file, session);
    DocumentModel userCollections = collectionManager.getUserDefaultCollections(null, session);
    DocumentModel userWorkspace = session.getParentDocument(userCollections.getRef());
    log.trace("Create \"testFolder\" in \"/default-domain/UserWorkspaces/Administrator\"");
    DocumentModel testFolder = session.createDocumentModel(userWorkspace.getPathAsString(), "testFolder", "Folder");
    testFolder = session.createDocument(testFolder);
    log.trace("Register \"/default-domain/UserWorkspaces/Administrator\" as a synchronization root for Administrator");
    nuxeoDriveManager.registerSynchronizationRoot(principal, userWorkspace, session);
    log.trace("Scroll through the descendants of \"/default-domain/UserWorkspaces/Administrator\", expecting one: \"testFolder\", " + "the \"Collections\" folder and its descendants being ignored");
    FileSystemItemFactory defaultSyncRootFolderItemFactory = ((FileSystemItemAdapterServiceImpl) fileSystemItemAdapterService).getFileSystemItemFactory("defaultSyncRootFolderItemFactory");
    FolderItem userWorkspaceFolderItem = (FolderItem) defaultSyncRootFolderItemFactory.getFileSystemItem(userWorkspace);
    ScrollFileSystemItemList descendants = userWorkspaceFolderItem.scrollDescendants(null, 10, 1000);
    assertEquals(1, descendants.size());
    FileSystemItem descendant = descendants.get(0);
    assertTrue(descendant.isFolder());
    assertEquals("testFolder", descendant.getName());
}
Also used : ScrollFileSystemItemList(org.nuxeo.drive.adapter.ScrollFileSystemItemList) 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 3 with FolderItem

use of org.nuxeo.drive.adapter.FolderItem in project nuxeo-drive-server by nuxeo.

the class PermissionSyncRootFactory method getParentItem.

/*------------------ AbstractSyncRootFolderItemFactory ------------------*/
@Override
protected FolderItem getParentItem(DocumentModel doc) {
    Principal principal = doc.getCoreSession().getPrincipal();
    String docCreator = (String) doc.getPropertyValue("dc:creator");
    if (principal.getName().equals(docCreator)) {
        FolderItem parent = getFileSystemAdapterService().getVirtualFolderItemFactory(userSyncRootParentFactoryName).getVirtualFolderItem(principal);
        if (parent == null) {
            throw new NuxeoException(String.format("Cannot find the parent of document %s: virtual folder from factory %s.", doc.getId(), userSyncRootParentFactoryName));
        }
        return parent;
    } else {
        FolderItem parent = getFileSystemAdapterService().getVirtualFolderItemFactory(sharedSyncRootParentFactoryName).getVirtualFolderItem(principal);
        if (parent == null) {
            throw new NuxeoException(String.format("Cannot find the parent of document %s: virtual folder from factory %s.", doc.getId(), sharedSyncRootParentFactoryName));
        }
        return parent;
    }
}
Also used : FolderItem(org.nuxeo.drive.adapter.FolderItem) DefaultSyncRootFolderItem(org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException) Principal(java.security.Principal)

Example 4 with FolderItem

use of org.nuxeo.drive.adapter.FolderItem in project nuxeo-drive-server by nuxeo.

the class SharedSyncRootParentFactory method getVirtualFolderItem.

@Override
public FolderItem getVirtualFolderItem(Principal principal) {
    FileSystemItemManager fileSystemItemManager = Framework.getService(FileSystemItemManager.class);
    FolderItem topLevelFolder = fileSystemItemManager.getTopLevelFolder(principal);
    if (topLevelFolder == null) {
        throw new NuxeoException("Found no top level folder item. Please check your contribution to the following extension point: <extension target=\"org.nuxeo.drive.service.FileSystemItemAdapterService\" point=\"topLevelFolderItemFactory\">.");
    }
    return new SharedSyncRootParentFolderItem(getName(), principal, topLevelFolder.getId(), topLevelFolder.getPath(), folderName);
}
Also used : FileSystemItemManager(org.nuxeo.drive.service.FileSystemItemManager) SharedSyncRootParentFolderItem(org.nuxeo.drive.hierarchy.permission.adapter.SharedSyncRootParentFolderItem) FolderItem(org.nuxeo.drive.adapter.FolderItem) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException) SharedSyncRootParentFolderItem(org.nuxeo.drive.hierarchy.permission.adapter.SharedSyncRootParentFolderItem)

Example 5 with FolderItem

use of org.nuxeo.drive.adapter.FolderItem in project nuxeo-drive-server by nuxeo.

the class UserWorkspaceSyncRootFactory method getParentItem.

/*------------------ AbstractSyncRootFolderItemFactory ------------------*/
@Override
protected FolderItem getParentItem(DocumentModel doc) {
    Principal principal = doc.getCoreSession().getPrincipal();
    FolderItem parent = getFileSystemAdapterService().getVirtualFolderItemFactory(syncRootParentFactoryName).getVirtualFolderItem(principal);
    if (parent == null) {
        throw new NuxeoException(String.format("Cannot find the parent of document %s: virtual folder from factory %s.", doc.getId(), syncRootParentFactoryName));
    }
    return parent;
}
Also used : DefaultSyncRootFolderItem(org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem) FolderItem(org.nuxeo.drive.adapter.FolderItem) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException) Principal(java.security.Principal)

Aggregations

FolderItem (org.nuxeo.drive.adapter.FolderItem)43 FileSystemItem (org.nuxeo.drive.adapter.FileSystemItem)24 Test (org.junit.Test)22 DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)16 NuxeoException (org.nuxeo.ecm.core.api.NuxeoException)14 CloseableCoreSession (org.nuxeo.ecm.core.api.CloseableCoreSession)10 StringBlob (org.nuxeo.ecm.core.api.impl.blob.StringBlob)10 FileItem (org.nuxeo.drive.adapter.FileItem)8 DefaultSyncRootFolderItem (org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem)8 FileSystemItemAdapterServiceImpl (org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl)8 Blob (org.nuxeo.ecm.core.api.Blob)8 ScrollFileSystemItemList (org.nuxeo.drive.adapter.ScrollFileSystemItemList)7 FileSystemItemFactory (org.nuxeo.drive.service.FileSystemItemFactory)7 DefaultFileSystemItemFactory (org.nuxeo.drive.service.impl.DefaultFileSystemItemFactory)6 FileSystemItemManager (org.nuxeo.drive.service.FileSystemItemManager)4 DocumentRef (org.nuxeo.ecm.core.api.DocumentRef)4 Deploy (org.nuxeo.runtime.test.runner.Deploy)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 DocumentBackedFolderItem (org.nuxeo.drive.adapter.impl.DocumentBackedFolderItem)3