|
8 | 8 |
|
9 | 9 | namespace OCA\DAV\DAV; |
10 | 10 |
|
| 11 | +use OCA\DAV\Connector\Sabre\Directory; |
11 | 12 | use OCA\DAV\Connector\Sabre\Exception\Forbidden; |
12 | 13 | use OCA\DAV\Connector\Sabre\File as DavFile; |
13 | 14 | use OCA\Files_Versions\Sabre\VersionFile; |
@@ -79,30 +80,37 @@ public function checkViewOnly(RequestInterface $request): bool { |
79 | 80 | } |
80 | 81 |
|
81 | 82 | $storage = $node->getStorage(); |
82 | | - |
83 | 83 | if (!$storage->instanceOfStorage(ISharedStorage::class)) { |
84 | 84 | return true; |
85 | 85 | } |
86 | 86 |
|
87 | | - // Extract extra permissions |
88 | 87 | /** @var ISharedStorage $storage */ |
89 | 88 | $share = $storage->getShare(); |
90 | | - $attributes = $share->getAttributes(); |
91 | | - if ($attributes === null) { |
92 | | - return true; |
93 | | - } |
94 | | - |
95 | | - // We have two options here, if download is disabled, but viewing is allowed, |
96 | | - // we still allow the GET request to return the file content. |
97 | | - $canDownload = $attributes->getAttribute('permissions', 'download'); |
98 | | - if (!$share->canSeeContent()) { |
99 | | - throw new Forbidden('Access to this shared resource has been denied because its download permission is disabled.'); |
100 | | - } |
| 89 | + switch ($request->getMethod()) { |
| 90 | + case 'GET': |
| 91 | + // If download is disabled, but viewing is allowed, we still allow the GET method to return the file content. |
| 92 | + if (!$share->canSeeContent()) { |
| 93 | + throw new Forbidden('Access to this shared resource has been denied because its download permission is disabled.'); |
| 94 | + } |
| 95 | + break; |
| 96 | + case 'COPY': |
| 97 | + case 'MOVE': |
| 98 | + $destinationPath = $this->server->getCopyAndMoveInfo($request)['destination']; |
| 99 | + $destinationParentPath = dirname($destinationPath); |
| 100 | + if ($destinationParentPath === '.') { |
| 101 | + $destinationParentPath = ''; |
| 102 | + } |
| 103 | + $destinationParent = $this->server->tree->getNodeForPath($destinationParentPath); |
| 104 | + // Copy and move operations within the same storage are allowed, because the destination has the same restrictions. |
| 105 | + if (($destinationParent instanceof Directory) && $destinationParent->getNode()->getStorage()->getId() === $storage->getId()) { |
| 106 | + break; |
| 107 | + } |
101 | 108 |
|
102 | | - // If download is disabled, we disable the COPY and MOVE methods even if the |
103 | | - // shareapi_allow_view_without_download is set to true. |
104 | | - if ($request->getMethod() !== 'GET' && ($canDownload !== null && !$canDownload)) { |
105 | | - throw new Forbidden('Access to this shared resource has been denied because its download permission is disabled.'); |
| 109 | + // If download is disabled, we disable the COPY and MOVE methods even if the shareapi_allow_view_without_download is set to true. |
| 110 | + if (!$share->canDownload()) { |
| 111 | + throw new Forbidden('Access to this shared resource has been denied because its download permission is disabled.'); |
| 112 | + } |
| 113 | + break; |
106 | 114 | } |
107 | 115 | } catch (NotFound $e) { |
108 | 116 | // File not found |
|
0 commit comments