Open bossm8 opened 1 year ago
@bossm8 In Moodle Developer chat, Andrew Lyons today essentially answered to some similar question ("it is kind of annoying there's no core webservice upload function that doesn't go to the draft area or let you specify which file area it goes to"), saying:
That’s just how file upload in Moodle works everywhere. You upload to a draft area and copy it into place.
Having an open copy to file area web service would be a huge security risk as there’s nothing to check the target permissions.
For example, take the case of an assignment with file submissions. You can only add files to a submission in certain conditions and the assignment is responsible for those.
If you had an open WS which accepted just any target file area and itemid, you could just add your file to a closed submission and, essentially, cheat.
We upload to draft files and then have a separate service-specific ws call to check all of the target rights and then copy the files into the target area and create a new submission using all of the relevant APIs.
There is no generic way to do that.
So if im getting this correctly the request is still valid?
I'm not essentially asking to skip the draft area but only the need to save to the private files to prevent the need for manual interaction after coping the file to the destination.
The current implementation has this path:
The proposed path would just be:
The origin of the request is that would like to automate course creation with external tools like gitlab CI/CD. However, the current implementation almost makes this impossible because we still would need to manually interact to delete the files which have been saved to the private area.
Hello everyone, I'm not too familiar with moodle development so this is kind of a feature-request question 😄
Problem
Currently when I want to upload files to a course section I need to perform the following steps (ref):
upload.php
add_user_private_files
local_rsync_create_file_resource
However, this results in my private space being filled up relatively quickly as I have limited storage capacity there as files saved in my private area cannot be deleted again via the webservice (at least not with the standard API). So I have to go and delete them manually to prevent my space from being filled.
Feature Request
My request would be to check if it is possible to move files directly from the draft to the course. Meaning, instead of using the filename as parameter in
local_rsync_create_file_resource
check if it is possible to use thedraftid
(and the filename if needed) and move the files from the draft are directly so that files do not need to be saved.Currently the code used creates a new ephemeral draft to move the file (code).
Could you check if it is possible to move it from the uploaded draft directly with e.g. file_save_draft_area_files such as the function required to call in the process described above does (add_user_private_files) instead of requiring to save the file beforehand?
References