Skip to content

Commit 1a097cc

Browse files
committed
Modified the implementation for the guest user, to support ip groups. #10554
1 parent b34e1fe commit 1a097cc

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

src/main/java/edu/harvard/iq/dataverse/search/SearchServiceBean.java

+27-4
Original file line numberDiff line numberDiff line change
@@ -1004,20 +1004,43 @@ private String getPermissionFilterQuery(DataverseRequest dataverseRequest, SolrQ
10041004

10051005
// ----------------------------------------------------
10061006
// (1) Is this a GuestUser?
1007-
// Yes, see if GuestUser is part of any groups such as IP Groups.
10081007
// ----------------------------------------------------
10091008
if (user instanceof GuestUser) {
1009+
1010+
StringBuilder sb = new StringBuilder();
1011+
1012+
// Yes, see if GuestUser is part of any groups, such as IP Groups.
1013+
Set<Group> groups = groupService.collectAncestors(groupService.groupsFor(dataverseRequest));
1014+
10101015
if (FeatureFlags.AVOID_EXPENSIVE_SOLR_JOIN.enabled()) {
10111016
/**
10121017
* Instead of doing an expensive join, narrow down to only
10131018
* public objects. This field is indexed on the content document
10141019
* itself, rather than a permission document.
10151020
*/
1016-
return SearchFields.PUBLIC_OBJECT + ":" + true;
1021+
sb.append(SearchFields.PUBLIC_OBJECT + ":" + true);
1022+
1023+
// If there are any IP groups, we'll add separate (and much cheaper)
1024+
// joins on them.
1025+
// Note that in order for these potential extra joins to work with
1026+
// the above, we need to use a query syntax that is a bit different
1027+
// from what we normally use (below):
1028+
int groupCounter = 0;
1029+
for (Group group : groups) {
1030+
logger.fine("found group " + group.getIdentifier() + " with alias " + group.getAlias());
1031+
String groupAlias = group.getAlias();
1032+
if (groupAlias != null && !groupAlias.isEmpty() && !groupAlias.startsWith("builtIn")) {
1033+
groupCounter++;
1034+
solrQuery.setParam("q" + groupCounter, SearchFields.DISCOVERABLE_BY + ":" + IndexServiceBean.getGroupPrefix() + groupAlias);
1035+
sb.append(" OR ");
1036+
sb.append("{!join from=" + SearchFields.DEFINITION_POINT + " to=id v=$q" + groupCounter + "}");
1037+
}
1038+
}
1039+
String ret = sb.toString();
1040+
logger.info("Returning experimental query for Guest user: " + ret);
1041+
return ret;
10171042
}
10181043
String groupsFromProviders = "";
1019-
Set<Group> groups = groupService.collectAncestors(groupService.groupsFor(dataverseRequest));
1020-
StringBuilder sb = new StringBuilder();
10211044
for (Group group : groups) {
10221045
logger.fine("found group " + group.getIdentifier() + " with alias " + group.getAlias());
10231046
String groupAlias = group.getAlias();

0 commit comments

Comments
 (0)