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