use of org.nuxeo.ecm.core.api.IdRef in project nuxeo-drive-server by nuxeo.
the class TestPermissionHierarchyFileSystemChanges method testAdaptableUnregisteredSyncRootChange.
/**
* When an unregistered synchronization root can still be adapted as a FileSystemItem, for example in the case of
* the "My Docs" virtual folder in the permission based hierarchy implementation, checks that the related
* {@link FileSystemItemChange} computed by the {@link AuditChangeFinder} contains a null {@code fileSystemItem}
* attribute, see https://jira.nuxeo.com/browse/NXP-16478.
*/
@Test
public void testAdaptableUnregisteredSyncRootChange() throws InterruptedException {
commitAndWaitForAsyncCompletion();
lastEventLogId = nuxeoDriveManager.getChangeFinder().getUpperBound();
// user1
try {
nuxeoDriveManager.registerSynchronizationRoot(session1.getPrincipal(), userWorkspace1, session1);
assertTrue(nuxeoDriveManager.getSynchronizationRootReferences(session1).contains(new IdRef(userWorkspace1.getId())));
} finally {
commitAndWaitForAsyncCompletion();
}
// Check file system item change
try {
List<FileSystemItemChange> changes = getChanges(principal1);
assertEquals(1, changes.size());
FileSystemItemChange change = changes.get(0);
assertEquals(userWorkspace1ItemId, change.getFileSystemItemId());
assertEquals("My Docs", change.getFileSystemItemName());
assertNotNull(change.getFileSystemItem());
} finally {
commitAndWaitForAsyncCompletion();
}
// user1
try {
nuxeoDriveManager.unregisterSynchronizationRoot(session1.getPrincipal(), userWorkspace1, session1);
assertFalse(nuxeoDriveManager.getSynchronizationRootReferences(session1).contains(new IdRef(userWorkspace1.getId())));
} finally {
commitAndWaitForAsyncCompletion();
}
// Check file system item change
try {
List<FileSystemItemChange> changes = getChanges(principal1);
assertEquals(1, changes.size());
FileSystemItemChange change = changes.get(0);
assertEquals("test#" + userWorkspace1.getId(), change.getFileSystemItemId());
assertNull(change.getFileSystemItemName());
assertNull(change.getFileSystemItem());
} finally {
commitAndWaitForAsyncCompletion();
}
}
use of org.nuxeo.ecm.core.api.IdRef in project nuxeo-drive-server by nuxeo.
the class TestPermissionHierarchyFileSystemChanges method testRootlessItems.
/**
* Tests the rootless file system items, typically:
* <ul>
* <li>A folder registered as a synchronization root but that is not adaptable as a {@link FileSystemItem}. For
* example if it is handled by the {@link PermissionSyncRootFactory} and
* {@link PermissionSyncRootFactory#isFileSystemItem(DocumentModel, boolean)} returns {@code false} because of the
* missing required permission.</li>
* <li>A file created in such a folder.</li>
* <li>A file created in a folder registered as a synchronization root on which the user doesn't have Read
* access.</li>
* </ul>
* For the test, the required permission for a folder to be adapted by the {@link PermissionSyncRootFactory} is
* Everything.
*
* <pre>
* Server side hierarchy for the test
* ==================================
*
* /user1 (user workspace)
* |-- user1Folder1 (registered as a synchronization root with Everything permission for user2)
* |-- user1Folder2 (registered as a synchronization root with ReadWrite permission only for user2)
* | |-- user1File1
* | |-- user1File2
* </pre>
*/
@Test
@Deploy("org.nuxeo.drive.operations.test:OSGI-INF/test-nuxeodrive-hierarchy-permission-adapter-contrib.xml")
public void testRootlessItems() throws Exception {
commitAndWaitForAsyncCompletion();
DocumentModel user1Folder1;
DocumentModel user1Folder2;
DocumentModel user1File2;
try {
// Populate user1's personal workspace
user1Folder1 = createFolder(session1, userWorkspace1.getPathAsString(), "user1Folder1", "Folder");
user1Folder2 = createFolder(session1, userWorkspace1.getPathAsString(), "user1Folder2", "Folder");
session1.save();
setPermission(session1, user1Folder1, "user2", SecurityConstants.EVERYTHING, true);
setPermission(session1, user1Folder2, "user2", SecurityConstants.READ_WRITE, true);
} finally {
commitAndWaitForAsyncCompletion();
}
lastEventLogId = nuxeoDriveManager.getChangeFinder().getUpperBound();
// so appears in the file system changes
try {
nuxeoDriveManager.registerSynchronizationRoot(session2.getPrincipal(), user1Folder1, session2);
assertTrue(nuxeoDriveManager.getSynchronizationRootReferences(session2).contains(new IdRef(user1Folder1.getId())));
} finally {
commitAndWaitForAsyncCompletion();
}
try {
List<FileSystemItemChange> changes = getChanges(principal2);
assertEquals(1, changes.size());
FileSystemItemChange change = changes.get(0);
assertEquals(SYNC_ROOT_ID_PREFIX + user1Folder1.getId(), change.getFileSystemItemId());
assertEquals("user1Folder1", change.getFileSystemItemName());
assertNotNull(change.getFileSystemItem());
} finally {
commitAndWaitForAsyncCompletion();
}
// adaptable so doesn't appear in the file system changes
try {
nuxeoDriveManager.registerSynchronizationRoot(session2.getPrincipal(), user1Folder2, session2);
assertTrue(nuxeoDriveManager.getSynchronizationRootReferences(session2).contains(new IdRef(user1Folder2.getId())));
} finally {
commitAndWaitForAsyncCompletion();
}
try {
List<FileSystemItemChange> changes = getChanges(principal2);
assertTrue(changes.isEmpty());
} finally {
commitAndWaitForAsyncCompletion();
}
// the file system changes
try {
createFile(session1, user1Folder2.getPathAsString(), "user1File1", "File", "user1File1.txt", CONTENT_PREFIX + "user1File1");
session1.save();
} finally {
commitAndWaitForAsyncCompletion();
}
try {
List<FileSystemItemChange> changes = getChanges(principal2);
assertTrue(changes.isEmpty());
} finally {
commitAndWaitForAsyncCompletion();
}
// the file system changes
try {
resetPermissions(session1, user1Folder2.getRef(), "user2");
user1File2 = createFile(session1, user1Folder2.getPathAsString(), "user1File2", "File", "user1File2.txt", CONTENT_PREFIX + "user1File2");
setPermission(session1, user1File2, "user2", SecurityConstants.READ, true);
} finally {
commitAndWaitForAsyncCompletion();
}
try {
// Security updates
List<FileSystemItemChange> changes = getChanges(principal2);
assertEquals(2, changes.size());
FileSystemItemChange change = changes.get(0);
assertEquals("securityUpdated", change.getEventId());
assertEquals("test#" + user1File2.getId(), change.getFileSystemItemId());
assertNull(change.getFileSystemItemName());
// Not adaptable as a FileSystemItem since parent is not
assertNull(change.getFileSystemItem());
change = changes.get(1);
assertEquals("securityUpdated", change.getEventId());
assertEquals("test#" + user1Folder2.getId(), change.getFileSystemItemId());
assertNull(change.getFileSystemItemName());
// Not adaptable as a FileSystemItem since no Read permission
assertNull(change.getFileSystemItem());
} finally {
commitAndWaitForAsyncCompletion();
}
}
use of org.nuxeo.ecm.core.api.IdRef in project nuxeo-drive-server by nuxeo.
the class TestPermissionHierarchyFileSystemChanges method getChanges.
protected List<FileSystemItemChange> getChanges(Principal principal) throws InterruptedException {
FileSystemChangeSummary changeSummary = nuxeoDriveManager.getChangeSummaryIntegerBounds(principal, Collections.<String, Set<IdRef>>emptyMap(), lastEventLogId);
assertNotNull(changeSummary);
lastEventLogId = changeSummary.getUpperBound();
return changeSummary.getFileSystemChanges();
}
use of org.nuxeo.ecm.core.api.IdRef 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()));
}
use of org.nuxeo.ecm.core.api.IdRef in project nuxeo-drive-server by nuxeo.
the class TestFileSystemItemOperations method testDelete.
@Test
public void testDelete() throws Exception {
// ------------------------------------------------------
// Delete file in sync root: should trash it
// ------------------------------------------------------
clientSession.newRequest(NuxeoDriveDelete.ID).set("id", DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file1.getId()).execute();
// Need to flush VCS cache to be aware of changes in the session used by the file system item
TransactionHelper.commitOrRollbackTransaction();
TransactionHelper.startTransaction();
DocumentModel deletedFileDoc = session.getDocument(new IdRef(file1.getId()));
assertTrue(deletedFileDoc.isTrashed());
// ------------------------------------------------------
// Delete sync root: should unregister it
// ------------------------------------------------------
clientSession.newRequest(NuxeoDriveDelete.ID).set("id", SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot2.getId()).execute();
TransactionHelper.commitOrRollbackTransaction();
TransactionHelper.startTransaction();
assertFalse(nuxeoDriveManager.getSynchronizationRootReferences(session).contains(new IdRef(syncRoot2.getId())));
// ------------------------------------------------------
try {
clientSession.newRequest(NuxeoDriveDelete.ID).set("id", fileSystemItemAdapterService.getTopLevelFolderItemFactory().getTopLevelFolderItem(session.getPrincipal()).getId()).execute();
fail("Top level folder item deletion should be unsupported.");
} catch (Exception e) {
assertEquals("Failed to invoke operation: NuxeoDrive.Delete", e.getMessage());
}
}
Aggregations