Closed griffri closed 1 week ago
In UpsertCollection
and in CreateCollection
we have:
var parentCollection = await dbContext.RetrieveCollectionAsync(request.CustomerId,
request.Collection.Parent.GetLastPathElement(), true, cancellationToken);
which seems like it would turn https://iiif.dlc.services/99/collections/my-flat-identifier
to my-flat-identifier
, and indeed it does.
However, in both cases when it comes to setting the Parent
property we just rewrite the request.Collection.Parent
, ignoring the fact we have already resolved the parent collection (to verify it exists etc.). It seems we can just replace those usages with the id retrieved from the actual entity.
Tried that, wrote some tests where we set the parent (in either create or update requests) to some full URI, and it seems to correctly cut it down, saving only that last bit.
Which of course explains the last part of this ticket where we have to deal with someone setting a parent to a full URL, but because they are providing the hierarchical link, not flat one, the last URL segment is not unique id but it is a slug instead.
We can't instantly figure out which scenario are we dealing with, at least without baking-in some specific paths/routes. My current idea, which I'll check in a second, is to split the flow:
if is_full_url(parent)
then
generate a flat id full URL for the resolved parent (as we do elsewhere)
return error if it does not match parent from request
endif
which reuses whatever code generates the full URLs instead of duplicating it elsewhere, creating maintenance nightmare.
// If full URI was used, verify it indeed is pointing to the resolved parent collection
if (Uri.IsWellFormedUriString(request.Collection.Parent, UriKind.Absolute)
&& !parentCollection.GenerateFlatCollectionId(request.UrlRoots).Equals(request.Collection.Parent))
return ErrorHelper.NullParentResponse<PresentationCollection>();
this seems to work nicely :D
Currently you can set the
parent
value of a Presentation resource to an ID and it will work, but a full path won't be handled correctly:This issue also occurs when the presentation root path (e.g
https://presentation-api.dlcs.digirati.io/1/collections/root
) is passed, but only on PUT - this seems to be working correctly for POST.Hierarchical paths can also be passed through, which shouldn't be allowed. (reported by @JackLewis-digirati)
Acceptance Criteria
parent
field, and is correctly resolvedparent
value visible in POST/PUT and GET responses is a valid URL to the parent