Skip to content

Commit fae1e6f

Browse files
committed
Fix merge conflicts
2 parents 487a3d1 + 68d437d commit fae1e6f

File tree

3 files changed

+61
-11
lines changed

3 files changed

+61
-11
lines changed

laboratory/src/org/labkey/laboratory/DemographicsSource.java

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.labkey.api.query.QueryService;
1717
import org.labkey.api.query.UserSchema;
1818
import org.labkey.api.security.User;
19+
import org.labkey.api.security.permissions.ReadPermission;
1920
import org.labkey.api.study.Dataset;
2021
import org.labkey.api.study.DatasetTable;
2122

@@ -40,7 +41,11 @@ public DemographicsSource(String label, String containerId, String schemaName, S
4041

4142
public static DemographicsSource getFromParts(Container c, User u, String label, String containerId, String schemaName, String queryName, String targetColumn) throws IllegalArgumentException
4243
{
43-
DemographicsSource.validateKey(c, u, containerId, schemaName, queryName, targetColumn, label);
44+
if (!isValidSource(c, u, containerId, schemaName, queryName, targetColumn, label))
45+
{
46+
return null;
47+
}
48+
4449
return new DemographicsSource(label, containerId, schemaName, queryName, targetColumn);
4550
}
4651

@@ -60,7 +65,10 @@ public static DemographicsSource getFromParts(Container c, User u, String label,
6065
String label = json.getString("label");
6166
String targetColumn = json.getString("targetColumn");
6267

63-
validateKey(c, u, containerId, schemaName, queryName, targetColumn, label);
68+
if (!isValidSource(c, u, containerId, schemaName, queryName, targetColumn, label))
69+
{
70+
return null;
71+
}
6472

6573
return new DemographicsSource(label, containerId, schemaName, queryName, targetColumn);
6674
}
@@ -103,23 +111,39 @@ public JSONObject toJSON(Container c, User u, boolean includeTotals)
103111
return json;
104112
}
105113

106-
public static boolean validateKey(Container defaultContainer, User u, @Nullable String containerId, String schemaName, String queryName, String targetColumn, String label) throws IllegalArgumentException
114+
private static boolean isValidSource(Container defaultContainer, User u, @Nullable String containerId, String schemaName, String queryName, String targetColumn, String label) throws IllegalArgumentException
107115
{
108116
Container target;
109117
if (containerId == null)
118+
{
110119
target = defaultContainer;
120+
}
111121
else
122+
{
112123
target = ContainerManager.getForId(containerId);
124+
}
113125

114126
if (target == null)
127+
{
115128
target = defaultContainer;
129+
}
130+
131+
if (!target.hasPermission(u, ReadPermission.class))
132+
{
133+
return false;
134+
}
116135

117136
UserSchema us = QueryService.get().getUserSchema(u, target, schemaName);
118-
if (target == null)
137+
if (us == null)
119138
{
120139
throw new IllegalArgumentException("Unknown schema in saved data source: " + schemaName);
121140
}
122141

142+
if (!us.canReadSchema())
143+
{
144+
return false;
145+
}
146+
123147
QueryDefinition qd = us.getQueryDefForTable(queryName);
124148
if (qd == null)
125149
{
@@ -131,19 +155,28 @@ public static boolean validateKey(Container defaultContainer, User u, @Nullable
131155
throw new IllegalArgumentException("Missing targetColumn");
132156
}
133157

134-
List<QueryException> errors = new ArrayList<QueryException>();
158+
List<QueryException> errors = new ArrayList<>();
135159
TableInfo ti = qd.getTable(errors, true);
136-
if (errors.size() != 0 || ti == null)
160+
161+
if (!errors.isEmpty())
137162
{
138163
_log.error("Unable to create TableInfo for query: " + queryName + ". there were " + errors.size() + " errors");
139164
for (QueryException e : errors)
140165
{
141166
_log.error(e.getMessage());
142167
}
143-
if (errors.size() > 0)
144-
throw new IllegalArgumentException("Unable to create table for query: " + queryName, errors.get(0));
145-
else
146-
throw new IllegalArgumentException("Unable to create table for query: " + queryName);
168+
169+
throw new IllegalArgumentException("Unable to create table for query: " + queryName, errors.get(0));
170+
}
171+
172+
if (ti == null)
173+
{
174+
throw new IllegalArgumentException("Unable to create table for query: " + queryName);
175+
}
176+
177+
if (!ti.hasPermission(u, ReadPermission.class))
178+
{
179+
return false;
147180
}
148181

149182
ColumnInfo col = ti.getColumn(targetColumn);
@@ -160,6 +193,11 @@ public static boolean validateKey(Container defaultContainer, User u, @Nullable
160193
if (ti instanceof DatasetTable)
161194
{
162195
Dataset ds = ((DatasetTable)ti).getDataset();
196+
if (!ds.hasPermission(u, ReadPermission.class))
197+
{
198+
return false;
199+
}
200+
163201
if (!(ds.isDemographicData() && ds.getStudy().getSubjectColumnName().equalsIgnoreCase(col.getName())))
164202
{
165203
throw new IllegalArgumentException("Target column is not a key field: " + targetColumn);
@@ -177,7 +215,9 @@ public static boolean validateKey(Container defaultContainer, User u, @Nullable
177215
}
178216

179217
if (StringUtils.trimToNull(label) == null)
218+
{
180219
throw new IllegalArgumentException("Label must not be blank");
220+
}
181221

182222
return true;
183223
}

laboratory/src/org/labkey/laboratory/LaboratoryController.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,11 @@ public ApiResponse execute(SetDataSourcesForm form, BindException errors)
13091309
return null;
13101310
}
13111311

1312-
sources.add(DemographicsSource.getFromParts(getContainer(), getUser(), label, containerId, schemaName, queryName, targetColumn));
1312+
DemographicsSource s = DemographicsSource.getFromParts(getContainer(), getUser(), label, containerId, schemaName, queryName, targetColumn);
1313+
if (s != null)
1314+
{
1315+
sources.add(s);
1316+
}
13131317
}
13141318

13151319
try

laboratory/src/org/labkey/laboratory/LaboratoryServiceImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,9 @@ public Set<DemographicsSource> getDemographicsSources(Container c, User u) throw
383383
{
384384
DemographicsSource source = DemographicsSource.getFromPropertyManager(target, u, key, properties.get(key));
385385
if (source != null)
386+
{
386387
qds.add(source);
388+
}
387389
}
388390
catch (IllegalArgumentException e)
389391
{
@@ -458,11 +460,15 @@ public Map<Container, Set<DemographicsSource>> getAllDemographicsSources(User u)
458460
{
459461
Container c = ContainerManager.getForId(entry.getObjectId());
460462
if (c == null || !c.hasPermission(u, ReadPermission.class))
463+
{
461464
continue;
465+
}
462466

463467
Set<DemographicsSource> set = map.get(c);
464468
if (set == null)
469+
{
465470
set = new HashSet<>();
471+
}
466472

467473
DemographicsSource source = DemographicsSource.getFromPropertyManager(c, u, entry.getKey(), entry.getValue());
468474
if (source == null)

0 commit comments

Comments
 (0)