Skip to content

Commit db08a0e

Browse files
committed
Update search behavior for restricted issues.
1 parent 2a179bd commit db08a0e

2 files changed

Lines changed: 54 additions & 33 deletions

File tree

issues/src/org/labkey/issue/model/IssueManager.java

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,11 @@ private static class IndexGroup implements Consumer<SearchService.TaskIndexingQu
948948
public void accept(SearchService.TaskIndexingQueue a)
949949
{
950950
User user = new LimitedUser(UserManager.getGuestUser(), ReaderRole.class);
951+
if (IssuesListDefService.get().getRestrictedIssueProvider() != null)
952+
{
953+
// Pass in an admin user to allow all restricted issues to be indexed by the crawler
954+
user = User.getAdminServiceUser();
955+
}
951956
indexIssues(a, user, _ids);
952957
}
953958
}
@@ -968,16 +973,9 @@ public static void indexIssues(SearchService.TaskIndexingQueue queue, User user,
968973

969974
for (Integer id : ids)
970975
{
971-
try
972-
{
973-
IssueObject issue = IssueManager.getIssue(container, user, id);
974-
if (issue != null)
975-
queueIssue(queue, id, issue.getProperties(), issue.getCommentObjects());
976-
}
977-
catch (UnauthorizedException e)
978-
{
979-
// Issue 51607 ignore restricted issue failures
980-
}
976+
IssueObject issue = IssueManager.getIssue(container, user, id, false);
977+
if (issue != null)
978+
queueIssue(queue, id, issue.getProperties(), issue.getCommentObjects());
981979
}
982980
}
983981

@@ -1015,6 +1013,8 @@ public WebdavResource resolve(@NotNull String resourceIdentifier)
10151013
public HttpView getCustomSearchResult(User user, @NotNull String resourceIdentifier)
10161014
{
10171015
int issueId;
1016+
boolean isRestricted = false; // controls rendering for a restricted issue
1017+
10181018
try
10191019
{
10201020
issueId = Integer.parseInt(resourceIdentifier);
@@ -1024,23 +1024,34 @@ public HttpView getCustomSearchResult(User user, @NotNull String resourceIdentif
10241024
return null;
10251025
}
10261026

1027-
final IssueObject issue = getIssue(null, user, issueId, false);
1027+
IssueObject issue = getIssue(null, user, issueId, false);
10281028
if (null == issue)
1029-
return null;
1029+
{
1030+
if (IssuesListDefService.get().getRestrictedIssueProvider() != null)
1031+
{
1032+
// allow users to see the summary of a restricted issue, but there will be limited
1033+
// information that is rendered.
1034+
issue = getIssue(null, User.getAdminServiceUser(), issueId, false);
1035+
isRestricted = true;
1036+
}
1037+
1038+
if (issue == null)
1039+
return null;
1040+
}
10301041
Container c = issue.lookupContainer();
10311042
if (null == c || !c.hasPermission(user, ReadPermission.class))
10321043
return null;
10331044

1034-
return new IssueSummaryView(issue);
1045+
return new IssueSummaryView(issue, isRestricted);
10351046
}
10361047
};
10371048
}
10381049

10391050
public static class IssueSummaryView extends JspView
10401051
{
1041-
IssueSummaryView(IssueObject issue)
1052+
IssueSummaryView(IssueObject issue, boolean isRestricted)
10421053
{
1043-
super("/org/labkey/issue/view/searchSummary.jsp", issue);
1054+
super("/org/labkey/issue/view/searchSummary.jsp", new Pair<>(issue, isRestricted));
10441055
}
10451056
}
10461057

issues/src/org/labkey/issue/view/searchSummary.jsp

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@
2323
<%@ page import="java.util.regex.Matcher" %>
2424
<%@ page import="java.util.regex.Pattern" %>
2525
<%@ page import="org.apache.commons.lang3.Strings" %>
26+
<%@ page import="org.labkey.api.util.Pair" %>
2627
<%@ taglib prefix="labkey" uri="http://www.labkey.org/taglib" %>
2728
<%@ page extends="org.labkey.api.jsp.JspBase" %>
2829
<%
29-
JspView<IssueObject> me = HttpView.currentView();
30-
final IssueObject issue = me.getModelBean();
30+
JspView<Pair<IssueObject, Boolean>> me = HttpView.currentView();
31+
final Pair<IssueObject, Boolean> rec = me.getModelBean();
3132
final User user = getUser();
33+
final IssueObject issue = rec.first;
34+
final Boolean isRestricted = rec.second;
3235
final boolean isClosed = Strings.CI.equals(issue.getStatus(),"closed");
3336
final boolean isOpen = Strings.CI.equals(issue.getStatus(),"open");
3437
%>
@@ -47,29 +50,36 @@
4750
<%
4851
StringBuilder html = new StringBuilder();
4952
boolean hasTextComment = false;
50-
for (IssueObject.CommentObject comment : issue.getCommentObjects())
53+
if (isRestricted)
5154
{
52-
String s = comment.getHtmlComment().toString();
53-
String pattern1 = "<div class=\"labkey-wiki\">";
54-
String pattern2 = "</div>";
55-
String regexString = Pattern.quote(pattern1) + "(?s)(.*?)" + Pattern.quote(pattern2);
56-
Pattern p = Pattern.compile(regexString);
57-
Matcher matcher = p.matcher(s);
58-
while (matcher.find())
55+
html.append("<div class=\"labkey-error\">Restricted Issue: You do not have access. Contact your administrator for access.</div>");
56+
}
57+
else
58+
{
59+
for (IssueObject.CommentObject comment : issue.getCommentObjects())
5960
{
60-
String commentContentText = matcher.group(1);
61-
if (!StringUtils.isEmpty(commentContentText))
61+
String s = comment.getHtmlComment().toString();
62+
String pattern1 = "<div class=\"labkey-wiki\">";
63+
String pattern2 = "</div>";
64+
String regexString = Pattern.quote(pattern1) + "(?s)(.*?)" + Pattern.quote(pattern2);
65+
Pattern p = Pattern.compile(regexString);
66+
Matcher matcher = p.matcher(s);
67+
while (matcher.find())
6268
{
63-
hasTextComment = true;
64-
html.append(commentContentText);
65-
html.append("<br>");
66-
if (html.length() > 500)
67-
break;
69+
String commentContentText = matcher.group(1);
70+
if (!StringUtils.isEmpty(commentContentText))
71+
{
72+
hasTextComment = true;
73+
html.append(commentContentText);
74+
html.append("<br>");
75+
if (html.length() > 500)
76+
break;
77+
}
6878
}
6979
}
7080
}
7181
72-
if (hasTextComment) { %>
82+
if (hasTextComment && !isRestricted) { %>
7383
<label style="text-decoration: underline">Comments</label>
7484
<% } %>
7585
<div style="max-height:4em; overflow-y:hidden; word-wrap:break-word; white-space: normal; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;"><%= unsafe(html.toString()) %></div>

0 commit comments

Comments
 (0)