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