|
39 | 39 | use OCP\AppFramework\OCSController; |
40 | 40 | use OCP\AppFramework\QueryException; |
41 | 41 | use OCP\Constants; |
42 | | -use OCP\Files\Folder; |
43 | 42 | use OCP\Files\Node; |
44 | 43 | use OCP\Files\NotFoundException; |
45 | 44 | use OCP\IConfig; |
@@ -242,6 +241,9 @@ protected function formatShare(\OCP\Share\IShare $share, Node $recipientNode = n |
242 | 241 |
|
243 | 242 | $shareWithStart = ($hasCircleId? strrpos($share->getSharedWith(), '[') + 1: 0); |
244 | 243 | $shareWithLength = ($hasCircleId? -1: strpos($share->getSharedWith(), ' ')); |
| 244 | + if (is_bool($shareWithLength)) { |
| 245 | + $shareWithLength = -1; |
| 246 | + } |
245 | 247 | $result['share_with'] = substr($share->getSharedWith(), $shareWithStart, $shareWithLength); |
246 | 248 | } else if ($share->getShareType() === Share::SHARE_TYPE_ROOM) { |
247 | 249 | $result['share_with'] = $share->getSharedWith(); |
@@ -730,15 +732,29 @@ public function getShares( |
730 | 732 | $shares = array_merge($shares, $federatedShares); |
731 | 733 | } |
732 | 734 |
|
733 | | - $formatted = []; |
| 735 | + $formatted = $miniFormatted = []; |
| 736 | + $resharingRight = false; |
734 | 737 | foreach ($shares as $share) { |
| 738 | + /** @var IShare $share */ |
735 | 739 | try { |
736 | | - $formatted[] = $this->formatShare($share, $path); |
737 | | - } catch (NotFoundException $e) { |
| 740 | + $format = $this->formatShare($share, $path); |
| 741 | + $formatted[] = $format; |
| 742 | + if ($share->getSharedBy() === $this->currentUser) { |
| 743 | + $miniFormatted[] = $format; |
| 744 | + } |
| 745 | + |
| 746 | + if (!$resharingRight && $this->shareProviderResharingRights($this->currentUser, $share, $path)) { |
| 747 | + $resharingRight = true; |
| 748 | + } |
| 749 | + } catch (\Exception $e) { |
738 | 750 | //Ignore share |
739 | 751 | } |
740 | 752 | } |
741 | 753 |
|
| 754 | + if (!$resharingRight) { |
| 755 | + $formatted = $miniFormatted; |
| 756 | + } |
| 757 | + |
742 | 758 | if ($include_tags) { |
743 | 759 | $formatted = Helper::populateTags($formatted, 'file_source', \OC::$server->getTagManager()); |
744 | 760 | } |
@@ -1122,4 +1138,64 @@ private function getRoomShareHelper() { |
1122 | 1138 |
|
1123 | 1139 | return $this->serverContainer->query('\OCA\Spreed\Share\Helper\ShareAPIController'); |
1124 | 1140 | } |
| 1141 | + |
| 1142 | + |
| 1143 | + /** |
| 1144 | + * Returns if we can find resharing rights in an IShare object for a specific user. |
| 1145 | + * |
| 1146 | + * @suppress PhanUndeclaredClassMethod |
| 1147 | + * |
| 1148 | + * @param string $userId |
| 1149 | + * @param IShare $share |
| 1150 | + * @param Node $node |
| 1151 | + * @return bool |
| 1152 | + * @throws NotFoundException |
| 1153 | + * @throws \OCP\Files\InvalidPathException |
| 1154 | + */ |
| 1155 | + private function shareProviderResharingRights(string $userId, IShare $share, $node): bool { |
| 1156 | + |
| 1157 | + if ($share->getShareOwner() === $userId) { |
| 1158 | + return true; |
| 1159 | + } |
| 1160 | + |
| 1161 | + // we check that current user have parent resharing rights on the current file |
| 1162 | + if ($node !== null && ($node->getPermissions() & \OCP\Constants::PERMISSION_SHARE) !== 0) { |
| 1163 | + return true; |
| 1164 | + } |
| 1165 | + |
| 1166 | + if ((\OCP\Constants::PERMISSION_SHARE & $share->getPermissions()) === 0) { |
| 1167 | + return false; |
| 1168 | + } |
| 1169 | + |
| 1170 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && $share->getSharedWith() === $userId) { |
| 1171 | + return true; |
| 1172 | + } |
| 1173 | + |
| 1174 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP && $this->groupManager->isInGroup($userId, $share->getSharedWith())) { |
| 1175 | + return true; |
| 1176 | + } |
| 1177 | + |
| 1178 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE && \OC::$server->getAppManager()->isEnabledForUser('circles') && |
| 1179 | + class_exists('\OCA\Circles\Api\v1\Circles')) { |
| 1180 | + $hasCircleId = (substr($share->getSharedWith(), -1) === ']'); |
| 1181 | + $shareWithStart = ($hasCircleId ? strrpos($share->getSharedWith(), '[') + 1 : 0); |
| 1182 | + $shareWithLength = ($hasCircleId ? -1 : strpos($share->getSharedWith(), ' ')); |
| 1183 | + if (is_bool($shareWithLength)) { |
| 1184 | + $shareWithLength = -1; |
| 1185 | + } |
| 1186 | + $sharedWith = substr($share->getSharedWith(), $shareWithStart, $shareWithLength); |
| 1187 | + try { |
| 1188 | + $member = \OCA\Circles\Api\v1\Circles::getMember($sharedWith, $userId, 1); |
| 1189 | + if ($member->getLevel() >= 4) { |
| 1190 | + return true; |
| 1191 | + } |
| 1192 | + return false; |
| 1193 | + } catch (QueryException $e) { |
| 1194 | + return false; |
| 1195 | + } |
| 1196 | + } |
| 1197 | + |
| 1198 | + return false; |
| 1199 | + } |
| 1200 | + |
1125 | 1201 | } |
0 commit comments