Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into fb_requireComments
Browse files Browse the repository at this point in the history
  • Loading branch information
labkey-susanh committed Jan 19, 2024
2 parents d93b299 + 4cadccd commit b805a65
Show file tree
Hide file tree
Showing 17 changed files with 69 additions and 19 deletions.
2 changes: 2 additions & 0 deletions api/src/org/labkey/api/data/JsonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,14 @@ public void jsonOrgViaJackson() throws IOException
obj.put("str", "hello");
obj.put("arr", new JSONArray(Arrays.asList("one", null, 3, new JSONObject(Collections.singletonMap("four", 4)))));
obj.put("nul", (Object)null);
obj.put("key", "</tricky\tvalue\\");
// obj.put("d", d); //TODO: new JSONObject serializes date-times as ISO

// Verify serializing JSONObject via Jackson is equivalent
String jacksonToString = mapper.writeValueAsString(obj);
String jsonOrgToString = obj.toString();
assertEquals(jsonOrgToString, jacksonToString);
assertTrue(jsonOrgToString.contains("<\\/"));

// Verify deserializing JSONObject via Jackson is equivalent
// NOTE: In both cases, the date value is deserialized as a string because JSON sucks
Expand Down
5 changes: 3 additions & 2 deletions api/src/org/labkey/api/exp/api/ExperimentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ enum DataTypeForExclusion
SampleType,
DataClass,
AssayDesign,
StorageLocation
StorageLocation,
DashboardSampleType
}

@Nullable
Expand Down Expand Up @@ -962,7 +963,7 @@ List<? extends ExpProtocol> getExpProtocolsWithParameterValue(

Set<String> getDataTypeContainerExclusions(@NotNull DataTypeForExclusion dataType, @NotNull Integer dataTypeRowId);

void ensureContainerDataTypeExclusions(@NotNull DataTypeForExclusion dataType, @Nullable Collection<Integer> excludedDataTypeRowIds, @NotNull String excludedContainerId, User user);
void ensureContainerDataTypeExclusions(@NotNull DataTypeForExclusion dataType, @Nullable DataTypeForExclusion relatedDataType, @Nullable Collection<Integer> excludedDataTypeRowIds, @NotNull String excludedContainerId, User user);

void ensureDataTypeContainerExclusions(@NotNull DataTypeForExclusion dataType, @Nullable Collection<String> excludedContainerIds, @NotNull Integer dataTypeId, User user);

Expand Down
4 changes: 3 additions & 1 deletion api/src/org/labkey/api/exp/api/SampleTypeDomainKind.java
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ public Domain createDomain(GWTDomain domain, @Nullable SampleTypeDomainKindPrope
String category = null;
Map<String, String> aliases = null;
List<String> excludedContainerIds = null;
List<String> excludedDashboardContainerIds = null;

if (arguments != null)
{
Expand All @@ -557,12 +558,13 @@ public Domain createDomain(GWTDomain domain, @Nullable SampleTypeDomainKindPrope
category = StringUtils.trimToNull(arguments.getCategory());
aliases = arguments.getImportAliases();
excludedContainerIds = arguments.getExcludedContainerIds();
excludedDashboardContainerIds = arguments.getExcludedDashboardContainerIds();
}
ExpSampleType st;
try
{
st = SampleTypeService.get().createSampleType(container, user, name, description, properties, indices, idCol1, idCol2, idCol3, parentCol, nameExpression, aliquotNameExpression,
templateInfo, aliases, labelColor, metricUnit, autoLinkTargetContainer, autoLinkCategory, category, domain.getDisabledSystemFields(), excludedContainerIds);
templateInfo, aliases, labelColor, metricUnit, autoLinkTargetContainer, autoLinkCategory, category, domain.getDisabledSystemFields(), excludedContainerIds, excludedDashboardContainerIds);
}
catch (SQLException e)
{
Expand Down
11 changes: 11 additions & 0 deletions api/src/org/labkey/api/exp/api/SampleTypeDomainKindProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public SampleTypeDomainKindProperties(ExpSampleType st)
private Integer parentCol;
private String category;
private List<String> excludedContainerIds;
private List<String> excludedDashboardContainerIds;

//Ignored on import/save, use Domain.name & Domain.description instead
private String name;
Expand Down Expand Up @@ -236,4 +237,14 @@ public void setExcludedContainerIds(List<String> excludedContainerIds)
{
this.excludedContainerIds = excludedContainerIds;
}

public List<String> getExcludedDashboardContainerIds()
{
return excludedDashboardContainerIds;
}

public void setExcludedDashboardContainerIds(List<String> excludedDashboardContainerIds)
{
this.excludedDashboardContainerIds = excludedDashboardContainerIds;
}
}
3 changes: 2 additions & 1 deletion api/src/org/labkey/api/exp/api/SampleTypeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ ExpSampleType createSampleType(Container container, User user, String name, Stri
@NotNull
ExpSampleType createSampleType(Container c, User u, String name, String description, List<GWTPropertyDescriptor> properties, List<GWTIndex> indices, int idCol1, int idCol2, int idCol3, int parentCol,
String nameExpression, String aliquotNameExpression, @Nullable TemplateInfo templateInfo, @Nullable Map<String, String> importAliases, @Nullable String labelColor, @Nullable String metricUnit,
@Nullable Container autoLinkTargetContainer, @Nullable String autoLinkCategory, @Nullable String category, @Nullable List<String> disabledSystemField, @Nullable List<String> excludedContainerIds)
@Nullable Container autoLinkTargetContainer, @Nullable String autoLinkCategory, @Nullable String category, @Nullable List<String> disabledSystemField,
@Nullable List<String> excludedContainerIds, @Nullable List<String> excludedDashboardContainerIds)
throws ExperimentException, SQLException;

@NotNull
Expand Down
2 changes: 1 addition & 1 deletion api/src/org/labkey/api/notification/notificationpanel.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
%>
<a id="<%=h(linkId)%>" href="#">
<i class="fa fa-inbox labkey-notification-inbox"></i>
<span id=<%=q(notificationCountId)%>>&nbsp;</span>
<span id="<%=h(notificationCountId)%>">&nbsp;</span>
</a>
</li>

Expand Down
2 changes: 2 additions & 0 deletions api/src/org/labkey/api/reports/report/r/RReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ public static synchronized String getDefaultRPath()
return DEFAULT_APP_PATH;
}


public static String toR(String s)
{
if (s == null)
Expand Down Expand Up @@ -259,6 +260,7 @@ public static String toR(String s)
return r.toString();
}


// static for access by RserveScriptEngine with no backing report
public static void appendParamList(StringBuilder labkey, Map<String, Object> inputParameters)
{
Expand Down
13 changes: 13 additions & 0 deletions core/src/org/labkey/core/CoreModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.labkey.core;

import com.fasterxml.jackson.core.io.CharTypes;
import com.google.common.collect.Sets;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -317,6 +318,18 @@ public class CoreModule extends SpringModule implements SearchService.DocumentPr

// Register dialect extra early, since we need to initialize the data sources before calling DefaultModule.initialize()
SqlDialectRegistry.register(new PostgreSqlDialectFactory());

try
{
var field = CharTypes.class.getDeclaredField("sOutputEscapes128");
field.setAccessible(true);
((int[])field.get(null))['/'] = '/';
field.setAccessible(false);
}
catch (NoSuchFieldException|IllegalArgumentException|IllegalAccessException x)
{
// pass
}
}

private CoreWarningProvider _warningProvider;
Expand Down
7 changes: 5 additions & 2 deletions core/src/org/labkey/core/admin/AdminController.java
Original file line number Diff line number Diff line change
Expand Up @@ -11120,6 +11120,10 @@ public Object execute(SimpleApiJsonForm form, BindException errors) throws Excep
if (!_log.isWarnEnabled())
return ret;

var userAgent = getViewContext().getRequest().getHeader("User-Agent");
if (PageFlowUtil.isRobotUserAgent(userAgent) && !_log.isDebugEnabled())
return ret;

// NOTE User will always be "guest". Seems like a bad design to force the server to accept guest w/o CSRF here.
var jsonObj = form.getJsonObject();
if (null != jsonObj)
Expand All @@ -11131,9 +11135,8 @@ public Object execute(SimpleApiJsonForm form, BindException errors) throws Excep
if (urlString != null)
{
String path = new URLHelper(urlString).deleteParameters().getPath();
if (null == reports.put(path, Boolean.TRUE))
if (null == reports.put(path, Boolean.TRUE) || _log.isDebugEnabled())
{
var userAgent = getViewContext().getRequest().getHeader("User-Agent");
if (isNotBlank(userAgent))
jsonObj.put("user-agent", userAgent);
var jsonStr = jsonObj.toString(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private String getSanitizedUrl(ViewContext context)
private static final String GA4_TRACKING_SCRIPT_TEMPLATE =
"""
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="${GA4_JS:htmlEncode}"></script>
<script async src="${GA4_JS:htmlEncode}" nonce="${SCRIPT_NONCE:htmlEncode}"></script>
<script nonce="${SCRIPT_NONCE:htmlEncode}">
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
Expand Down
4 changes: 2 additions & 2 deletions core/src/org/labkey/core/analytics/analyticsSettings.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@
<td style="padding-left: 1em;">
<strong><label for="customScript">Custom JavaScript Analytics</label></strong>
<p>
Add <label for="ff_trackingScript">custom analytics script</label> to the <code>&lt;head&gt;</code> of every page. Include required <code>&lt;script&gt;</code> tags.
Add <label for="ff_trackingScript">custom analytics script</label> to the <code>&lt;head&gt;</code> of every page. Include required <code>&lt;script&gt;</code> tags. If the server enforces a Content Security Policy, script blocks may need a nonce to function: <code>&lt;script nonce="\${SCRIPT_NONCE:htmlEncode}"&gt;</code>.
</p>
<p>
<strong>NOTE:</strong> You can mess up your site if you make a mistake here. You may want to bookmark this page to aid in making corrections, just in case.
<strong>NOTE:</strong> You can mess up your site if you make a mistake here. You may want to bookmark this page to aid in making corrections, just in case.
</p>
<textarea <%=unsafe(hasAdminOpsPerms?"":"disabled=\"disabled\"")%> style="width:100%; height:15em;" id="ff_trackingScript" name="ff_trackingScript"><%=h(settingsForm.ff_trackingScript)%></textarea>
</td>
Expand Down
2 changes: 1 addition & 1 deletion core/src/org/labkey/core/user/securityAccess.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
However, if this account were re-enabled, it would have the following permissions.</div>
<% } %>

<table id=<%=q(accessRegion.getDomId())%> lk-region-name=<%=q(accessRegion.getName())%> class="labkey-data-region-legacy labkey-show-borders">
<table id="<%=h(accessRegion.getDomId())%>" lk-region-name="<%=h(accessRegion.getName())%>" class="labkey-data-region-legacy labkey-show-borders">
<colgroup><col><col><col></colgroup>
<tr id="dataregion_column_header_row_access">
<th>&nbsp;</th>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8643,12 +8643,13 @@ private Set<Integer> _getContainerDataTypeExclusions(DataTypeForExclusion dataTy
}

@Override
public void ensureContainerDataTypeExclusions(@NotNull DataTypeForExclusion dataType, @Nullable Collection<Integer> excludedDataTypeRowIds, @NotNull String excludedContainerId, User user)
public void ensureContainerDataTypeExclusions(@NotNull DataTypeForExclusion dataType, @Nullable DataTypeForExclusion relatedDataType, @Nullable Collection<Integer> excludedDataTypeRowIds, @NotNull String excludedContainerId, User user)
{
if (excludedDataTypeRowIds == null)
return;

Set<Integer> previousExclusions = _getContainerDataTypeExclusions(dataType, excludedContainerId);
Set<Integer> relatedExclusions = relatedDataType != null ? _getContainerDataTypeExclusions(relatedDataType, excludedContainerId) : null;
Set<Integer> updatedExclusions = new HashSet<>(excludedDataTypeRowIds);

Set<Integer> toAdd = new HashSet<>(updatedExclusions);
Expand All @@ -8660,7 +8661,15 @@ public void ensureContainerDataTypeExclusions(@NotNull DataTypeForExclusion data
if (!toAdd.isEmpty())
{
for (Integer add : toAdd)
{
addDataTypeExclusion(add, dataType, excludedContainerId, user);

// Prevent "double exclusion" for related exclusion types (i.e. if a sample type is excluded from the
// project, then we can delete any "Dashboard Sample Type" exclusions for that same sample type).
// Note that "double exclusions" won't cause any harm, they just aren't necessary and can be cleaned up here.
if (relatedExclusions != null && relatedExclusions.contains(add))
removeDataTypeExclusion(Collections.singleton(add), relatedDataType, excludedContainerId);
}
}

if (!toRemove.isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ public void deleteSampleType(int rowId, Container c, User user, @Nullable String
addSampleTypeDeletedAuditEvent(user, c, source, transaction.getAuditId(), auditUserComment);

ExperimentService.get().removeDataTypeExclusion(Collections.singleton(rowId), ExperimentService.DataTypeForExclusion.SampleType);
ExperimentService.get().removeDataTypeExclusion(Collections.singleton(rowId), ExperimentService.DataTypeForExclusion.DashboardSampleType);

transaction.addCommitTask(() -> clearMaterialSourceCache(c), DbScope.CommitTaskOption.IMMEDIATE, POSTCOMMIT, POSTROLLBACK);
transaction.commit();
Expand Down Expand Up @@ -691,14 +692,15 @@ public ExpSampleTypeImpl createSampleType(Container c, User u, String name, Stri
public ExpSampleTypeImpl createSampleType(Container c, User u, String name, String description, List<GWTPropertyDescriptor> properties, List<GWTIndex> indices, int idCol1, int idCol2, int idCol3, int parentCol,
String nameExpression, String aliquotNameExpression, @Nullable TemplateInfo templateInfo, @Nullable Map<String, String> importAliases, @Nullable String labelColor, @Nullable String metricUnit) throws ExperimentException
{
return createSampleType(c, u, name, description, properties, indices, idCol1, idCol2, idCol3, parentCol, nameExpression, aliquotNameExpression, templateInfo, importAliases, labelColor, metricUnit, null, null, null, null, null);
return createSampleType(c, u, name, description, properties, indices, idCol1, idCol2, idCol3, parentCol, nameExpression, aliquotNameExpression, templateInfo, importAliases, labelColor, metricUnit, null, null, null, null, null, null);
}

@NotNull
@Override
public ExpSampleTypeImpl createSampleType(Container c, User u, String name, String description, List<GWTPropertyDescriptor> properties, List<GWTIndex> indices, int idCol1, int idCol2, int idCol3, int parentCol,
String nameExpression, String aliquotNameExpression, @Nullable TemplateInfo templateInfo, @Nullable Map<String, String> importAliases, @Nullable String labelColor, @Nullable String metricUnit,
@Nullable Container autoLinkTargetContainer, @Nullable String autoLinkCategory, @Nullable String category, @Nullable List<String> disabledSystemField, @Nullable List<String> excludedContainerIds)
@Nullable Container autoLinkTargetContainer, @Nullable String autoLinkCategory, @Nullable String category, @Nullable List<String> disabledSystemField,
@Nullable List<String> excludedContainerIds, @Nullable List<String> excludedDashboardContainerIds)
throws ExperimentException
{
if (name == null)
Expand Down Expand Up @@ -877,6 +879,8 @@ public ExpSampleTypeImpl createSampleType(Container c, User u, String name, Stri
DefaultValueService.get().setDefaultValues(domain.getContainer(), defaultValues);
if (excludedContainerIds != null && !excludedContainerIds.isEmpty())
ExperimentService.get().ensureDataTypeContainerExclusions(ExperimentService.DataTypeForExclusion.SampleType, excludedContainerIds, st.getRowId(), u);
if (excludedDashboardContainerIds != null && !excludedDashboardContainerIds.isEmpty())
ExperimentService.get().ensureDataTypeContainerExclusions(ExperimentService.DataTypeForExclusion.DashboardSampleType, excludedDashboardContainerIds, st.getRowId(), u);
transaction.addCommitTask(() -> clearMaterialSourceCache(c), DbScope.CommitTaskOption.IMMEDIATE, POSTCOMMIT, POSTROLLBACK);
return st;
}
Expand Down Expand Up @@ -1046,6 +1050,8 @@ public ValidationException updateSampleType(GWTDomain<? extends GWTPropertyDescr

if (options != null && options.getExcludedContainerIds() != null)
ExperimentService.get().ensureDataTypeContainerExclusions(ExperimentService.DataTypeForExclusion.SampleType, options.getExcludedContainerIds(), st.getRowId(), user);
if (options != null && options.getExcludedDashboardContainerIds() != null)
ExperimentService.get().ensureDataTypeContainerExclusions(ExperimentService.DataTypeForExclusion.DashboardSampleType, options.getExcludedDashboardContainerIds(), st.getRowId(), user);

if (!errors.hasErrors())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void testTopLevelItems() throws Exception

private String getDeployedDistributionName()
{
File distFile = new File(TestFileUtils.getDefaultDeployDir(), "labkeyWebapp/WEB-INF/classes/distribution");
File distFile = new File(TestFileUtils.getDefaultWebAppRoot(), "WEB-INF/classes/distribution");
if (distFile.exists())
{
// Deployed from distribution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
%>

This webpart displays a list of survey instances created by the end user. Select which survey design this webpart should use:<br><br>
<div id=<%=q(divId)%>></div>
<div id="<%=h(divId)%>"></div>

<script type="text/javascript" nonce="<%=getScriptNonce()%>">
Ext4.onReady(function(){
Expand Down
6 changes: 3 additions & 3 deletions survey/src/org/labkey/survey/view/surveyWizard.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@
else
{
%>
<div id=<%=q(headerRenderId)%>></div>
<div id=<%=q(formRenderId)%>></div>
<div id=<%=q(footerRenderId)%>></div>
<div id="<%=h(headerRenderId)%>"></div>
<div id="<%=h(formRenderId)%>"></div>
<div id="<%=h(footerRenderId)%>"></div>
<script type="text/javascript" nonce="<%=getScriptNonce()%>">
Ext4.onReady(function(){
Expand Down

0 comments on commit b805a65

Please sign in to comment.