11using Altinn . App . Api . Infrastructure . Filters ;
22using Altinn . App . Api . Models ;
3+ using Altinn . App . Core . Features ;
34using Altinn . App . Core . Features . Auth ;
45using Altinn . App . Core . Features . Signing . Models ;
56using Altinn . App . Core . Features . Signing . Services ;
89using Altinn . App . Core . Internal . Data ;
910using Altinn . App . Core . Internal . Instances ;
1011using Altinn . App . Core . Internal . Process ;
12+ using Altinn . App . Core . Internal . Process . Elements ;
1113using Altinn . App . Core . Internal . Process . Elements . AltinnExtensionProperties ;
1214using Altinn . Platform . Storage . Interface . Models ;
1315using Microsoft . AspNetCore . Mvc ;
@@ -61,6 +63,7 @@ ILogger<SigningController> logger
6163 /// <param name="instanceGuid">unique id to identify the instance</param>
6264 /// <param name="ct">Cancellation token, populated by the framework</param>
6365 /// <param name="language">The currently used language by the user (or null if not available)</param>
66+ /// <param name="taskId">If data should be loaded from a different task than the current one.</param>
6467 /// <returns>An object containing updated signee state</returns>
6568 [ HttpGet ]
6669 [ ProducesResponseType ( typeof ( SigningStateResponse ) , StatusCodes . Status200OK ) ]
@@ -71,7 +74,8 @@ public async Task<IActionResult> GetSigneesState(
7174 [ FromRoute ] int instanceOwnerPartyId ,
7275 [ FromRoute ] Guid instanceGuid ,
7376 CancellationToken ct ,
74- [ FromQuery ] string ? language = null
77+ [ FromQuery ] string ? language = null ,
78+ [ FromQuery ] string ? taskId = null
7579 )
7680 {
7781 Instance instance = await _instanceClient . GetInstance ( app , org , instanceOwnerPartyId , instanceGuid ) ;
@@ -84,24 +88,24 @@ public async Task<IActionResult> GetSigneesState(
8488 instanceOwnerPartyId
8589 ) ;
8690
87- string ? taskId = instance . Process . CurrentTask . ElementId ;
88- InstanceDataUnitOfWork cachedDataMutator = await _instanceDataUnitOfWorkInitializer . Init (
89- instance ,
90- taskId ,
91- language
92- ) ;
93-
94- if ( instance . Process . CurrentTask . AltinnTaskType != "signing" )
91+ string ? finalTaskId = taskId ?? instance . Process ? . CurrentTask ? . ElementId ;
92+ if ( string . IsNullOrEmpty ( finalTaskId ) || ! VerifyIsSigningTask ( finalTaskId ) )
9593 {
9694 return NotSigningTask ( ) ;
9795 }
9896
97+ IInstanceDataAccessor instanceDataAccessor = await _instanceDataUnitOfWorkInitializer . Init (
98+ instance ,
99+ finalTaskId ,
100+ language
101+ ) ;
102+
99103 AltinnSignatureConfiguration signingConfiguration =
100- ( _processReader . GetAltinnTaskExtension ( instance . Process . CurrentTask . ElementId ) ? . SignatureConfiguration )
104+ ( _processReader . GetAltinnTaskExtension ( finalTaskId ) ? . SignatureConfiguration )
101105 ?? throw new ApplicationConfigException ( "Signing configuration not found in AltinnTaskExtension" ) ;
102106
103107 List < SigneeContext > signeeContexts = await _signingService . GetSigneeContexts (
104- cachedDataMutator ,
108+ instanceDataAccessor ,
105109 signingConfiguration ,
106110 ct
107111 ) ;
@@ -165,6 +169,7 @@ .. signeeContexts
165169 /// <param name="instanceGuid">unique id to identify the instance</param>
166170 /// <param name="ct">Cancellation token, populated by the framework</param>
167171 /// <param name="language">The currently used language by the user (or null if not available)</param>
172+ /// <param name="taskId">If data should be loaded from a different task than the current one.</param>
168173 /// <returns>An object containing a list of organizations that the user can sign on behalf of</returns>
169174 [ HttpGet ( "organizations" ) ]
170175 [ ProducesResponseType ( typeof ( SigningAuthorizedOrganizationsResponse ) , StatusCodes . Status200OK ) ]
@@ -176,25 +181,26 @@ public async Task<IActionResult> GetAuthorizedOrganizations(
176181 [ FromRoute ] int instanceOwnerPartyId ,
177182 [ FromRoute ] Guid instanceGuid ,
178183 CancellationToken ct ,
179- [ FromQuery ] string ? language = null
184+ [ FromQuery ] string ? language = null ,
185+ [ FromQuery ] string ? taskId = null
180186 )
181187 {
182188 Instance instance = await _instanceClient . GetInstance ( app , org , instanceOwnerPartyId , instanceGuid ) ;
183189
184- string ? taskId = instance . Process . CurrentTask . ElementId ;
185- InstanceDataUnitOfWork cachedDataMutator = await _instanceDataUnitOfWorkInitializer . Init (
186- instance ,
187- taskId ,
188- language
189- ) ;
190-
191- if ( instance . Process . CurrentTask . AltinnTaskType != "signing" )
190+ string ? finalTaskId = taskId ?? instance . Process ? . CurrentTask ? . ElementId ;
191+ if ( string . IsNullOrEmpty ( finalTaskId ) || ! VerifyIsSigningTask ( finalTaskId ) )
192192 {
193193 return NotSigningTask ( ) ;
194194 }
195195
196+ IInstanceDataAccessor instanceDataAccessor = await _instanceDataUnitOfWorkInitializer . Init (
197+ instance ,
198+ finalTaskId ,
199+ language
200+ ) ;
201+
196202 AltinnSignatureConfiguration signingConfiguration =
197- ( _processReader . GetAltinnTaskExtension ( instance . Process . CurrentTask . ElementId ) ? . SignatureConfiguration )
203+ ( _processReader . GetAltinnTaskExtension ( finalTaskId ) ? . SignatureConfiguration )
198204 ?? throw new ApplicationConfigException ( "Signing configuration not found in AltinnTaskExtension" ) ;
199205
200206 Authenticated currentAuth = _authenticationContext . Current ;
@@ -211,7 +217,7 @@ public async Task<IActionResult> GetAuthorizedOrganizations(
211217 }
212218
213219 List < OrganizationSignee > authorizedOrganizations = await _signingService . GetAuthorizedOrganizationSignees (
214- cachedDataMutator ,
220+ instanceDataAccessor ,
215221 signingConfiguration ,
216222 userId . Value ,
217223 ct
@@ -241,6 +247,7 @@ public async Task<IActionResult> GetAuthorizedOrganizations(
241247 /// <param name="instanceOwnerPartyId">unique id of the party that this the owner of the instance</param>
242248 /// <param name="instanceGuid">unique id to identify the instance</param>
243249 /// <param name="language">The currently used language by the user (or null if not available)</param>
250+ /// <param name="taskId">If data should be loaded from a different task than the current one.</param>
244251 /// <returns>An object containing the documents to be signed</returns>
245252 [ HttpGet ( "data-elements" ) ]
246253 [ ProducesResponseType ( typeof ( SigningDataElementsResponse ) , StatusCodes . Status200OK ) ]
@@ -250,18 +257,20 @@ public async Task<IActionResult> GetDataElements(
250257 [ FromRoute ] string app ,
251258 [ FromRoute ] int instanceOwnerPartyId ,
252259 [ FromRoute ] Guid instanceGuid ,
253- [ FromQuery ] string ? language = null
260+ [ FromQuery ] string ? language = null ,
261+ [ FromQuery ] string ? taskId = null
254262 )
255263 {
256264 Instance instance = await _instanceClient . GetInstance ( app , org , instanceOwnerPartyId , instanceGuid ) ;
257265
258- if ( instance . Process . CurrentTask . AltinnTaskType != "signing" )
266+ string ? finalTaskId = taskId ?? instance . Process ? . CurrentTask ? . ElementId ;
267+ if ( string . IsNullOrEmpty ( finalTaskId ) || ! VerifyIsSigningTask ( finalTaskId ) )
259268 {
260269 return NotSigningTask ( ) ;
261270 }
262271
263272 AltinnSignatureConfiguration ? signingConfiguration =
264- ( _processReader . GetAltinnTaskExtension ( instance . Process . CurrentTask . ElementId ) ? . SignatureConfiguration )
273+ ( _processReader . GetAltinnTaskExtension ( finalTaskId ) ? . SignatureConfiguration )
265274 ?? throw new ApplicationConfigException ( "Signing configuration not found in AltinnTaskExtension" ) ;
266275
267276 List < DataElement > dataElements =
@@ -282,13 +291,22 @@ .. instance
282291 return Ok ( response ) ;
283292 }
284293
294+ private bool VerifyIsSigningTask ( string taskId )
295+ {
296+ List < ProcessTask > allTasks = _processReader . GetProcessTasks ( ) ;
297+ ProcessTask ? processTask = allTasks . FirstOrDefault ( t => t . Id == taskId ) ;
298+
299+ return processTask ? . ExtensionElements ? . TaskExtension ? . TaskType == "signing" ;
300+ }
301+
285302 private BadRequestObjectResult NotSigningTask ( )
286303 {
287304 return BadRequest (
288305 new ProblemDetails
289306 {
290307 Title = "Not a signing task" ,
291- Detail = "This endpoint is only callable while the current task is a signing task." ,
308+ Detail =
309+ $ "This endpoint is only callable while the current task is a signing task, or when taskId query param is set to a signing task's ID.",
292310 Status = StatusCodes . Status400BadRequest ,
293311 }
294312 ) ;
0 commit comments