Merge branch 'fix/Search-2096' into 'master'

Fix/search 2096

See merge request search_discovery/insightengine!371
This commit is contained in:
Meenal Bhave
2020-02-25 14:40:57 +00:00
2 changed files with 78 additions and 15 deletions
@@ -21,12 +21,15 @@ package org.alfresco.test.search.functional.searchServices.search;
import javax.json.Json;
import javax.json.JsonObject;
import org.alfresco.dataprep.SiteService.Visibility;
import org.alfresco.rest.search.SearchResponse;
import org.alfresco.test.search.functional.AbstractE2EFunctionalTest;
import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.data.RandomData;
import org.alfresco.utility.model.FileModel;
import org.alfresco.utility.model.FileType;
import org.alfresco.utility.model.FolderModel;
import org.alfresco.utility.model.SiteModel;
import org.alfresco.utility.model.UserModel;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
@@ -53,6 +56,7 @@ public class SearchPermissionsTest extends AbstractE2EFunctionalTest
* |------ permFile1
* |-- permChild2
* |------ permFile2
* |-- permChild3 (Later: In test 2)
*/
parentFolder = new FolderModel("permGrandParent");
@@ -105,8 +109,8 @@ public class SearchPermissionsTest extends AbstractE2EFunctionalTest
waitForContentIndexing(file2.getContent(), true);
}
@Test
@Test(priority = 1)
public void searchResultsRespectInheritedPermissions()
{
// Search as testUser: expect all: 5 results: When user is a Site Manager
@@ -129,4 +133,72 @@ public class SearchPermissionsTest extends AbstractE2EFunctionalTest
resultCount = response.getPagination().getCount();
Assert.assertTrue(resultCount == 0, "Unexpected Result count for testUser3: Expected 0, received: " + resultCount);
}
@Test(priority = 2)
public void searchResultsRespectInheritedPermissionsDisabled() throws Exception
{
// Create folder
FolderModel folder3 = dataContent.usingUser(testUser).usingSite(testSite).usingResource(parentFolder).createFolderCmisApi("permChild32");
// Turn off inherited permissions for folder3
JsonObject userPermission = Json.createObjectBuilder().add("permissions", Json.createObjectBuilder().add("isInheritanceEnabled", false)).build();
String putBody = userPermission.toString();
restClient.authenticateUser(testUser).withCoreAPI().usingNode(folder3).updateNode(putBody);
// Wait for indexing
waitForIndexing(folder3.getName(), true);
// Search as testUser: expect all: 5 results: When user is a Site Manager
SearchResponse response = queryAsUser(testUser, "cm:name:perm*");
int resultCount = response.getPagination().getCount();
Assert.assertTrue(resultCount == 6, "Unexpected Result count for testUser: Expected 5, received: " + resultCount);
// Search as testUser1: expect 3 results: when user is a site member but without permission to a content
response = queryAsUser(testUser1, "cm:name:perm*");
resultCount = response.getPagination().getCount();
Assert.assertTrue(resultCount == 3, "Unexpected Result count for testUser1: Expected 3, received: " + resultCount);
// Search as testUser2: expect 1 result: When user isn't a site member but has granular permissions to a content
response = queryAsUser(testUser2, "cm:name:perm*");
resultCount = response.getPagination().getCount();
Assert.assertTrue(resultCount == 1, "Unexpected Result count for testUser2: Expected 1, received: " + resultCount);
// Search as testUser3: expect none: 0 results: When user isn't a site member / does not have granular permissions to the content
response = queryAsUser(testUser3, "cm:name:perm*");
resultCount = response.getPagination().getCount();
Assert.assertTrue(resultCount == 0, "Unexpected Result count for testUser3: Expected 0, received: " + resultCount);
}
@Test(priority = 3)
public void searchResultsOnChangingSiteVisibility() throws Exception
{
// Create Site
SiteModel testPermissionsSite = new SiteModel(RandomData.getRandomName("SiteSearchPermissions"));
testPermissionsSite.setVisibility(Visibility.PUBLIC);
dataSite.usingUser(adminUserModel).createSite(testPermissionsSite);
// Add Users to the site
dataUser.addUserToSite(testUser, testPermissionsSite, UserRole.SiteCollaborator);
// Create a folder
String folderName = "Folder" + unique_searchString;
FolderModel folder = dataContent.usingUser(testUser).usingSite(testPermissionsSite).createFolderCmisApi(folderName);
// Query
Assert.assertTrue(waitForIndexing(folder.getName(), true), "Folder isn't yet indexed");
// Edit Site Visibility
testPermissionsSite.setDescription("PrivateSite".concat(testPermissionsSite.getDescription()));
testPermissionsSite.setVisibility(Visibility.PRIVATE);
restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(testPermissionsSite).updateSite(testPermissionsSite);
// Wait for indexing
Assert.assertTrue(waitForIndexing("description:" + testPermissionsSite.getDescription(), true), "New Site Description isn't yet been indexed");
// Query
SearchResponse response = queryAsUser(testUser, folderName);
int resultCount = response.getPagination().getCount();
Assert.assertTrue(resultCount == 1, "Unexpected Result count for testUser: Expected 1, received: " + resultCount);
}
}
@@ -151,7 +151,6 @@ import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.LongPoint;
import org.apache.lucene.index.IndexCommit;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.index.LeafReaderContext;
@@ -194,7 +193,6 @@ import org.apache.solr.schema.SchemaField;
import org.apache.solr.search.DelegatingCollector;
import org.apache.solr.search.DocIterator;
import org.apache.solr.search.DocList;
import org.apache.solr.search.DocSet;
import org.apache.solr.search.QueryWrapperFilter;
import org.apache.solr.search.SolrIndexSearcher;
import org.apache.solr.update.AddUpdateCommand;
@@ -2251,11 +2249,8 @@ public class SolrInformationServer implements InformationServer
{
String errorDocId = PREFIX_ERROR + node.getId();
// Try finding the node before performing removal operation
DocSet docSet = request.getSearcher().getDocSet(new TermQuery(new Term(FIELD_SOLR4_ID, errorDocId)));
if (docSet.size() > 0)
// Remove document only when it exists
if (getDocListSize(FIELD_SOLR4_ID + ":" + errorDocId) > 0)
{
DeleteUpdateCommand delErrorDocCmd = new DeleteUpdateCommand(request);
delErrorDocCmd.setId(errorDocId);
@@ -2275,17 +2270,13 @@ public class SolrInformationServer implements InformationServer
private void deleteNode(UpdateRequestProcessor processor, SolrQueryRequest request, long dbid) throws IOException
{
// Try finding the node before performing removal operation
DocSet docSet = request.getSearcher().getDocSet(LongPoint.newExactQuery(FIELD_DBID, dbid));
if (docSet.size() > 0)
// Remove document only when it exists
if (getDocListSize(FIELD_DBID + ":" + dbid) > 0)
{
DeleteUpdateCommand delDocCmd = new DeleteUpdateCommand(request);
delDocCmd.setQuery(FIELD_DBID + ":" + dbid);
processor.processDelete(delDocCmd);
}
}
private boolean isContentIndexedForNode(Map<QName, PropertyValue> properties)