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");
}
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());
}
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;
}
}
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);
}
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;
}
Aggregations