Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-77596

Nextcloud error: A Webdav request to move a file failed

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 4.1.1
    • Repositories
    • 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

        1. 01_nextcloud.PNG
          01_nextcloud.PNG
          60 kB
        2. 02_nextcloud.PNG
          02_nextcloud.PNG
          62 kB
        3. 04_nextcloud.PNG
          04_nextcloud.PNG
          67 kB
        4. repository_nextcloud_lib.php.patch
          2 kB

            Unassigned Unassigned
            zaitez Xabi Martin
            Votes:
            2 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.