]> source.dussan.org Git - nextcloud-server.git/commitdiff
Move Dav fileid and permissions logic into OCP\Util to be able to use it for BulkUpload
authorCôme Chilliet <come.chilliet@nextcloud.com>
Mon, 29 Aug 2022 08:37:08 +0000 (10:37 +0200)
committerCôme Chilliet <come.chilliet@nextcloud.com>
Mon, 29 Aug 2022 11:55:08 +0000 (13:55 +0200)
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
apps/dav/lib/BulkUpload/BulkUploadPlugin.php
apps/dav/lib/Connector/Sabre/Node.php
apps/dav/lib/Server.php
lib/public/Util.php

index 79a1561ef5bfb0404161236d86cc72e9faab9c66..b5400ec58d21374cd1947068eebf4aab142afb69 100644 (file)
@@ -33,14 +33,13 @@ use OCP\AppFramework\Http;
 use OCA\DAV\Connector\Sabre\MtimeSanitizer;
 
 class BulkUploadPlugin extends ServerPlugin {
+       private Folder $userFolder;
+       private LoggerInterface $logger;
 
-       /** @var Folder */
-       private $userFolder;
-
-       /** @var LoggerInterface */
-       private $logger;
-
-       public function __construct(Folder $userFolder, LoggerInterface $logger) {
+       public function __construct(
+               Folder $userFolder,
+               LoggerInterface $logger
+       ) {
                $this->userFolder = $userFolder;
                $this->logger = $logger;
        }
@@ -96,8 +95,8 @@ class BulkUploadPlugin extends ServerPlugin {
                                $writtenFiles[$headers['x-file-path']] = [
                                        "error" => false,
                                        "etag" => $node->getETag(),
-                                       "fileid" => $node->getFileId(),
-                                       "permissions" => $node->getDavPermissions(),
+                                       "fileid" => \OCP\Util::getDavFileId($node->getId()),
+                                       "permissions" => \OCP\Util::getDavPermissions($node),
                                ];
                        } catch (\Exception $e) {
                                $this->logger->error($e->getMessage(), ['path' => $headers['x-file-path']]);
index 87f2fea394fdb78ce5c844bfdc39f859a3489f83..c4fc6282f84113e3220a9b98fb9a24d6e9bac42c 100644 (file)
@@ -252,10 +252,8 @@ abstract class Node implements \Sabre\DAV\INode {
         * @return string|null
         */
        public function getFileId() {
-               if ($this->info->getId()) {
-                       $instanceId = \OC_Util::getInstanceId();
-                       $id = sprintf('%08d', $this->info->getId());
-                       return $id . $instanceId;
+               if ($id = $this->info->getId()) {
+                       return \OCP\Util::getDavFileId($id);
                }
 
                return null;
@@ -381,35 +379,7 @@ abstract class Node implements \Sabre\DAV\INode {
         * @return string
         */
        public function getDavPermissions() {
-               $p = '';
-               if ($this->info->isShared()) {
-                       $p .= 'S';
-               }
-               if ($this->info->isShareable()) {
-                       $p .= 'R';
-               }
-               if ($this->info->isMounted()) {
-                       $p .= 'M';
-               }
-               if ($this->info->isReadable()) {
-                       $p .= 'G';
-               }
-               if ($this->info->isDeletable()) {
-                       $p .= 'D';
-               }
-               if ($this->info->isUpdateable()) {
-                       $p .= 'NV'; // Renameable, Moveable
-               }
-               if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) {
-                       if ($this->info->isUpdateable()) {
-                               $p .= 'W';
-                       }
-               } else {
-                       if ($this->info->isCreatable()) {
-                               $p .= 'CK';
-                       }
-               }
-               return $p;
+               return \OCP\Util::getDavPermissions($this->info);
        }
 
        public function getOwner() {
index 2cfcb3f5393754791ac70b5506cd3ca4a012bb78..f98dba229256d4e18613078df2adb5cef50517a6 100644 (file)
@@ -313,7 +313,10 @@ class Server {
                                                $view
                                        ));
                                        $this->server->addPlugin(
-                                               new BulkUploadPlugin($userFolder, $logger)
+                                               new BulkUploadPlugin(
+                                                       $userFolder,
+                                                       $logger
+                                               )
                                        );
                                }
                                $this->server->addPlugin(new \OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin(
index 6cd3eaa7f8551e37f561690ea1bab5a9fcc01be7..ad8818df3ca8a3659408bb853203f31411d3e291 100644 (file)
@@ -628,4 +628,45 @@ class Util {
                }
                return true;
        }
+
+       /**
+        * @param int $id Id of the file returned by FileInfo::getId
+        */
+       public static function getDavFileId(int $id): string {
+               $instanceId = \OC_Util::getInstanceId();
+               $id = sprintf('%08d', $id);
+               return $id . $instanceId;
+       }
+
+       public static function getDavPermissions(\OCP\Files\FileInfo $info): string {
+               $p = '';
+               if ($info->isShared()) {
+                       $p .= 'S';
+               }
+               if ($info->isShareable()) {
+                       $p .= 'R';
+               }
+               if ($info->isMounted()) {
+                       $p .= 'M';
+               }
+               if ($info->isReadable()) {
+                       $p .= 'G';
+               }
+               if ($info->isDeletable()) {
+                       $p .= 'D';
+               }
+               if ($info->isUpdateable()) {
+                       $p .= 'NV'; // Renameable, Moveable
+               }
+               if ($info->getType() === \OCP\Files\FileInfo::TYPE_FILE) {
+                       if ($info->isUpdateable()) {
+                               $p .= 'W';
+                       }
+               } else {
+                       if ($info->isCreatable()) {
+                               $p .= 'CK';
+                       }
+               }
+               return $p;
+       }
 }