Skip to content

Commit

Permalink
[ADD] check if Post is allowed on Frozen IterationSetup; fixes #361
Browse files Browse the repository at this point in the history
  • Loading branch information
lxatstariongroup authored Jun 19, 2024
1 parent 11670f3 commit 5a3fe36
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions CometServer/Modules/10-25/EngineeringModelApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,12 @@ protected async Task PostResponseData(PostRequestData postRequestData, string re
credentialsService.Credentials.IsParticipant = true;

var iteration = DetermineIteration(resourceProcessor, partition, routeSegments);

if (!IsPostAllowedOnIterationSetup(resourceProcessor, iteration))
{
throw new Cdp4ModelValidationException($"It is not allowed to write data to a Frozen {nameof(IterationSetup)}, or its full containment tree. (#FROZEN_ITERATION).");
}

credentialsService.Credentials.Iteration = iteration;
}

Expand Down Expand Up @@ -1423,6 +1429,36 @@ private static Iteration DetermineIteration(ResourceProcessor processor, string
return null;
}

/// <summary>
/// Determine is a Post request is allowed based on the <see cref="IterationSetup"/>s data.
/// </summary>
/// <param name="processor">
/// The processor instance.
/// </param>
/// <param name="iteration">
/// The <see cref="Iteration"/>
/// </param>
/// <returns>
/// A boolean indication if writing data to an <see cref="Iteration"/> is allowed
/// </returns>
private static bool IsPostAllowedOnIterationSetup(ResourceProcessor processor, Iteration iteration)
{
var securityContext = new RequestSecurityContext { ContainerReadAllowed = true };

var partition = "SiteDirectory";
var requestedIterationSetupId = iteration.IterationSetup;
var iterationSetups = processor.GetResource("IterationSetup", partition, new List<Guid> { requestedIterationSetupId }, securityContext).OfType<IterationSetup>().ToList();

if (iterationSetups.Count != 1)
{
throw new ThingNotFoundException($"IterationSetup {requestedIterationSetupId} could not be resolved");
}

var iterationSetup = iterationSetups.First();

return !iterationSetup.FrozenOn.HasValue;
}

/// <summary>
/// Checks if a route is a valid route for returning a filearchive response for a <see cref="DomainFileStore"/>
/// </summary>
Expand Down

0 comments on commit 5a3fe36

Please sign in to comment.