Altinn / altinn-storage

Altinn platform microservice for handling instance storage
2 stars 3 forks source link

PUT storage/api/v1/instances/{instanceOwnerPartyId:int}/{instanceGuid:guid}/dataelements/{dataGuid} can't update filename #328

Open ivarne opened 9 months ago

ivarne commented 9 months ago

Description of the bug

The DataElement.FileName property seems to be not whitelisted as an allowed property here

https://github.com/Altinn/altinn-storage/blob/e798be95adedfca6cf488347cbe2c89296e181b8/src/Storage/Controllers/DataController.cs#L458-L467

And the same for localtest

https://github.com/Altinn/app-localtest/blob/2200dd547233f56b88fffc0cdac7acbaa118b806/src/Controllers/Storage/DataController.cs#L447-L453

This seems weird.

Steps To Reproduce

Run code similar to this in an Altinn app

_dataClient = // fetch IDataClient from constructor in whatever hook you want (eg IDataProcessing)
var instance = // get instance
var dataElement = instance.Data.FirstOrDefault(/* your selector*/);
dataElement.FileName = $"CODE_{dataElement.FileName}";
await _dataClient.Update(instance, dataElement);

Additional Information

No response

SandGrainOne commented 9 months ago

File name is assigned during the upload of the file. I gues you're looking a way to rename a file?

ivarne commented 9 months ago

Yes that is the requested functionality. The method in apps to call this API is named DataClient.Update(Instance, DataElement) with description "Updates the data element metadata object."

SandGrainOne commented 9 months ago

One thing we would need to handle is changes to file extensions, maybe? DataType validation in regards to file types. defined in application metadata.

ivarne commented 9 months ago

This api is for the application itself to update data elements. Not exposed to random users (I hope!). There are lots of worse ways to shoot yourself in the foot as an app developer.

A better way to fix this particular issue would be to allow app developers to modify the filename while uploading, but the main issue here is that it is confusing that this does not work.

olebhansen commented 3 weeks ago

FYI, the issue originated in eFormidling, where the solution was to create unique/new filenames for each attempt/shipment(?). This issue is still relevant, but more from an API completeness sense. Low pri, as there are no immediate usecases depending on this.