|
9 | 9 | namespace OCA\Richdocuments; |
10 | 10 |
|
11 | 11 | use OCP\Constants; |
| 12 | +use OCP\Files\Cache\ICacheEntry; |
12 | 13 | use OCP\Files\Node; |
13 | 14 | use OCP\IConfig; |
14 | 15 | use OCP\IGroupManager; |
@@ -112,18 +113,19 @@ public function userIsFeatureLocked(?string $userId = null): bool { |
112 | 113 | return false; |
113 | 114 | } |
114 | 115 |
|
115 | | - public function shouldWatermark(Node $node, ?string $userId = null, ?IShare $share = null): bool { |
| 116 | + public function shouldWatermark(Node|ICacheEntry $nodeOrCacheEntry, ?string $userId = null, ?IShare $share = null, ?string $ownerId = null): bool { |
116 | 117 | if ($this->config->getAppValue(AppConfig::WATERMARK_APP_NAMESPACE, 'watermark_enabled', 'no') === 'no') { |
117 | 118 | return false; |
118 | 119 | } |
119 | 120 |
|
120 | | - if (!in_array($node->getMimetype(), $this->appConfig->getMimeTypes(), true)) { |
| 121 | + if (!in_array($nodeOrCacheEntry->getMimetype(), $this->appConfig->getMimeTypes(), true)) { |
121 | 122 | return false; |
122 | 123 | } |
123 | 124 |
|
124 | | - $fileId = $node->getId(); |
125 | | - |
126 | | - $isUpdatable = $node->isUpdateable() && (!$share || $share->getPermissions() & Constants::PERMISSION_UPDATE); |
| 125 | + $isUpdatable = $nodeOrCacheEntry instanceof Node |
| 126 | + ? $nodeOrCacheEntry->isUpdateable() |
| 127 | + : $nodeOrCacheEntry->getPermissions() & Constants::PERMISSION_UPDATE; |
| 128 | + $isUpdatable = $isUpdatable && (!$share || $share->getPermissions() & Constants::PERMISSION_UPDATE); |
127 | 129 |
|
128 | 130 | $hasShareAttributes = $share && method_exists($share, 'getAttributes') && $share->getAttributes() instanceof IAttributes; |
129 | 131 | $isDisabledDownload = $hasShareAttributes && $share->getAttributes()->getAttribute('permissions', 'download') === false; |
@@ -153,7 +155,10 @@ public function shouldWatermark(Node $node, ?string $userId = null, ?IShare $sha |
153 | 155 | } |
154 | 156 |
|
155 | 157 | if ($this->config->getAppValue(AppConfig::WATERMARK_APP_NAMESPACE, 'watermark_shareAll', 'no') === 'yes') { |
156 | | - if ($userId === null || $node->getOwner()?->getUID() !== $userId) { |
| 158 | + if (!$ownerId && $nodeOrCacheEntry instanceof Node) { |
| 159 | + $ownerId = $nodeOrCacheEntry->getOwner()?->getUID(); |
| 160 | + } |
| 161 | + if ($userId === null || $ownerId !== $userId) { |
157 | 162 | return true; |
158 | 163 | } |
159 | 164 | } |
|
0 commit comments