use of org.alfresco.repo.model.Repository in project alfresco-repository by Alfresco.
the class DownloadServiceIntegrationTest method deleteBeforeDateAsNormalUserFromAllSysDownloadFolders.
// see MNT-20212
@Test
public void deleteBeforeDateAsNormalUserFromAllSysDownloadFolders() throws InterruptedException {
String randomUsername = createRandomUser();
NamespaceService namespaceService = APP_CONTEXT_INIT.getApplicationContext().getBean("namespaceService", NamespaceService.class);
Repository repositoryHelper = APP_CONTEXT_INIT.getApplicationContext().getBean("repositoryHelper", Repository.class);
FileFolderService fileFolderService = APP_CONTEXT_INIT.getApplicationContext().getBean("fileFolderService", FileFolderService.class);
// this value should be similar to whatever is set in the properties files for:
// system.downloads_container.childname=sys:downloads
final String nodeName = "sys:downloads";
QName container = QName.createQName(nodeName, namespaceService);
final NodeRef problematicDuplicateSystemDownloadNode = createProblematicDuplicateSystemNode(container, NODE_SERVICE, repositoryHelper);
try {
// add "downloads_container"
assertNotEquals(problematicDuplicateSystemDownloadNode.getId(), nodeName);
// downloads_container is taken from the downloadsSpace.xml uuid setting
assertNotEquals(problematicDuplicateSystemDownloadNode.getId(), "downloads_container");
Authentication previousAuth = AuthenticationUtil.getFullAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(randomUsername);
NodeRef beforeNodeRef;
NodeRef afterNodeRef;
Date beforeTime;
try {
beforeNodeRef = DOWNLOAD_SERVICE.createDownload(new NodeRef[] { level1Folder1 }, true);
testNodes.addNodeRef(beforeNodeRef);
waitForDownload(beforeNodeRef);
beforeTime = new Date();
afterNodeRef = DOWNLOAD_SERVICE.createDownload(new NodeRef[] { level1Folder2 }, true);
testNodes.addNodeRef(afterNodeRef);
waitForDownload(afterNodeRef);
} finally {
// assuming previous authentication is the system user
AuthenticationUtil.setFullAuthentication(previousAuth);
}
moveDownloadedFileToProblematicFolder(fileFolderService, problematicDuplicateSystemDownloadNode, beforeNodeRef);
deleteDownloadsAndCheckParameters(beforeNodeRef, afterNodeRef, beforeTime);
} finally {
cleanProblematicFolder(problematicDuplicateSystemDownloadNode);
}
}
use of org.alfresco.repo.model.Repository in project alfresco-repository by Alfresco.
the class ScriptNodeTest method testConvertMultiplePropertyForActivitiScriptNode.
/**
* MNT-16053: Conversion for property with multiple=true, on an Activiti script node, fails.
*/
@Test
public void testConvertMultiplePropertyForActivitiScriptNode() {
ArrayList<String> numbers = new ArrayList<>();
numbers.add("Phone #1");
numbers.add("Phone #2");
Repository repositoryHelper = (Repository) APP_CONTEXT_INIT.getApplicationContext().getBean("repositoryHelper");
NodeRef companyHome = repositoryHelper.getCompanyHome();
ActivitiScriptNode scriptNode = new ActivitiScriptNode(companyHome, SERVICE_REGISTRY);
try {
// Do a conversion of a multiple property (this is a residual property, but it doesn't matter, the conversion code is the same, regardless of the property being in the model or not).
scriptNode.getValueConverter().convertValueForScript(QName.createQName("cm:phonenumbers"), numbers);
} catch (Exception e) {
fail("Converting multiple property for Activiti script fails with " + e);
}
}
use of org.alfresco.repo.model.Repository in project alfresco-repository by Alfresco.
the class ScriptNodeTest method createTestContent.
/**
* Create test content, can be versionable.
* @param versionable boolean
*/
private void createTestContent(boolean versionable) {
Repository repositoryHelper = (Repository) APP_CONTEXT_INIT.getApplicationContext().getBean("repositoryHelper");
NodeRef companyHome = repositoryHelper.getCompanyHome();
// Create some test content
testNode = testNodes.createQuickFile(MimetypeMap.MIMETYPE_TEXT_PLAIN, companyHome, "userOnesDoc", TEST_USER1.getUsername(), versionable);
}
use of org.alfresco.repo.model.Repository in project alfresco-repository by Alfresco.
the class ScriptNodeTest method testCreateRemoveAssociation.
/**
* Test associations related script api, after the permissions checks have been pushed to the NodeService level (MNT-20833).
*/
@Test
public void testCreateRemoveAssociation() throws Exception {
Repository repositoryHelper = (Repository) APP_CONTEXT_INIT.getApplicationContext().getBean("repositoryHelper");
NodeRef companyHome = repositoryHelper.getCompanyHome();
AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE_NAME);
NodeRef newNode1 = testNodes.createNode(companyHome, "theTestFolder", ContentModel.TYPE_FOLDER, AuthenticationUtil.getFullyAuthenticatedUser());
NodeRef newNode2 = testNodes.createNode(companyHome, "theTestContent", ContentModel.TYPE_CONTENT, AuthenticationUtil.getFullyAuthenticatedUser());
// Give USER_TWO READ permission similar to the Consumer role
PERMISSION_SERVICE.setPermission(newNode1, USER_TWO_NAME, PermissionService.READ, true);
PERMISSION_SERVICE.setPermission(newNode2, USER_TWO_NAME, PermissionService.READ, true);
AuthenticationUtil.setFullyAuthenticatedUser(USER_TWO_NAME);
ScriptNode sourceScriptNode = SEARCH_SCRIPT.findNode(newNode1);
assertNotNull(sourceScriptNode);
ScriptNode targetScriptNode = SEARCH_SCRIPT.findNode(newNode2);
assertNotNull(targetScriptNode);
// Create associations
String assocType = "cm:contains";
try {
sourceScriptNode.createAssociation(targetScriptNode, assocType);
fail("Creating associations without write permission on source is not allowed.");
} catch (AccessDeniedException ade) {
// expected
}
// Give USER_TWO WRITE permission to be able to successfully create an association from sourceScriptNode to targetScriptNode
AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE_NAME);
PERMISSION_SERVICE.setPermission(newNode1, USER_TWO_NAME, PermissionService.WRITE, true);
AuthenticationUtil.setFullyAuthenticatedUser(USER_TWO_NAME);
assertTrue(sourceScriptNode.hasPermission(PermissionService.WRITE_PROPERTIES));
assertNotNull(sourceScriptNode.createAssociation(targetScriptNode, assocType));
// Remove associations
try {
sourceScriptNode.removeAssociation(targetScriptNode, assocType);
fail("Removing associations without delete permission on source is not allowed.");
} catch (AccessDeniedException ade) {
// expected
}
// Give USER_TWO DELETE permission to be able to successfully remove an association from sourceScriptNode to targetScriptNode
AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE_NAME);
PERMISSION_SERVICE.setPermission(newNode1, USER_TWO_NAME, PermissionService.DELETE, true);
AuthenticationUtil.setFullyAuthenticatedUser(USER_TWO_NAME);
sourceScriptNode.removeAssociation(targetScriptNode, assocType);
}
use of org.alfresco.repo.model.Repository in project alfresco-repository by Alfresco.
the class InviteSenderTest method mockRepository.
/**
* Mocks up a Repository that will return the inviter as the current user.
*
* @return Repository
*/
private Repository mockRepository() {
Repository repository = mock(Repository.class);
when(repository.getPerson()).thenReturn(inviter.node);
return repository;
}
Aggregations