use of org.alfresco.util.FileFilterMode.Client in project alfresco-repository by Alfresco.
the class FileFolderServiceImpl method toFileInfo.
/**
* Helper method to convert a node reference instance to a file info
*/
private FileInfo toFileInfo(NodeRef nodeRef, boolean addTranslations) throws InvalidTypeException {
// Get the file attributes
Map<QName, Serializable> properties = nodeService.getProperties(nodeRef);
// Is it a folder
QName typeQName = nodeService.getType(nodeRef);
FileFolderServiceType type = getType(typeQName);
boolean isFolder = type.equals(FileFolderServiceType.FOLDER);
boolean isHidden = false;
Client client = FileFilterMode.getClient();
if (hiddenAspect.getVisibility(client, nodeRef) == Visibility.HiddenAttribute) {
isHidden = true;
}
// Construct the file info and add to the results
FileInfo fileInfo = new FileInfoImpl(nodeRef, typeQName, isFolder, isHidden, properties);
// Done
return fileInfo;
}
use of org.alfresco.util.FileFilterMode.Client in project alfresco-repository by Alfresco.
the class GetChildrenCannedQuery method includeImpl.
protected boolean includeImpl(boolean ret, NodeRef nodeRef) {
// only visible files are returned, relative to the client type.
try {
if (!nodeService.exists(nodeRef)) {
// Node has disappeared
return ret;
}
final Client client = FileFilterMode.getClient();
boolean notHidden = hiddenAspect.getVisibility(client, nodeRef) != Visibility.NotVisible;
boolean notIgnore = true;
if (ignoreAspectQNames != null) {
if (ignoreAspectQNames.size() > 1) {
Set<QName> nodeAspects = nodeService.getAspects(nodeRef);
notIgnore = (!nodeAspects.removeAll(ignoreAspectQNames));
} else if (ignoreAspectQNames.size() == 1) {
if (nodeService.hasAspect(nodeRef, ignoreAspectQNames.iterator().next())) {
notIgnore = false;
}
}
}
return ret && notHidden && notIgnore;
} catch (AccessDeniedException e) {
// user may not have permission to determine the visibility of the node
return ret;
}
}
use of org.alfresco.util.FileFilterMode.Client in project alfresco-repository by Alfresco.
the class HiddenAspect method removeHidden.
public void removeHidden(NodeRef nodeRef) {
Client saveClient = FileFilterMode.getClient();
FileFilterMode.setClient(Client.admin);
try {
PagingRequest pagingRequest = new PagingRequest(0, Integer.MAX_VALUE, null);
PagingResults<FileInfo> results = fileFolderService.list(nodeRef, true, true, null, null, pagingRequest);
List<FileInfo> files = results.getPage();
for (FileInfo file : files) {
String name = (String) nodeService.getProperty(file.getNodeRef(), ContentModel.PROP_NAME);
// remove hidden aspect only if it doesn't match a hidden pattern
if (isHidden(name) == null) {
behaviourFilter.disableBehaviour(file.getNodeRef(), ContentModel.ASPECT_LOCKABLE);
try {
if (hasHiddenAspect(file.getNodeRef())) {
removeHiddenAspect(file.getNodeRef());
}
if (hasIndexControlAspect(file.getNodeRef())) {
removeIndexControlAspect(file.getNodeRef());
}
} finally {
behaviourFilter.enableBehaviour(file.getNodeRef(), ContentModel.ASPECT_LOCKABLE);
}
if (file.isFolder()) {
removeHidden(file.getNodeRef());
}
}
}
} finally {
FileFilterMode.setClient(saveClient);
}
}
use of org.alfresco.util.FileFilterMode.Client in project alfresco-repository by Alfresco.
the class FileFolderServiceImplTest method testList_HiddenFiles.
public void testList_HiddenFiles() {
// Test that hidden files are not returned for clients that should not be able to see them,
// and that the total result count is correct.
Client saveClient = FileFilterMode.setClient(Client.webdav);
try {
// create some hidden files
NodeRef nodeRef = fileFolderService.create(workingRootNodeRef, "" + System.currentTimeMillis(), ContentModel.TYPE_CONTENT).getNodeRef();
NodeRef nodeRef1 = fileFolderService.create(nodeRef, "parent", ContentModel.TYPE_CONTENT).getNodeRef();
for (int i = 0; i < 10; i++) {
fileFolderService.create(nodeRef1, ".child" + i, ContentModel.TYPE_CONTENT).getNodeRef();
}
// and some visible files
for (int i = 0; i < 10; i++) {
fileFolderService.create(nodeRef1, "visiblechild" + i, ContentModel.TYPE_CONTENT).getNodeRef();
}
// switch to a client that should not see the hidden files
saveClient = FileFilterMode.setClient(Client.cmis);
PagingRequest pagingRequest = new PagingRequest(0, Integer.MAX_VALUE);
// need this so that total count is set
pagingRequest.setRequestTotalCountMax(10000);
PagingResults<FileInfo> results = fileFolderService.list(nodeRef1, true, true, null, null, pagingRequest);
Pair<Integer, Integer> totalResultCount = results.getTotalResultCount();
assertNotNull(totalResultCount.getFirst());
assertEquals("Total result lower count should be 10", 10, totalResultCount.getFirst().intValue());
assertNotNull(totalResultCount.getSecond());
assertEquals("Total result upper count should be 10", 10, totalResultCount.getSecond().intValue());
for (FileInfo fileInfo : results.getPage()) {
assertTrue(fileInfo.getName().startsWith("visiblechild"));
}
assertEquals("Expected only 10 results", 10, results.getPage().size());
} finally {
FileFilterMode.setClient(saveClient);
}
}
use of org.alfresco.util.FileFilterMode.Client in project alfresco-repository by Alfresco.
the class HiddenAspectTest method testHiddenFilesEnhancedClient.
@Test
public void testHiddenFilesEnhancedClient() {
FileFilterMode.setClient(Client.webdav);
try {
// check temporary file
NodeRef parent = fileFolderService.create(topNodeRef, "New Folder", ContentModel.TYPE_FOLDER).getNodeRef();
NodeRef child = fileFolderService.create(parent, "file.tmp", ContentModel.TYPE_CONTENT).getNodeRef();
assertTrue(nodeService.hasAspect(child, ContentModel.ASPECT_TEMPORARY));
assertFalse(nodeService.hasAspect(child, ContentModel.ASPECT_HIDDEN));
List<FileInfo> children = fileFolderService.list(parent);
assertEquals(1, children.size());
// check hidden files - should be hidden for an enhanced client
parent = fileFolderService.create(topNodeRef, "abc", ContentModel.TYPE_FOLDER).getNodeRef();
child = fileFolderService.create(parent, ".TemporaryItems", ContentModel.TYPE_FOLDER).getNodeRef();
NodeRef child1 = fileFolderService.create(child, "inTemporaryItems", ContentModel.TYPE_FOLDER).getNodeRef();
assertTrue(nodeService.hasAspect(child, ContentModel.ASPECT_TEMPORARY));
assertTrue(nodeService.hasAspect(child, ContentModel.ASPECT_HIDDEN));
assertTrue(nodeService.hasAspect(child, ContentModel.ASPECT_INDEX_CONTROL));
assertTrue(nodeService.hasAspect(child1, ContentModel.ASPECT_TEMPORARY));
assertTrue(nodeService.hasAspect(child1, ContentModel.ASPECT_HIDDEN));
assertTrue(nodeService.hasAspect(child1, ContentModel.ASPECT_INDEX_CONTROL));
children = fileFolderService.list(parent);
assertEquals(1, children.size());
Client saveClient = FileFilterMode.setClient(Client.script);
try {
children = fileFolderService.list(parent);
} finally {
FileFilterMode.setClient(saveClient);
}
assertEquals(0, children.size());
parent = fileFolderService.create(topNodeRef, "Folder 2", ContentModel.TYPE_FOLDER).getNodeRef();
child = fileFolderService.create(parent, "Thumbs.db", ContentModel.TYPE_CONTENT).getNodeRef();
assertFalse(nodeService.hasAspect(child, ContentModel.ASPECT_TEMPORARY));
assertTrue(nodeService.hasAspect(child, ContentModel.ASPECT_HIDDEN));
assertTrue(nodeService.hasAspect(child, ContentModel.ASPECT_INDEX_CONTROL));
children = fileFolderService.list(parent);
assertEquals(1, children.size());
// set hidden attribute for cifs, webdav. ftp, nfs should be able to see, other clients not
assertEquals(Visibility.Visible, hiddenAspect.getVisibility(Client.ftp, child));
assertEquals(Visibility.Visible, hiddenAspect.getVisibility(Client.nfs, child));
assertEquals(Visibility.Visible, hiddenAspect.getVisibility(Client.webdav, child));
assertEquals(Visibility.HiddenAttribute, hiddenAspect.getVisibility(Client.cifs, child));
assertEquals(Visibility.NotVisible, hiddenAspect.getVisibility(Client.script, child));
assertEquals(Visibility.NotVisible, hiddenAspect.getVisibility(Client.webclient, child));
// surf-config should not be visible to any client
NodeRef node = fileFolderService.create(topNodeRef, "surf-config", ContentModel.TYPE_FOLDER).getNodeRef();
assertTrue(nodeService.hasAspect(node, ContentModel.ASPECT_HIDDEN));
assertTrue(nodeService.hasAspect(node, ContentModel.ASPECT_INDEX_CONTROL));
for (Client client : hiddenAspect.getClients()) {
if (!client.equals(Client.admin)) {
assertEquals(Visibility.NotVisible, hiddenAspect.getVisibility(client, node));
}
}
// .DS_Store is a system path and so is visible in nfs and webdav, as a hidden file in cifs and hidden to all other clients
node = fileFolderService.create(topNodeRef, ".DS_Store", ContentModel.TYPE_CONTENT).getNodeRef();
assertTrue(nodeService.hasAspect(node, ContentModel.ASPECT_HIDDEN));
assertTrue(nodeService.hasAspect(node, ContentModel.ASPECT_INDEX_CONTROL));
for (Client client : hiddenAspect.getClients()) {
if (client == Client.cifs) {
assertEquals("Should have hidden attribute set for client " + client, Visibility.HiddenAttribute, hiddenAspect.getVisibility(client, node));
} else if (client == Client.webdav || client == Client.nfs || client == Client.ftp) {
assertEquals("Should be visible for client " + client, Visibility.Visible, hiddenAspect.getVisibility(client, node));
} else if (client != Client.admin) {
assertEquals("Should not be visible for client " + client, Visibility.NotVisible, hiddenAspect.getVisibility(client, node));
}
}
// Resource fork should not be visible to any client except webdav(see MNT-10333)
node = fileFolderService.create(topNodeRef, "._resourceFork", ContentModel.TYPE_FOLDER).getNodeRef();
assertTrue(nodeService.hasAspect(node, ContentModel.ASPECT_HIDDEN));
assertTrue(nodeService.hasAspect(node, ContentModel.ASPECT_INDEX_CONTROL));
for (Client client : hiddenAspect.getClients()) {
if (client != Client.admin) {
if (client != Client.webdav) {
assertEquals("Client " + client.toString(), Visibility.NotVisible, hiddenAspect.getVisibility(client, node));
}
}
}
} finally {
FileFilterMode.clearClient();
}
}
Aggregations