Skip to content

Commit d8e37ff

Browse files
committed
Tighten behavior around cross-container actions
1 parent 9a96634 commit d8e37ff

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

laboratory/api-src/org/labkey/api/laboratory/assay/DefaultAssayParser.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.labkey.api.assay.AssayService;
3030
import org.labkey.api.collections.CaseInsensitiveHashMap;
3131
import org.labkey.api.data.Container;
32+
import org.labkey.api.data.ContainerManager;
3233
import org.labkey.api.data.ContainerType;
3334
import org.labkey.api.data.ConvertHelper;
3435
import org.labkey.api.data.SimpleFilter;
@@ -605,6 +606,18 @@ protected Map<String, Map<String, Object>> getTemplateRowMap(ImportContext conte
605606

606607
Map<String, Object> map = maps[0];
607608
JSONObject templateJson = new JSONObject((String)map.get("json"));
609+
610+
// This enforces that the request and existing record are from the same container, including for workbook/parents:
611+
Container rowContainer = ContainerManager.getForId(String.valueOf(map.get("container")));
612+
if (rowContainer == null)
613+
{
614+
throw new IllegalStateException("Unable to determine the container for template: " + templateId);
615+
}
616+
else if (!rowContainer.equals(context.getViewContext().getContainer()))
617+
{
618+
throw new IllegalStateException("Template is from the wrong container: " + templateId);
619+
}
620+
608621
JSONArray rows = templateJson.getJSONArray("ResultRows");
609622
for (JSONObject row : JsonUtil.toJSONObjectList(rows))
610623
{

laboratory/src/org/labkey/laboratory/assay/AssayHelper.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,10 @@ public void validateTemplate(User u, Container c, ExpProtocol protocol, @Nullabl
195195
throw errors;
196196
}
197197

198-
// Verify if this template exists and permissions:
198+
// Verify if this template exists and permissions. This expects any existing row to be present in the current container:
199199
if (templateId != null)
200200
{
201+
// This queries the current container+workbooks to identify the existence of rows in other reasonable containers:
201202
UserSchema us = QueryService.get().getUserSchema(u, c.getContainerFor(ContainerType.DataType.tabParent), "laboratory");
202203
TableInfo ti = us.getTable("assay_run_templates");
203204
TableSelector ts = new TableSelector(ti, PageFlowUtil.set("container"), new SimpleFilter(FieldKey.fromString("rowId"), templateId), null);
@@ -215,6 +216,12 @@ public void validateTemplate(User u, Container c, ExpProtocol protocol, @Nullabl
215216
errors.addRowError(new ValidationException("The current user does not have permission to edit template: " + templateId));
216217
throw errors;
217218
}
219+
220+
if (!c.equals(rowContainer))
221+
{
222+
errors.addRowError(new ValidationException("Template " + templateId + " is not from this folder"));
223+
throw errors;
224+
}
218225
}
219226
else
220227
{

0 commit comments

Comments
 (0)