use of org.nuxeo.ecm.core.api.Lock 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");
}
Aggregations