-
Bug
-
Resolution: Unresolved
-
Minor
-
None
-
4.1.1
-
None
-
MOODLE_401_STABLE
Hi
An error occurs when a user is trying to download a share with the "Create an access controlled link to the file" option a second and successive time.
We have made the connection between a Nextcloud instance in version 25.0.3 and Moodle 4.1 (Build: 20221128).
To reproduce it:
- A teacher creates a thread in a forum by putting an attached file of the type "Create an access controlled link to the file" from the Nextcloud repository.
- The Teacher or any student can consult the thread and when downloading the file the first time it is downloaded correctly, the second or successive times it gives the error "A Webdav request to move a file failed" from the image that I have attached.
Reviewing the code I see that in the file "repository/nextcloud/lib.php > public function send_file()", Nextcloud 25.0.3 returns a statuscode of 100 when the share was already created before calling create_share. Moodle expects a statuscode of 403.
I have found a way to fix the 100 statuscode of a create_share response when the share was already created before the create_share call. I use this workaround because the "filetarget" path contains the "controlledlinkfoldername" (by default, Moodlefiles folder) when the share was already created before calling create_share.
While this solution provides a quick fix for the error, it is possible that Nextcloud may change the response of the destination path in future revisions. The correct solution will be to find a way to check if a share has already been created before calling create_share using another Nextcloud call.
repository/nextcloud/lib.php
// Creates a share between the systemaccount and the user. |
$responsecreateshare = $linkmanager->create_share_user_sysaccount($reference->link, $username, $maywrite); |
|
$statuscode = $responsecreateshare['statuscode']; |
|
// cheat fix:
|
if (strpos($responsecreateshare['filetarget'], '/' . $this->controlledlinkfoldername) === 0) { |
$statuscode = 403; |
}
|
// end cheat fix
|
|
if ($statuscode == 403) { |
$shareid = $linkmanager->get_shares_from_path($reference->link, $username); |
} else if ($statuscode == 100) { |
|
|
I attach the file repository_nextcloud_lib.php.patch created with the command "git diff repository/nextcloud/lib.php > repository_nextcloud_lib.php.patch" with the changes I have made.
Regards
- blocks
-
MDL-79944 Moodle wrong permission on Nextcloud repository, only with S3?
- Open