1616package org .labkey .api .assay .dilution ;
1717
1818import org .jetbrains .annotations .Nullable ;
19+ import org .labkey .api .assay .AbstractAssayProvider ;
20+ import org .labkey .api .assay .AssayProtocolSchema ;
21+ import org .labkey .api .assay .AssayService ;
1922import org .labkey .api .assay .dilution .query .DilutionProviderSchema ;
2023import org .labkey .api .assay .nab .Luc5Assay ;
2124import org .labkey .api .assay .nab .NabGraph ;
2225import org .labkey .api .assay .nab .NabSpecimen ;
2326import org .labkey .api .assay .nab .RenderAssayBean ;
2427import org .labkey .api .assay .nab .view .RunDetailOptions ;
28+ import org .labkey .api .assay .plate .WellGroup ;
2529import org .labkey .api .collections .CaseInsensitiveHashMap ;
2630import org .labkey .api .data .ColumnInfo ;
2731import org .labkey .api .data .Container ;
4246import org .labkey .api .query .CustomView ;
4347import org .labkey .api .query .FieldKey ;
4448import org .labkey .api .query .QueryService ;
49+ import org .labkey .api .security .ElevatedUser ;
4550import org .labkey .api .security .User ;
46- import org .labkey .api .assay .plate .WellGroup ;
47- import org .labkey .api .assay .AbstractAssayProvider ;
48- import org .labkey .api .assay .AssayProtocolSchema ;
49- import org .labkey .api .assay .AssayService ;
51+ import org .labkey .api .security .UserManager ;
52+ import org .labkey .api .security .impersonation .ImpersonationContext ;
5053import org .labkey .api .view .NotFoundException ;
5154import org .labkey .api .view .ViewContext ;
5255
6467import java .util .Set ;
6568import java .util .TreeMap ;
6669
67- /**
68- * User: klum
69- * Date: 5/8/13
70- */
7170public abstract class DilutionAssayRun extends Luc5Assay
7271{
7372 protected ExpProtocol _protocol ;
74- protected DilutionAssayProvider _provider ;
73+ protected DilutionAssayProvider <?> _provider ;
7574 protected Map <PropertyDescriptor , Object > _runProperties ;
7675 protected Map <PropertyDescriptor , Object > _runDisplayProperties ;
7776 protected List <SampleResult > _sampleResults ;
7877 protected Map <String , Object > _virusNames ;
7978 protected ExpRun _run ;
80- // Be extremely careful to not leak this user out in any objects (e.g, via schemas or tables) as it may have elevated permissions.
81- protected User _user ;
8279 protected StatsService .CurveFitType _savedCurveFitType = null ;
8380 protected Map <ExpMaterial , List <WellGroup >> _materialWellGroupMapping ;
8481 protected Map <WellGroup , ExpMaterial > _wellGroupMaterialMapping ;
8582
86- public DilutionAssayRun (DilutionAssayProvider provider , ExpRun run ,
83+ // Objects of this class are cached (held by NAbRunWrapper), so we don't want to hold onto a User object. The
84+ // passed in user might have elevated permissions, so stash the impersonation context along with the user ID.
85+ private final int _userId ;
86+ private final ImpersonationContext _impersonationContext ;
87+ private final Map <FieldKey , PropertyDescriptor > _fieldKeys ;
88+
89+ public DilutionAssayRun (DilutionAssayProvider <?> provider , ExpRun run ,
8790 User user , List <Integer > cutoffs , StatsService .CurveFitType renderCurveFitType )
8891 {
8992 super (run .getRowId (), cutoffs , renderCurveFitType );
9093 _run = run ;
91- _user = user ;
94+ _userId = user .getUserId ();
95+ _impersonationContext = user instanceof ElevatedUser eu ? eu .getImpersonationContext () : null ;
9296 _protocol = run .getProtocol ();
9397 _provider = provider ;
98+ _fieldKeys = getFieldKeys (user );
9499
95- for (Map .Entry <PropertyDescriptor , Object > property : getRunProperties ().entrySet ())
100+ TableInfo runTable = AssayService .get ().createRunTable (_protocol , _provider , user , _run .getContainer (), null );
101+ Map <FieldKey , ColumnInfo > cols = QueryService .get ().getColumns (runTable , _fieldKeys .keySet ());
102+ Map <PropertyDescriptor , Object > runProperties = new TreeMap <>(new PropertyDescriptorComparator ());
103+ runProperties .putAll (getRunProperties (runTable , _fieldKeys , cols ));
104+ _runProperties = Collections .unmodifiableMap (runProperties );
105+
106+ for (Map .Entry <PropertyDescriptor , Object > property : _runProperties .entrySet ())
96107 {
97108 if (DilutionAssayProvider .CURVE_FIT_METHOD_PROPERTY_NAME .equals (property .getKey ().getName ()))
98109 {
@@ -102,7 +113,13 @@ public DilutionAssayRun(DilutionAssayProvider provider, ExpRun run,
102113 }
103114 }
104115
105- public DilutionAssayProvider getProvider ()
116+ protected User getUser ()
117+ {
118+ User user = UserManager .getUser (_userId );
119+ return _impersonationContext != null ? ElevatedUser .getElevatedUser (user , _impersonationContext ) : user ;
120+ }
121+
122+ public DilutionAssayProvider <?> getProvider ()
106123 {
107124 return _provider ;
108125 }
@@ -119,6 +136,11 @@ public String getRunName()
119136 }
120137
121138 private Map <FieldKey , PropertyDescriptor > getFieldKeys ()
139+ {
140+ return _fieldKeys ;
141+ }
142+
143+ private Map <FieldKey , PropertyDescriptor > getFieldKeys (User user )
122144 {
123145 Map <FieldKey , PropertyDescriptor > fieldKeys = new HashMap <>();
124146 for (DomainProperty property : _provider .getBatchDomain (_protocol ).getProperties ())
@@ -127,7 +149,7 @@ private Map<FieldKey, PropertyDescriptor> getFieldKeys()
127149 fieldKeys .put (FieldKey .fromParts (property .getName ()), property .getPropertyDescriptor ());
128150
129151 // Add all of the hard columns to the set of properties we can show
130- TableInfo runTableInfo = AssayService .get ().createRunTable (_protocol , _provider , _user , _run .getContainer (), null );
152+ TableInfo runTableInfo = AssayService .get ().createRunTable (_protocol , _provider , user , _run .getContainer (), null );
131153 for (ColumnInfo runColumn : runTableInfo .getColumns ())
132154 {
133155 // These columns cause an UnauthorizedException if the user has permission to see the dataset
@@ -149,7 +171,7 @@ private Map<FieldKey, PropertyDescriptor> getFieldKeys()
149171 }
150172 }
151173
152- return fieldKeys ;
174+ return Collections . unmodifiableMap ( fieldKeys ) ;
153175 }
154176
155177 public StatsService .CurveFitType getSavedCurveFitType ()
@@ -196,7 +218,7 @@ public Map<PropertyDescriptor, Object> getRunDisplayProperties(ViewContext conte
196218 if (_runDisplayProperties == null )
197219 {
198220 Map <FieldKey , PropertyDescriptor > fieldKeys = getFieldKeys ();
199- TableInfo runTable = AssayService .get ().createRunTable (_protocol , _provider , _user , _run .getContainer (), null );
221+ TableInfo runTable = AssayService .get ().createRunTable (_protocol , _provider , getUser () , _run .getContainer (), null );
200222
201223 CustomView runView = getRunsCustomView (context );
202224 Collection <FieldKey > fieldKeysToShow ;
@@ -211,7 +233,7 @@ public Map<PropertyDescriptor, Object> getRunDisplayProperties(ViewContext conte
211233 fieldKeysToShow = new ArrayList <>(runTable .getDefaultVisibleColumns ());
212234 }
213235 // The list of available columns is reduced from the default set because the user may not have
214- // permission to join to all of the lookups. Remove any columns that aren't part of the acceptable set,
236+ // permission to join to all the lookups. Remove any columns that aren't part of the acceptable set,
215237 // which is built up by getFieldKeys()
216238 List <FieldKey > newFieldKeysToShow = new ArrayList <>();
217239 for (FieldKey fieldKey : fieldKeysToShow )
@@ -229,9 +251,9 @@ public Map<PropertyDescriptor, Object> getRunDisplayProperties(ViewContext conte
229251 }
230252
231253 Map <FieldKey , ColumnInfo > selectCols = QueryService .get ().getColumns (runTable , newFieldKeysToShow );
232- _runDisplayProperties = getRunProperties (runTable , fieldKeys , selectCols );
254+ _runDisplayProperties = Collections . unmodifiableMap ( getRunProperties (runTable , fieldKeys , selectCols ) );
233255 }
234- return Collections . unmodifiableMap ( _runDisplayProperties ) ;
256+ return _runDisplayProperties ;
235257 }
236258
237259 protected Map <String , Map <PropertyDescriptor , Object >> getSampleProperties ()
@@ -256,7 +278,7 @@ protected Map<String, DilutionResultProperties> getSampleProperties(ExpData outp
256278 {
257279 Map <String , DilutionResultProperties > dilutionResultPropertiesMap = new HashMap <>();
258280
259- AssayProtocolSchema schema = _provider .createProtocolSchema (_user , _run .getContainer (), _protocol , null );
281+ AssayProtocolSchema schema = _provider .createProtocolSchema (getUser () , _run .getContainer (), _protocol , null );
260282 TableInfo virusTable = schema .createTable (DilutionManager .VIRUS_TABLE_NAME , null );
261283
262284 // Do a query to get all the info we need to do the linkage
@@ -316,23 +338,15 @@ protected CustomView getRunsCustomView(ViewContext context)
316338
317339 public Map <PropertyDescriptor , Object > getRunProperties ()
318340 {
319- if (_runProperties == null )
320- {
321- Map <FieldKey , PropertyDescriptor > fieldKeys = getFieldKeys ();
322- TableInfo runTable = AssayService .get ().createRunTable (_protocol , _provider , _user , _run .getContainer (), null );
323- Map <FieldKey , ColumnInfo > cols = QueryService .get ().getColumns (runTable , fieldKeys .keySet ());
324- _runProperties = new TreeMap <>(new PropertyDescriptorComparator ());
325- _runProperties .putAll (getRunProperties (runTable , fieldKeys , cols ));
326- }
327- return Collections .unmodifiableMap (_runProperties );
341+ return _runProperties ;
328342 }
329343
330344 public abstract List <SampleResult > getSampleResults ();
331345
332346 public Map <String , Object > getVirusNames ()
333347 {
334348 if (_virusNames == null )
335- _virusNames = Collections .EMPTY_MAP ;
349+ _virusNames = Collections .emptyMap () ;
336350 return _virusNames ;
337351 }
338352
@@ -377,7 +391,7 @@ public static class SampleResult
377391 private boolean _longCaptions = false ;
378392 private final DilutionManager _mgr = new DilutionManager ();
379393
380- public SampleResult (DilutionAssayProvider provider , ExpData data , DilutionSummary dilutionSummary , DilutionMaterialKey materialKey ,
394+ public SampleResult (DilutionAssayProvider <?> provider , ExpData data , DilutionSummary dilutionSummary , DilutionMaterialKey materialKey ,
381395 Map <PropertyDescriptor , Object > sampleProperties , DilutionResultProperties dilutionResultProperties )
382396 {
383397 _dilutionSummary = dilutionSummary ;
0 commit comments