forms icon indicating copy to clipboard operation
forms copied to clipboard

Delete uploaded files when answer is deleted

Open do-it4fun opened this issue 8 months ago • 3 comments

Please use the 👍 reaction to show that you are affected by the same issue. Please don't comment if you have no relevant information to add!

Describe the bug I have a form in which participants can attach files to their answers. If I delete an answer, the corresponding files are not deleted, which leads to unnecessary storage consumption.

To Reproduce Steps to reproduce the behavior:

  1. Create a form with a question of the type file
  2. Answer the form and upload a file
  3. A new folder is created for the uploaded file:

Image

  1. In the Form go to Results > Answers and delete the answer using the 3-dot menu:

Image

  1. The answer is deleted from the overview.
  2. The previously created subfolder for the answer containing the uploaded file remains.
  3. Expected behavior: The subfolder of the corresponding answer and the containing files should be deleted when the answer is deleted.

Nextcloud (please complete the following information):

  • Nextcloud-Version: Nextcloud Hub 9 (30.0.6)
  • Forms-Version: 5.0.4

Additional context The form is shared with other users who can also delete the answers, but it does not matter which user deletes the answer.

do-it4fun avatar Apr 03 '25 12:04 do-it4fun

@Chartman123 yeah, we can improve that. But before we've started, let's clarify few things:

  • do we need ask for file removal confirmation? I mean is it possible to remove submission but keep files?
  • am I right that we should do the same for question/form removal?
    • do we need introduce async job for cleanup or do everything in same request?
  • do we need cleanup just files or empty folders as well?

Koc avatar Apr 09 '25 14:04 Koc

  • do we need ask for file removal confirmation? I mean is it possible to remove submission but keep files?

Would be nice... I think it depends. When I use this question type I normally take the files from the upload folder and put them somewhere else. In this case the folders/files can also be deleted when I delete the submission.

  • am I right that we should do the same for question/form removal?

Yes, definitely makes sense. The rest of data will then also be deleted from the database if I remember correctly, at least when the whole form gets deleted.

  • do we need introduce async job for cleanup or do everything in same request?

I'd say that we should delete the files directly upon deletion of the submission/question/form + scheduled job that cleans up remaining files?

  • do we need cleanup just files or empty folders as well?

Empty folders would be great, too, but they are already deleted by the existing cleanup job, aren't they?

@susnux what do you think?

Chartman123 avatar Apr 09 '25 14:04 Chartman123

As I'm currently finishing the PR to allow editing of a user's submissions and this involves also that the user is then able to delete his submission, we need to take these actions into account, too.

When a user edits his submission for a form with a file question, the old file should get removed and the new file should be stored.

When a user deletes his submission, corresponding files should also be deleted.

Both cases of course can fail, if the form owner already moved the files out of the submission folder.

Chartman123 avatar Apr 24 '25 14:04 Chartman123

* do we need ask for file removal confirmation? I mean is it possible to remove submission but keep files?

Would not be bad to ask. But I think in general if you remove a submission than files belong to it just like all other data. Also consider e.g. GDPR, if the submission is deleted based on that we MUST delete also the files. If there is no other automated way later to remove user supplied files if the submission is already deleted then this is a no-go and we must delete the files with the submission.

* am I right that we should do the same for question/form removal?

Yes

  * do we need introduce async job for cleanup or do everything in same request?

I do not think this is needed as unlink is quite fast, so can be done in the same request.

* do we need cleanup just files or empty folders as well?

best case they are also removed.

susnux avatar Sep 13 '25 09:09 susnux