@@ -32,76 +32,76 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | interface ICloudFederationProviderManager { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Registers an callback function which must return an cloud federation provider |
|
| 37 | - * |
|
| 38 | - * @param string $resourceType which resource type does the provider handles |
|
| 39 | - * @param string $displayName user facing name of the federated share provider |
|
| 40 | - * @param callable $callback |
|
| 41 | - * @throws Exceptions\ProviderAlreadyExistsException |
|
| 42 | - * |
|
| 43 | - * @since 14.0.0 |
|
| 44 | - */ |
|
| 45 | - public function addCloudFederationProvider($resourceType, $displayName, callable $callback); |
|
| 35 | + /** |
|
| 36 | + * Registers an callback function which must return an cloud federation provider |
|
| 37 | + * |
|
| 38 | + * @param string $resourceType which resource type does the provider handles |
|
| 39 | + * @param string $displayName user facing name of the federated share provider |
|
| 40 | + * @param callable $callback |
|
| 41 | + * @throws Exceptions\ProviderAlreadyExistsException |
|
| 42 | + * |
|
| 43 | + * @since 14.0.0 |
|
| 44 | + */ |
|
| 45 | + public function addCloudFederationProvider($resourceType, $displayName, callable $callback); |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * remove cloud federation provider |
|
| 49 | - * |
|
| 50 | - * @param string $resourceType |
|
| 51 | - * |
|
| 52 | - * @since 14.0.0 |
|
| 53 | - */ |
|
| 54 | - public function removeCloudFederationProvider($resourceType); |
|
| 47 | + /** |
|
| 48 | + * remove cloud federation provider |
|
| 49 | + * |
|
| 50 | + * @param string $resourceType |
|
| 51 | + * |
|
| 52 | + * @since 14.0.0 |
|
| 53 | + */ |
|
| 54 | + public function removeCloudFederationProvider($resourceType); |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * get a list of all cloudFederationProviders |
|
| 58 | - * |
|
| 59 | - * @return array [resourceType => ['resourceType' => $resourceType, 'displayName' => $displayName, 'callback' => callback]] |
|
| 60 | - * |
|
| 61 | - * @since 14.0.0 |
|
| 62 | - */ |
|
| 63 | - public function getAllCloudFederationProviders(); |
|
| 56 | + /** |
|
| 57 | + * get a list of all cloudFederationProviders |
|
| 58 | + * |
|
| 59 | + * @return array [resourceType => ['resourceType' => $resourceType, 'displayName' => $displayName, 'callback' => callback]] |
|
| 60 | + * |
|
| 61 | + * @since 14.0.0 |
|
| 62 | + */ |
|
| 63 | + public function getAllCloudFederationProviders(); |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * get a specific cloud federation provider |
|
| 67 | - * |
|
| 68 | - * @param string $resourceType |
|
| 69 | - * @return ICloudFederationProvider |
|
| 70 | - * @throws Exceptions\ProviderDoesNotExistsException; |
|
| 71 | - * |
|
| 72 | - * @since 14.0.0 |
|
| 73 | - */ |
|
| 74 | - public function getCloudFederationProvider($resourceType); |
|
| 65 | + /** |
|
| 66 | + * get a specific cloud federation provider |
|
| 67 | + * |
|
| 68 | + * @param string $resourceType |
|
| 69 | + * @return ICloudFederationProvider |
|
| 70 | + * @throws Exceptions\ProviderDoesNotExistsException; |
|
| 71 | + * |
|
| 72 | + * @since 14.0.0 |
|
| 73 | + */ |
|
| 74 | + public function getCloudFederationProvider($resourceType); |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * send federated share |
|
| 78 | - * |
|
| 79 | - * @param ICloudFederationShare $share |
|
| 80 | - * @return mixed |
|
| 81 | - * |
|
| 82 | - * @since 14.0.0 |
|
| 83 | - */ |
|
| 84 | - public function sendShare(ICloudFederationShare $share); |
|
| 76 | + /** |
|
| 77 | + * send federated share |
|
| 78 | + * |
|
| 79 | + * @param ICloudFederationShare $share |
|
| 80 | + * @return mixed |
|
| 81 | + * |
|
| 82 | + * @since 14.0.0 |
|
| 83 | + */ |
|
| 84 | + public function sendShare(ICloudFederationShare $share); |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * send notification about existing share |
|
| 88 | - * |
|
| 89 | - * @param string $url |
|
| 90 | - * @param ICloudFederationNotification $notification |
|
| 91 | - * @return mixed |
|
| 92 | - * |
|
| 93 | - * @since 14.0.0 |
|
| 94 | - */ |
|
| 95 | - public function sendNotification($url, ICloudFederationNotification $notification); |
|
| 86 | + /** |
|
| 87 | + * send notification about existing share |
|
| 88 | + * |
|
| 89 | + * @param string $url |
|
| 90 | + * @param ICloudFederationNotification $notification |
|
| 91 | + * @return mixed |
|
| 92 | + * |
|
| 93 | + * @since 14.0.0 |
|
| 94 | + */ |
|
| 95 | + public function sendNotification($url, ICloudFederationNotification $notification); |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * check if the new cloud federation API is ready to be used |
|
| 99 | - * |
|
| 100 | - * @return bool |
|
| 101 | - * |
|
| 102 | - * @since 14.0.0 |
|
| 103 | - */ |
|
| 104 | - public function isReady(); |
|
| 97 | + /** |
|
| 98 | + * check if the new cloud federation API is ready to be used |
|
| 99 | + * |
|
| 100 | + * @return bool |
|
| 101 | + * |
|
| 102 | + * @since 14.0.0 |
|
| 103 | + */ |
|
| 104 | + public function isReady(); |
|
| 105 | 105 | |
| 106 | 106 | |
| 107 | 107 | } |
@@ -25,332 +25,332 @@ |
||
| 25 | 25 | |
| 26 | 26 | class CloudFederationShare implements ICloudFederationShare { |
| 27 | 27 | |
| 28 | - private $share = [ |
|
| 29 | - 'shareWith' => '', |
|
| 30 | - 'shareType' => '', |
|
| 31 | - 'name' => '', |
|
| 32 | - 'resourceType' => '', |
|
| 33 | - 'description' => '', |
|
| 34 | - 'providerId' => '', |
|
| 35 | - 'owner' => '', |
|
| 36 | - 'ownerDisplayName' => '', |
|
| 37 | - 'sharedBy' => '', |
|
| 38 | - 'sharedByDisplayName' => '', |
|
| 39 | - 'protocol' => [] |
|
| 40 | - ]; |
|
| 28 | + private $share = [ |
|
| 29 | + 'shareWith' => '', |
|
| 30 | + 'shareType' => '', |
|
| 31 | + 'name' => '', |
|
| 32 | + 'resourceType' => '', |
|
| 33 | + 'description' => '', |
|
| 34 | + 'providerId' => '', |
|
| 35 | + 'owner' => '', |
|
| 36 | + 'ownerDisplayName' => '', |
|
| 37 | + 'sharedBy' => '', |
|
| 38 | + 'sharedByDisplayName' => '', |
|
| 39 | + 'protocol' => [] |
|
| 40 | + ]; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * get a CloudFederationShare Object to prepare a share you want to send |
|
| 44 | - * |
|
| 45 | - * @param string $shareWith |
|
| 46 | - * @param string $name resource name (e.g. document.odt) |
|
| 47 | - * @param string $description share description (optional) |
|
| 48 | - * @param string $providerId resource UID on the provider side |
|
| 49 | - * @param string $owner provider specific UID of the user who owns the resource |
|
| 50 | - * @param string $ownerDisplayName display name of the user who shared the item |
|
| 51 | - * @param string $sharedBy provider specific UID of the user who shared the resource |
|
| 52 | - * @param string $sharedByDisplayName display name of the user who shared the resource |
|
| 53 | - * @param string $shareType ('group' or 'user' share) |
|
| 54 | - * @param string $resourceType ('file', 'calendar',...) |
|
| 55 | - * @param string $sharedSecret |
|
| 56 | - */ |
|
| 57 | - public function __construct($shareWith = '', |
|
| 58 | - $name = '', |
|
| 59 | - $description = '', |
|
| 60 | - $providerId = '', |
|
| 61 | - $owner = '', |
|
| 62 | - $ownerDisplayName = '', |
|
| 63 | - $sharedBy = '', |
|
| 64 | - $sharedByDisplayName = '', |
|
| 65 | - $shareType = '', |
|
| 66 | - $resourceType = '', |
|
| 67 | - $sharedSecret = '' |
|
| 68 | - ) { |
|
| 69 | - $this->setShareWith($shareWith); |
|
| 70 | - $this->setResourceName($name); |
|
| 71 | - $this->setDescription($description); |
|
| 72 | - $this->setProviderId($providerId); |
|
| 73 | - $this->setOwner($owner); |
|
| 74 | - $this->setOwnerDisplayName($ownerDisplayName); |
|
| 75 | - $this->setSharedBy($sharedBy); |
|
| 76 | - $this->setSharedByDisplayName($sharedByDisplayName); |
|
| 77 | - $this->setProtocol([ |
|
| 78 | - 'name' => 'webdav', |
|
| 79 | - 'options' => [ |
|
| 80 | - 'sharedSecret' => $sharedSecret, |
|
| 81 | - 'permissions' => '{http://open-cloud-mesh.org/ns}share-permissions' |
|
| 82 | - ] |
|
| 83 | - ]); |
|
| 84 | - $this->setShareType($shareType); |
|
| 85 | - $this->setResourceType($resourceType); |
|
| 42 | + /** |
|
| 43 | + * get a CloudFederationShare Object to prepare a share you want to send |
|
| 44 | + * |
|
| 45 | + * @param string $shareWith |
|
| 46 | + * @param string $name resource name (e.g. document.odt) |
|
| 47 | + * @param string $description share description (optional) |
|
| 48 | + * @param string $providerId resource UID on the provider side |
|
| 49 | + * @param string $owner provider specific UID of the user who owns the resource |
|
| 50 | + * @param string $ownerDisplayName display name of the user who shared the item |
|
| 51 | + * @param string $sharedBy provider specific UID of the user who shared the resource |
|
| 52 | + * @param string $sharedByDisplayName display name of the user who shared the resource |
|
| 53 | + * @param string $shareType ('group' or 'user' share) |
|
| 54 | + * @param string $resourceType ('file', 'calendar',...) |
|
| 55 | + * @param string $sharedSecret |
|
| 56 | + */ |
|
| 57 | + public function __construct($shareWith = '', |
|
| 58 | + $name = '', |
|
| 59 | + $description = '', |
|
| 60 | + $providerId = '', |
|
| 61 | + $owner = '', |
|
| 62 | + $ownerDisplayName = '', |
|
| 63 | + $sharedBy = '', |
|
| 64 | + $sharedByDisplayName = '', |
|
| 65 | + $shareType = '', |
|
| 66 | + $resourceType = '', |
|
| 67 | + $sharedSecret = '' |
|
| 68 | + ) { |
|
| 69 | + $this->setShareWith($shareWith); |
|
| 70 | + $this->setResourceName($name); |
|
| 71 | + $this->setDescription($description); |
|
| 72 | + $this->setProviderId($providerId); |
|
| 73 | + $this->setOwner($owner); |
|
| 74 | + $this->setOwnerDisplayName($ownerDisplayName); |
|
| 75 | + $this->setSharedBy($sharedBy); |
|
| 76 | + $this->setSharedByDisplayName($sharedByDisplayName); |
|
| 77 | + $this->setProtocol([ |
|
| 78 | + 'name' => 'webdav', |
|
| 79 | + 'options' => [ |
|
| 80 | + 'sharedSecret' => $sharedSecret, |
|
| 81 | + 'permissions' => '{http://open-cloud-mesh.org/ns}share-permissions' |
|
| 82 | + ] |
|
| 83 | + ]); |
|
| 84 | + $this->setShareType($shareType); |
|
| 85 | + $this->setResourceType($resourceType); |
|
| 86 | 86 | |
| 87 | - } |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * set uid of the recipient |
|
| 91 | - * |
|
| 92 | - * @param string $user |
|
| 93 | - * |
|
| 94 | - * @since 14.0.0 |
|
| 95 | - */ |
|
| 96 | - public function setShareWith($user) { |
|
| 97 | - $this->share['shareWith'] = $user; |
|
| 98 | - } |
|
| 89 | + /** |
|
| 90 | + * set uid of the recipient |
|
| 91 | + * |
|
| 92 | + * @param string $user |
|
| 93 | + * |
|
| 94 | + * @since 14.0.0 |
|
| 95 | + */ |
|
| 96 | + public function setShareWith($user) { |
|
| 97 | + $this->share['shareWith'] = $user; |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * set resource name (e.g. document.odt) |
|
| 102 | - * |
|
| 103 | - * @param string $name |
|
| 104 | - * |
|
| 105 | - * @since 14.0.0 |
|
| 106 | - */ |
|
| 107 | - public function setResourceName($name) { |
|
| 108 | - $this->share['name'] = $name; |
|
| 109 | - } |
|
| 100 | + /** |
|
| 101 | + * set resource name (e.g. document.odt) |
|
| 102 | + * |
|
| 103 | + * @param string $name |
|
| 104 | + * |
|
| 105 | + * @since 14.0.0 |
|
| 106 | + */ |
|
| 107 | + public function setResourceName($name) { |
|
| 108 | + $this->share['name'] = $name; |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * set resource type (e.g. file, calendar, contact,...) |
|
| 113 | - * |
|
| 114 | - * @param string $resourceType |
|
| 115 | - * |
|
| 116 | - * @since 14.0.0 |
|
| 117 | - */ |
|
| 118 | - public function setResourceType($resourceType) { |
|
| 119 | - $this->share['resourceType'] = $resourceType; |
|
| 120 | - } |
|
| 111 | + /** |
|
| 112 | + * set resource type (e.g. file, calendar, contact,...) |
|
| 113 | + * |
|
| 114 | + * @param string $resourceType |
|
| 115 | + * |
|
| 116 | + * @since 14.0.0 |
|
| 117 | + */ |
|
| 118 | + public function setResourceType($resourceType) { |
|
| 119 | + $this->share['resourceType'] = $resourceType; |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * set resource description (optional) |
|
| 124 | - * |
|
| 125 | - * @param string $description |
|
| 126 | - * |
|
| 127 | - * @since 14.0.0 |
|
| 128 | - */ |
|
| 129 | - public function setDescription($description) { |
|
| 130 | - $this->share['description'] = $description; |
|
| 131 | - } |
|
| 122 | + /** |
|
| 123 | + * set resource description (optional) |
|
| 124 | + * |
|
| 125 | + * @param string $description |
|
| 126 | + * |
|
| 127 | + * @since 14.0.0 |
|
| 128 | + */ |
|
| 129 | + public function setDescription($description) { |
|
| 130 | + $this->share['description'] = $description; |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * set provider ID (e.g. file ID) |
|
| 135 | - * |
|
| 136 | - * @param string $providerId |
|
| 137 | - * |
|
| 138 | - * @since 14.0.0 |
|
| 139 | - */ |
|
| 140 | - public function setProviderId($providerId) { |
|
| 141 | - $this->share['providerId'] = $providerId; |
|
| 142 | - } |
|
| 133 | + /** |
|
| 134 | + * set provider ID (e.g. file ID) |
|
| 135 | + * |
|
| 136 | + * @param string $providerId |
|
| 137 | + * |
|
| 138 | + * @since 14.0.0 |
|
| 139 | + */ |
|
| 140 | + public function setProviderId($providerId) { |
|
| 141 | + $this->share['providerId'] = $providerId; |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * set owner UID |
|
| 146 | - * |
|
| 147 | - * @param string $owner |
|
| 148 | - * |
|
| 149 | - * @since 14.0.0 |
|
| 150 | - */ |
|
| 151 | - public function setOwner($owner) { |
|
| 152 | - $this->share['owner'] = $owner; |
|
| 153 | - } |
|
| 144 | + /** |
|
| 145 | + * set owner UID |
|
| 146 | + * |
|
| 147 | + * @param string $owner |
|
| 148 | + * |
|
| 149 | + * @since 14.0.0 |
|
| 150 | + */ |
|
| 151 | + public function setOwner($owner) { |
|
| 152 | + $this->share['owner'] = $owner; |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - /** |
|
| 156 | - * set owner display name |
|
| 157 | - * |
|
| 158 | - * @param string $ownerDisplayName |
|
| 159 | - * |
|
| 160 | - * @since 14.0.0 |
|
| 161 | - */ |
|
| 162 | - public function setOwnerDisplayName($ownerDisplayName) { |
|
| 163 | - $this->share['ownerDisplayName'] = $ownerDisplayName; |
|
| 164 | - } |
|
| 155 | + /** |
|
| 156 | + * set owner display name |
|
| 157 | + * |
|
| 158 | + * @param string $ownerDisplayName |
|
| 159 | + * |
|
| 160 | + * @since 14.0.0 |
|
| 161 | + */ |
|
| 162 | + public function setOwnerDisplayName($ownerDisplayName) { |
|
| 163 | + $this->share['ownerDisplayName'] = $ownerDisplayName; |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * set UID of the user who sends the share |
|
| 168 | - * |
|
| 169 | - * @param string $sharedBy |
|
| 170 | - * |
|
| 171 | - * @since 14.0.0 |
|
| 172 | - */ |
|
| 173 | - public function setSharedBy($sharedBy) { |
|
| 174 | - $this->share['sharedBy'] = $sharedBy; |
|
| 175 | - } |
|
| 166 | + /** |
|
| 167 | + * set UID of the user who sends the share |
|
| 168 | + * |
|
| 169 | + * @param string $sharedBy |
|
| 170 | + * |
|
| 171 | + * @since 14.0.0 |
|
| 172 | + */ |
|
| 173 | + public function setSharedBy($sharedBy) { |
|
| 174 | + $this->share['sharedBy'] = $sharedBy; |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * set display name of the user who sends the share |
|
| 179 | - * |
|
| 180 | - * @param $sharedByDisplayName |
|
| 181 | - * |
|
| 182 | - * @since 14.0.0 |
|
| 183 | - */ |
|
| 184 | - public function setSharedByDisplayName($sharedByDisplayName) { |
|
| 185 | - $this->share['sharedByDisplayName'] = $sharedByDisplayName; |
|
| 186 | - } |
|
| 177 | + /** |
|
| 178 | + * set display name of the user who sends the share |
|
| 179 | + * |
|
| 180 | + * @param $sharedByDisplayName |
|
| 181 | + * |
|
| 182 | + * @since 14.0.0 |
|
| 183 | + */ |
|
| 184 | + public function setSharedByDisplayName($sharedByDisplayName) { |
|
| 185 | + $this->share['sharedByDisplayName'] = $sharedByDisplayName; |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | - /** |
|
| 189 | - * set protocol specification |
|
| 190 | - * |
|
| 191 | - * @param array $protocol |
|
| 192 | - * |
|
| 193 | - * @since 14.0.0 |
|
| 194 | - */ |
|
| 195 | - public function setProtocol(array $protocol) { |
|
| 196 | - $this->share['protocol'] = $protocol; |
|
| 197 | - } |
|
| 188 | + /** |
|
| 189 | + * set protocol specification |
|
| 190 | + * |
|
| 191 | + * @param array $protocol |
|
| 192 | + * |
|
| 193 | + * @since 14.0.0 |
|
| 194 | + */ |
|
| 195 | + public function setProtocol(array $protocol) { |
|
| 196 | + $this->share['protocol'] = $protocol; |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - /** |
|
| 200 | - * share type (group or user) |
|
| 201 | - * |
|
| 202 | - * @param string $shareType |
|
| 203 | - * |
|
| 204 | - * @since 14.0.0 |
|
| 205 | - */ |
|
| 206 | - public function setShareType($shareType) { |
|
| 207 | - if ($shareType === 'group' || $shareType === \OCP\Share::SHARE_TYPE_REMOTE_GROUP) { |
|
| 208 | - $this->share['shareType'] = 'group'; |
|
| 209 | - } else { |
|
| 210 | - $this->share['shareType'] = 'user'; |
|
| 211 | - } |
|
| 212 | - } |
|
| 199 | + /** |
|
| 200 | + * share type (group or user) |
|
| 201 | + * |
|
| 202 | + * @param string $shareType |
|
| 203 | + * |
|
| 204 | + * @since 14.0.0 |
|
| 205 | + */ |
|
| 206 | + public function setShareType($shareType) { |
|
| 207 | + if ($shareType === 'group' || $shareType === \OCP\Share::SHARE_TYPE_REMOTE_GROUP) { |
|
| 208 | + $this->share['shareType'] = 'group'; |
|
| 209 | + } else { |
|
| 210 | + $this->share['shareType'] = 'user'; |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | - /** |
|
| 215 | - * get the whole share, ready to send out |
|
| 216 | - * |
|
| 217 | - * @return array |
|
| 218 | - * |
|
| 219 | - * @since 14.0.0 |
|
| 220 | - */ |
|
| 221 | - public function getShare() { |
|
| 222 | - return $this->share; |
|
| 223 | - } |
|
| 214 | + /** |
|
| 215 | + * get the whole share, ready to send out |
|
| 216 | + * |
|
| 217 | + * @return array |
|
| 218 | + * |
|
| 219 | + * @since 14.0.0 |
|
| 220 | + */ |
|
| 221 | + public function getShare() { |
|
| 222 | + return $this->share; |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - /** |
|
| 226 | - * get uid of the recipient |
|
| 227 | - * |
|
| 228 | - * @return string |
|
| 229 | - * |
|
| 230 | - * @since 14.0.0 |
|
| 231 | - */ |
|
| 232 | - public function getShareWith() { |
|
| 233 | - return $this->share['shareWith']; |
|
| 234 | - } |
|
| 225 | + /** |
|
| 226 | + * get uid of the recipient |
|
| 227 | + * |
|
| 228 | + * @return string |
|
| 229 | + * |
|
| 230 | + * @since 14.0.0 |
|
| 231 | + */ |
|
| 232 | + public function getShareWith() { |
|
| 233 | + return $this->share['shareWith']; |
|
| 234 | + } |
|
| 235 | 235 | |
| 236 | - /** |
|
| 237 | - * get resource name (e.g. file, calendar, contact,...) |
|
| 238 | - * |
|
| 239 | - * @return string |
|
| 240 | - * |
|
| 241 | - * @since 14.0.0 |
|
| 242 | - */ |
|
| 243 | - public function getResourceName() { |
|
| 244 | - return $this->share['name']; |
|
| 245 | - } |
|
| 236 | + /** |
|
| 237 | + * get resource name (e.g. file, calendar, contact,...) |
|
| 238 | + * |
|
| 239 | + * @return string |
|
| 240 | + * |
|
| 241 | + * @since 14.0.0 |
|
| 242 | + */ |
|
| 243 | + public function getResourceName() { |
|
| 244 | + return $this->share['name']; |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | - /** |
|
| 248 | - * get resource type (e.g. file, calendar, contact,...) |
|
| 249 | - * |
|
| 250 | - * @return string |
|
| 251 | - * |
|
| 252 | - * @since 14.0.0 |
|
| 253 | - */ |
|
| 254 | - public function getResourceType() { |
|
| 255 | - return $this->share['resourceType']; |
|
| 256 | - } |
|
| 247 | + /** |
|
| 248 | + * get resource type (e.g. file, calendar, contact,...) |
|
| 249 | + * |
|
| 250 | + * @return string |
|
| 251 | + * |
|
| 252 | + * @since 14.0.0 |
|
| 253 | + */ |
|
| 254 | + public function getResourceType() { |
|
| 255 | + return $this->share['resourceType']; |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | - /** |
|
| 259 | - * get resource description (optional) |
|
| 260 | - * |
|
| 261 | - * @return string |
|
| 262 | - * |
|
| 263 | - * @since 14.0.0 |
|
| 264 | - */ |
|
| 265 | - public function getDescription() { |
|
| 266 | - return $this->share['description']; |
|
| 267 | - } |
|
| 258 | + /** |
|
| 259 | + * get resource description (optional) |
|
| 260 | + * |
|
| 261 | + * @return string |
|
| 262 | + * |
|
| 263 | + * @since 14.0.0 |
|
| 264 | + */ |
|
| 265 | + public function getDescription() { |
|
| 266 | + return $this->share['description']; |
|
| 267 | + } |
|
| 268 | 268 | |
| 269 | - /** |
|
| 270 | - * get provider ID (e.g. file ID) |
|
| 271 | - * |
|
| 272 | - * @return string |
|
| 273 | - * |
|
| 274 | - * @since 14.0.0 |
|
| 275 | - */ |
|
| 276 | - public function getProviderId() { |
|
| 277 | - return $this->share['providerId']; |
|
| 278 | - } |
|
| 269 | + /** |
|
| 270 | + * get provider ID (e.g. file ID) |
|
| 271 | + * |
|
| 272 | + * @return string |
|
| 273 | + * |
|
| 274 | + * @since 14.0.0 |
|
| 275 | + */ |
|
| 276 | + public function getProviderId() { |
|
| 277 | + return $this->share['providerId']; |
|
| 278 | + } |
|
| 279 | 279 | |
| 280 | - /** |
|
| 281 | - * get owner UID |
|
| 282 | - * |
|
| 283 | - * @return string |
|
| 284 | - * |
|
| 285 | - * @since 14.0.0 |
|
| 286 | - */ |
|
| 287 | - public function getOwner() { |
|
| 288 | - return $this->share['owner']; |
|
| 289 | - } |
|
| 280 | + /** |
|
| 281 | + * get owner UID |
|
| 282 | + * |
|
| 283 | + * @return string |
|
| 284 | + * |
|
| 285 | + * @since 14.0.0 |
|
| 286 | + */ |
|
| 287 | + public function getOwner() { |
|
| 288 | + return $this->share['owner']; |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | - /** |
|
| 292 | - * get owner display name |
|
| 293 | - * |
|
| 294 | - * @return string |
|
| 295 | - * |
|
| 296 | - * @since 14.0.0 |
|
| 297 | - */ |
|
| 298 | - public function getOwnerDisplayName() { |
|
| 299 | - return $this->share['ownerDisplayName']; |
|
| 300 | - } |
|
| 291 | + /** |
|
| 292 | + * get owner display name |
|
| 293 | + * |
|
| 294 | + * @return string |
|
| 295 | + * |
|
| 296 | + * @since 14.0.0 |
|
| 297 | + */ |
|
| 298 | + public function getOwnerDisplayName() { |
|
| 299 | + return $this->share['ownerDisplayName']; |
|
| 300 | + } |
|
| 301 | 301 | |
| 302 | - /** |
|
| 303 | - * get UID of the user who sends the share |
|
| 304 | - * |
|
| 305 | - * @return string |
|
| 306 | - * |
|
| 307 | - * @since 14.0.0 |
|
| 308 | - */ |
|
| 309 | - public function getSharedBy() { |
|
| 310 | - return $this->share['sharedBy']; |
|
| 311 | - } |
|
| 302 | + /** |
|
| 303 | + * get UID of the user who sends the share |
|
| 304 | + * |
|
| 305 | + * @return string |
|
| 306 | + * |
|
| 307 | + * @since 14.0.0 |
|
| 308 | + */ |
|
| 309 | + public function getSharedBy() { |
|
| 310 | + return $this->share['sharedBy']; |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | - /** |
|
| 314 | - * get display name of the user who sends the share |
|
| 315 | - * |
|
| 316 | - * @return string |
|
| 317 | - * |
|
| 318 | - * @since 14.0.0 |
|
| 319 | - */ |
|
| 320 | - public function getSharedByDisplayName() { |
|
| 321 | - return $this->share['sharedByDisplayName']; |
|
| 322 | - } |
|
| 313 | + /** |
|
| 314 | + * get display name of the user who sends the share |
|
| 315 | + * |
|
| 316 | + * @return string |
|
| 317 | + * |
|
| 318 | + * @since 14.0.0 |
|
| 319 | + */ |
|
| 320 | + public function getSharedByDisplayName() { |
|
| 321 | + return $this->share['sharedByDisplayName']; |
|
| 322 | + } |
|
| 323 | 323 | |
| 324 | - /** |
|
| 325 | - * get share type (group or user) |
|
| 326 | - * |
|
| 327 | - * @return string |
|
| 328 | - * |
|
| 329 | - * @since 14.0.0 |
|
| 330 | - */ |
|
| 331 | - public function getShareType() { |
|
| 332 | - return $this->share['shareType']; |
|
| 333 | - } |
|
| 324 | + /** |
|
| 325 | + * get share type (group or user) |
|
| 326 | + * |
|
| 327 | + * @return string |
|
| 328 | + * |
|
| 329 | + * @since 14.0.0 |
|
| 330 | + */ |
|
| 331 | + public function getShareType() { |
|
| 332 | + return $this->share['shareType']; |
|
| 333 | + } |
|
| 334 | 334 | |
| 335 | - /** |
|
| 336 | - * get share Secret |
|
| 337 | - * |
|
| 338 | - * @return string |
|
| 339 | - * |
|
| 340 | - * @since 14.0.0 |
|
| 341 | - */ |
|
| 342 | - public function getShareSecret() { |
|
| 343 | - return $this->share['protocol']['options']['sharedSecret']; |
|
| 344 | - } |
|
| 335 | + /** |
|
| 336 | + * get share Secret |
|
| 337 | + * |
|
| 338 | + * @return string |
|
| 339 | + * |
|
| 340 | + * @since 14.0.0 |
|
| 341 | + */ |
|
| 342 | + public function getShareSecret() { |
|
| 343 | + return $this->share['protocol']['options']['sharedSecret']; |
|
| 344 | + } |
|
| 345 | 345 | |
| 346 | - /** |
|
| 347 | - * get protocol specification |
|
| 348 | - * |
|
| 349 | - * @return array |
|
| 350 | - * |
|
| 351 | - * @since 14.0.0 |
|
| 352 | - */ |
|
| 353 | - public function getProtocol() { |
|
| 354 | - return $this->share['protocol']; |
|
| 355 | - } |
|
| 346 | + /** |
|
| 347 | + * get protocol specification |
|
| 348 | + * |
|
| 349 | + * @return array |
|
| 350 | + * |
|
| 351 | + * @since 14.0.0 |
|
| 352 | + */ |
|
| 353 | + public function getProtocol() { |
|
| 354 | + return $this->share['protocol']; |
|
| 355 | + } |
|
| 356 | 356 | } |
@@ -42,191 +42,191 @@ |
||
| 42 | 42 | */ |
| 43 | 43 | class CloudFederationProviderManager implements ICloudFederationProviderManager { |
| 44 | 44 | |
| 45 | - /** @var array list of available cloud federation providers */ |
|
| 46 | - private $cloudFederationProvider; |
|
| 47 | - |
|
| 48 | - /** @var IAppManager */ |
|
| 49 | - private $appManager; |
|
| 50 | - |
|
| 51 | - /** @var IClientService */ |
|
| 52 | - private $httpClientService; |
|
| 53 | - |
|
| 54 | - /** @var ICloudIdManager */ |
|
| 55 | - private $cloudIdManager; |
|
| 56 | - |
|
| 57 | - /** @var ILogger */ |
|
| 58 | - private $logger; |
|
| 59 | - |
|
| 60 | - private $supportedAPIVersion = '1.0-proposal1'; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * CloudFederationProviderManager constructor. |
|
| 64 | - * |
|
| 65 | - * @param IAppManager $appManager |
|
| 66 | - * @param IClientService $httpClientService |
|
| 67 | - * @param ICloudIdManager $cloudIdManager |
|
| 68 | - * @param ILogger $logger |
|
| 69 | - */ |
|
| 70 | - public function __construct(IAppManager $appManager, |
|
| 71 | - IClientService $httpClientService, |
|
| 72 | - ICloudIdManager $cloudIdManager, |
|
| 73 | - ILogger $logger) { |
|
| 74 | - $this->cloudFederationProvider= []; |
|
| 75 | - $this->appManager = $appManager; |
|
| 76 | - $this->httpClientService = $httpClientService; |
|
| 77 | - $this->cloudIdManager = $cloudIdManager; |
|
| 78 | - $this->logger = $logger; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Registers an callback function which must return an cloud federation provider |
|
| 84 | - * |
|
| 85 | - * @param string $resourceType which resource type does the provider handles |
|
| 86 | - * @param string $displayName user facing name of the federated share provider |
|
| 87 | - * @param callable $callback |
|
| 88 | - */ |
|
| 89 | - public function addCloudFederationProvider($resourceType, $displayName, callable $callback) { |
|
| 90 | - $this->cloudFederationProvider[$resourceType] = [ |
|
| 91 | - 'resourceType' => $resourceType, |
|
| 92 | - 'displayName' => $displayName, |
|
| 93 | - 'callback' => $callback, |
|
| 94 | - ]; |
|
| 95 | - |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * remove cloud federation provider |
|
| 100 | - * |
|
| 101 | - * @param string $providerId |
|
| 102 | - */ |
|
| 103 | - public function removeCloudFederationProvider($providerId) { |
|
| 104 | - unset($this->cloudFederationProvider[$providerId]); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * get a list of all cloudFederationProviders |
|
| 109 | - * |
|
| 110 | - * @return array [resourceType => ['resourceType' => $resourceType, 'displayName' => $displayName, 'callback' => callback]] |
|
| 111 | - */ |
|
| 112 | - public function getAllCloudFederationProviders() { |
|
| 113 | - return $this->cloudFederationProvider; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * get a specific cloud federation provider |
|
| 118 | - * |
|
| 119 | - * @param string $resourceType |
|
| 120 | - * @return ICloudFederationProvider |
|
| 121 | - * @throws ProviderDoesNotExistsException |
|
| 122 | - */ |
|
| 123 | - public function getCloudFederationProvider($resourceType) { |
|
| 124 | - if (isset($this->cloudFederationProvider[$resourceType])) { |
|
| 125 | - return call_user_func($this->cloudFederationProvider[$resourceType]['callback']); |
|
| 126 | - } else { |
|
| 127 | - throw new ProviderDoesNotExistsException($resourceType); |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - public function sendShare(ICloudFederationShare $share) { |
|
| 132 | - $cloudID = $this->cloudIdManager->resolveCloudId($share->getShareWith()); |
|
| 133 | - $ocmEndPoint = $this->getOCMEndPoint($cloudID->getRemote()); |
|
| 134 | - |
|
| 135 | - if (empty($ocmEndPoint)) { |
|
| 136 | - return false; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - $client = $this->httpClientService->newClient(); |
|
| 140 | - try { |
|
| 141 | - $response = $client->post($ocmEndPoint . '/shares', [ |
|
| 142 | - 'body' => $share->getShare(), |
|
| 143 | - 'timeout' => 10, |
|
| 144 | - 'connect_timeout' => 10, |
|
| 145 | - ]); |
|
| 146 | - |
|
| 147 | - if ($response->getStatusCode() === Http::STATUS_CREATED) { |
|
| 148 | - $result = json_decode($response->getBody(), true); |
|
| 149 | - return (is_array($result)) ? $result : []; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - } catch (\Exception $e) { |
|
| 153 | - // if flat re-sharing is not supported by the remote server |
|
| 154 | - // we re-throw the exception and fall back to the old behaviour. |
|
| 155 | - // (flat re-shares has been introduced in Nextcloud 9.1) |
|
| 156 | - if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) { |
|
| 157 | - $this->logger->debug($e->getMessage()); |
|
| 158 | - throw $e; |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - return false; |
|
| 163 | - |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * @param string $url |
|
| 168 | - * @param ICloudFederationNotification $notification |
|
| 169 | - * @return mixed |
|
| 170 | - */ |
|
| 171 | - public function sendNotification($url, ICloudFederationNotification $notification) { |
|
| 172 | - $ocmEndPoint = $this->getOCMEndPoint($url); |
|
| 173 | - |
|
| 174 | - if (empty($ocmEndPoint)) { |
|
| 175 | - return false; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - $client = $this->httpClientService->newClient(); |
|
| 179 | - try { |
|
| 180 | - $response = $client->post($ocmEndPoint . '/notifications', [ |
|
| 181 | - 'body' => $notification->getMessage(), |
|
| 182 | - 'timeout' => 10, |
|
| 183 | - 'connect_timeout' => 10, |
|
| 184 | - ]); |
|
| 185 | - if ($response->getStatusCode() === Http::STATUS_CREATED) { |
|
| 186 | - $result = json_decode($response->getBody(), true); |
|
| 187 | - return (is_array($result)) ? $result : []; |
|
| 188 | - } |
|
| 189 | - } catch (\Exception $e) { |
|
| 190 | - // log the error and return false |
|
| 191 | - $this->logger->error('error while sending notification for federated share: ' . $e->getMessage()); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - return false; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * check if the new cloud federation API is ready to be used |
|
| 199 | - * |
|
| 200 | - * @return bool |
|
| 201 | - */ |
|
| 202 | - public function isReady() { |
|
| 203 | - return $this->appManager->isEnabledForUser('cloud_federation_api'); |
|
| 204 | - } |
|
| 205 | - /** |
|
| 206 | - * check if server supports the new OCM api and ask for the correct end-point |
|
| 207 | - * |
|
| 208 | - * @param string $url full base URL of the cloud server |
|
| 209 | - * @return string |
|
| 210 | - */ |
|
| 211 | - protected function getOCMEndPoint($url) { |
|
| 212 | - $client = $this->httpClientService->newClient(); |
|
| 213 | - try { |
|
| 214 | - $response = $client->get($url . '/ocm-provider/', ['timeout' => 10, 'connect_timeout' => 10]); |
|
| 215 | - } catch (\Exception $e) { |
|
| 216 | - return ''; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - $result = $response->getBody(); |
|
| 220 | - $result = json_decode($result, true); |
|
| 221 | - |
|
| 222 | - $supportedVersion = isset($result['apiVersion']) && $result['apiVersion'] === $this->supportedAPIVersion; |
|
| 223 | - |
|
| 224 | - if (isset($result['endPoint']) && $supportedVersion) { |
|
| 225 | - return $result['endPoint']; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - return ''; |
|
| 229 | - } |
|
| 45 | + /** @var array list of available cloud federation providers */ |
|
| 46 | + private $cloudFederationProvider; |
|
| 47 | + |
|
| 48 | + /** @var IAppManager */ |
|
| 49 | + private $appManager; |
|
| 50 | + |
|
| 51 | + /** @var IClientService */ |
|
| 52 | + private $httpClientService; |
|
| 53 | + |
|
| 54 | + /** @var ICloudIdManager */ |
|
| 55 | + private $cloudIdManager; |
|
| 56 | + |
|
| 57 | + /** @var ILogger */ |
|
| 58 | + private $logger; |
|
| 59 | + |
|
| 60 | + private $supportedAPIVersion = '1.0-proposal1'; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * CloudFederationProviderManager constructor. |
|
| 64 | + * |
|
| 65 | + * @param IAppManager $appManager |
|
| 66 | + * @param IClientService $httpClientService |
|
| 67 | + * @param ICloudIdManager $cloudIdManager |
|
| 68 | + * @param ILogger $logger |
|
| 69 | + */ |
|
| 70 | + public function __construct(IAppManager $appManager, |
|
| 71 | + IClientService $httpClientService, |
|
| 72 | + ICloudIdManager $cloudIdManager, |
|
| 73 | + ILogger $logger) { |
|
| 74 | + $this->cloudFederationProvider= []; |
|
| 75 | + $this->appManager = $appManager; |
|
| 76 | + $this->httpClientService = $httpClientService; |
|
| 77 | + $this->cloudIdManager = $cloudIdManager; |
|
| 78 | + $this->logger = $logger; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Registers an callback function which must return an cloud federation provider |
|
| 84 | + * |
|
| 85 | + * @param string $resourceType which resource type does the provider handles |
|
| 86 | + * @param string $displayName user facing name of the federated share provider |
|
| 87 | + * @param callable $callback |
|
| 88 | + */ |
|
| 89 | + public function addCloudFederationProvider($resourceType, $displayName, callable $callback) { |
|
| 90 | + $this->cloudFederationProvider[$resourceType] = [ |
|
| 91 | + 'resourceType' => $resourceType, |
|
| 92 | + 'displayName' => $displayName, |
|
| 93 | + 'callback' => $callback, |
|
| 94 | + ]; |
|
| 95 | + |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * remove cloud federation provider |
|
| 100 | + * |
|
| 101 | + * @param string $providerId |
|
| 102 | + */ |
|
| 103 | + public function removeCloudFederationProvider($providerId) { |
|
| 104 | + unset($this->cloudFederationProvider[$providerId]); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * get a list of all cloudFederationProviders |
|
| 109 | + * |
|
| 110 | + * @return array [resourceType => ['resourceType' => $resourceType, 'displayName' => $displayName, 'callback' => callback]] |
|
| 111 | + */ |
|
| 112 | + public function getAllCloudFederationProviders() { |
|
| 113 | + return $this->cloudFederationProvider; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * get a specific cloud federation provider |
|
| 118 | + * |
|
| 119 | + * @param string $resourceType |
|
| 120 | + * @return ICloudFederationProvider |
|
| 121 | + * @throws ProviderDoesNotExistsException |
|
| 122 | + */ |
|
| 123 | + public function getCloudFederationProvider($resourceType) { |
|
| 124 | + if (isset($this->cloudFederationProvider[$resourceType])) { |
|
| 125 | + return call_user_func($this->cloudFederationProvider[$resourceType]['callback']); |
|
| 126 | + } else { |
|
| 127 | + throw new ProviderDoesNotExistsException($resourceType); |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + public function sendShare(ICloudFederationShare $share) { |
|
| 132 | + $cloudID = $this->cloudIdManager->resolveCloudId($share->getShareWith()); |
|
| 133 | + $ocmEndPoint = $this->getOCMEndPoint($cloudID->getRemote()); |
|
| 134 | + |
|
| 135 | + if (empty($ocmEndPoint)) { |
|
| 136 | + return false; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + $client = $this->httpClientService->newClient(); |
|
| 140 | + try { |
|
| 141 | + $response = $client->post($ocmEndPoint . '/shares', [ |
|
| 142 | + 'body' => $share->getShare(), |
|
| 143 | + 'timeout' => 10, |
|
| 144 | + 'connect_timeout' => 10, |
|
| 145 | + ]); |
|
| 146 | + |
|
| 147 | + if ($response->getStatusCode() === Http::STATUS_CREATED) { |
|
| 148 | + $result = json_decode($response->getBody(), true); |
|
| 149 | + return (is_array($result)) ? $result : []; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + } catch (\Exception $e) { |
|
| 153 | + // if flat re-sharing is not supported by the remote server |
|
| 154 | + // we re-throw the exception and fall back to the old behaviour. |
|
| 155 | + // (flat re-shares has been introduced in Nextcloud 9.1) |
|
| 156 | + if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) { |
|
| 157 | + $this->logger->debug($e->getMessage()); |
|
| 158 | + throw $e; |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + return false; |
|
| 163 | + |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * @param string $url |
|
| 168 | + * @param ICloudFederationNotification $notification |
|
| 169 | + * @return mixed |
|
| 170 | + */ |
|
| 171 | + public function sendNotification($url, ICloudFederationNotification $notification) { |
|
| 172 | + $ocmEndPoint = $this->getOCMEndPoint($url); |
|
| 173 | + |
|
| 174 | + if (empty($ocmEndPoint)) { |
|
| 175 | + return false; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + $client = $this->httpClientService->newClient(); |
|
| 179 | + try { |
|
| 180 | + $response = $client->post($ocmEndPoint . '/notifications', [ |
|
| 181 | + 'body' => $notification->getMessage(), |
|
| 182 | + 'timeout' => 10, |
|
| 183 | + 'connect_timeout' => 10, |
|
| 184 | + ]); |
|
| 185 | + if ($response->getStatusCode() === Http::STATUS_CREATED) { |
|
| 186 | + $result = json_decode($response->getBody(), true); |
|
| 187 | + return (is_array($result)) ? $result : []; |
|
| 188 | + } |
|
| 189 | + } catch (\Exception $e) { |
|
| 190 | + // log the error and return false |
|
| 191 | + $this->logger->error('error while sending notification for federated share: ' . $e->getMessage()); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + return false; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * check if the new cloud federation API is ready to be used |
|
| 199 | + * |
|
| 200 | + * @return bool |
|
| 201 | + */ |
|
| 202 | + public function isReady() { |
|
| 203 | + return $this->appManager->isEnabledForUser('cloud_federation_api'); |
|
| 204 | + } |
|
| 205 | + /** |
|
| 206 | + * check if server supports the new OCM api and ask for the correct end-point |
|
| 207 | + * |
|
| 208 | + * @param string $url full base URL of the cloud server |
|
| 209 | + * @return string |
|
| 210 | + */ |
|
| 211 | + protected function getOCMEndPoint($url) { |
|
| 212 | + $client = $this->httpClientService->newClient(); |
|
| 213 | + try { |
|
| 214 | + $response = $client->get($url . '/ocm-provider/', ['timeout' => 10, 'connect_timeout' => 10]); |
|
| 215 | + } catch (\Exception $e) { |
|
| 216 | + return ''; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + $result = $response->getBody(); |
|
| 220 | + $result = json_decode($result, true); |
|
| 221 | + |
|
| 222 | + $supportedVersion = isset($result['apiVersion']) && $result['apiVersion'] === $this->supportedAPIVersion; |
|
| 223 | + |
|
| 224 | + if (isset($result['endPoint']) && $supportedVersion) { |
|
| 225 | + return $result['endPoint']; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + return ''; |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | 231 | |
| 232 | 232 | } |
@@ -48,236 +48,236 @@ |
||
| 48 | 48 | */ |
| 49 | 49 | class ProviderFactory implements IProviderFactory { |
| 50 | 50 | |
| 51 | - /** @var IServerContainer */ |
|
| 52 | - private $serverContainer; |
|
| 53 | - /** @var DefaultShareProvider */ |
|
| 54 | - private $defaultProvider = null; |
|
| 55 | - /** @var FederatedShareProvider */ |
|
| 56 | - private $federatedProvider = null; |
|
| 57 | - /** @var ShareByMailProvider */ |
|
| 58 | - private $shareByMailProvider; |
|
| 59 | - /** @var \OCA\Circles\ShareByCircleProvider */ |
|
| 60 | - private $shareByCircleProvider = null; |
|
| 61 | - /** @var bool */ |
|
| 62 | - private $circlesAreNotAvailable = false; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * IProviderFactory constructor. |
|
| 66 | - * |
|
| 67 | - * @param IServerContainer $serverContainer |
|
| 68 | - */ |
|
| 69 | - public function __construct(IServerContainer $serverContainer) { |
|
| 70 | - $this->serverContainer = $serverContainer; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Create the default share provider. |
|
| 75 | - * |
|
| 76 | - * @return DefaultShareProvider |
|
| 77 | - */ |
|
| 78 | - protected function defaultShareProvider() { |
|
| 79 | - if ($this->defaultProvider === null) { |
|
| 80 | - $this->defaultProvider = new DefaultShareProvider( |
|
| 81 | - $this->serverContainer->getDatabaseConnection(), |
|
| 82 | - $this->serverContainer->getUserManager(), |
|
| 83 | - $this->serverContainer->getGroupManager(), |
|
| 84 | - $this->serverContainer->getLazyRootFolder() |
|
| 85 | - ); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - return $this->defaultProvider; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Create the federated share provider |
|
| 93 | - * |
|
| 94 | - * @return FederatedShareProvider |
|
| 95 | - */ |
|
| 96 | - protected function federatedShareProvider() { |
|
| 97 | - if ($this->federatedProvider === null) { |
|
| 98 | - /* |
|
| 51 | + /** @var IServerContainer */ |
|
| 52 | + private $serverContainer; |
|
| 53 | + /** @var DefaultShareProvider */ |
|
| 54 | + private $defaultProvider = null; |
|
| 55 | + /** @var FederatedShareProvider */ |
|
| 56 | + private $federatedProvider = null; |
|
| 57 | + /** @var ShareByMailProvider */ |
|
| 58 | + private $shareByMailProvider; |
|
| 59 | + /** @var \OCA\Circles\ShareByCircleProvider */ |
|
| 60 | + private $shareByCircleProvider = null; |
|
| 61 | + /** @var bool */ |
|
| 62 | + private $circlesAreNotAvailable = false; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * IProviderFactory constructor. |
|
| 66 | + * |
|
| 67 | + * @param IServerContainer $serverContainer |
|
| 68 | + */ |
|
| 69 | + public function __construct(IServerContainer $serverContainer) { |
|
| 70 | + $this->serverContainer = $serverContainer; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Create the default share provider. |
|
| 75 | + * |
|
| 76 | + * @return DefaultShareProvider |
|
| 77 | + */ |
|
| 78 | + protected function defaultShareProvider() { |
|
| 79 | + if ($this->defaultProvider === null) { |
|
| 80 | + $this->defaultProvider = new DefaultShareProvider( |
|
| 81 | + $this->serverContainer->getDatabaseConnection(), |
|
| 82 | + $this->serverContainer->getUserManager(), |
|
| 83 | + $this->serverContainer->getGroupManager(), |
|
| 84 | + $this->serverContainer->getLazyRootFolder() |
|
| 85 | + ); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + return $this->defaultProvider; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Create the federated share provider |
|
| 93 | + * |
|
| 94 | + * @return FederatedShareProvider |
|
| 95 | + */ |
|
| 96 | + protected function federatedShareProvider() { |
|
| 97 | + if ($this->federatedProvider === null) { |
|
| 98 | + /* |
|
| 99 | 99 | * Check if the app is enabled |
| 100 | 100 | */ |
| 101 | - $appManager = $this->serverContainer->getAppManager(); |
|
| 102 | - if (!$appManager->isEnabledForUser('federatedfilesharing')) { |
|
| 103 | - return null; |
|
| 104 | - } |
|
| 101 | + $appManager = $this->serverContainer->getAppManager(); |
|
| 102 | + if (!$appManager->isEnabledForUser('federatedfilesharing')) { |
|
| 103 | + return null; |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - /* |
|
| 106 | + /* |
|
| 107 | 107 | * TODO: add factory to federated sharing app |
| 108 | 108 | */ |
| 109 | - $l = $this->serverContainer->getL10N('federatedfilessharing'); |
|
| 110 | - $addressHandler = new AddressHandler( |
|
| 111 | - $this->serverContainer->getURLGenerator(), |
|
| 112 | - $l, |
|
| 113 | - $this->serverContainer->getCloudIdManager() |
|
| 114 | - ); |
|
| 115 | - $notifications = new Notifications( |
|
| 116 | - $addressHandler, |
|
| 117 | - $this->serverContainer->getHTTPClientService(), |
|
| 118 | - $this->serverContainer->query(\OCP\OCS\IDiscoveryService::class), |
|
| 119 | - $this->serverContainer->getJobList(), |
|
| 120 | - \OC::$server->getCloudFederationProviderManager(), |
|
| 121 | - \OC::$server->getCloudFederationFactory() |
|
| 122 | - ); |
|
| 123 | - $tokenHandler = new TokenHandler( |
|
| 124 | - $this->serverContainer->getSecureRandom() |
|
| 125 | - ); |
|
| 126 | - |
|
| 127 | - $this->federatedProvider = new FederatedShareProvider( |
|
| 128 | - $this->serverContainer->getDatabaseConnection(), |
|
| 129 | - $addressHandler, |
|
| 130 | - $notifications, |
|
| 131 | - $tokenHandler, |
|
| 132 | - $l, |
|
| 133 | - $this->serverContainer->getLogger(), |
|
| 134 | - $this->serverContainer->getLazyRootFolder(), |
|
| 135 | - $this->serverContainer->getConfig(), |
|
| 136 | - $this->serverContainer->getUserManager(), |
|
| 137 | - $this->serverContainer->getCloudIdManager(), |
|
| 138 | - $this->serverContainer->getGlobalScaleConfig(), |
|
| 139 | - $this->serverContainer->getCloudFederationProviderManager() |
|
| 140 | - ); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - return $this->federatedProvider; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * Create the federated share provider |
|
| 148 | - * |
|
| 149 | - * @return ShareByMailProvider |
|
| 150 | - */ |
|
| 151 | - protected function getShareByMailProvider() { |
|
| 152 | - if ($this->shareByMailProvider === null) { |
|
| 153 | - /* |
|
| 109 | + $l = $this->serverContainer->getL10N('federatedfilessharing'); |
|
| 110 | + $addressHandler = new AddressHandler( |
|
| 111 | + $this->serverContainer->getURLGenerator(), |
|
| 112 | + $l, |
|
| 113 | + $this->serverContainer->getCloudIdManager() |
|
| 114 | + ); |
|
| 115 | + $notifications = new Notifications( |
|
| 116 | + $addressHandler, |
|
| 117 | + $this->serverContainer->getHTTPClientService(), |
|
| 118 | + $this->serverContainer->query(\OCP\OCS\IDiscoveryService::class), |
|
| 119 | + $this->serverContainer->getJobList(), |
|
| 120 | + \OC::$server->getCloudFederationProviderManager(), |
|
| 121 | + \OC::$server->getCloudFederationFactory() |
|
| 122 | + ); |
|
| 123 | + $tokenHandler = new TokenHandler( |
|
| 124 | + $this->serverContainer->getSecureRandom() |
|
| 125 | + ); |
|
| 126 | + |
|
| 127 | + $this->federatedProvider = new FederatedShareProvider( |
|
| 128 | + $this->serverContainer->getDatabaseConnection(), |
|
| 129 | + $addressHandler, |
|
| 130 | + $notifications, |
|
| 131 | + $tokenHandler, |
|
| 132 | + $l, |
|
| 133 | + $this->serverContainer->getLogger(), |
|
| 134 | + $this->serverContainer->getLazyRootFolder(), |
|
| 135 | + $this->serverContainer->getConfig(), |
|
| 136 | + $this->serverContainer->getUserManager(), |
|
| 137 | + $this->serverContainer->getCloudIdManager(), |
|
| 138 | + $this->serverContainer->getGlobalScaleConfig(), |
|
| 139 | + $this->serverContainer->getCloudFederationProviderManager() |
|
| 140 | + ); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + return $this->federatedProvider; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * Create the federated share provider |
|
| 148 | + * |
|
| 149 | + * @return ShareByMailProvider |
|
| 150 | + */ |
|
| 151 | + protected function getShareByMailProvider() { |
|
| 152 | + if ($this->shareByMailProvider === null) { |
|
| 153 | + /* |
|
| 154 | 154 | * Check if the app is enabled |
| 155 | 155 | */ |
| 156 | - $appManager = $this->serverContainer->getAppManager(); |
|
| 157 | - if (!$appManager->isEnabledForUser('sharebymail')) { |
|
| 158 | - return null; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - $settingsManager = new SettingsManager($this->serverContainer->getConfig()); |
|
| 162 | - |
|
| 163 | - $this->shareByMailProvider = new ShareByMailProvider( |
|
| 164 | - $this->serverContainer->getDatabaseConnection(), |
|
| 165 | - $this->serverContainer->getSecureRandom(), |
|
| 166 | - $this->serverContainer->getUserManager(), |
|
| 167 | - $this->serverContainer->getLazyRootFolder(), |
|
| 168 | - $this->serverContainer->getL10N('sharebymail'), |
|
| 169 | - $this->serverContainer->getLogger(), |
|
| 170 | - $this->serverContainer->getMailer(), |
|
| 171 | - $this->serverContainer->getURLGenerator(), |
|
| 172 | - $this->serverContainer->getActivityManager(), |
|
| 173 | - $settingsManager, |
|
| 174 | - $this->serverContainer->query(Defaults::class), |
|
| 175 | - $this->serverContainer->getHasher(), |
|
| 176 | - $this->serverContainer->query(CapabilitiesManager::class) |
|
| 177 | - ); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - return $this->shareByMailProvider; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * Create the circle share provider |
|
| 186 | - * |
|
| 187 | - * @return FederatedShareProvider |
|
| 188 | - * |
|
| 189 | - * @suppress PhanUndeclaredClassMethod |
|
| 190 | - */ |
|
| 191 | - protected function getShareByCircleProvider() { |
|
| 192 | - |
|
| 193 | - if ($this->circlesAreNotAvailable) { |
|
| 194 | - return null; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - if (!$this->serverContainer->getAppManager()->isEnabledForUser('circles') || |
|
| 198 | - !class_exists('\OCA\Circles\ShareByCircleProvider') |
|
| 199 | - ) { |
|
| 200 | - $this->circlesAreNotAvailable = true; |
|
| 201 | - return null; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - if ($this->shareByCircleProvider === null) { |
|
| 205 | - |
|
| 206 | - $this->shareByCircleProvider = new \OCA\Circles\ShareByCircleProvider( |
|
| 207 | - $this->serverContainer->getDatabaseConnection(), |
|
| 208 | - $this->serverContainer->getSecureRandom(), |
|
| 209 | - $this->serverContainer->getUserManager(), |
|
| 210 | - $this->serverContainer->getLazyRootFolder(), |
|
| 211 | - $this->serverContainer->getL10N('circles'), |
|
| 212 | - $this->serverContainer->getLogger(), |
|
| 213 | - $this->serverContainer->getURLGenerator() |
|
| 214 | - ); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - return $this->shareByCircleProvider; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * @inheritdoc |
|
| 223 | - */ |
|
| 224 | - public function getProvider($id) { |
|
| 225 | - $provider = null; |
|
| 226 | - if ($id === 'ocinternal') { |
|
| 227 | - $provider = $this->defaultShareProvider(); |
|
| 228 | - } else if ($id === 'ocFederatedSharing') { |
|
| 229 | - $provider = $this->federatedShareProvider(); |
|
| 230 | - } else if ($id === 'ocMailShare') { |
|
| 231 | - $provider = $this->getShareByMailProvider(); |
|
| 232 | - } else if ($id === 'ocCircleShare') { |
|
| 233 | - $provider = $this->getShareByCircleProvider(); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - if ($provider === null) { |
|
| 237 | - throw new ProviderException('No provider with id .' . $id . ' found.'); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - return $provider; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * @inheritdoc |
|
| 245 | - */ |
|
| 246 | - public function getProviderForType($shareType) { |
|
| 247 | - $provider = null; |
|
| 248 | - |
|
| 249 | - if ($shareType === \OCP\Share::SHARE_TYPE_USER || |
|
| 250 | - $shareType === \OCP\Share::SHARE_TYPE_GROUP || |
|
| 251 | - $shareType === \OCP\Share::SHARE_TYPE_LINK |
|
| 252 | - ) { |
|
| 253 | - $provider = $this->defaultShareProvider(); |
|
| 254 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
| 255 | - $provider = $this->federatedShareProvider(); |
|
| 256 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 257 | - $provider = $this->getShareByMailProvider(); |
|
| 258 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
| 259 | - $provider = $this->getShareByCircleProvider(); |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - |
|
| 263 | - if ($provider === null) { |
|
| 264 | - throw new ProviderException('No share provider for share type ' . $shareType); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - return $provider; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - public function getAllProviders() { |
|
| 271 | - $shares = [$this->defaultShareProvider(), $this->federatedShareProvider()]; |
|
| 272 | - $shareByMail = $this->getShareByMailProvider(); |
|
| 273 | - if ($shareByMail !== null) { |
|
| 274 | - $shares[] = $shareByMail; |
|
| 275 | - } |
|
| 276 | - $shareByCircle = $this->getShareByCircleProvider(); |
|
| 277 | - if ($shareByCircle !== null) { |
|
| 278 | - $shares[] = $shareByCircle; |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - return $shares; |
|
| 282 | - } |
|
| 156 | + $appManager = $this->serverContainer->getAppManager(); |
|
| 157 | + if (!$appManager->isEnabledForUser('sharebymail')) { |
|
| 158 | + return null; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + $settingsManager = new SettingsManager($this->serverContainer->getConfig()); |
|
| 162 | + |
|
| 163 | + $this->shareByMailProvider = new ShareByMailProvider( |
|
| 164 | + $this->serverContainer->getDatabaseConnection(), |
|
| 165 | + $this->serverContainer->getSecureRandom(), |
|
| 166 | + $this->serverContainer->getUserManager(), |
|
| 167 | + $this->serverContainer->getLazyRootFolder(), |
|
| 168 | + $this->serverContainer->getL10N('sharebymail'), |
|
| 169 | + $this->serverContainer->getLogger(), |
|
| 170 | + $this->serverContainer->getMailer(), |
|
| 171 | + $this->serverContainer->getURLGenerator(), |
|
| 172 | + $this->serverContainer->getActivityManager(), |
|
| 173 | + $settingsManager, |
|
| 174 | + $this->serverContainer->query(Defaults::class), |
|
| 175 | + $this->serverContainer->getHasher(), |
|
| 176 | + $this->serverContainer->query(CapabilitiesManager::class) |
|
| 177 | + ); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + return $this->shareByMailProvider; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * Create the circle share provider |
|
| 186 | + * |
|
| 187 | + * @return FederatedShareProvider |
|
| 188 | + * |
|
| 189 | + * @suppress PhanUndeclaredClassMethod |
|
| 190 | + */ |
|
| 191 | + protected function getShareByCircleProvider() { |
|
| 192 | + |
|
| 193 | + if ($this->circlesAreNotAvailable) { |
|
| 194 | + return null; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + if (!$this->serverContainer->getAppManager()->isEnabledForUser('circles') || |
|
| 198 | + !class_exists('\OCA\Circles\ShareByCircleProvider') |
|
| 199 | + ) { |
|
| 200 | + $this->circlesAreNotAvailable = true; |
|
| 201 | + return null; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + if ($this->shareByCircleProvider === null) { |
|
| 205 | + |
|
| 206 | + $this->shareByCircleProvider = new \OCA\Circles\ShareByCircleProvider( |
|
| 207 | + $this->serverContainer->getDatabaseConnection(), |
|
| 208 | + $this->serverContainer->getSecureRandom(), |
|
| 209 | + $this->serverContainer->getUserManager(), |
|
| 210 | + $this->serverContainer->getLazyRootFolder(), |
|
| 211 | + $this->serverContainer->getL10N('circles'), |
|
| 212 | + $this->serverContainer->getLogger(), |
|
| 213 | + $this->serverContainer->getURLGenerator() |
|
| 214 | + ); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + return $this->shareByCircleProvider; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * @inheritdoc |
|
| 223 | + */ |
|
| 224 | + public function getProvider($id) { |
|
| 225 | + $provider = null; |
|
| 226 | + if ($id === 'ocinternal') { |
|
| 227 | + $provider = $this->defaultShareProvider(); |
|
| 228 | + } else if ($id === 'ocFederatedSharing') { |
|
| 229 | + $provider = $this->federatedShareProvider(); |
|
| 230 | + } else if ($id === 'ocMailShare') { |
|
| 231 | + $provider = $this->getShareByMailProvider(); |
|
| 232 | + } else if ($id === 'ocCircleShare') { |
|
| 233 | + $provider = $this->getShareByCircleProvider(); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + if ($provider === null) { |
|
| 237 | + throw new ProviderException('No provider with id .' . $id . ' found.'); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + return $provider; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * @inheritdoc |
|
| 245 | + */ |
|
| 246 | + public function getProviderForType($shareType) { |
|
| 247 | + $provider = null; |
|
| 248 | + |
|
| 249 | + if ($shareType === \OCP\Share::SHARE_TYPE_USER || |
|
| 250 | + $shareType === \OCP\Share::SHARE_TYPE_GROUP || |
|
| 251 | + $shareType === \OCP\Share::SHARE_TYPE_LINK |
|
| 252 | + ) { |
|
| 253 | + $provider = $this->defaultShareProvider(); |
|
| 254 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
| 255 | + $provider = $this->federatedShareProvider(); |
|
| 256 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 257 | + $provider = $this->getShareByMailProvider(); |
|
| 258 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
| 259 | + $provider = $this->getShareByCircleProvider(); |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + |
|
| 263 | + if ($provider === null) { |
|
| 264 | + throw new ProviderException('No share provider for share type ' . $shareType); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + return $provider; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + public function getAllProviders() { |
|
| 271 | + $shares = [$this->defaultShareProvider(), $this->federatedShareProvider()]; |
|
| 272 | + $shareByMail = $this->getShareByMailProvider(); |
|
| 273 | + if ($shareByMail !== null) { |
|
| 274 | + $shares[] = $shareByMail; |
|
| 275 | + } |
|
| 276 | + $shareByCircle = $this->getShareByCircleProvider(); |
|
| 277 | + if ($shareByCircle !== null) { |
|
| 278 | + $shares[] = $shareByCircle; |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + return $shares; |
|
| 282 | + } |
|
| 283 | 283 | } |
@@ -52,249 +52,249 @@ |
||
| 52 | 52 | */ |
| 53 | 53 | class RequestHandlerController extends Controller { |
| 54 | 54 | |
| 55 | - /** @var ILogger */ |
|
| 56 | - private $logger; |
|
| 57 | - |
|
| 58 | - /** @var IUserManager */ |
|
| 59 | - private $userManager; |
|
| 60 | - |
|
| 61 | - /** @var IGroupManager */ |
|
| 62 | - private $groupManager; |
|
| 63 | - |
|
| 64 | - /** @var IURLGenerator */ |
|
| 65 | - private $urlGenerator; |
|
| 66 | - |
|
| 67 | - /** @var ICloudFederationProviderManager */ |
|
| 68 | - private $cloudFederationProviderManager; |
|
| 69 | - |
|
| 70 | - /** @var Config */ |
|
| 71 | - private $config; |
|
| 72 | - |
|
| 73 | - /** @var ICloudFederationFactory */ |
|
| 74 | - private $factory; |
|
| 75 | - |
|
| 76 | - /** @var ICloudIdManager */ |
|
| 77 | - private $cloudIdManager; |
|
| 78 | - |
|
| 79 | - public function __construct($appName, |
|
| 80 | - IRequest $request, |
|
| 81 | - ILogger $logger, |
|
| 82 | - IUserManager $userManager, |
|
| 83 | - IGroupManager $groupManager, |
|
| 84 | - IURLGenerator $urlGenerator, |
|
| 85 | - ICloudFederationProviderManager $cloudFederationProviderManager, |
|
| 86 | - Config $config, |
|
| 87 | - ICloudFederationFactory $factory, |
|
| 88 | - ICloudIdManager $cloudIdManager |
|
| 89 | - ) { |
|
| 90 | - parent::__construct($appName, $request); |
|
| 91 | - |
|
| 92 | - $this->logger = $logger; |
|
| 93 | - $this->userManager = $userManager; |
|
| 94 | - $this->groupManager = $groupManager; |
|
| 95 | - $this->urlGenerator = $urlGenerator; |
|
| 96 | - $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
| 97 | - $this->config = $config; |
|
| 98 | - $this->factory = $factory; |
|
| 99 | - $this->cloudIdManager = $cloudIdManager; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * add share |
|
| 104 | - * |
|
| 105 | - * @NoCSRFRequired |
|
| 106 | - * @PublicPage |
|
| 107 | - * @BruteForceProtection(action=receiveFederatedShare) |
|
| 108 | - * |
|
| 109 | - * @param string $shareWith |
|
| 110 | - * @param string $name resource name (e.g. document.odt) |
|
| 111 | - * @param string $description share description (optional) |
|
| 112 | - * @param string $providerId resource UID on the provider side |
|
| 113 | - * @param string $owner provider specific UID of the user who owns the resource |
|
| 114 | - * @param string $ownerDisplayName display name of the user who shared the item |
|
| 115 | - * @param string $sharedBy provider specific UID of the user who shared the resource |
|
| 116 | - * @param string $sharedByDisplayName display name of the user who shared the resource |
|
| 117 | - * @param array $protocol (e,.g. ['name' => 'webdav', 'options' => ['username' => 'john', 'permissions' => 31]]) |
|
| 118 | - * @param string $shareType ('group' or 'user' share) |
|
| 119 | - * @param $resourceType ('file', 'calendar',...) |
|
| 120 | - * @return Http\DataResponse|JSONResponse |
|
| 121 | - * |
|
| 122 | - * Example: curl -H "Content-Type: application/json" -X POST -d '{"shareWith":"admin1@serve1","name":"welcome server2.txt","description":"desc","providerId":"2","owner":"admin2@http://localhost/server2","ownerDisplayName":"admin2 display","shareType":"user","resourceType":"file","protocol":{"name":"webdav","options":{"sharedSecret":"secret","permissions":"webdav-property"}}}' http://localhost/server/index.php/ocm/shares |
|
| 123 | - */ |
|
| 124 | - public function addShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $protocol, $shareType, $resourceType) { |
|
| 125 | - |
|
| 126 | - // check if all required parameters are set |
|
| 127 | - if ($shareWith === null || |
|
| 128 | - $name === null || |
|
| 129 | - $providerId === null || |
|
| 130 | - $owner === null || |
|
| 131 | - $resourceType === null || |
|
| 132 | - $shareType === null || |
|
| 133 | - !is_array($protocol) || |
|
| 134 | - !isset($protocol['name']) || |
|
| 135 | - !isset ($protocol['options']) || |
|
| 136 | - !is_array($protocol['options']) || |
|
| 137 | - !isset($protocol['options']['sharedSecret']) |
|
| 138 | - ) { |
|
| 139 | - return new JSONResponse( |
|
| 140 | - ['message' => 'Missing arguments'], |
|
| 141 | - Http::STATUS_BAD_REQUEST |
|
| 142 | - ); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - $supportedShareTypes = $this->config->getSupportedShareTypes($resourceType); |
|
| 146 | - if (!in_array($shareType, $supportedShareTypes)) { |
|
| 147 | - return new JSONResponse( |
|
| 148 | - ['message' => 'Share type "' . $shareType . '" not implemented'], |
|
| 149 | - Http::STATUS_NOT_IMPLEMENTED |
|
| 150 | - ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - $cloudId = $this->cloudIdManager->resolveCloudId($shareWith); |
|
| 154 | - $shareWith = $cloudId->getUser(); |
|
| 155 | - |
|
| 156 | - if ($shareType === 'user') { |
|
| 157 | - $shareWith = $this->mapUid($shareWith); |
|
| 158 | - |
|
| 159 | - if (!$this->userManager->userExists($shareWith)) { |
|
| 160 | - return new JSONResponse( |
|
| 161 | - ['message' => 'User "' . $shareWith . '" does not exists at ' . $this->urlGenerator->getBaseUrl()], |
|
| 162 | - Http::STATUS_BAD_REQUEST |
|
| 163 | - ); |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - if ($shareType === 'group') { |
|
| 168 | - if(!$this->groupManager->groupExists($shareWith)) { |
|
| 169 | - return new JSONResponse( |
|
| 170 | - ['message' => 'Group "' . $shareWith . '" does not exists at ' . $this->urlGenerator->getBaseUrl()], |
|
| 171 | - Http::STATUS_BAD_REQUEST |
|
| 172 | - ); |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - // if no explicit display name is given, we use the uid as display name |
|
| 177 | - $ownerDisplayName = $ownerDisplayName === null ? $owner : $ownerDisplayName; |
|
| 178 | - $sharedByDisplayName = $sharedByDisplayName === null ? $sharedBy : $sharedByDisplayName; |
|
| 179 | - |
|
| 180 | - // sharedBy* parameter is optional, if nothing is set we assume that it is the same user as the owner |
|
| 181 | - if ($sharedBy === null) { |
|
| 182 | - $sharedBy = $owner; |
|
| 183 | - $sharedByDisplayName = $ownerDisplayName; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - try { |
|
| 187 | - $provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType); |
|
| 188 | - $share = $this->factory->getCloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, '', $shareType, $resourceType); |
|
| 189 | - $share->setProtocol($protocol); |
|
| 190 | - $provider->shareReceived($share); |
|
| 191 | - } catch (ProviderDoesNotExistsException $e) { |
|
| 192 | - return new JSONResponse( |
|
| 193 | - ['message' => $e->getMessage()], |
|
| 194 | - Http::STATUS_NOT_IMPLEMENTED |
|
| 195 | - ); |
|
| 196 | - } catch (ProviderCouldNotAddShareException $e) { |
|
| 197 | - return new JSONResponse( |
|
| 198 | - ['message' => $e->getMessage()], |
|
| 199 | - $e->getCode() |
|
| 200 | - ); |
|
| 201 | - } catch (\Exception $e) { |
|
| 202 | - return new JSONResponse( |
|
| 203 | - ['message' => 'Internal error at ' . $this->urlGenerator->getBaseUrl()], |
|
| 204 | - Http::STATUS_BAD_REQUEST |
|
| 205 | - ); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - $user = $this->userManager->get($shareWith); |
|
| 209 | - $recipientDisplayName = ''; |
|
| 210 | - if($user) { |
|
| 211 | - $recipientDisplayName = $user->getDisplayName(); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - return new JSONResponse( |
|
| 215 | - ['recipientDisplayName' => $recipientDisplayName], |
|
| 216 | - Http::STATUS_CREATED); |
|
| 217 | - |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * receive notification about existing share |
|
| 222 | - * |
|
| 223 | - * @NoCSRFRequired |
|
| 224 | - * @PublicPage |
|
| 225 | - * @BruteForceProtection(action=receiveFederatedShareNotification) |
|
| 226 | - * |
|
| 227 | - * @param string $notificationType (notification type, e.g. SHARE_ACCEPTED) |
|
| 228 | - * @param string $resourceType (calendar, file, contact,...) |
|
| 229 | - * @param string $providerId id of the share |
|
| 230 | - * @param array $notification the actual payload of the notification |
|
| 231 | - * @return JSONResponse |
|
| 232 | - */ |
|
| 233 | - public function receiveNotification($notificationType, $resourceType, $providerId, array $notification) { |
|
| 234 | - |
|
| 235 | - // check if all required parameters are set |
|
| 236 | - if ($notificationType === null || |
|
| 237 | - $resourceType === null || |
|
| 238 | - $providerId === null || |
|
| 239 | - !is_array($notification) |
|
| 240 | - ) { |
|
| 241 | - return new JSONResponse( |
|
| 242 | - ['message' => 'Missing arguments'], |
|
| 243 | - Http::STATUS_BAD_REQUEST |
|
| 244 | - ); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - try { |
|
| 248 | - $provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType); |
|
| 249 | - $result = $provider->notificationReceived($notificationType, $providerId, $notification); |
|
| 250 | - } catch (ProviderDoesNotExistsException $e) { |
|
| 251 | - return new JSONResponse( |
|
| 252 | - ['message' => $e->getMessage()], |
|
| 253 | - Http::STATUS_BAD_REQUEST |
|
| 254 | - ); |
|
| 255 | - } catch (ShareNotFound $e) { |
|
| 256 | - return new JSONResponse( |
|
| 257 | - ['message' => $e->getMessage()], |
|
| 258 | - Http::STATUS_BAD_REQUEST |
|
| 259 | - ); |
|
| 260 | - } catch (ActionNotSupportedException $e) { |
|
| 261 | - return new JSONResponse( |
|
| 262 | - ['message' => $e->getMessage()], |
|
| 263 | - Http::STATUS_NOT_IMPLEMENTED |
|
| 264 | - ); |
|
| 265 | - } catch (BadRequestException $e) { |
|
| 266 | - return new JSONResponse($e->getReturnMessage(), Http::STATUS_BAD_REQUEST); |
|
| 267 | - } catch (AuthenticationFailedException $e) { |
|
| 268 | - return new JSONResponse(["message" => "RESOURCE_NOT_FOUND"], Http::STATUS_FORBIDDEN); |
|
| 269 | - } |
|
| 270 | - catch (\Exception $e) { |
|
| 271 | - return new JSONResponse( |
|
| 272 | - ['message' => 'Internal error at ' . $this->urlGenerator->getBaseUrl()], |
|
| 273 | - Http::STATUS_BAD_REQUEST |
|
| 274 | - ); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - return new JSONResponse($result,Http::STATUS_CREATED); |
|
| 278 | - |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * map login name to internal LDAP UID if a LDAP backend is in use |
|
| 283 | - * |
|
| 284 | - * @param string $uid |
|
| 285 | - * @return string mixed |
|
| 286 | - */ |
|
| 287 | - private function mapUid($uid) { |
|
| 288 | - // FIXME this should be a method in the user management instead |
|
| 289 | - $this->logger->debug('shareWith before, ' . $uid, ['app' => $this->appName]); |
|
| 290 | - \OCP\Util::emitHook( |
|
| 291 | - '\OCA\Files_Sharing\API\Server2Server', |
|
| 292 | - 'preLoginNameUsedAsUserName', |
|
| 293 | - array('uid' => &$uid) |
|
| 294 | - ); |
|
| 295 | - $this->logger->debug('shareWith after, ' . $uid, ['app' => $this->appName]); |
|
| 296 | - |
|
| 297 | - return $uid; |
|
| 298 | - } |
|
| 55 | + /** @var ILogger */ |
|
| 56 | + private $logger; |
|
| 57 | + |
|
| 58 | + /** @var IUserManager */ |
|
| 59 | + private $userManager; |
|
| 60 | + |
|
| 61 | + /** @var IGroupManager */ |
|
| 62 | + private $groupManager; |
|
| 63 | + |
|
| 64 | + /** @var IURLGenerator */ |
|
| 65 | + private $urlGenerator; |
|
| 66 | + |
|
| 67 | + /** @var ICloudFederationProviderManager */ |
|
| 68 | + private $cloudFederationProviderManager; |
|
| 69 | + |
|
| 70 | + /** @var Config */ |
|
| 71 | + private $config; |
|
| 72 | + |
|
| 73 | + /** @var ICloudFederationFactory */ |
|
| 74 | + private $factory; |
|
| 75 | + |
|
| 76 | + /** @var ICloudIdManager */ |
|
| 77 | + private $cloudIdManager; |
|
| 78 | + |
|
| 79 | + public function __construct($appName, |
|
| 80 | + IRequest $request, |
|
| 81 | + ILogger $logger, |
|
| 82 | + IUserManager $userManager, |
|
| 83 | + IGroupManager $groupManager, |
|
| 84 | + IURLGenerator $urlGenerator, |
|
| 85 | + ICloudFederationProviderManager $cloudFederationProviderManager, |
|
| 86 | + Config $config, |
|
| 87 | + ICloudFederationFactory $factory, |
|
| 88 | + ICloudIdManager $cloudIdManager |
|
| 89 | + ) { |
|
| 90 | + parent::__construct($appName, $request); |
|
| 91 | + |
|
| 92 | + $this->logger = $logger; |
|
| 93 | + $this->userManager = $userManager; |
|
| 94 | + $this->groupManager = $groupManager; |
|
| 95 | + $this->urlGenerator = $urlGenerator; |
|
| 96 | + $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
| 97 | + $this->config = $config; |
|
| 98 | + $this->factory = $factory; |
|
| 99 | + $this->cloudIdManager = $cloudIdManager; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * add share |
|
| 104 | + * |
|
| 105 | + * @NoCSRFRequired |
|
| 106 | + * @PublicPage |
|
| 107 | + * @BruteForceProtection(action=receiveFederatedShare) |
|
| 108 | + * |
|
| 109 | + * @param string $shareWith |
|
| 110 | + * @param string $name resource name (e.g. document.odt) |
|
| 111 | + * @param string $description share description (optional) |
|
| 112 | + * @param string $providerId resource UID on the provider side |
|
| 113 | + * @param string $owner provider specific UID of the user who owns the resource |
|
| 114 | + * @param string $ownerDisplayName display name of the user who shared the item |
|
| 115 | + * @param string $sharedBy provider specific UID of the user who shared the resource |
|
| 116 | + * @param string $sharedByDisplayName display name of the user who shared the resource |
|
| 117 | + * @param array $protocol (e,.g. ['name' => 'webdav', 'options' => ['username' => 'john', 'permissions' => 31]]) |
|
| 118 | + * @param string $shareType ('group' or 'user' share) |
|
| 119 | + * @param $resourceType ('file', 'calendar',...) |
|
| 120 | + * @return Http\DataResponse|JSONResponse |
|
| 121 | + * |
|
| 122 | + * Example: curl -H "Content-Type: application/json" -X POST -d '{"shareWith":"admin1@serve1","name":"welcome server2.txt","description":"desc","providerId":"2","owner":"admin2@http://localhost/server2","ownerDisplayName":"admin2 display","shareType":"user","resourceType":"file","protocol":{"name":"webdav","options":{"sharedSecret":"secret","permissions":"webdav-property"}}}' http://localhost/server/index.php/ocm/shares |
|
| 123 | + */ |
|
| 124 | + public function addShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $protocol, $shareType, $resourceType) { |
|
| 125 | + |
|
| 126 | + // check if all required parameters are set |
|
| 127 | + if ($shareWith === null || |
|
| 128 | + $name === null || |
|
| 129 | + $providerId === null || |
|
| 130 | + $owner === null || |
|
| 131 | + $resourceType === null || |
|
| 132 | + $shareType === null || |
|
| 133 | + !is_array($protocol) || |
|
| 134 | + !isset($protocol['name']) || |
|
| 135 | + !isset ($protocol['options']) || |
|
| 136 | + !is_array($protocol['options']) || |
|
| 137 | + !isset($protocol['options']['sharedSecret']) |
|
| 138 | + ) { |
|
| 139 | + return new JSONResponse( |
|
| 140 | + ['message' => 'Missing arguments'], |
|
| 141 | + Http::STATUS_BAD_REQUEST |
|
| 142 | + ); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + $supportedShareTypes = $this->config->getSupportedShareTypes($resourceType); |
|
| 146 | + if (!in_array($shareType, $supportedShareTypes)) { |
|
| 147 | + return new JSONResponse( |
|
| 148 | + ['message' => 'Share type "' . $shareType . '" not implemented'], |
|
| 149 | + Http::STATUS_NOT_IMPLEMENTED |
|
| 150 | + ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + $cloudId = $this->cloudIdManager->resolveCloudId($shareWith); |
|
| 154 | + $shareWith = $cloudId->getUser(); |
|
| 155 | + |
|
| 156 | + if ($shareType === 'user') { |
|
| 157 | + $shareWith = $this->mapUid($shareWith); |
|
| 158 | + |
|
| 159 | + if (!$this->userManager->userExists($shareWith)) { |
|
| 160 | + return new JSONResponse( |
|
| 161 | + ['message' => 'User "' . $shareWith . '" does not exists at ' . $this->urlGenerator->getBaseUrl()], |
|
| 162 | + Http::STATUS_BAD_REQUEST |
|
| 163 | + ); |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + if ($shareType === 'group') { |
|
| 168 | + if(!$this->groupManager->groupExists($shareWith)) { |
|
| 169 | + return new JSONResponse( |
|
| 170 | + ['message' => 'Group "' . $shareWith . '" does not exists at ' . $this->urlGenerator->getBaseUrl()], |
|
| 171 | + Http::STATUS_BAD_REQUEST |
|
| 172 | + ); |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + // if no explicit display name is given, we use the uid as display name |
|
| 177 | + $ownerDisplayName = $ownerDisplayName === null ? $owner : $ownerDisplayName; |
|
| 178 | + $sharedByDisplayName = $sharedByDisplayName === null ? $sharedBy : $sharedByDisplayName; |
|
| 179 | + |
|
| 180 | + // sharedBy* parameter is optional, if nothing is set we assume that it is the same user as the owner |
|
| 181 | + if ($sharedBy === null) { |
|
| 182 | + $sharedBy = $owner; |
|
| 183 | + $sharedByDisplayName = $ownerDisplayName; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + try { |
|
| 187 | + $provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType); |
|
| 188 | + $share = $this->factory->getCloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, '', $shareType, $resourceType); |
|
| 189 | + $share->setProtocol($protocol); |
|
| 190 | + $provider->shareReceived($share); |
|
| 191 | + } catch (ProviderDoesNotExistsException $e) { |
|
| 192 | + return new JSONResponse( |
|
| 193 | + ['message' => $e->getMessage()], |
|
| 194 | + Http::STATUS_NOT_IMPLEMENTED |
|
| 195 | + ); |
|
| 196 | + } catch (ProviderCouldNotAddShareException $e) { |
|
| 197 | + return new JSONResponse( |
|
| 198 | + ['message' => $e->getMessage()], |
|
| 199 | + $e->getCode() |
|
| 200 | + ); |
|
| 201 | + } catch (\Exception $e) { |
|
| 202 | + return new JSONResponse( |
|
| 203 | + ['message' => 'Internal error at ' . $this->urlGenerator->getBaseUrl()], |
|
| 204 | + Http::STATUS_BAD_REQUEST |
|
| 205 | + ); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + $user = $this->userManager->get($shareWith); |
|
| 209 | + $recipientDisplayName = ''; |
|
| 210 | + if($user) { |
|
| 211 | + $recipientDisplayName = $user->getDisplayName(); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + return new JSONResponse( |
|
| 215 | + ['recipientDisplayName' => $recipientDisplayName], |
|
| 216 | + Http::STATUS_CREATED); |
|
| 217 | + |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * receive notification about existing share |
|
| 222 | + * |
|
| 223 | + * @NoCSRFRequired |
|
| 224 | + * @PublicPage |
|
| 225 | + * @BruteForceProtection(action=receiveFederatedShareNotification) |
|
| 226 | + * |
|
| 227 | + * @param string $notificationType (notification type, e.g. SHARE_ACCEPTED) |
|
| 228 | + * @param string $resourceType (calendar, file, contact,...) |
|
| 229 | + * @param string $providerId id of the share |
|
| 230 | + * @param array $notification the actual payload of the notification |
|
| 231 | + * @return JSONResponse |
|
| 232 | + */ |
|
| 233 | + public function receiveNotification($notificationType, $resourceType, $providerId, array $notification) { |
|
| 234 | + |
|
| 235 | + // check if all required parameters are set |
|
| 236 | + if ($notificationType === null || |
|
| 237 | + $resourceType === null || |
|
| 238 | + $providerId === null || |
|
| 239 | + !is_array($notification) |
|
| 240 | + ) { |
|
| 241 | + return new JSONResponse( |
|
| 242 | + ['message' => 'Missing arguments'], |
|
| 243 | + Http::STATUS_BAD_REQUEST |
|
| 244 | + ); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + try { |
|
| 248 | + $provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType); |
|
| 249 | + $result = $provider->notificationReceived($notificationType, $providerId, $notification); |
|
| 250 | + } catch (ProviderDoesNotExistsException $e) { |
|
| 251 | + return new JSONResponse( |
|
| 252 | + ['message' => $e->getMessage()], |
|
| 253 | + Http::STATUS_BAD_REQUEST |
|
| 254 | + ); |
|
| 255 | + } catch (ShareNotFound $e) { |
|
| 256 | + return new JSONResponse( |
|
| 257 | + ['message' => $e->getMessage()], |
|
| 258 | + Http::STATUS_BAD_REQUEST |
|
| 259 | + ); |
|
| 260 | + } catch (ActionNotSupportedException $e) { |
|
| 261 | + return new JSONResponse( |
|
| 262 | + ['message' => $e->getMessage()], |
|
| 263 | + Http::STATUS_NOT_IMPLEMENTED |
|
| 264 | + ); |
|
| 265 | + } catch (BadRequestException $e) { |
|
| 266 | + return new JSONResponse($e->getReturnMessage(), Http::STATUS_BAD_REQUEST); |
|
| 267 | + } catch (AuthenticationFailedException $e) { |
|
| 268 | + return new JSONResponse(["message" => "RESOURCE_NOT_FOUND"], Http::STATUS_FORBIDDEN); |
|
| 269 | + } |
|
| 270 | + catch (\Exception $e) { |
|
| 271 | + return new JSONResponse( |
|
| 272 | + ['message' => 'Internal error at ' . $this->urlGenerator->getBaseUrl()], |
|
| 273 | + Http::STATUS_BAD_REQUEST |
|
| 274 | + ); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + return new JSONResponse($result,Http::STATUS_CREATED); |
|
| 278 | + |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * map login name to internal LDAP UID if a LDAP backend is in use |
|
| 283 | + * |
|
| 284 | + * @param string $uid |
|
| 285 | + * @return string mixed |
|
| 286 | + */ |
|
| 287 | + private function mapUid($uid) { |
|
| 288 | + // FIXME this should be a method in the user management instead |
|
| 289 | + $this->logger->debug('shareWith before, ' . $uid, ['app' => $this->appName]); |
|
| 290 | + \OCP\Util::emitHook( |
|
| 291 | + '\OCA\Files_Sharing\API\Server2Server', |
|
| 292 | + 'preLoginNameUsedAsUserName', |
|
| 293 | + array('uid' => &$uid) |
|
| 294 | + ); |
|
| 295 | + $this->logger->debug('shareWith after, ' . $uid, ['app' => $this->appName]); |
|
| 296 | + |
|
| 297 | + return $uid; |
|
| 298 | + } |
|
| 299 | 299 | |
| 300 | 300 | } |
@@ -39,117 +39,117 @@ |
||
| 39 | 39 | |
| 40 | 40 | class Application extends App { |
| 41 | 41 | |
| 42 | - /** @var FederatedShareProvider */ |
|
| 43 | - protected $federatedShareProvider; |
|
| 42 | + /** @var FederatedShareProvider */ |
|
| 43 | + protected $federatedShareProvider; |
|
| 44 | 44 | |
| 45 | - public function __construct() { |
|
| 46 | - parent::__construct('federatedfilesharing'); |
|
| 45 | + public function __construct() { |
|
| 46 | + parent::__construct('federatedfilesharing'); |
|
| 47 | 47 | |
| 48 | - $container = $this->getContainer(); |
|
| 49 | - $server = $container->getServer(); |
|
| 48 | + $container = $this->getContainer(); |
|
| 49 | + $server = $container->getServer(); |
|
| 50 | 50 | |
| 51 | - $cloudFederationManager = $server->getCloudFederationProviderManager(); |
|
| 52 | - $cloudFederationManager->addCloudFederationProvider('file', |
|
| 53 | - 'Federated Files Sharing', |
|
| 54 | - function() use ($container) { |
|
| 55 | - $server = $container->getServer(); |
|
| 56 | - return new CloudFederationProviderFiles( |
|
| 57 | - $server->getAppManager(), |
|
| 58 | - $server->query(FederatedShareProvider::class), |
|
| 59 | - $server->query(AddressHandler::class), |
|
| 60 | - $server->getLogger(), |
|
| 61 | - $server->getUserManager(), |
|
| 62 | - $server->getCloudIdManager(), |
|
| 63 | - $server->getActivityManager(), |
|
| 64 | - $server->getNotificationManager(), |
|
| 65 | - $server->getURLGenerator(), |
|
| 66 | - $server->getCloudFederationFactory(), |
|
| 67 | - $server->getCloudFederationProviderManager(), |
|
| 68 | - $server->getDatabaseConnection(), |
|
| 69 | - $server->getGroupManager() |
|
| 70 | - ); |
|
| 71 | - }); |
|
| 51 | + $cloudFederationManager = $server->getCloudFederationProviderManager(); |
|
| 52 | + $cloudFederationManager->addCloudFederationProvider('file', |
|
| 53 | + 'Federated Files Sharing', |
|
| 54 | + function() use ($container) { |
|
| 55 | + $server = $container->getServer(); |
|
| 56 | + return new CloudFederationProviderFiles( |
|
| 57 | + $server->getAppManager(), |
|
| 58 | + $server->query(FederatedShareProvider::class), |
|
| 59 | + $server->query(AddressHandler::class), |
|
| 60 | + $server->getLogger(), |
|
| 61 | + $server->getUserManager(), |
|
| 62 | + $server->getCloudIdManager(), |
|
| 63 | + $server->getActivityManager(), |
|
| 64 | + $server->getNotificationManager(), |
|
| 65 | + $server->getURLGenerator(), |
|
| 66 | + $server->getCloudFederationFactory(), |
|
| 67 | + $server->getCloudFederationProviderManager(), |
|
| 68 | + $server->getDatabaseConnection(), |
|
| 69 | + $server->getGroupManager() |
|
| 70 | + ); |
|
| 71 | + }); |
|
| 72 | 72 | |
| 73 | - $container->registerService('RequestHandlerController', function(SimpleContainer $c) use ($server) { |
|
| 74 | - $addressHandler = new AddressHandler( |
|
| 75 | - $server->getURLGenerator(), |
|
| 76 | - $server->getL10N('federatedfilesharing'), |
|
| 77 | - $server->getCloudIdManager() |
|
| 78 | - ); |
|
| 79 | - $notification = new Notifications( |
|
| 80 | - $addressHandler, |
|
| 81 | - $server->getHTTPClientService(), |
|
| 82 | - $server->query(\OCP\OCS\IDiscoveryService::class), |
|
| 83 | - \OC::$server->getJobList(), |
|
| 84 | - \OC::$server->getCloudFederationProviderManager(), |
|
| 85 | - \OC::$server->getCloudFederationFactory() |
|
| 86 | - ); |
|
| 87 | - return new RequestHandlerController( |
|
| 88 | - $c->query('AppName'), |
|
| 89 | - $server->getRequest(), |
|
| 90 | - $this->getFederatedShareProvider(), |
|
| 91 | - $server->getDatabaseConnection(), |
|
| 92 | - $server->getShareManager(), |
|
| 93 | - $notification, |
|
| 94 | - $addressHandler, |
|
| 95 | - $server->getUserManager(), |
|
| 96 | - $server->getCloudIdManager(), |
|
| 97 | - $server->getLogger(), |
|
| 98 | - $server->getCloudFederationFactory(), |
|
| 99 | - $server->getCloudFederationProviderManager() |
|
| 100 | - ); |
|
| 101 | - }); |
|
| 102 | - } |
|
| 73 | + $container->registerService('RequestHandlerController', function(SimpleContainer $c) use ($server) { |
|
| 74 | + $addressHandler = new AddressHandler( |
|
| 75 | + $server->getURLGenerator(), |
|
| 76 | + $server->getL10N('federatedfilesharing'), |
|
| 77 | + $server->getCloudIdManager() |
|
| 78 | + ); |
|
| 79 | + $notification = new Notifications( |
|
| 80 | + $addressHandler, |
|
| 81 | + $server->getHTTPClientService(), |
|
| 82 | + $server->query(\OCP\OCS\IDiscoveryService::class), |
|
| 83 | + \OC::$server->getJobList(), |
|
| 84 | + \OC::$server->getCloudFederationProviderManager(), |
|
| 85 | + \OC::$server->getCloudFederationFactory() |
|
| 86 | + ); |
|
| 87 | + return new RequestHandlerController( |
|
| 88 | + $c->query('AppName'), |
|
| 89 | + $server->getRequest(), |
|
| 90 | + $this->getFederatedShareProvider(), |
|
| 91 | + $server->getDatabaseConnection(), |
|
| 92 | + $server->getShareManager(), |
|
| 93 | + $notification, |
|
| 94 | + $addressHandler, |
|
| 95 | + $server->getUserManager(), |
|
| 96 | + $server->getCloudIdManager(), |
|
| 97 | + $server->getLogger(), |
|
| 98 | + $server->getCloudFederationFactory(), |
|
| 99 | + $server->getCloudFederationProviderManager() |
|
| 100 | + ); |
|
| 101 | + }); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * get instance of federated share provider |
|
| 106 | - * |
|
| 107 | - * @return FederatedShareProvider |
|
| 108 | - */ |
|
| 109 | - public function getFederatedShareProvider() { |
|
| 110 | - if ($this->federatedShareProvider === null) { |
|
| 111 | - $this->initFederatedShareProvider(); |
|
| 112 | - } |
|
| 113 | - return $this->federatedShareProvider; |
|
| 114 | - } |
|
| 104 | + /** |
|
| 105 | + * get instance of federated share provider |
|
| 106 | + * |
|
| 107 | + * @return FederatedShareProvider |
|
| 108 | + */ |
|
| 109 | + public function getFederatedShareProvider() { |
|
| 110 | + if ($this->federatedShareProvider === null) { |
|
| 111 | + $this->initFederatedShareProvider(); |
|
| 112 | + } |
|
| 113 | + return $this->federatedShareProvider; |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - /** |
|
| 117 | - * initialize federated share provider |
|
| 118 | - */ |
|
| 119 | - protected function initFederatedShareProvider() { |
|
| 120 | - $c = $this->getContainer(); |
|
| 121 | - $addressHandler = new \OCA\FederatedFileSharing\AddressHandler( |
|
| 122 | - \OC::$server->getURLGenerator(), |
|
| 123 | - \OC::$server->getL10N('federatedfilesharing'), |
|
| 124 | - \OC::$server->getCloudIdManager() |
|
| 125 | - ); |
|
| 126 | - $notifications = new \OCA\FederatedFileSharing\Notifications( |
|
| 127 | - $addressHandler, |
|
| 128 | - \OC::$server->getHTTPClientService(), |
|
| 129 | - \OC::$server->query(\OCP\OCS\IDiscoveryService::class), |
|
| 130 | - \OC::$server->getJobList(), |
|
| 131 | - \OC::$server->getCloudFederationProviderManager(), |
|
| 132 | - \OC::$server->getCloudFederationFactory() |
|
| 133 | - ); |
|
| 134 | - $tokenHandler = new \OCA\FederatedFileSharing\TokenHandler( |
|
| 135 | - \OC::$server->getSecureRandom() |
|
| 136 | - ); |
|
| 116 | + /** |
|
| 117 | + * initialize federated share provider |
|
| 118 | + */ |
|
| 119 | + protected function initFederatedShareProvider() { |
|
| 120 | + $c = $this->getContainer(); |
|
| 121 | + $addressHandler = new \OCA\FederatedFileSharing\AddressHandler( |
|
| 122 | + \OC::$server->getURLGenerator(), |
|
| 123 | + \OC::$server->getL10N('federatedfilesharing'), |
|
| 124 | + \OC::$server->getCloudIdManager() |
|
| 125 | + ); |
|
| 126 | + $notifications = new \OCA\FederatedFileSharing\Notifications( |
|
| 127 | + $addressHandler, |
|
| 128 | + \OC::$server->getHTTPClientService(), |
|
| 129 | + \OC::$server->query(\OCP\OCS\IDiscoveryService::class), |
|
| 130 | + \OC::$server->getJobList(), |
|
| 131 | + \OC::$server->getCloudFederationProviderManager(), |
|
| 132 | + \OC::$server->getCloudFederationFactory() |
|
| 133 | + ); |
|
| 134 | + $tokenHandler = new \OCA\FederatedFileSharing\TokenHandler( |
|
| 135 | + \OC::$server->getSecureRandom() |
|
| 136 | + ); |
|
| 137 | 137 | |
| 138 | - $this->federatedShareProvider = new \OCA\FederatedFileSharing\FederatedShareProvider( |
|
| 139 | - \OC::$server->getDatabaseConnection(), |
|
| 140 | - $addressHandler, |
|
| 141 | - $notifications, |
|
| 142 | - $tokenHandler, |
|
| 143 | - \OC::$server->getL10N('federatedfilesharing'), |
|
| 144 | - \OC::$server->getLogger(), |
|
| 145 | - \OC::$server->getLazyRootFolder(), |
|
| 146 | - \OC::$server->getConfig(), |
|
| 147 | - \OC::$server->getUserManager(), |
|
| 148 | - \OC::$server->getCloudIdManager(), |
|
| 149 | - $c->query(IConfig::class), |
|
| 150 | - \OC::$server->getCloudFederationProviderManager() |
|
| 138 | + $this->federatedShareProvider = new \OCA\FederatedFileSharing\FederatedShareProvider( |
|
| 139 | + \OC::$server->getDatabaseConnection(), |
|
| 140 | + $addressHandler, |
|
| 141 | + $notifications, |
|
| 142 | + $tokenHandler, |
|
| 143 | + \OC::$server->getL10N('federatedfilesharing'), |
|
| 144 | + \OC::$server->getLogger(), |
|
| 145 | + \OC::$server->getLazyRootFolder(), |
|
| 146 | + \OC::$server->getConfig(), |
|
| 147 | + \OC::$server->getUserManager(), |
|
| 148 | + \OC::$server->getCloudIdManager(), |
|
| 149 | + $c->query(IConfig::class), |
|
| 150 | + \OC::$server->getCloudFederationProviderManager() |
|
| 151 | 151 | |
| 152 | - ); |
|
| 153 | - } |
|
| 152 | + ); |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | 155 | } |
@@ -54,1033 +54,1033 @@ |
||
| 54 | 54 | */ |
| 55 | 55 | class FederatedShareProvider implements IShareProvider { |
| 56 | 56 | |
| 57 | - const SHARE_TYPE_REMOTE = 6; |
|
| 58 | - |
|
| 59 | - /** @var IDBConnection */ |
|
| 60 | - private $dbConnection; |
|
| 61 | - |
|
| 62 | - /** @var AddressHandler */ |
|
| 63 | - private $addressHandler; |
|
| 64 | - |
|
| 65 | - /** @var Notifications */ |
|
| 66 | - private $notifications; |
|
| 67 | - |
|
| 68 | - /** @var TokenHandler */ |
|
| 69 | - private $tokenHandler; |
|
| 70 | - |
|
| 71 | - /** @var IL10N */ |
|
| 72 | - private $l; |
|
| 73 | - |
|
| 74 | - /** @var ILogger */ |
|
| 75 | - private $logger; |
|
| 76 | - |
|
| 77 | - /** @var IRootFolder */ |
|
| 78 | - private $rootFolder; |
|
| 79 | - |
|
| 80 | - /** @var IConfig */ |
|
| 81 | - private $config; |
|
| 82 | - |
|
| 83 | - /** @var string */ |
|
| 84 | - private $externalShareTable = 'share_external'; |
|
| 85 | - |
|
| 86 | - /** @var IUserManager */ |
|
| 87 | - private $userManager; |
|
| 88 | - |
|
| 89 | - /** @var ICloudIdManager */ |
|
| 90 | - private $cloudIdManager; |
|
| 91 | - |
|
| 92 | - /** @var \OCP\GlobalScale\IConfig */ |
|
| 93 | - private $gsConfig; |
|
| 94 | - |
|
| 95 | - /** @var ICloudFederationProviderManager */ |
|
| 96 | - private $cloudFederationProviderManager; |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * DefaultShareProvider constructor. |
|
| 100 | - * |
|
| 101 | - * @param IDBConnection $connection |
|
| 102 | - * @param AddressHandler $addressHandler |
|
| 103 | - * @param Notifications $notifications |
|
| 104 | - * @param TokenHandler $tokenHandler |
|
| 105 | - * @param IL10N $l10n |
|
| 106 | - * @param ILogger $logger |
|
| 107 | - * @param IRootFolder $rootFolder |
|
| 108 | - * @param IConfig $config |
|
| 109 | - * @param IUserManager $userManager |
|
| 110 | - * @param ICloudIdManager $cloudIdManager |
|
| 111 | - * @param \OCP\GlobalScale\IConfig $globalScaleConfig |
|
| 112 | - * @param ICloudFederationProviderManager $cloudFederationProviderManager |
|
| 113 | - */ |
|
| 114 | - public function __construct( |
|
| 115 | - IDBConnection $connection, |
|
| 116 | - AddressHandler $addressHandler, |
|
| 117 | - Notifications $notifications, |
|
| 118 | - TokenHandler $tokenHandler, |
|
| 119 | - IL10N $l10n, |
|
| 120 | - ILogger $logger, |
|
| 121 | - IRootFolder $rootFolder, |
|
| 122 | - IConfig $config, |
|
| 123 | - IUserManager $userManager, |
|
| 124 | - ICloudIdManager $cloudIdManager, |
|
| 125 | - \OCP\GlobalScale\IConfig $globalScaleConfig, |
|
| 126 | - ICloudFederationProviderManager $cloudFederationProviderManager |
|
| 127 | - ) { |
|
| 128 | - $this->dbConnection = $connection; |
|
| 129 | - $this->addressHandler = $addressHandler; |
|
| 130 | - $this->notifications = $notifications; |
|
| 131 | - $this->tokenHandler = $tokenHandler; |
|
| 132 | - $this->l = $l10n; |
|
| 133 | - $this->logger = $logger; |
|
| 134 | - $this->rootFolder = $rootFolder; |
|
| 135 | - $this->config = $config; |
|
| 136 | - $this->userManager = $userManager; |
|
| 137 | - $this->cloudIdManager = $cloudIdManager; |
|
| 138 | - $this->gsConfig = $globalScaleConfig; |
|
| 139 | - $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Return the identifier of this provider. |
|
| 144 | - * |
|
| 145 | - * @return string Containing only [a-zA-Z0-9] |
|
| 146 | - */ |
|
| 147 | - public function identifier() { |
|
| 148 | - return 'ocFederatedSharing'; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * Share a path |
|
| 153 | - * |
|
| 154 | - * @param IShare $share |
|
| 155 | - * @return IShare The share object |
|
| 156 | - * @throws ShareNotFound |
|
| 157 | - * @throws \Exception |
|
| 158 | - */ |
|
| 159 | - public function create(IShare $share) { |
|
| 160 | - |
|
| 161 | - $shareWith = $share->getSharedWith(); |
|
| 162 | - $itemSource = $share->getNodeId(); |
|
| 163 | - $itemType = $share->getNodeType(); |
|
| 164 | - $permissions = $share->getPermissions(); |
|
| 165 | - $sharedBy = $share->getSharedBy(); |
|
| 166 | - $shareType = $share->getShareType(); |
|
| 167 | - |
|
| 168 | - if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE_GROUP && |
|
| 169 | - !$this->isOutgoingServer2serverGroupShareEnabled() |
|
| 170 | - ) { |
|
| 171 | - $message = 'It is not allowed to send federated group shares from this server.'; |
|
| 172 | - $message_t = $this->l->t('It is not allowed to send federated group shares from this server.'); |
|
| 173 | - $this->logger->debug($message, ['app' => 'Federated File Sharing']); |
|
| 174 | - throw new \Exception($message_t); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /* |
|
| 57 | + const SHARE_TYPE_REMOTE = 6; |
|
| 58 | + |
|
| 59 | + /** @var IDBConnection */ |
|
| 60 | + private $dbConnection; |
|
| 61 | + |
|
| 62 | + /** @var AddressHandler */ |
|
| 63 | + private $addressHandler; |
|
| 64 | + |
|
| 65 | + /** @var Notifications */ |
|
| 66 | + private $notifications; |
|
| 67 | + |
|
| 68 | + /** @var TokenHandler */ |
|
| 69 | + private $tokenHandler; |
|
| 70 | + |
|
| 71 | + /** @var IL10N */ |
|
| 72 | + private $l; |
|
| 73 | + |
|
| 74 | + /** @var ILogger */ |
|
| 75 | + private $logger; |
|
| 76 | + |
|
| 77 | + /** @var IRootFolder */ |
|
| 78 | + private $rootFolder; |
|
| 79 | + |
|
| 80 | + /** @var IConfig */ |
|
| 81 | + private $config; |
|
| 82 | + |
|
| 83 | + /** @var string */ |
|
| 84 | + private $externalShareTable = 'share_external'; |
|
| 85 | + |
|
| 86 | + /** @var IUserManager */ |
|
| 87 | + private $userManager; |
|
| 88 | + |
|
| 89 | + /** @var ICloudIdManager */ |
|
| 90 | + private $cloudIdManager; |
|
| 91 | + |
|
| 92 | + /** @var \OCP\GlobalScale\IConfig */ |
|
| 93 | + private $gsConfig; |
|
| 94 | + |
|
| 95 | + /** @var ICloudFederationProviderManager */ |
|
| 96 | + private $cloudFederationProviderManager; |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * DefaultShareProvider constructor. |
|
| 100 | + * |
|
| 101 | + * @param IDBConnection $connection |
|
| 102 | + * @param AddressHandler $addressHandler |
|
| 103 | + * @param Notifications $notifications |
|
| 104 | + * @param TokenHandler $tokenHandler |
|
| 105 | + * @param IL10N $l10n |
|
| 106 | + * @param ILogger $logger |
|
| 107 | + * @param IRootFolder $rootFolder |
|
| 108 | + * @param IConfig $config |
|
| 109 | + * @param IUserManager $userManager |
|
| 110 | + * @param ICloudIdManager $cloudIdManager |
|
| 111 | + * @param \OCP\GlobalScale\IConfig $globalScaleConfig |
|
| 112 | + * @param ICloudFederationProviderManager $cloudFederationProviderManager |
|
| 113 | + */ |
|
| 114 | + public function __construct( |
|
| 115 | + IDBConnection $connection, |
|
| 116 | + AddressHandler $addressHandler, |
|
| 117 | + Notifications $notifications, |
|
| 118 | + TokenHandler $tokenHandler, |
|
| 119 | + IL10N $l10n, |
|
| 120 | + ILogger $logger, |
|
| 121 | + IRootFolder $rootFolder, |
|
| 122 | + IConfig $config, |
|
| 123 | + IUserManager $userManager, |
|
| 124 | + ICloudIdManager $cloudIdManager, |
|
| 125 | + \OCP\GlobalScale\IConfig $globalScaleConfig, |
|
| 126 | + ICloudFederationProviderManager $cloudFederationProviderManager |
|
| 127 | + ) { |
|
| 128 | + $this->dbConnection = $connection; |
|
| 129 | + $this->addressHandler = $addressHandler; |
|
| 130 | + $this->notifications = $notifications; |
|
| 131 | + $this->tokenHandler = $tokenHandler; |
|
| 132 | + $this->l = $l10n; |
|
| 133 | + $this->logger = $logger; |
|
| 134 | + $this->rootFolder = $rootFolder; |
|
| 135 | + $this->config = $config; |
|
| 136 | + $this->userManager = $userManager; |
|
| 137 | + $this->cloudIdManager = $cloudIdManager; |
|
| 138 | + $this->gsConfig = $globalScaleConfig; |
|
| 139 | + $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Return the identifier of this provider. |
|
| 144 | + * |
|
| 145 | + * @return string Containing only [a-zA-Z0-9] |
|
| 146 | + */ |
|
| 147 | + public function identifier() { |
|
| 148 | + return 'ocFederatedSharing'; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * Share a path |
|
| 153 | + * |
|
| 154 | + * @param IShare $share |
|
| 155 | + * @return IShare The share object |
|
| 156 | + * @throws ShareNotFound |
|
| 157 | + * @throws \Exception |
|
| 158 | + */ |
|
| 159 | + public function create(IShare $share) { |
|
| 160 | + |
|
| 161 | + $shareWith = $share->getSharedWith(); |
|
| 162 | + $itemSource = $share->getNodeId(); |
|
| 163 | + $itemType = $share->getNodeType(); |
|
| 164 | + $permissions = $share->getPermissions(); |
|
| 165 | + $sharedBy = $share->getSharedBy(); |
|
| 166 | + $shareType = $share->getShareType(); |
|
| 167 | + |
|
| 168 | + if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE_GROUP && |
|
| 169 | + !$this->isOutgoingServer2serverGroupShareEnabled() |
|
| 170 | + ) { |
|
| 171 | + $message = 'It is not allowed to send federated group shares from this server.'; |
|
| 172 | + $message_t = $this->l->t('It is not allowed to send federated group shares from this server.'); |
|
| 173 | + $this->logger->debug($message, ['app' => 'Federated File Sharing']); |
|
| 174 | + throw new \Exception($message_t); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /* |
|
| 178 | 178 | * Check if file is not already shared with the remote user |
| 179 | 179 | */ |
| 180 | - $alreadyShared = $this->getSharedWith($shareWith, self::SHARE_TYPE_REMOTE, $share->getNode(), 1, 0); |
|
| 181 | - if (!empty($alreadyShared)) { |
|
| 182 | - $message = 'Sharing %s failed, because this item is already shared with %s'; |
|
| 183 | - $message_t = $this->l->t('Sharing %s failed, because this item is already shared with %s', array($share->getNode()->getName(), $shareWith)); |
|
| 184 | - $this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']); |
|
| 185 | - throw new \Exception($message_t); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - // don't allow federated shares if source and target server are the same |
|
| 190 | - $cloudId = $this->cloudIdManager->resolveCloudId($shareWith); |
|
| 191 | - $currentServer = $this->addressHandler->generateRemoteURL(); |
|
| 192 | - $currentUser = $sharedBy; |
|
| 193 | - if ($this->addressHandler->compareAddresses($cloudId->getUser(), $cloudId->getRemote(), $currentUser, $currentServer)) { |
|
| 194 | - $message = 'Not allowed to create a federated share with the same user.'; |
|
| 195 | - $message_t = $this->l->t('Not allowed to create a federated share with the same user'); |
|
| 196 | - $this->logger->debug($message, ['app' => 'Federated File Sharing']); |
|
| 197 | - throw new \Exception($message_t); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - |
|
| 201 | - $share->setSharedWith($cloudId->getId()); |
|
| 202 | - |
|
| 203 | - try { |
|
| 204 | - $remoteShare = $this->getShareFromExternalShareTable($share); |
|
| 205 | - } catch (ShareNotFound $e) { |
|
| 206 | - $remoteShare = null; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - if ($remoteShare) { |
|
| 210 | - try { |
|
| 211 | - $ownerCloudId = $this->cloudIdManager->getCloudId($remoteShare['owner'], $remoteShare['remote']); |
|
| 212 | - $shareId = $this->addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $ownerCloudId->getId(), $permissions, 'tmp_token_' . time()); |
|
| 213 | - $share->setId($shareId); |
|
| 214 | - list($token, $remoteId) = $this->askOwnerToReShare($shareWith, $share, $shareId); |
|
| 215 | - // remote share was create successfully if we get a valid token as return |
|
| 216 | - $send = is_string($token) && $token !== ''; |
|
| 217 | - } catch (\Exception $e) { |
|
| 218 | - // fall back to old re-share behavior if the remote server |
|
| 219 | - // doesn't support flat re-shares (was introduced with Nextcloud 9.1) |
|
| 220 | - $this->removeShareFromTable($share); |
|
| 221 | - $shareId = $this->createFederatedShare($share); |
|
| 222 | - } |
|
| 223 | - if ($send) { |
|
| 224 | - $this->updateSuccessfulReshare($shareId, $token); |
|
| 225 | - $this->storeRemoteId($shareId, $remoteId); |
|
| 226 | - } else { |
|
| 227 | - $this->removeShareFromTable($share); |
|
| 228 | - $message_t = $this->l->t('File is already shared with %s', [$shareWith]); |
|
| 229 | - throw new \Exception($message_t); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - } else { |
|
| 233 | - $shareId = $this->createFederatedShare($share); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - $data = $this->getRawShare($shareId); |
|
| 237 | - return $this->createShareObject($data); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * create federated share and inform the recipient |
|
| 242 | - * |
|
| 243 | - * @param IShare $share |
|
| 244 | - * @return int |
|
| 245 | - * @throws ShareNotFound |
|
| 246 | - * @throws \Exception |
|
| 247 | - */ |
|
| 248 | - protected function createFederatedShare(IShare $share) { |
|
| 249 | - $token = $this->tokenHandler->generateToken(); |
|
| 250 | - $shareId = $this->addShareToDB( |
|
| 251 | - $share->getNodeId(), |
|
| 252 | - $share->getNodeType(), |
|
| 253 | - $share->getSharedWith(), |
|
| 254 | - $share->getSharedBy(), |
|
| 255 | - $share->getShareOwner(), |
|
| 256 | - $share->getPermissions(), |
|
| 257 | - $token |
|
| 258 | - ); |
|
| 259 | - |
|
| 260 | - $failure = false; |
|
| 261 | - |
|
| 262 | - try { |
|
| 263 | - $sharedByFederatedId = $share->getSharedBy(); |
|
| 264 | - if ($this->userManager->userExists($sharedByFederatedId)) { |
|
| 265 | - $cloudId = $this->cloudIdManager->getCloudId($sharedByFederatedId, $this->addressHandler->generateRemoteURL()); |
|
| 266 | - $sharedByFederatedId = $cloudId->getId(); |
|
| 267 | - } |
|
| 268 | - $ownerCloudId = $this->cloudIdManager->getCloudId($share->getShareOwner(), $this->addressHandler->generateRemoteURL()); |
|
| 269 | - $send = $this->notifications->sendRemoteShare( |
|
| 270 | - $token, |
|
| 271 | - $share->getSharedWith(), |
|
| 272 | - $share->getNode()->getName(), |
|
| 273 | - $shareId, |
|
| 274 | - $share->getShareOwner(), |
|
| 275 | - $ownerCloudId->getId(), |
|
| 276 | - $share->getSharedBy(), |
|
| 277 | - $sharedByFederatedId, |
|
| 278 | - $share->getShareType() |
|
| 279 | - ); |
|
| 280 | - |
|
| 281 | - if ($send === false) { |
|
| 282 | - $failure = true; |
|
| 283 | - } |
|
| 284 | - } catch (\Exception $e) { |
|
| 285 | - $this->logger->logException($e, [ |
|
| 286 | - 'message' => 'Failed to notify remote server of federated share, removing share.', |
|
| 287 | - 'level' => ILogger::ERROR, |
|
| 288 | - 'app' => 'federatedfilesharing', |
|
| 289 | - ]); |
|
| 290 | - $failure = true; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - if($failure) { |
|
| 294 | - $this->removeShareFromTableById($shareId); |
|
| 295 | - $message_t = $this->l->t('Sharing %s failed, could not find %s, maybe the server is currently unreachable or uses a self-signed certificate.', |
|
| 296 | - [$share->getNode()->getName(), $share->getSharedWith()]); |
|
| 297 | - throw new \Exception($message_t); |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - return $shareId; |
|
| 301 | - |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * @param string $shareWith |
|
| 306 | - * @param IShare $share |
|
| 307 | - * @param string $shareId internal share Id |
|
| 308 | - * @return array |
|
| 309 | - * @throws \Exception |
|
| 310 | - */ |
|
| 311 | - protected function askOwnerToReShare($shareWith, IShare $share, $shareId) { |
|
| 312 | - |
|
| 313 | - $remoteShare = $this->getShareFromExternalShareTable($share); |
|
| 314 | - $token = $remoteShare['share_token']; |
|
| 315 | - $remoteId = $remoteShare['remote_id']; |
|
| 316 | - $remote = $remoteShare['remote']; |
|
| 317 | - |
|
| 318 | - list($token, $remoteId) = $this->notifications->requestReShare( |
|
| 319 | - $token, |
|
| 320 | - $remoteId, |
|
| 321 | - $shareId, |
|
| 322 | - $remote, |
|
| 323 | - $shareWith, |
|
| 324 | - $share->getPermissions(), |
|
| 325 | - $share->getNode()->getName() |
|
| 326 | - ); |
|
| 327 | - |
|
| 328 | - return [$token, $remoteId]; |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - /** |
|
| 332 | - * get federated share from the share_external table but exclude mounted link shares |
|
| 333 | - * |
|
| 334 | - * @param IShare $share |
|
| 335 | - * @return array |
|
| 336 | - * @throws ShareNotFound |
|
| 337 | - */ |
|
| 338 | - protected function getShareFromExternalShareTable(IShare $share) { |
|
| 339 | - $query = $this->dbConnection->getQueryBuilder(); |
|
| 340 | - $query->select('*')->from($this->externalShareTable) |
|
| 341 | - ->where($query->expr()->eq('user', $query->createNamedParameter($share->getShareOwner()))) |
|
| 342 | - ->andWhere($query->expr()->eq('mountpoint', $query->createNamedParameter($share->getTarget()))); |
|
| 343 | - $result = $query->execute()->fetchAll(); |
|
| 344 | - |
|
| 345 | - if (isset($result[0]) && (int)$result[0]['remote_id'] > 0) { |
|
| 346 | - return $result[0]; |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - throw new ShareNotFound('share not found in share_external table'); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * add share to the database and return the ID |
|
| 354 | - * |
|
| 355 | - * @param int $itemSource |
|
| 356 | - * @param string $itemType |
|
| 357 | - * @param string $shareWith |
|
| 358 | - * @param string $sharedBy |
|
| 359 | - * @param string $uidOwner |
|
| 360 | - * @param int $permissions |
|
| 361 | - * @param string $token |
|
| 362 | - * @return int |
|
| 363 | - */ |
|
| 364 | - private function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token) { |
|
| 365 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 366 | - $qb->insert('share') |
|
| 367 | - ->setValue('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE)) |
|
| 368 | - ->setValue('item_type', $qb->createNamedParameter($itemType)) |
|
| 369 | - ->setValue('item_source', $qb->createNamedParameter($itemSource)) |
|
| 370 | - ->setValue('file_source', $qb->createNamedParameter($itemSource)) |
|
| 371 | - ->setValue('share_with', $qb->createNamedParameter($shareWith)) |
|
| 372 | - ->setValue('uid_owner', $qb->createNamedParameter($uidOwner)) |
|
| 373 | - ->setValue('uid_initiator', $qb->createNamedParameter($sharedBy)) |
|
| 374 | - ->setValue('permissions', $qb->createNamedParameter($permissions)) |
|
| 375 | - ->setValue('token', $qb->createNamedParameter($token)) |
|
| 376 | - ->setValue('stime', $qb->createNamedParameter(time())); |
|
| 377 | - |
|
| 378 | - /* |
|
| 180 | + $alreadyShared = $this->getSharedWith($shareWith, self::SHARE_TYPE_REMOTE, $share->getNode(), 1, 0); |
|
| 181 | + if (!empty($alreadyShared)) { |
|
| 182 | + $message = 'Sharing %s failed, because this item is already shared with %s'; |
|
| 183 | + $message_t = $this->l->t('Sharing %s failed, because this item is already shared with %s', array($share->getNode()->getName(), $shareWith)); |
|
| 184 | + $this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']); |
|
| 185 | + throw new \Exception($message_t); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + // don't allow federated shares if source and target server are the same |
|
| 190 | + $cloudId = $this->cloudIdManager->resolveCloudId($shareWith); |
|
| 191 | + $currentServer = $this->addressHandler->generateRemoteURL(); |
|
| 192 | + $currentUser = $sharedBy; |
|
| 193 | + if ($this->addressHandler->compareAddresses($cloudId->getUser(), $cloudId->getRemote(), $currentUser, $currentServer)) { |
|
| 194 | + $message = 'Not allowed to create a federated share with the same user.'; |
|
| 195 | + $message_t = $this->l->t('Not allowed to create a federated share with the same user'); |
|
| 196 | + $this->logger->debug($message, ['app' => 'Federated File Sharing']); |
|
| 197 | + throw new \Exception($message_t); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + |
|
| 201 | + $share->setSharedWith($cloudId->getId()); |
|
| 202 | + |
|
| 203 | + try { |
|
| 204 | + $remoteShare = $this->getShareFromExternalShareTable($share); |
|
| 205 | + } catch (ShareNotFound $e) { |
|
| 206 | + $remoteShare = null; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + if ($remoteShare) { |
|
| 210 | + try { |
|
| 211 | + $ownerCloudId = $this->cloudIdManager->getCloudId($remoteShare['owner'], $remoteShare['remote']); |
|
| 212 | + $shareId = $this->addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $ownerCloudId->getId(), $permissions, 'tmp_token_' . time()); |
|
| 213 | + $share->setId($shareId); |
|
| 214 | + list($token, $remoteId) = $this->askOwnerToReShare($shareWith, $share, $shareId); |
|
| 215 | + // remote share was create successfully if we get a valid token as return |
|
| 216 | + $send = is_string($token) && $token !== ''; |
|
| 217 | + } catch (\Exception $e) { |
|
| 218 | + // fall back to old re-share behavior if the remote server |
|
| 219 | + // doesn't support flat re-shares (was introduced with Nextcloud 9.1) |
|
| 220 | + $this->removeShareFromTable($share); |
|
| 221 | + $shareId = $this->createFederatedShare($share); |
|
| 222 | + } |
|
| 223 | + if ($send) { |
|
| 224 | + $this->updateSuccessfulReshare($shareId, $token); |
|
| 225 | + $this->storeRemoteId($shareId, $remoteId); |
|
| 226 | + } else { |
|
| 227 | + $this->removeShareFromTable($share); |
|
| 228 | + $message_t = $this->l->t('File is already shared with %s', [$shareWith]); |
|
| 229 | + throw new \Exception($message_t); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + } else { |
|
| 233 | + $shareId = $this->createFederatedShare($share); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + $data = $this->getRawShare($shareId); |
|
| 237 | + return $this->createShareObject($data); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * create federated share and inform the recipient |
|
| 242 | + * |
|
| 243 | + * @param IShare $share |
|
| 244 | + * @return int |
|
| 245 | + * @throws ShareNotFound |
|
| 246 | + * @throws \Exception |
|
| 247 | + */ |
|
| 248 | + protected function createFederatedShare(IShare $share) { |
|
| 249 | + $token = $this->tokenHandler->generateToken(); |
|
| 250 | + $shareId = $this->addShareToDB( |
|
| 251 | + $share->getNodeId(), |
|
| 252 | + $share->getNodeType(), |
|
| 253 | + $share->getSharedWith(), |
|
| 254 | + $share->getSharedBy(), |
|
| 255 | + $share->getShareOwner(), |
|
| 256 | + $share->getPermissions(), |
|
| 257 | + $token |
|
| 258 | + ); |
|
| 259 | + |
|
| 260 | + $failure = false; |
|
| 261 | + |
|
| 262 | + try { |
|
| 263 | + $sharedByFederatedId = $share->getSharedBy(); |
|
| 264 | + if ($this->userManager->userExists($sharedByFederatedId)) { |
|
| 265 | + $cloudId = $this->cloudIdManager->getCloudId($sharedByFederatedId, $this->addressHandler->generateRemoteURL()); |
|
| 266 | + $sharedByFederatedId = $cloudId->getId(); |
|
| 267 | + } |
|
| 268 | + $ownerCloudId = $this->cloudIdManager->getCloudId($share->getShareOwner(), $this->addressHandler->generateRemoteURL()); |
|
| 269 | + $send = $this->notifications->sendRemoteShare( |
|
| 270 | + $token, |
|
| 271 | + $share->getSharedWith(), |
|
| 272 | + $share->getNode()->getName(), |
|
| 273 | + $shareId, |
|
| 274 | + $share->getShareOwner(), |
|
| 275 | + $ownerCloudId->getId(), |
|
| 276 | + $share->getSharedBy(), |
|
| 277 | + $sharedByFederatedId, |
|
| 278 | + $share->getShareType() |
|
| 279 | + ); |
|
| 280 | + |
|
| 281 | + if ($send === false) { |
|
| 282 | + $failure = true; |
|
| 283 | + } |
|
| 284 | + } catch (\Exception $e) { |
|
| 285 | + $this->logger->logException($e, [ |
|
| 286 | + 'message' => 'Failed to notify remote server of federated share, removing share.', |
|
| 287 | + 'level' => ILogger::ERROR, |
|
| 288 | + 'app' => 'federatedfilesharing', |
|
| 289 | + ]); |
|
| 290 | + $failure = true; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + if($failure) { |
|
| 294 | + $this->removeShareFromTableById($shareId); |
|
| 295 | + $message_t = $this->l->t('Sharing %s failed, could not find %s, maybe the server is currently unreachable or uses a self-signed certificate.', |
|
| 296 | + [$share->getNode()->getName(), $share->getSharedWith()]); |
|
| 297 | + throw new \Exception($message_t); |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + return $shareId; |
|
| 301 | + |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * @param string $shareWith |
|
| 306 | + * @param IShare $share |
|
| 307 | + * @param string $shareId internal share Id |
|
| 308 | + * @return array |
|
| 309 | + * @throws \Exception |
|
| 310 | + */ |
|
| 311 | + protected function askOwnerToReShare($shareWith, IShare $share, $shareId) { |
|
| 312 | + |
|
| 313 | + $remoteShare = $this->getShareFromExternalShareTable($share); |
|
| 314 | + $token = $remoteShare['share_token']; |
|
| 315 | + $remoteId = $remoteShare['remote_id']; |
|
| 316 | + $remote = $remoteShare['remote']; |
|
| 317 | + |
|
| 318 | + list($token, $remoteId) = $this->notifications->requestReShare( |
|
| 319 | + $token, |
|
| 320 | + $remoteId, |
|
| 321 | + $shareId, |
|
| 322 | + $remote, |
|
| 323 | + $shareWith, |
|
| 324 | + $share->getPermissions(), |
|
| 325 | + $share->getNode()->getName() |
|
| 326 | + ); |
|
| 327 | + |
|
| 328 | + return [$token, $remoteId]; |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + /** |
|
| 332 | + * get federated share from the share_external table but exclude mounted link shares |
|
| 333 | + * |
|
| 334 | + * @param IShare $share |
|
| 335 | + * @return array |
|
| 336 | + * @throws ShareNotFound |
|
| 337 | + */ |
|
| 338 | + protected function getShareFromExternalShareTable(IShare $share) { |
|
| 339 | + $query = $this->dbConnection->getQueryBuilder(); |
|
| 340 | + $query->select('*')->from($this->externalShareTable) |
|
| 341 | + ->where($query->expr()->eq('user', $query->createNamedParameter($share->getShareOwner()))) |
|
| 342 | + ->andWhere($query->expr()->eq('mountpoint', $query->createNamedParameter($share->getTarget()))); |
|
| 343 | + $result = $query->execute()->fetchAll(); |
|
| 344 | + |
|
| 345 | + if (isset($result[0]) && (int)$result[0]['remote_id'] > 0) { |
|
| 346 | + return $result[0]; |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + throw new ShareNotFound('share not found in share_external table'); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * add share to the database and return the ID |
|
| 354 | + * |
|
| 355 | + * @param int $itemSource |
|
| 356 | + * @param string $itemType |
|
| 357 | + * @param string $shareWith |
|
| 358 | + * @param string $sharedBy |
|
| 359 | + * @param string $uidOwner |
|
| 360 | + * @param int $permissions |
|
| 361 | + * @param string $token |
|
| 362 | + * @return int |
|
| 363 | + */ |
|
| 364 | + private function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token) { |
|
| 365 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 366 | + $qb->insert('share') |
|
| 367 | + ->setValue('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE)) |
|
| 368 | + ->setValue('item_type', $qb->createNamedParameter($itemType)) |
|
| 369 | + ->setValue('item_source', $qb->createNamedParameter($itemSource)) |
|
| 370 | + ->setValue('file_source', $qb->createNamedParameter($itemSource)) |
|
| 371 | + ->setValue('share_with', $qb->createNamedParameter($shareWith)) |
|
| 372 | + ->setValue('uid_owner', $qb->createNamedParameter($uidOwner)) |
|
| 373 | + ->setValue('uid_initiator', $qb->createNamedParameter($sharedBy)) |
|
| 374 | + ->setValue('permissions', $qb->createNamedParameter($permissions)) |
|
| 375 | + ->setValue('token', $qb->createNamedParameter($token)) |
|
| 376 | + ->setValue('stime', $qb->createNamedParameter(time())); |
|
| 377 | + |
|
| 378 | + /* |
|
| 379 | 379 | * Added to fix https://github.com/owncloud/core/issues/22215 |
| 380 | 380 | * Can be removed once we get rid of ajax/share.php |
| 381 | 381 | */ |
| 382 | - $qb->setValue('file_target', $qb->createNamedParameter('')); |
|
| 383 | - |
|
| 384 | - $qb->execute(); |
|
| 385 | - $id = $qb->getLastInsertId(); |
|
| 386 | - |
|
| 387 | - return (int)$id; |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * Update a share |
|
| 392 | - * |
|
| 393 | - * @param IShare $share |
|
| 394 | - * @return IShare The share object |
|
| 395 | - */ |
|
| 396 | - public function update(IShare $share) { |
|
| 397 | - /* |
|
| 382 | + $qb->setValue('file_target', $qb->createNamedParameter('')); |
|
| 383 | + |
|
| 384 | + $qb->execute(); |
|
| 385 | + $id = $qb->getLastInsertId(); |
|
| 386 | + |
|
| 387 | + return (int)$id; |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * Update a share |
|
| 392 | + * |
|
| 393 | + * @param IShare $share |
|
| 394 | + * @return IShare The share object |
|
| 395 | + */ |
|
| 396 | + public function update(IShare $share) { |
|
| 397 | + /* |
|
| 398 | 398 | * We allow updating the permissions of federated shares |
| 399 | 399 | */ |
| 400 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 401 | - $qb->update('share') |
|
| 402 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
| 403 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
| 404 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
| 405 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
| 406 | - ->execute(); |
|
| 407 | - |
|
| 408 | - // send the updated permission to the owner/initiator, if they are not the same |
|
| 409 | - if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
| 410 | - $this->sendPermissionUpdate($share); |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - return $share; |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - /** |
|
| 417 | - * send the updated permission to the owner/initiator, if they are not the same |
|
| 418 | - * |
|
| 419 | - * @param IShare $share |
|
| 420 | - * @throws ShareNotFound |
|
| 421 | - * @throws \OC\HintException |
|
| 422 | - */ |
|
| 423 | - protected function sendPermissionUpdate(IShare $share) { |
|
| 424 | - $remoteId = $this->getRemoteId($share); |
|
| 425 | - // if the local user is the owner we send the permission change to the initiator |
|
| 426 | - if ($this->userManager->userExists($share->getShareOwner())) { |
|
| 427 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
| 428 | - } else { // ... if not we send the permission change to the owner |
|
| 429 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner()); |
|
| 430 | - } |
|
| 431 | - $this->notifications->sendPermissionChange($remote, $remoteId, $share->getToken(), $share->getPermissions()); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * update successful reShare with the correct token |
|
| 437 | - * |
|
| 438 | - * @param int $shareId |
|
| 439 | - * @param string $token |
|
| 440 | - */ |
|
| 441 | - protected function updateSuccessfulReShare($shareId, $token) { |
|
| 442 | - $query = $this->dbConnection->getQueryBuilder(); |
|
| 443 | - $query->update('share') |
|
| 444 | - ->where($query->expr()->eq('id', $query->createNamedParameter($shareId))) |
|
| 445 | - ->set('token', $query->createNamedParameter($token)) |
|
| 446 | - ->execute(); |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - /** |
|
| 450 | - * store remote ID in federated reShare table |
|
| 451 | - * |
|
| 452 | - * @param $shareId |
|
| 453 | - * @param $remoteId |
|
| 454 | - */ |
|
| 455 | - public function storeRemoteId($shareId, $remoteId) { |
|
| 456 | - $query = $this->dbConnection->getQueryBuilder(); |
|
| 457 | - $query->insert('federated_reshares') |
|
| 458 | - ->values( |
|
| 459 | - [ |
|
| 460 | - 'share_id' => $query->createNamedParameter($shareId), |
|
| 461 | - 'remote_id' => $query->createNamedParameter($remoteId), |
|
| 462 | - ] |
|
| 463 | - ); |
|
| 464 | - $query->execute(); |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * get share ID on remote server for federated re-shares |
|
| 469 | - * |
|
| 470 | - * @param IShare $share |
|
| 471 | - * @return int |
|
| 472 | - * @throws ShareNotFound |
|
| 473 | - */ |
|
| 474 | - public function getRemoteId(IShare $share) { |
|
| 475 | - $query = $this->dbConnection->getQueryBuilder(); |
|
| 476 | - $query->select('remote_id')->from('federated_reshares') |
|
| 477 | - ->where($query->expr()->eq('share_id', $query->createNamedParameter((int)$share->getId()))); |
|
| 478 | - $data = $query->execute()->fetch(); |
|
| 479 | - |
|
| 480 | - if (!is_array($data) || !isset($data['remote_id'])) { |
|
| 481 | - throw new ShareNotFound(); |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - return (int)$data['remote_id']; |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * @inheritdoc |
|
| 489 | - */ |
|
| 490 | - public function move(IShare $share, $recipient) { |
|
| 491 | - /* |
|
| 400 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 401 | + $qb->update('share') |
|
| 402 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
| 403 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
| 404 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
| 405 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
| 406 | + ->execute(); |
|
| 407 | + |
|
| 408 | + // send the updated permission to the owner/initiator, if they are not the same |
|
| 409 | + if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
| 410 | + $this->sendPermissionUpdate($share); |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + return $share; |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + /** |
|
| 417 | + * send the updated permission to the owner/initiator, if they are not the same |
|
| 418 | + * |
|
| 419 | + * @param IShare $share |
|
| 420 | + * @throws ShareNotFound |
|
| 421 | + * @throws \OC\HintException |
|
| 422 | + */ |
|
| 423 | + protected function sendPermissionUpdate(IShare $share) { |
|
| 424 | + $remoteId = $this->getRemoteId($share); |
|
| 425 | + // if the local user is the owner we send the permission change to the initiator |
|
| 426 | + if ($this->userManager->userExists($share->getShareOwner())) { |
|
| 427 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
| 428 | + } else { // ... if not we send the permission change to the owner |
|
| 429 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner()); |
|
| 430 | + } |
|
| 431 | + $this->notifications->sendPermissionChange($remote, $remoteId, $share->getToken(), $share->getPermissions()); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * update successful reShare with the correct token |
|
| 437 | + * |
|
| 438 | + * @param int $shareId |
|
| 439 | + * @param string $token |
|
| 440 | + */ |
|
| 441 | + protected function updateSuccessfulReShare($shareId, $token) { |
|
| 442 | + $query = $this->dbConnection->getQueryBuilder(); |
|
| 443 | + $query->update('share') |
|
| 444 | + ->where($query->expr()->eq('id', $query->createNamedParameter($shareId))) |
|
| 445 | + ->set('token', $query->createNamedParameter($token)) |
|
| 446 | + ->execute(); |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + /** |
|
| 450 | + * store remote ID in federated reShare table |
|
| 451 | + * |
|
| 452 | + * @param $shareId |
|
| 453 | + * @param $remoteId |
|
| 454 | + */ |
|
| 455 | + public function storeRemoteId($shareId, $remoteId) { |
|
| 456 | + $query = $this->dbConnection->getQueryBuilder(); |
|
| 457 | + $query->insert('federated_reshares') |
|
| 458 | + ->values( |
|
| 459 | + [ |
|
| 460 | + 'share_id' => $query->createNamedParameter($shareId), |
|
| 461 | + 'remote_id' => $query->createNamedParameter($remoteId), |
|
| 462 | + ] |
|
| 463 | + ); |
|
| 464 | + $query->execute(); |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * get share ID on remote server for federated re-shares |
|
| 469 | + * |
|
| 470 | + * @param IShare $share |
|
| 471 | + * @return int |
|
| 472 | + * @throws ShareNotFound |
|
| 473 | + */ |
|
| 474 | + public function getRemoteId(IShare $share) { |
|
| 475 | + $query = $this->dbConnection->getQueryBuilder(); |
|
| 476 | + $query->select('remote_id')->from('federated_reshares') |
|
| 477 | + ->where($query->expr()->eq('share_id', $query->createNamedParameter((int)$share->getId()))); |
|
| 478 | + $data = $query->execute()->fetch(); |
|
| 479 | + |
|
| 480 | + if (!is_array($data) || !isset($data['remote_id'])) { |
|
| 481 | + throw new ShareNotFound(); |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + return (int)$data['remote_id']; |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * @inheritdoc |
|
| 489 | + */ |
|
| 490 | + public function move(IShare $share, $recipient) { |
|
| 491 | + /* |
|
| 492 | 492 | * This function does nothing yet as it is just for outgoing |
| 493 | 493 | * federated shares. |
| 494 | 494 | */ |
| 495 | - return $share; |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - /** |
|
| 499 | - * Get all children of this share |
|
| 500 | - * |
|
| 501 | - * @param IShare $parent |
|
| 502 | - * @return IShare[] |
|
| 503 | - */ |
|
| 504 | - public function getChildren(IShare $parent) { |
|
| 505 | - $children = []; |
|
| 506 | - |
|
| 507 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 508 | - $qb->select('*') |
|
| 509 | - ->from('share') |
|
| 510 | - ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
| 511 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))) |
|
| 512 | - ->orderBy('id'); |
|
| 513 | - |
|
| 514 | - $cursor = $qb->execute(); |
|
| 515 | - while($data = $cursor->fetch()) { |
|
| 516 | - $children[] = $this->createShareObject($data); |
|
| 517 | - } |
|
| 518 | - $cursor->closeCursor(); |
|
| 519 | - |
|
| 520 | - return $children; |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - /** |
|
| 524 | - * Delete a share (owner unShares the file) |
|
| 525 | - * |
|
| 526 | - * @param IShare $share |
|
| 527 | - * @throws ShareNotFound |
|
| 528 | - * @throws \OC\HintException |
|
| 529 | - */ |
|
| 530 | - public function delete(IShare $share) { |
|
| 531 | - |
|
| 532 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedWith()); |
|
| 533 | - |
|
| 534 | - // if the local user is the owner we can send the unShare request directly... |
|
| 535 | - if ($this->userManager->userExists($share->getShareOwner())) { |
|
| 536 | - $this->notifications->sendRemoteUnShare($remote, $share->getId(), $share->getToken()); |
|
| 537 | - $this->revokeShare($share, true); |
|
| 538 | - } else { // ... if not we need to correct ID for the unShare request |
|
| 539 | - $remoteId = $this->getRemoteId($share); |
|
| 540 | - $this->notifications->sendRemoteUnShare($remote, $remoteId, $share->getToken()); |
|
| 541 | - $this->revokeShare($share, false); |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - // only remove the share when all messages are send to not lose information |
|
| 545 | - // about the share to early |
|
| 546 | - $this->removeShareFromTable($share); |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * in case of a re-share we need to send the other use (initiator or owner) |
|
| 551 | - * a message that the file was unshared |
|
| 552 | - * |
|
| 553 | - * @param IShare $share |
|
| 554 | - * @param bool $isOwner the user can either be the owner or the user who re-sahred it |
|
| 555 | - * @throws ShareNotFound |
|
| 556 | - * @throws \OC\HintException |
|
| 557 | - */ |
|
| 558 | - protected function revokeShare($share, $isOwner) { |
|
| 559 | - // also send a unShare request to the initiator, if this is a different user than the owner |
|
| 560 | - if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
| 561 | - if ($isOwner) { |
|
| 562 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
| 563 | - } else { |
|
| 564 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner()); |
|
| 565 | - } |
|
| 566 | - $remoteId = $this->getRemoteId($share); |
|
| 567 | - $this->notifications->sendRevokeShare($remote, $remoteId, $share->getToken()); |
|
| 568 | - } |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - /** |
|
| 572 | - * remove share from table |
|
| 573 | - * |
|
| 574 | - * @param IShare $share |
|
| 575 | - */ |
|
| 576 | - public function removeShareFromTable(IShare $share) { |
|
| 577 | - $this->removeShareFromTableById($share->getId()); |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - /** |
|
| 581 | - * remove share from table |
|
| 582 | - * |
|
| 583 | - * @param string $shareId |
|
| 584 | - */ |
|
| 585 | - private function removeShareFromTableById($shareId) { |
|
| 586 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 587 | - $qb->delete('share') |
|
| 588 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId))); |
|
| 589 | - $qb->execute(); |
|
| 590 | - |
|
| 591 | - $qb->delete('federated_reshares') |
|
| 592 | - ->where($qb->expr()->eq('share_id', $qb->createNamedParameter($shareId))); |
|
| 593 | - $qb->execute(); |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - /** |
|
| 597 | - * @inheritdoc |
|
| 598 | - */ |
|
| 599 | - public function deleteFromSelf(IShare $share, $recipient) { |
|
| 600 | - // nothing to do here. Technically deleteFromSelf in the context of federated |
|
| 601 | - // shares is a umount of a external storage. This is handled here |
|
| 602 | - // apps/files_sharing/lib/external/manager.php |
|
| 603 | - // TODO move this code over to this app |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - |
|
| 607 | - public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
| 608 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 609 | - $qb->select('*') |
|
| 610 | - ->from('share', 's') |
|
| 611 | - ->andWhere($qb->expr()->orX( |
|
| 612 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 613 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 614 | - )) |
|
| 615 | - ->andWhere( |
|
| 616 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE)) |
|
| 617 | - ); |
|
| 618 | - |
|
| 619 | - /** |
|
| 620 | - * Reshares for this user are shares where they are the owner. |
|
| 621 | - */ |
|
| 622 | - if ($reshares === false) { |
|
| 623 | - $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
| 624 | - } else { |
|
| 625 | - $qb->andWhere( |
|
| 626 | - $qb->expr()->orX( |
|
| 627 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 628 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
| 629 | - ) |
|
| 630 | - ); |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
| 634 | - $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
| 635 | - |
|
| 636 | - $qb->orderBy('id'); |
|
| 637 | - |
|
| 638 | - $cursor = $qb->execute(); |
|
| 639 | - $shares = []; |
|
| 640 | - while ($data = $cursor->fetch()) { |
|
| 641 | - $shares[$data['fileid']][] = $this->createShareObject($data); |
|
| 642 | - } |
|
| 643 | - $cursor->closeCursor(); |
|
| 644 | - |
|
| 645 | - return $shares; |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - /** |
|
| 649 | - * @inheritdoc |
|
| 650 | - */ |
|
| 651 | - public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
| 652 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 653 | - $qb->select('*') |
|
| 654 | - ->from('share'); |
|
| 655 | - |
|
| 656 | - $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))); |
|
| 657 | - |
|
| 658 | - /** |
|
| 659 | - * Reshares for this user are shares where they are the owner. |
|
| 660 | - */ |
|
| 661 | - if ($reshares === false) { |
|
| 662 | - //Special case for old shares created via the web UI |
|
| 663 | - $or1 = $qb->expr()->andX( |
|
| 664 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 665 | - $qb->expr()->isNull('uid_initiator') |
|
| 666 | - ); |
|
| 667 | - |
|
| 668 | - $qb->andWhere( |
|
| 669 | - $qb->expr()->orX( |
|
| 670 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)), |
|
| 671 | - $or1 |
|
| 672 | - ) |
|
| 673 | - ); |
|
| 674 | - } else { |
|
| 675 | - $qb->andWhere( |
|
| 676 | - $qb->expr()->orX( |
|
| 677 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 678 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
| 679 | - ) |
|
| 680 | - ); |
|
| 681 | - } |
|
| 682 | - |
|
| 683 | - if ($node !== null) { |
|
| 684 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - if ($limit !== -1) { |
|
| 688 | - $qb->setMaxResults($limit); |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - $qb->setFirstResult($offset); |
|
| 692 | - $qb->orderBy('id'); |
|
| 693 | - |
|
| 694 | - $cursor = $qb->execute(); |
|
| 695 | - $shares = []; |
|
| 696 | - while($data = $cursor->fetch()) { |
|
| 697 | - $shares[] = $this->createShareObject($data); |
|
| 698 | - } |
|
| 699 | - $cursor->closeCursor(); |
|
| 700 | - |
|
| 701 | - return $shares; |
|
| 702 | - } |
|
| 703 | - |
|
| 704 | - /** |
|
| 705 | - * @inheritdoc |
|
| 706 | - */ |
|
| 707 | - public function getShareById($id, $recipientId = null) { |
|
| 708 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 709 | - |
|
| 710 | - $qb->select('*') |
|
| 711 | - ->from('share') |
|
| 712 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
| 713 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))); |
|
| 714 | - |
|
| 715 | - $cursor = $qb->execute(); |
|
| 716 | - $data = $cursor->fetch(); |
|
| 717 | - $cursor->closeCursor(); |
|
| 718 | - |
|
| 719 | - if ($data === false) { |
|
| 720 | - throw new ShareNotFound('Can not find share with ID: ' . $id); |
|
| 721 | - } |
|
| 722 | - |
|
| 723 | - try { |
|
| 724 | - $share = $this->createShareObject($data); |
|
| 725 | - } catch (InvalidShare $e) { |
|
| 726 | - throw new ShareNotFound(); |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - return $share; |
|
| 730 | - } |
|
| 731 | - |
|
| 732 | - /** |
|
| 733 | - * Get shares for a given path |
|
| 734 | - * |
|
| 735 | - * @param \OCP\Files\Node $path |
|
| 736 | - * @return IShare[] |
|
| 737 | - */ |
|
| 738 | - public function getSharesByPath(Node $path) { |
|
| 739 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 740 | - |
|
| 741 | - $cursor = $qb->select('*') |
|
| 742 | - ->from('share') |
|
| 743 | - ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
| 744 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))) |
|
| 745 | - ->execute(); |
|
| 746 | - |
|
| 747 | - $shares = []; |
|
| 748 | - while($data = $cursor->fetch()) { |
|
| 749 | - $shares[] = $this->createShareObject($data); |
|
| 750 | - } |
|
| 751 | - $cursor->closeCursor(); |
|
| 752 | - |
|
| 753 | - return $shares; |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - /** |
|
| 757 | - * @inheritdoc |
|
| 758 | - */ |
|
| 759 | - public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
| 760 | - /** @var IShare[] $shares */ |
|
| 761 | - $shares = []; |
|
| 762 | - |
|
| 763 | - //Get shares directly with this user |
|
| 764 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 765 | - $qb->select('*') |
|
| 766 | - ->from('share'); |
|
| 767 | - |
|
| 768 | - // Order by id |
|
| 769 | - $qb->orderBy('id'); |
|
| 770 | - |
|
| 771 | - // Set limit and offset |
|
| 772 | - if ($limit !== -1) { |
|
| 773 | - $qb->setMaxResults($limit); |
|
| 774 | - } |
|
| 775 | - $qb->setFirstResult($offset); |
|
| 776 | - |
|
| 777 | - $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))); |
|
| 778 | - $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))); |
|
| 779 | - |
|
| 780 | - // Filter by node if provided |
|
| 781 | - if ($node !== null) { |
|
| 782 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
| 783 | - } |
|
| 784 | - |
|
| 785 | - $cursor = $qb->execute(); |
|
| 786 | - |
|
| 787 | - while($data = $cursor->fetch()) { |
|
| 788 | - $shares[] = $this->createShareObject($data); |
|
| 789 | - } |
|
| 790 | - $cursor->closeCursor(); |
|
| 791 | - |
|
| 792 | - |
|
| 793 | - return $shares; |
|
| 794 | - } |
|
| 795 | - |
|
| 796 | - /** |
|
| 797 | - * Get a share by token |
|
| 798 | - * |
|
| 799 | - * @param string $token |
|
| 800 | - * @return IShare |
|
| 801 | - * @throws ShareNotFound |
|
| 802 | - */ |
|
| 803 | - public function getShareByToken($token) { |
|
| 804 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 805 | - |
|
| 806 | - $cursor = $qb->select('*') |
|
| 807 | - ->from('share') |
|
| 808 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))) |
|
| 809 | - ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
| 810 | - ->execute(); |
|
| 811 | - |
|
| 812 | - $data = $cursor->fetch(); |
|
| 813 | - |
|
| 814 | - if ($data === false) { |
|
| 815 | - throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - try { |
|
| 819 | - $share = $this->createShareObject($data); |
|
| 820 | - } catch (InvalidShare $e) { |
|
| 821 | - throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
| 822 | - } |
|
| 823 | - |
|
| 824 | - return $share; |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - /** |
|
| 828 | - * get database row of a give share |
|
| 829 | - * |
|
| 830 | - * @param $id |
|
| 831 | - * @return array |
|
| 832 | - * @throws ShareNotFound |
|
| 833 | - */ |
|
| 834 | - private function getRawShare($id) { |
|
| 835 | - |
|
| 836 | - // Now fetch the inserted share and create a complete share object |
|
| 837 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 838 | - $qb->select('*') |
|
| 839 | - ->from('share') |
|
| 840 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
| 841 | - |
|
| 842 | - $cursor = $qb->execute(); |
|
| 843 | - $data = $cursor->fetch(); |
|
| 844 | - $cursor->closeCursor(); |
|
| 845 | - |
|
| 846 | - if ($data === false) { |
|
| 847 | - throw new ShareNotFound; |
|
| 848 | - } |
|
| 849 | - |
|
| 850 | - return $data; |
|
| 851 | - } |
|
| 852 | - |
|
| 853 | - /** |
|
| 854 | - * Create a share object from an database row |
|
| 855 | - * |
|
| 856 | - * @param array $data |
|
| 857 | - * @return IShare |
|
| 858 | - * @throws InvalidShare |
|
| 859 | - * @throws ShareNotFound |
|
| 860 | - */ |
|
| 861 | - private function createShareObject($data) { |
|
| 862 | - |
|
| 863 | - $share = new Share($this->rootFolder, $this->userManager); |
|
| 864 | - $share->setId((int)$data['id']) |
|
| 865 | - ->setShareType((int)$data['share_type']) |
|
| 866 | - ->setPermissions((int)$data['permissions']) |
|
| 867 | - ->setTarget($data['file_target']) |
|
| 868 | - ->setMailSend((bool)$data['mail_send']) |
|
| 869 | - ->setToken($data['token']); |
|
| 870 | - |
|
| 871 | - $shareTime = new \DateTime(); |
|
| 872 | - $shareTime->setTimestamp((int)$data['stime']); |
|
| 873 | - $share->setShareTime($shareTime); |
|
| 874 | - $share->setSharedWith($data['share_with']); |
|
| 875 | - |
|
| 876 | - if ($data['uid_initiator'] !== null) { |
|
| 877 | - $share->setShareOwner($data['uid_owner']); |
|
| 878 | - $share->setSharedBy($data['uid_initiator']); |
|
| 879 | - } else { |
|
| 880 | - //OLD SHARE |
|
| 881 | - $share->setSharedBy($data['uid_owner']); |
|
| 882 | - $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
| 883 | - |
|
| 884 | - $owner = $path->getOwner(); |
|
| 885 | - $share->setShareOwner($owner->getUID()); |
|
| 886 | - } |
|
| 887 | - |
|
| 888 | - $share->setNodeId((int)$data['file_source']); |
|
| 889 | - $share->setNodeType($data['item_type']); |
|
| 890 | - |
|
| 891 | - $share->setProviderId($this->identifier()); |
|
| 892 | - |
|
| 893 | - return $share; |
|
| 894 | - } |
|
| 895 | - |
|
| 896 | - /** |
|
| 897 | - * Get the node with file $id for $user |
|
| 898 | - * |
|
| 899 | - * @param string $userId |
|
| 900 | - * @param int $id |
|
| 901 | - * @return \OCP\Files\File|\OCP\Files\Folder |
|
| 902 | - * @throws InvalidShare |
|
| 903 | - */ |
|
| 904 | - private function getNode($userId, $id) { |
|
| 905 | - try { |
|
| 906 | - $userFolder = $this->rootFolder->getUserFolder($userId); |
|
| 907 | - } catch (NotFoundException $e) { |
|
| 908 | - throw new InvalidShare(); |
|
| 909 | - } |
|
| 910 | - |
|
| 911 | - $nodes = $userFolder->getById($id); |
|
| 912 | - |
|
| 913 | - if (empty($nodes)) { |
|
| 914 | - throw new InvalidShare(); |
|
| 915 | - } |
|
| 916 | - |
|
| 917 | - return $nodes[0]; |
|
| 918 | - } |
|
| 919 | - |
|
| 920 | - /** |
|
| 921 | - * A user is deleted from the system |
|
| 922 | - * So clean up the relevant shares. |
|
| 923 | - * |
|
| 924 | - * @param string $uid |
|
| 925 | - * @param int $shareType |
|
| 926 | - */ |
|
| 927 | - public function userDeleted($uid, $shareType) { |
|
| 928 | - //TODO: probabaly a good idea to send unshare info to remote servers |
|
| 929 | - |
|
| 930 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 931 | - |
|
| 932 | - $qb->delete('share') |
|
| 933 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE))) |
|
| 934 | - ->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))) |
|
| 935 | - ->execute(); |
|
| 936 | - } |
|
| 937 | - |
|
| 938 | - /** |
|
| 939 | - * This provider does not handle groups |
|
| 940 | - * |
|
| 941 | - * @param string $gid |
|
| 942 | - */ |
|
| 943 | - public function groupDeleted($gid) { |
|
| 944 | - // We don't handle groups here |
|
| 945 | - } |
|
| 946 | - |
|
| 947 | - /** |
|
| 948 | - * This provider does not handle groups |
|
| 949 | - * |
|
| 950 | - * @param string $uid |
|
| 951 | - * @param string $gid |
|
| 952 | - */ |
|
| 953 | - public function userDeletedFromGroup($uid, $gid) { |
|
| 954 | - // We don't handle groups here |
|
| 955 | - } |
|
| 956 | - |
|
| 957 | - /** |
|
| 958 | - * check if users from other Nextcloud instances are allowed to mount public links share by this instance |
|
| 959 | - * |
|
| 960 | - * @return bool |
|
| 961 | - */ |
|
| 962 | - public function isOutgoingServer2serverShareEnabled() { |
|
| 963 | - if ($this->gsConfig->onlyInternalFederation()) { |
|
| 964 | - return false; |
|
| 965 | - } |
|
| 966 | - $result = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes'); |
|
| 967 | - return ($result === 'yes'); |
|
| 968 | - } |
|
| 969 | - |
|
| 970 | - /** |
|
| 971 | - * check if users are allowed to mount public links from other Nextclouds |
|
| 972 | - * |
|
| 973 | - * @return bool |
|
| 974 | - */ |
|
| 975 | - public function isIncomingServer2serverShareEnabled() { |
|
| 976 | - if ($this->gsConfig->onlyInternalFederation()) { |
|
| 977 | - return false; |
|
| 978 | - } |
|
| 979 | - $result = $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes'); |
|
| 980 | - return ($result === 'yes'); |
|
| 981 | - } |
|
| 982 | - |
|
| 983 | - |
|
| 984 | - /** |
|
| 985 | - * check if users from other Nextcloud instances are allowed to send federated group shares |
|
| 986 | - * |
|
| 987 | - * @return bool |
|
| 988 | - */ |
|
| 989 | - public function isOutgoingServer2serverGroupShareEnabled() { |
|
| 990 | - if ($this->gsConfig->onlyInternalFederation()) { |
|
| 991 | - return false; |
|
| 992 | - } |
|
| 993 | - $result = $this->config->getAppValue('files_sharing', 'outgoing_server2server_group_share_enabled', 'no'); |
|
| 994 | - return ($result === 'yes'); |
|
| 995 | - } |
|
| 996 | - |
|
| 997 | - /** |
|
| 998 | - * check if users are allowed to receive federated group shares |
|
| 999 | - * |
|
| 1000 | - * @return bool |
|
| 1001 | - */ |
|
| 1002 | - public function isIncomingServer2serverGroupShareEnabled() { |
|
| 1003 | - if ($this->gsConfig->onlyInternalFederation()) { |
|
| 1004 | - return false; |
|
| 1005 | - } |
|
| 1006 | - $result = $this->config->getAppValue('files_sharing', 'incoming_server2server_group_share_enabled', 'no'); |
|
| 1007 | - return ($result === 'yes'); |
|
| 1008 | - } |
|
| 1009 | - |
|
| 1010 | - /** |
|
| 1011 | - * check if federated group sharing is supported, therefore the OCM API need to be enabled |
|
| 1012 | - * |
|
| 1013 | - * @return bool |
|
| 1014 | - */ |
|
| 1015 | - public function isFederatedGroupSharingSupported() { |
|
| 1016 | - return $this->cloudFederationProviderManager->isReady(); |
|
| 1017 | - } |
|
| 1018 | - |
|
| 1019 | - /** |
|
| 1020 | - * Check if querying sharees on the lookup server is enabled |
|
| 1021 | - * |
|
| 1022 | - * @return bool |
|
| 1023 | - */ |
|
| 1024 | - public function isLookupServerQueriesEnabled() { |
|
| 1025 | - // in a global scale setup we should always query the lookup server |
|
| 1026 | - if ($this->gsConfig->isGlobalScaleEnabled()) { |
|
| 1027 | - return true; |
|
| 1028 | - } |
|
| 1029 | - $result = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no'); |
|
| 1030 | - return ($result === 'yes'); |
|
| 1031 | - } |
|
| 1032 | - |
|
| 1033 | - |
|
| 1034 | - /** |
|
| 1035 | - * Check if it is allowed to publish user specific data to the lookup server |
|
| 1036 | - * |
|
| 1037 | - * @return bool |
|
| 1038 | - */ |
|
| 1039 | - public function isLookupServerUploadEnabled() { |
|
| 1040 | - // in a global scale setup the admin is responsible to keep the lookup server up-to-date |
|
| 1041 | - if ($this->gsConfig->isGlobalScaleEnabled()) { |
|
| 1042 | - return false; |
|
| 1043 | - } |
|
| 1044 | - $result = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes'); |
|
| 1045 | - return ($result === 'yes'); |
|
| 1046 | - } |
|
| 1047 | - |
|
| 1048 | - /** |
|
| 1049 | - * @inheritdoc |
|
| 1050 | - */ |
|
| 1051 | - public function getAccessList($nodes, $currentAccess) { |
|
| 1052 | - $ids = []; |
|
| 1053 | - foreach ($nodes as $node) { |
|
| 1054 | - $ids[] = $node->getId(); |
|
| 1055 | - } |
|
| 1056 | - |
|
| 1057 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 1058 | - $qb->select('share_with', 'token', 'file_source') |
|
| 1059 | - ->from('share') |
|
| 1060 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE))) |
|
| 1061 | - ->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
| 1062 | - ->andWhere($qb->expr()->orX( |
|
| 1063 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 1064 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 1065 | - )); |
|
| 1066 | - $cursor = $qb->execute(); |
|
| 1067 | - |
|
| 1068 | - if ($currentAccess === false) { |
|
| 1069 | - $remote = $cursor->fetch() !== false; |
|
| 1070 | - $cursor->closeCursor(); |
|
| 1071 | - |
|
| 1072 | - return ['remote' => $remote]; |
|
| 1073 | - } |
|
| 1074 | - |
|
| 1075 | - $remote = []; |
|
| 1076 | - while ($row = $cursor->fetch()) { |
|
| 1077 | - $remote[$row['share_with']] = [ |
|
| 1078 | - 'node_id' => $row['file_source'], |
|
| 1079 | - 'token' => $row['token'], |
|
| 1080 | - ]; |
|
| 1081 | - } |
|
| 1082 | - $cursor->closeCursor(); |
|
| 1083 | - |
|
| 1084 | - return ['remote' => $remote]; |
|
| 1085 | - } |
|
| 495 | + return $share; |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + /** |
|
| 499 | + * Get all children of this share |
|
| 500 | + * |
|
| 501 | + * @param IShare $parent |
|
| 502 | + * @return IShare[] |
|
| 503 | + */ |
|
| 504 | + public function getChildren(IShare $parent) { |
|
| 505 | + $children = []; |
|
| 506 | + |
|
| 507 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 508 | + $qb->select('*') |
|
| 509 | + ->from('share') |
|
| 510 | + ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
| 511 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))) |
|
| 512 | + ->orderBy('id'); |
|
| 513 | + |
|
| 514 | + $cursor = $qb->execute(); |
|
| 515 | + while($data = $cursor->fetch()) { |
|
| 516 | + $children[] = $this->createShareObject($data); |
|
| 517 | + } |
|
| 518 | + $cursor->closeCursor(); |
|
| 519 | + |
|
| 520 | + return $children; |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + /** |
|
| 524 | + * Delete a share (owner unShares the file) |
|
| 525 | + * |
|
| 526 | + * @param IShare $share |
|
| 527 | + * @throws ShareNotFound |
|
| 528 | + * @throws \OC\HintException |
|
| 529 | + */ |
|
| 530 | + public function delete(IShare $share) { |
|
| 531 | + |
|
| 532 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedWith()); |
|
| 533 | + |
|
| 534 | + // if the local user is the owner we can send the unShare request directly... |
|
| 535 | + if ($this->userManager->userExists($share->getShareOwner())) { |
|
| 536 | + $this->notifications->sendRemoteUnShare($remote, $share->getId(), $share->getToken()); |
|
| 537 | + $this->revokeShare($share, true); |
|
| 538 | + } else { // ... if not we need to correct ID for the unShare request |
|
| 539 | + $remoteId = $this->getRemoteId($share); |
|
| 540 | + $this->notifications->sendRemoteUnShare($remote, $remoteId, $share->getToken()); |
|
| 541 | + $this->revokeShare($share, false); |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + // only remove the share when all messages are send to not lose information |
|
| 545 | + // about the share to early |
|
| 546 | + $this->removeShareFromTable($share); |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * in case of a re-share we need to send the other use (initiator or owner) |
|
| 551 | + * a message that the file was unshared |
|
| 552 | + * |
|
| 553 | + * @param IShare $share |
|
| 554 | + * @param bool $isOwner the user can either be the owner or the user who re-sahred it |
|
| 555 | + * @throws ShareNotFound |
|
| 556 | + * @throws \OC\HintException |
|
| 557 | + */ |
|
| 558 | + protected function revokeShare($share, $isOwner) { |
|
| 559 | + // also send a unShare request to the initiator, if this is a different user than the owner |
|
| 560 | + if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
| 561 | + if ($isOwner) { |
|
| 562 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
| 563 | + } else { |
|
| 564 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner()); |
|
| 565 | + } |
|
| 566 | + $remoteId = $this->getRemoteId($share); |
|
| 567 | + $this->notifications->sendRevokeShare($remote, $remoteId, $share->getToken()); |
|
| 568 | + } |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + /** |
|
| 572 | + * remove share from table |
|
| 573 | + * |
|
| 574 | + * @param IShare $share |
|
| 575 | + */ |
|
| 576 | + public function removeShareFromTable(IShare $share) { |
|
| 577 | + $this->removeShareFromTableById($share->getId()); |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + /** |
|
| 581 | + * remove share from table |
|
| 582 | + * |
|
| 583 | + * @param string $shareId |
|
| 584 | + */ |
|
| 585 | + private function removeShareFromTableById($shareId) { |
|
| 586 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 587 | + $qb->delete('share') |
|
| 588 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId))); |
|
| 589 | + $qb->execute(); |
|
| 590 | + |
|
| 591 | + $qb->delete('federated_reshares') |
|
| 592 | + ->where($qb->expr()->eq('share_id', $qb->createNamedParameter($shareId))); |
|
| 593 | + $qb->execute(); |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + /** |
|
| 597 | + * @inheritdoc |
|
| 598 | + */ |
|
| 599 | + public function deleteFromSelf(IShare $share, $recipient) { |
|
| 600 | + // nothing to do here. Technically deleteFromSelf in the context of federated |
|
| 601 | + // shares is a umount of a external storage. This is handled here |
|
| 602 | + // apps/files_sharing/lib/external/manager.php |
|
| 603 | + // TODO move this code over to this app |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + |
|
| 607 | + public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
| 608 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 609 | + $qb->select('*') |
|
| 610 | + ->from('share', 's') |
|
| 611 | + ->andWhere($qb->expr()->orX( |
|
| 612 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 613 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 614 | + )) |
|
| 615 | + ->andWhere( |
|
| 616 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE)) |
|
| 617 | + ); |
|
| 618 | + |
|
| 619 | + /** |
|
| 620 | + * Reshares for this user are shares where they are the owner. |
|
| 621 | + */ |
|
| 622 | + if ($reshares === false) { |
|
| 623 | + $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
| 624 | + } else { |
|
| 625 | + $qb->andWhere( |
|
| 626 | + $qb->expr()->orX( |
|
| 627 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 628 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
| 629 | + ) |
|
| 630 | + ); |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
| 634 | + $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
| 635 | + |
|
| 636 | + $qb->orderBy('id'); |
|
| 637 | + |
|
| 638 | + $cursor = $qb->execute(); |
|
| 639 | + $shares = []; |
|
| 640 | + while ($data = $cursor->fetch()) { |
|
| 641 | + $shares[$data['fileid']][] = $this->createShareObject($data); |
|
| 642 | + } |
|
| 643 | + $cursor->closeCursor(); |
|
| 644 | + |
|
| 645 | + return $shares; |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + /** |
|
| 649 | + * @inheritdoc |
|
| 650 | + */ |
|
| 651 | + public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
| 652 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 653 | + $qb->select('*') |
|
| 654 | + ->from('share'); |
|
| 655 | + |
|
| 656 | + $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))); |
|
| 657 | + |
|
| 658 | + /** |
|
| 659 | + * Reshares for this user are shares where they are the owner. |
|
| 660 | + */ |
|
| 661 | + if ($reshares === false) { |
|
| 662 | + //Special case for old shares created via the web UI |
|
| 663 | + $or1 = $qb->expr()->andX( |
|
| 664 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 665 | + $qb->expr()->isNull('uid_initiator') |
|
| 666 | + ); |
|
| 667 | + |
|
| 668 | + $qb->andWhere( |
|
| 669 | + $qb->expr()->orX( |
|
| 670 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)), |
|
| 671 | + $or1 |
|
| 672 | + ) |
|
| 673 | + ); |
|
| 674 | + } else { |
|
| 675 | + $qb->andWhere( |
|
| 676 | + $qb->expr()->orX( |
|
| 677 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
| 678 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
| 679 | + ) |
|
| 680 | + ); |
|
| 681 | + } |
|
| 682 | + |
|
| 683 | + if ($node !== null) { |
|
| 684 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + if ($limit !== -1) { |
|
| 688 | + $qb->setMaxResults($limit); |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + $qb->setFirstResult($offset); |
|
| 692 | + $qb->orderBy('id'); |
|
| 693 | + |
|
| 694 | + $cursor = $qb->execute(); |
|
| 695 | + $shares = []; |
|
| 696 | + while($data = $cursor->fetch()) { |
|
| 697 | + $shares[] = $this->createShareObject($data); |
|
| 698 | + } |
|
| 699 | + $cursor->closeCursor(); |
|
| 700 | + |
|
| 701 | + return $shares; |
|
| 702 | + } |
|
| 703 | + |
|
| 704 | + /** |
|
| 705 | + * @inheritdoc |
|
| 706 | + */ |
|
| 707 | + public function getShareById($id, $recipientId = null) { |
|
| 708 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 709 | + |
|
| 710 | + $qb->select('*') |
|
| 711 | + ->from('share') |
|
| 712 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
| 713 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))); |
|
| 714 | + |
|
| 715 | + $cursor = $qb->execute(); |
|
| 716 | + $data = $cursor->fetch(); |
|
| 717 | + $cursor->closeCursor(); |
|
| 718 | + |
|
| 719 | + if ($data === false) { |
|
| 720 | + throw new ShareNotFound('Can not find share with ID: ' . $id); |
|
| 721 | + } |
|
| 722 | + |
|
| 723 | + try { |
|
| 724 | + $share = $this->createShareObject($data); |
|
| 725 | + } catch (InvalidShare $e) { |
|
| 726 | + throw new ShareNotFound(); |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + return $share; |
|
| 730 | + } |
|
| 731 | + |
|
| 732 | + /** |
|
| 733 | + * Get shares for a given path |
|
| 734 | + * |
|
| 735 | + * @param \OCP\Files\Node $path |
|
| 736 | + * @return IShare[] |
|
| 737 | + */ |
|
| 738 | + public function getSharesByPath(Node $path) { |
|
| 739 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 740 | + |
|
| 741 | + $cursor = $qb->select('*') |
|
| 742 | + ->from('share') |
|
| 743 | + ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
| 744 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))) |
|
| 745 | + ->execute(); |
|
| 746 | + |
|
| 747 | + $shares = []; |
|
| 748 | + while($data = $cursor->fetch()) { |
|
| 749 | + $shares[] = $this->createShareObject($data); |
|
| 750 | + } |
|
| 751 | + $cursor->closeCursor(); |
|
| 752 | + |
|
| 753 | + return $shares; |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + /** |
|
| 757 | + * @inheritdoc |
|
| 758 | + */ |
|
| 759 | + public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
| 760 | + /** @var IShare[] $shares */ |
|
| 761 | + $shares = []; |
|
| 762 | + |
|
| 763 | + //Get shares directly with this user |
|
| 764 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 765 | + $qb->select('*') |
|
| 766 | + ->from('share'); |
|
| 767 | + |
|
| 768 | + // Order by id |
|
| 769 | + $qb->orderBy('id'); |
|
| 770 | + |
|
| 771 | + // Set limit and offset |
|
| 772 | + if ($limit !== -1) { |
|
| 773 | + $qb->setMaxResults($limit); |
|
| 774 | + } |
|
| 775 | + $qb->setFirstResult($offset); |
|
| 776 | + |
|
| 777 | + $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))); |
|
| 778 | + $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))); |
|
| 779 | + |
|
| 780 | + // Filter by node if provided |
|
| 781 | + if ($node !== null) { |
|
| 782 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
| 783 | + } |
|
| 784 | + |
|
| 785 | + $cursor = $qb->execute(); |
|
| 786 | + |
|
| 787 | + while($data = $cursor->fetch()) { |
|
| 788 | + $shares[] = $this->createShareObject($data); |
|
| 789 | + } |
|
| 790 | + $cursor->closeCursor(); |
|
| 791 | + |
|
| 792 | + |
|
| 793 | + return $shares; |
|
| 794 | + } |
|
| 795 | + |
|
| 796 | + /** |
|
| 797 | + * Get a share by token |
|
| 798 | + * |
|
| 799 | + * @param string $token |
|
| 800 | + * @return IShare |
|
| 801 | + * @throws ShareNotFound |
|
| 802 | + */ |
|
| 803 | + public function getShareByToken($token) { |
|
| 804 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 805 | + |
|
| 806 | + $cursor = $qb->select('*') |
|
| 807 | + ->from('share') |
|
| 808 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))) |
|
| 809 | + ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
| 810 | + ->execute(); |
|
| 811 | + |
|
| 812 | + $data = $cursor->fetch(); |
|
| 813 | + |
|
| 814 | + if ($data === false) { |
|
| 815 | + throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + try { |
|
| 819 | + $share = $this->createShareObject($data); |
|
| 820 | + } catch (InvalidShare $e) { |
|
| 821 | + throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
| 822 | + } |
|
| 823 | + |
|
| 824 | + return $share; |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + /** |
|
| 828 | + * get database row of a give share |
|
| 829 | + * |
|
| 830 | + * @param $id |
|
| 831 | + * @return array |
|
| 832 | + * @throws ShareNotFound |
|
| 833 | + */ |
|
| 834 | + private function getRawShare($id) { |
|
| 835 | + |
|
| 836 | + // Now fetch the inserted share and create a complete share object |
|
| 837 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 838 | + $qb->select('*') |
|
| 839 | + ->from('share') |
|
| 840 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
| 841 | + |
|
| 842 | + $cursor = $qb->execute(); |
|
| 843 | + $data = $cursor->fetch(); |
|
| 844 | + $cursor->closeCursor(); |
|
| 845 | + |
|
| 846 | + if ($data === false) { |
|
| 847 | + throw new ShareNotFound; |
|
| 848 | + } |
|
| 849 | + |
|
| 850 | + return $data; |
|
| 851 | + } |
|
| 852 | + |
|
| 853 | + /** |
|
| 854 | + * Create a share object from an database row |
|
| 855 | + * |
|
| 856 | + * @param array $data |
|
| 857 | + * @return IShare |
|
| 858 | + * @throws InvalidShare |
|
| 859 | + * @throws ShareNotFound |
|
| 860 | + */ |
|
| 861 | + private function createShareObject($data) { |
|
| 862 | + |
|
| 863 | + $share = new Share($this->rootFolder, $this->userManager); |
|
| 864 | + $share->setId((int)$data['id']) |
|
| 865 | + ->setShareType((int)$data['share_type']) |
|
| 866 | + ->setPermissions((int)$data['permissions']) |
|
| 867 | + ->setTarget($data['file_target']) |
|
| 868 | + ->setMailSend((bool)$data['mail_send']) |
|
| 869 | + ->setToken($data['token']); |
|
| 870 | + |
|
| 871 | + $shareTime = new \DateTime(); |
|
| 872 | + $shareTime->setTimestamp((int)$data['stime']); |
|
| 873 | + $share->setShareTime($shareTime); |
|
| 874 | + $share->setSharedWith($data['share_with']); |
|
| 875 | + |
|
| 876 | + if ($data['uid_initiator'] !== null) { |
|
| 877 | + $share->setShareOwner($data['uid_owner']); |
|
| 878 | + $share->setSharedBy($data['uid_initiator']); |
|
| 879 | + } else { |
|
| 880 | + //OLD SHARE |
|
| 881 | + $share->setSharedBy($data['uid_owner']); |
|
| 882 | + $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
| 883 | + |
|
| 884 | + $owner = $path->getOwner(); |
|
| 885 | + $share->setShareOwner($owner->getUID()); |
|
| 886 | + } |
|
| 887 | + |
|
| 888 | + $share->setNodeId((int)$data['file_source']); |
|
| 889 | + $share->setNodeType($data['item_type']); |
|
| 890 | + |
|
| 891 | + $share->setProviderId($this->identifier()); |
|
| 892 | + |
|
| 893 | + return $share; |
|
| 894 | + } |
|
| 895 | + |
|
| 896 | + /** |
|
| 897 | + * Get the node with file $id for $user |
|
| 898 | + * |
|
| 899 | + * @param string $userId |
|
| 900 | + * @param int $id |
|
| 901 | + * @return \OCP\Files\File|\OCP\Files\Folder |
|
| 902 | + * @throws InvalidShare |
|
| 903 | + */ |
|
| 904 | + private function getNode($userId, $id) { |
|
| 905 | + try { |
|
| 906 | + $userFolder = $this->rootFolder->getUserFolder($userId); |
|
| 907 | + } catch (NotFoundException $e) { |
|
| 908 | + throw new InvalidShare(); |
|
| 909 | + } |
|
| 910 | + |
|
| 911 | + $nodes = $userFolder->getById($id); |
|
| 912 | + |
|
| 913 | + if (empty($nodes)) { |
|
| 914 | + throw new InvalidShare(); |
|
| 915 | + } |
|
| 916 | + |
|
| 917 | + return $nodes[0]; |
|
| 918 | + } |
|
| 919 | + |
|
| 920 | + /** |
|
| 921 | + * A user is deleted from the system |
|
| 922 | + * So clean up the relevant shares. |
|
| 923 | + * |
|
| 924 | + * @param string $uid |
|
| 925 | + * @param int $shareType |
|
| 926 | + */ |
|
| 927 | + public function userDeleted($uid, $shareType) { |
|
| 928 | + //TODO: probabaly a good idea to send unshare info to remote servers |
|
| 929 | + |
|
| 930 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 931 | + |
|
| 932 | + $qb->delete('share') |
|
| 933 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE))) |
|
| 934 | + ->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))) |
|
| 935 | + ->execute(); |
|
| 936 | + } |
|
| 937 | + |
|
| 938 | + /** |
|
| 939 | + * This provider does not handle groups |
|
| 940 | + * |
|
| 941 | + * @param string $gid |
|
| 942 | + */ |
|
| 943 | + public function groupDeleted($gid) { |
|
| 944 | + // We don't handle groups here |
|
| 945 | + } |
|
| 946 | + |
|
| 947 | + /** |
|
| 948 | + * This provider does not handle groups |
|
| 949 | + * |
|
| 950 | + * @param string $uid |
|
| 951 | + * @param string $gid |
|
| 952 | + */ |
|
| 953 | + public function userDeletedFromGroup($uid, $gid) { |
|
| 954 | + // We don't handle groups here |
|
| 955 | + } |
|
| 956 | + |
|
| 957 | + /** |
|
| 958 | + * check if users from other Nextcloud instances are allowed to mount public links share by this instance |
|
| 959 | + * |
|
| 960 | + * @return bool |
|
| 961 | + */ |
|
| 962 | + public function isOutgoingServer2serverShareEnabled() { |
|
| 963 | + if ($this->gsConfig->onlyInternalFederation()) { |
|
| 964 | + return false; |
|
| 965 | + } |
|
| 966 | + $result = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes'); |
|
| 967 | + return ($result === 'yes'); |
|
| 968 | + } |
|
| 969 | + |
|
| 970 | + /** |
|
| 971 | + * check if users are allowed to mount public links from other Nextclouds |
|
| 972 | + * |
|
| 973 | + * @return bool |
|
| 974 | + */ |
|
| 975 | + public function isIncomingServer2serverShareEnabled() { |
|
| 976 | + if ($this->gsConfig->onlyInternalFederation()) { |
|
| 977 | + return false; |
|
| 978 | + } |
|
| 979 | + $result = $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes'); |
|
| 980 | + return ($result === 'yes'); |
|
| 981 | + } |
|
| 982 | + |
|
| 983 | + |
|
| 984 | + /** |
|
| 985 | + * check if users from other Nextcloud instances are allowed to send federated group shares |
|
| 986 | + * |
|
| 987 | + * @return bool |
|
| 988 | + */ |
|
| 989 | + public function isOutgoingServer2serverGroupShareEnabled() { |
|
| 990 | + if ($this->gsConfig->onlyInternalFederation()) { |
|
| 991 | + return false; |
|
| 992 | + } |
|
| 993 | + $result = $this->config->getAppValue('files_sharing', 'outgoing_server2server_group_share_enabled', 'no'); |
|
| 994 | + return ($result === 'yes'); |
|
| 995 | + } |
|
| 996 | + |
|
| 997 | + /** |
|
| 998 | + * check if users are allowed to receive federated group shares |
|
| 999 | + * |
|
| 1000 | + * @return bool |
|
| 1001 | + */ |
|
| 1002 | + public function isIncomingServer2serverGroupShareEnabled() { |
|
| 1003 | + if ($this->gsConfig->onlyInternalFederation()) { |
|
| 1004 | + return false; |
|
| 1005 | + } |
|
| 1006 | + $result = $this->config->getAppValue('files_sharing', 'incoming_server2server_group_share_enabled', 'no'); |
|
| 1007 | + return ($result === 'yes'); |
|
| 1008 | + } |
|
| 1009 | + |
|
| 1010 | + /** |
|
| 1011 | + * check if federated group sharing is supported, therefore the OCM API need to be enabled |
|
| 1012 | + * |
|
| 1013 | + * @return bool |
|
| 1014 | + */ |
|
| 1015 | + public function isFederatedGroupSharingSupported() { |
|
| 1016 | + return $this->cloudFederationProviderManager->isReady(); |
|
| 1017 | + } |
|
| 1018 | + |
|
| 1019 | + /** |
|
| 1020 | + * Check if querying sharees on the lookup server is enabled |
|
| 1021 | + * |
|
| 1022 | + * @return bool |
|
| 1023 | + */ |
|
| 1024 | + public function isLookupServerQueriesEnabled() { |
|
| 1025 | + // in a global scale setup we should always query the lookup server |
|
| 1026 | + if ($this->gsConfig->isGlobalScaleEnabled()) { |
|
| 1027 | + return true; |
|
| 1028 | + } |
|
| 1029 | + $result = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no'); |
|
| 1030 | + return ($result === 'yes'); |
|
| 1031 | + } |
|
| 1032 | + |
|
| 1033 | + |
|
| 1034 | + /** |
|
| 1035 | + * Check if it is allowed to publish user specific data to the lookup server |
|
| 1036 | + * |
|
| 1037 | + * @return bool |
|
| 1038 | + */ |
|
| 1039 | + public function isLookupServerUploadEnabled() { |
|
| 1040 | + // in a global scale setup the admin is responsible to keep the lookup server up-to-date |
|
| 1041 | + if ($this->gsConfig->isGlobalScaleEnabled()) { |
|
| 1042 | + return false; |
|
| 1043 | + } |
|
| 1044 | + $result = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes'); |
|
| 1045 | + return ($result === 'yes'); |
|
| 1046 | + } |
|
| 1047 | + |
|
| 1048 | + /** |
|
| 1049 | + * @inheritdoc |
|
| 1050 | + */ |
|
| 1051 | + public function getAccessList($nodes, $currentAccess) { |
|
| 1052 | + $ids = []; |
|
| 1053 | + foreach ($nodes as $node) { |
|
| 1054 | + $ids[] = $node->getId(); |
|
| 1055 | + } |
|
| 1056 | + |
|
| 1057 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 1058 | + $qb->select('share_with', 'token', 'file_source') |
|
| 1059 | + ->from('share') |
|
| 1060 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE))) |
|
| 1061 | + ->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
| 1062 | + ->andWhere($qb->expr()->orX( |
|
| 1063 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
| 1064 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
| 1065 | + )); |
|
| 1066 | + $cursor = $qb->execute(); |
|
| 1067 | + |
|
| 1068 | + if ($currentAccess === false) { |
|
| 1069 | + $remote = $cursor->fetch() !== false; |
|
| 1070 | + $cursor->closeCursor(); |
|
| 1071 | + |
|
| 1072 | + return ['remote' => $remote]; |
|
| 1073 | + } |
|
| 1074 | + |
|
| 1075 | + $remote = []; |
|
| 1076 | + while ($row = $cursor->fetch()) { |
|
| 1077 | + $remote[$row['share_with']] = [ |
|
| 1078 | + 'node_id' => $row['file_source'], |
|
| 1079 | + 'token' => $row['token'], |
|
| 1080 | + ]; |
|
| 1081 | + } |
|
| 1082 | + $cursor->closeCursor(); |
|
| 1083 | + |
|
| 1084 | + return ['remote' => $remote]; |
|
| 1085 | + } |
|
| 1086 | 1086 | } |
@@ -52,780 +52,780 @@ |
||
| 52 | 52 | |
| 53 | 53 | class CloudFederationProviderFiles implements ICloudFederationProvider { |
| 54 | 54 | |
| 55 | - /** @var IAppManager */ |
|
| 56 | - private $appManager; |
|
| 57 | - |
|
| 58 | - /** @var FederatedShareProvider */ |
|
| 59 | - private $federatedShareProvider; |
|
| 60 | - |
|
| 61 | - /** @var AddressHandler */ |
|
| 62 | - private $addressHandler; |
|
| 63 | - |
|
| 64 | - /** @var ILogger */ |
|
| 65 | - private $logger; |
|
| 66 | - |
|
| 67 | - /** @var IUserManager */ |
|
| 68 | - private $userManager; |
|
| 69 | - |
|
| 70 | - /** @var ICloudIdManager */ |
|
| 71 | - private $cloudIdManager; |
|
| 72 | - |
|
| 73 | - /** @var IActivityManager */ |
|
| 74 | - private $activityManager; |
|
| 75 | - |
|
| 76 | - /** @var INotificationManager */ |
|
| 77 | - private $notificationManager; |
|
| 78 | - |
|
| 79 | - /** @var IURLGenerator */ |
|
| 80 | - private $urlGenerator; |
|
| 81 | - |
|
| 82 | - /** @var ICloudFederationFactory */ |
|
| 83 | - private $cloudFederationFactory; |
|
| 84 | - |
|
| 85 | - /** @var ICloudFederationProviderManager */ |
|
| 86 | - private $cloudFederationProviderManager; |
|
| 87 | - |
|
| 88 | - /** @var IDBConnection */ |
|
| 89 | - private $connection; |
|
| 90 | - |
|
| 91 | - /** @var IGroupManager */ |
|
| 92 | - private $groupManager; |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * CloudFederationProvider constructor. |
|
| 96 | - * |
|
| 97 | - * @param IAppManager $appManager |
|
| 98 | - * @param FederatedShareProvider $federatedShareProvider |
|
| 99 | - * @param AddressHandler $addressHandler |
|
| 100 | - * @param ILogger $logger |
|
| 101 | - * @param IUserManager $userManager |
|
| 102 | - * @param ICloudIdManager $cloudIdManager |
|
| 103 | - * @param IActivityManager $activityManager |
|
| 104 | - * @param INotificationManager $notificationManager |
|
| 105 | - * @param IURLGenerator $urlGenerator |
|
| 106 | - * @param ICloudFederationFactory $cloudFederationFactory |
|
| 107 | - * @param ICloudFederationProviderManager $cloudFederationProviderManager |
|
| 108 | - * @param IDBConnection $connection |
|
| 109 | - * @param IGroupManager $groupManager |
|
| 110 | - */ |
|
| 111 | - public function __construct(IAppManager $appManager, |
|
| 112 | - FederatedShareProvider $federatedShareProvider, |
|
| 113 | - AddressHandler $addressHandler, |
|
| 114 | - ILogger $logger, |
|
| 115 | - IUserManager $userManager, |
|
| 116 | - ICloudIdManager $cloudIdManager, |
|
| 117 | - IActivityManager $activityManager, |
|
| 118 | - INotificationManager $notificationManager, |
|
| 119 | - IURLGenerator $urlGenerator, |
|
| 120 | - ICloudFederationFactory $cloudFederationFactory, |
|
| 121 | - ICloudFederationProviderManager $cloudFederationProviderManager, |
|
| 122 | - IDBConnection $connection, |
|
| 123 | - IGroupManager $groupManager |
|
| 124 | - ) { |
|
| 125 | - $this->appManager = $appManager; |
|
| 126 | - $this->federatedShareProvider = $federatedShareProvider; |
|
| 127 | - $this->addressHandler = $addressHandler; |
|
| 128 | - $this->logger = $logger; |
|
| 129 | - $this->userManager = $userManager; |
|
| 130 | - $this->cloudIdManager = $cloudIdManager; |
|
| 131 | - $this->activityManager = $activityManager; |
|
| 132 | - $this->notificationManager = $notificationManager; |
|
| 133 | - $this->urlGenerator = $urlGenerator; |
|
| 134 | - $this->cloudFederationFactory = $cloudFederationFactory; |
|
| 135 | - $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
| 136 | - $this->connection = $connection; |
|
| 137 | - $this->groupManager = $groupManager; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * @return string |
|
| 144 | - */ |
|
| 145 | - public function getShareType() { |
|
| 146 | - return 'file'; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * share received from another server |
|
| 151 | - * |
|
| 152 | - * @param ICloudFederationShare $share |
|
| 153 | - * @return string provider specific unique ID of the share |
|
| 154 | - * |
|
| 155 | - * @throws ProviderCouldNotAddShareException |
|
| 156 | - * @throws \OCP\AppFramework\QueryException |
|
| 157 | - * @throws \OC\HintException |
|
| 158 | - * @since 14.0.0 |
|
| 159 | - */ |
|
| 160 | - public function shareReceived(ICloudFederationShare $share) { |
|
| 161 | - |
|
| 162 | - if (!$this->isS2SEnabled(true)) { |
|
| 163 | - throw new ProviderCouldNotAddShareException('Server does not support federated cloud sharing', '', Http::STATUS_SERVICE_UNAVAILABLE); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - $protocol = $share->getProtocol(); |
|
| 167 | - if ($protocol['name'] !== 'webdav') { |
|
| 168 | - throw new ProviderCouldNotAddShareException('Unsupported protocol for data exchange.', '', Http::STATUS_NOT_IMPLEMENTED); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - list($ownerUid, $remote) = $this->addressHandler->splitUserRemote($share->getOwner()); |
|
| 172 | - // for backward compatibility make sure that the remote url stored in the |
|
| 173 | - // database ends with a trailing slash |
|
| 174 | - if (substr($remote, -1) !== '/') { |
|
| 175 | - $remote = $remote . '/'; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - $token = $share->getShareSecret(); |
|
| 179 | - $name = $share->getResourceName(); |
|
| 180 | - $owner = $share->getOwnerDisplayName(); |
|
| 181 | - $sharedBy = $share->getSharedByDisplayName(); |
|
| 182 | - $shareWith = $share->getShareWith(); |
|
| 183 | - $remoteId = $share->getProviderId(); |
|
| 184 | - $sharedByFederatedId = $share->getSharedBy(); |
|
| 185 | - $ownerFederatedId = $share->getOwner(); |
|
| 186 | - $shareType = $this->mapShareTypeToNextcloud($share->getShareType()); |
|
| 187 | - |
|
| 188 | - // if no explicit information about the person who created the share was send |
|
| 189 | - // we assume that the share comes from the owner |
|
| 190 | - if ($sharedByFederatedId === null) { |
|
| 191 | - $sharedBy = $owner; |
|
| 192 | - $sharedByFederatedId = $ownerFederatedId; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - if ($remote && $token && $name && $owner && $remoteId && $shareWith) { |
|
| 196 | - |
|
| 197 | - if (!Util::isValidFileName($name)) { |
|
| 198 | - throw new ProviderCouldNotAddShareException('The mountpoint name contains invalid characters.', '', Http::STATUS_BAD_REQUEST); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - // FIXME this should be a method in the user management instead |
|
| 202 | - if ($shareType === Share::SHARE_TYPE_USER) { |
|
| 203 | - $this->logger->debug('shareWith before, ' . $shareWith, ['app' => 'files_sharing']); |
|
| 204 | - Util::emitHook( |
|
| 205 | - '\OCA\Files_Sharing\API\Server2Server', |
|
| 206 | - 'preLoginNameUsedAsUserName', |
|
| 207 | - array('uid' => &$shareWith) |
|
| 208 | - ); |
|
| 209 | - $this->logger->debug('shareWith after, ' . $shareWith, ['app' => 'files_sharing']); |
|
| 210 | - |
|
| 211 | - if (!$this->userManager->userExists($shareWith)) { |
|
| 212 | - throw new ProviderCouldNotAddShareException('User does not exists', '',Http::STATUS_BAD_REQUEST); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - \OC_Util::setupFS($shareWith); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - if ($shareType === Share::SHARE_TYPE_GROUP && !$this->groupManager->groupExists($shareWith)) { |
|
| 219 | - throw new ProviderCouldNotAddShareException('Group does not exists', '',Http::STATUS_BAD_REQUEST); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - $externalManager = new \OCA\Files_Sharing\External\Manager( |
|
| 223 | - \OC::$server->getDatabaseConnection(), |
|
| 224 | - Filesystem::getMountManager(), |
|
| 225 | - Filesystem::getLoader(), |
|
| 226 | - \OC::$server->getHTTPClientService(), |
|
| 227 | - \OC::$server->getNotificationManager(), |
|
| 228 | - \OC::$server->query(\OCP\OCS\IDiscoveryService::class), |
|
| 229 | - \OC::$server->getCloudFederationProviderManager(), |
|
| 230 | - \OC::$server->getCloudFederationFactory(), |
|
| 231 | - $shareWith |
|
| 232 | - ); |
|
| 233 | - |
|
| 234 | - try { |
|
| 235 | - $externalManager->addShare($remote, $token, '', $name, $owner, $shareType,false, $shareWith, $remoteId); |
|
| 236 | - $shareId = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share_external'); |
|
| 237 | - |
|
| 238 | - if ($shareType === Share::SHARE_TYPE_USER) { |
|
| 239 | - $event = $this->activityManager->generateEvent(); |
|
| 240 | - $event->setApp('files_sharing') |
|
| 241 | - ->setType('remote_share') |
|
| 242 | - ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')]) |
|
| 243 | - ->setAffectedUser($shareWith) |
|
| 244 | - ->setObject('remote_share', (int)$shareId, $name); |
|
| 245 | - \OC::$server->getActivityManager()->publish($event); |
|
| 246 | - $this->notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name); |
|
| 247 | - } else { |
|
| 248 | - $groupMembers = $this->groupManager->get($shareWith)->getUsers(); |
|
| 249 | - foreach ($groupMembers as $user) { |
|
| 250 | - $event = $this->activityManager->generateEvent(); |
|
| 251 | - $event->setApp('files_sharing') |
|
| 252 | - ->setType('remote_share') |
|
| 253 | - ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')]) |
|
| 254 | - ->setAffectedUser($user->getUID()) |
|
| 255 | - ->setObject('remote_share', (int)$shareId, $name); |
|
| 256 | - \OC::$server->getActivityManager()->publish($event); |
|
| 257 | - $this->notifyAboutNewShare($user->getUID(), $shareId, $ownerFederatedId, $sharedByFederatedId, $name); |
|
| 258 | - } |
|
| 259 | - } |
|
| 260 | - return $shareId; |
|
| 261 | - } catch (\Exception $e) { |
|
| 262 | - $this->logger->logException($e, [ |
|
| 263 | - 'message' => 'Server can not add remote share.', |
|
| 264 | - 'level' => ILogger::ERROR, |
|
| 265 | - 'app' => 'files_sharing' |
|
| 266 | - ]); |
|
| 267 | - throw new ProviderCouldNotAddShareException('internal server error, was not able to add share from ' . $remote, '', HTTP::STATUS_INTERNAL_SERVER_ERROR); |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - throw new ProviderCouldNotAddShareException('server can not add remote share, missing parameter', '', HTTP::STATUS_BAD_REQUEST); |
|
| 272 | - |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * notification received from another server |
|
| 277 | - * |
|
| 278 | - * @param string $notificationType (e.g. SHARE_ACCEPTED) |
|
| 279 | - * @param string $providerId id of the share |
|
| 280 | - * @param array $notification payload of the notification |
|
| 281 | - * @return array data send back to the sender |
|
| 282 | - * |
|
| 283 | - * @throws ActionNotSupportedException |
|
| 284 | - * @throws AuthenticationFailedException |
|
| 285 | - * @throws BadRequestException |
|
| 286 | - * @throws \OC\HintException |
|
| 287 | - * @since 14.0.0 |
|
| 288 | - */ |
|
| 289 | - public function notificationReceived($notificationType, $providerId, array $notification) { |
|
| 290 | - |
|
| 291 | - switch ($notificationType) { |
|
| 292 | - case 'SHARE_ACCEPTED': |
|
| 293 | - return $this->shareAccepted($providerId, $notification); |
|
| 294 | - case 'SHARE_DECLINED': |
|
| 295 | - return $this->shareDeclined($providerId, $notification); |
|
| 296 | - case 'SHARE_UNSHARED': |
|
| 297 | - return $this->unshare($providerId, $notification); |
|
| 298 | - case 'REQUEST_RESHARE': |
|
| 299 | - return $this->reshareRequested($providerId, $notification); |
|
| 300 | - case 'RESHARE_UNDO': |
|
| 301 | - return $this->undoReshare($providerId, $notification); |
|
| 302 | - case 'RESHARE_CHANGE_PERMISSION': |
|
| 303 | - return $this->updateResharePermissions($providerId, $notification); |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - |
|
| 307 | - throw new BadRequestException([$notificationType]); |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * map OCM share type (strings) to Nextcloud internal share types (integer) |
|
| 312 | - * |
|
| 313 | - * @param string $shareType |
|
| 314 | - * @return int |
|
| 315 | - */ |
|
| 316 | - private function mapShareTypeToNextcloud($shareType) { |
|
| 317 | - $result = Share::SHARE_TYPE_USER; |
|
| 318 | - if ($shareType === 'group') { |
|
| 319 | - $result = Share::SHARE_TYPE_GROUP; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - return $result; |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - /** |
|
| 326 | - * notify user about new federated share |
|
| 327 | - * |
|
| 328 | - * @param $shareWith |
|
| 329 | - * @param $shareId |
|
| 330 | - * @param $ownerFederatedId |
|
| 331 | - * @param $sharedByFederatedId |
|
| 332 | - * @param $name |
|
| 333 | - */ |
|
| 334 | - private function notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name) { |
|
| 335 | - $notification = $this->notificationManager->createNotification(); |
|
| 336 | - $notification->setApp('files_sharing') |
|
| 337 | - ->setUser($shareWith) |
|
| 338 | - ->setDateTime(new \DateTime()) |
|
| 339 | - ->setObject('remote_share', $shareId) |
|
| 340 | - ->setSubject('remote_share', [$ownerFederatedId, $sharedByFederatedId, trim($name, '/')]); |
|
| 341 | - |
|
| 342 | - $declineAction = $notification->createAction(); |
|
| 343 | - $declineAction->setLabel('decline') |
|
| 344 | - ->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'DELETE'); |
|
| 345 | - $notification->addAction($declineAction); |
|
| 346 | - |
|
| 347 | - $acceptAction = $notification->createAction(); |
|
| 348 | - $acceptAction->setLabel('accept') |
|
| 349 | - ->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'POST'); |
|
| 350 | - $notification->addAction($acceptAction); |
|
| 351 | - |
|
| 352 | - $this->notificationManager->notify($notification); |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * process notification that the recipient accepted a share |
|
| 357 | - * |
|
| 358 | - * @param string $id |
|
| 359 | - * @param array $notification |
|
| 360 | - * @return array |
|
| 361 | - * @throws ActionNotSupportedException |
|
| 362 | - * @throws AuthenticationFailedException |
|
| 363 | - * @throws BadRequestException |
|
| 364 | - * @throws \OC\HintException |
|
| 365 | - */ |
|
| 366 | - private function shareAccepted($id, array $notification) { |
|
| 367 | - |
|
| 368 | - if (!$this->isS2SEnabled()) { |
|
| 369 | - throw new ActionNotSupportedException('Server does not support federated cloud sharing'); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - if (!isset($notification['sharedSecret'])) { |
|
| 373 | - throw new BadRequestException(['sharedSecret']); |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - $token = $notification['sharedSecret']; |
|
| 377 | - |
|
| 378 | - $share = $this->federatedShareProvider->getShareById($id); |
|
| 379 | - |
|
| 380 | - $this->verifyShare($share, $token); |
|
| 381 | - $this->executeAcceptShare($share); |
|
| 382 | - if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
| 383 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
| 384 | - $remoteId = $this->federatedShareProvider->getRemoteId($share); |
|
| 385 | - $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
| 386 | - $notification->setMessage( |
|
| 387 | - 'SHARE_ACCEPTED', |
|
| 388 | - 'file', |
|
| 389 | - $remoteId, |
|
| 390 | - [ |
|
| 391 | - 'sharedSecret' => $token, |
|
| 392 | - 'message' => 'Recipient accepted the re-share' |
|
| 393 | - ] |
|
| 394 | - |
|
| 395 | - ); |
|
| 396 | - $this->cloudFederationProviderManager->sendNotification($remote, $notification); |
|
| 397 | - |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - return []; |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * @param IShare $share |
|
| 405 | - * @throws ShareNotFound |
|
| 406 | - */ |
|
| 407 | - protected function executeAcceptShare(IShare $share) { |
|
| 408 | - try { |
|
| 409 | - $fileId = (int)$share->getNode()->getId(); |
|
| 410 | - list($file, $link) = $this->getFile($this->getCorrectUid($share), $fileId); |
|
| 411 | - } catch (\Exception $e) { |
|
| 412 | - throw new ShareNotFound(); |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - $event = $this->activityManager->generateEvent(); |
|
| 416 | - $event->setApp('files_sharing') |
|
| 417 | - ->setType('remote_share') |
|
| 418 | - ->setAffectedUser($this->getCorrectUid($share)) |
|
| 419 | - ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_ACCEPTED, [$share->getSharedWith(), [$fileId => $file]]) |
|
| 420 | - ->setObject('files', $fileId, $file) |
|
| 421 | - ->setLink($link); |
|
| 422 | - $this->activityManager->publish($event); |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - /** |
|
| 426 | - * process notification that the recipient declined a share |
|
| 427 | - * |
|
| 428 | - * @param string $id |
|
| 429 | - * @param array $notification |
|
| 430 | - * @return array |
|
| 431 | - * @throws ActionNotSupportedException |
|
| 432 | - * @throws AuthenticationFailedException |
|
| 433 | - * @throws BadRequestException |
|
| 434 | - * @throws ShareNotFound |
|
| 435 | - * @throws \OC\HintException |
|
| 436 | - * |
|
| 437 | - */ |
|
| 438 | - protected function shareDeclined($id, array $notification) { |
|
| 439 | - |
|
| 440 | - if (!$this->isS2SEnabled()) { |
|
| 441 | - throw new ActionNotSupportedException('Server does not support federated cloud sharing'); |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - if (!isset($notification['sharedSecret'])) { |
|
| 445 | - throw new BadRequestException(['sharedSecret']); |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - $token = $notification['sharedSecret']; |
|
| 449 | - |
|
| 450 | - $share = $this->federatedShareProvider->getShareById($id); |
|
| 451 | - |
|
| 452 | - $this->verifyShare($share, $token); |
|
| 453 | - |
|
| 454 | - if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
| 455 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
| 456 | - $remoteId = $this->federatedShareProvider->getRemoteId($share); |
|
| 457 | - $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
| 458 | - $notification->setMessage( |
|
| 459 | - 'SHARE_DECLINED', |
|
| 460 | - 'file', |
|
| 461 | - $remoteId, |
|
| 462 | - [ |
|
| 463 | - 'sharedSecret' => $token, |
|
| 464 | - 'message' => 'Recipient declined the re-share' |
|
| 465 | - ] |
|
| 466 | - |
|
| 467 | - ); |
|
| 468 | - $this->cloudFederationProviderManager->sendNotification($remote, $notification); |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - $this->executeDeclineShare($share); |
|
| 472 | - |
|
| 473 | - return []; |
|
| 474 | - |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - /** |
|
| 478 | - * delete declined share and create a activity |
|
| 479 | - * |
|
| 480 | - * @param IShare $share |
|
| 481 | - * @throws ShareNotFound |
|
| 482 | - */ |
|
| 483 | - protected function executeDeclineShare(IShare $share) { |
|
| 484 | - $this->federatedShareProvider->removeShareFromTable($share); |
|
| 485 | - |
|
| 486 | - try { |
|
| 487 | - $fileId = (int)$share->getNode()->getId(); |
|
| 488 | - list($file, $link) = $this->getFile($this->getCorrectUid($share), $fileId); |
|
| 489 | - } catch (\Exception $e) { |
|
| 490 | - throw new ShareNotFound(); |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - $event = $this->activityManager->generateEvent(); |
|
| 494 | - $event->setApp('files_sharing') |
|
| 495 | - ->setType('remote_share') |
|
| 496 | - ->setAffectedUser($this->getCorrectUid($share)) |
|
| 497 | - ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_DECLINED, [$share->getSharedWith(), [$fileId => $file]]) |
|
| 498 | - ->setObject('files', $fileId, $file) |
|
| 499 | - ->setLink($link); |
|
| 500 | - $this->activityManager->publish($event); |
|
| 501 | - |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - /** |
|
| 505 | - * received the notification that the owner unshared a file from you |
|
| 506 | - * |
|
| 507 | - * @param string $id |
|
| 508 | - * @param array $notification |
|
| 509 | - * @return array |
|
| 510 | - * @throws AuthenticationFailedException |
|
| 511 | - * @throws BadRequestException |
|
| 512 | - */ |
|
| 513 | - private function undoReshare($id, array $notification) { |
|
| 514 | - if (!isset($notification['sharedSecret'])) { |
|
| 515 | - throw new BadRequestException(['sharedSecret']); |
|
| 516 | - } |
|
| 517 | - $token = $notification['sharedSecret']; |
|
| 518 | - |
|
| 519 | - $share = $this->federatedShareProvider->getShareById($id); |
|
| 520 | - |
|
| 521 | - $this->verifyShare($share, $token); |
|
| 522 | - $this->federatedShareProvider->removeShareFromTable($share); |
|
| 523 | - return []; |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - /** |
|
| 527 | - * unshare file from self |
|
| 528 | - * |
|
| 529 | - * @param string $id |
|
| 530 | - * @param array $notification |
|
| 531 | - * @return array |
|
| 532 | - * @throws ActionNotSupportedException |
|
| 533 | - * @throws BadRequestException |
|
| 534 | - */ |
|
| 535 | - private function unshare($id, array $notification) { |
|
| 536 | - |
|
| 537 | - if (!$this->isS2SEnabled(true)) { |
|
| 538 | - throw new ActionNotSupportedException("incoming shares disabled!"); |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - if (!isset($notification['sharedSecret'])) { |
|
| 542 | - throw new BadRequestException(['sharedSecret']); |
|
| 543 | - } |
|
| 544 | - $token = $notification['sharedSecret']; |
|
| 545 | - |
|
| 546 | - $qb = $this->connection->getQueryBuilder(); |
|
| 547 | - $qb->select('*') |
|
| 548 | - ->from('share_external') |
|
| 549 | - ->where( |
|
| 550 | - $qb->expr()->andX( |
|
| 551 | - $qb->expr()->eq('remote_id', $qb->createNamedParameter($id)), |
|
| 552 | - $qb->expr()->eq('share_token', $qb->createNamedParameter($token)) |
|
| 553 | - ) |
|
| 554 | - ); |
|
| 555 | - |
|
| 556 | - $result = $qb->execute(); |
|
| 557 | - $share = $result->fetch(); |
|
| 558 | - $result->closeCursor(); |
|
| 559 | - |
|
| 560 | - if ($token && $id && !empty($share)) { |
|
| 561 | - |
|
| 562 | - $remote = $this->cleanupRemote($share['remote']); |
|
| 563 | - |
|
| 564 | - $owner = $this->cloudIdManager->getCloudId($share['owner'], $remote); |
|
| 565 | - $mountpoint = $share['mountpoint']; |
|
| 566 | - $user = $share['user']; |
|
| 567 | - |
|
| 568 | - $qb = $this->connection->getQueryBuilder(); |
|
| 569 | - $qb->delete('share_external') |
|
| 570 | - ->where( |
|
| 571 | - $qb->expr()->andX( |
|
| 572 | - $qb->expr()->eq('remote_id', $qb->createNamedParameter($id)), |
|
| 573 | - $qb->expr()->eq('share_token', $qb->createNamedParameter($token)) |
|
| 574 | - ) |
|
| 575 | - ); |
|
| 576 | - |
|
| 577 | - $qb->execute(); |
|
| 578 | - |
|
| 579 | - if ($share['accepted']) { |
|
| 580 | - $path = trim($mountpoint, '/'); |
|
| 581 | - } else { |
|
| 582 | - $path = trim($share['name'], '/'); |
|
| 583 | - } |
|
| 584 | - |
|
| 585 | - $notification = $this->notificationManager->createNotification(); |
|
| 586 | - $notification->setApp('files_sharing') |
|
| 587 | - ->setUser($share['user']) |
|
| 588 | - ->setObject('remote_share', (int)$share['id']); |
|
| 589 | - $this->notificationManager->markProcessed($notification); |
|
| 590 | - |
|
| 591 | - $event = $this->activityManager->generateEvent(); |
|
| 592 | - $event->setApp('files_sharing') |
|
| 593 | - ->setType('remote_share') |
|
| 594 | - ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_UNSHARED, [$owner->getId(), $path]) |
|
| 595 | - ->setAffectedUser($user) |
|
| 596 | - ->setObject('remote_share', (int)$share['id'], $path); |
|
| 597 | - \OC::$server->getActivityManager()->publish($event); |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - return []; |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - private function cleanupRemote($remote) { |
|
| 604 | - $remote = substr($remote, strpos($remote, '://') + 3); |
|
| 605 | - |
|
| 606 | - return rtrim($remote, '/'); |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - /** |
|
| 610 | - * recipient of a share request to re-share the file with another user |
|
| 611 | - * |
|
| 612 | - * @param string $id |
|
| 613 | - * @param array $notification |
|
| 614 | - * @return array |
|
| 615 | - * @throws AuthenticationFailedException |
|
| 616 | - * @throws BadRequestException |
|
| 617 | - * @throws ProviderCouldNotAddShareException |
|
| 618 | - * @throws ShareNotFound |
|
| 619 | - */ |
|
| 620 | - protected function reshareRequested($id, array $notification) { |
|
| 621 | - |
|
| 622 | - if (!isset($notification['sharedSecret'])) { |
|
| 623 | - throw new BadRequestException(['sharedSecret']); |
|
| 624 | - } |
|
| 625 | - $token = $notification['sharedSecret']; |
|
| 626 | - |
|
| 627 | - if (!isset($notification['shareWith'])) { |
|
| 628 | - throw new BadRequestException(['shareWith']); |
|
| 629 | - } |
|
| 630 | - $shareWith = $notification['shareWith']; |
|
| 631 | - |
|
| 632 | - if (!isset($notification['senderId'])) { |
|
| 633 | - throw new BadRequestException(['senderId']); |
|
| 634 | - } |
|
| 635 | - $senderId = $notification['senderId']; |
|
| 636 | - |
|
| 637 | - $share = $this->federatedShareProvider->getShareById($id); |
|
| 638 | - // don't allow to share a file back to the owner |
|
| 639 | - try { |
|
| 640 | - list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith); |
|
| 641 | - $owner = $share->getShareOwner(); |
|
| 642 | - $currentServer = $this->addressHandler->generateRemoteURL(); |
|
| 643 | - if ($this->addressHandler->compareAddresses($user, $remote, $owner, $currentServer)) { |
|
| 644 | - throw new ProviderCouldNotAddShareException('Resharing back to the owner is not allowed: ' . $id); |
|
| 645 | - } |
|
| 646 | - } catch (\Exception $e) { |
|
| 647 | - throw new ProviderCouldNotAddShareException($e->getMessage()); |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - $this->verifyShare($share, $token); |
|
| 651 | - |
|
| 652 | - // check if re-sharing is allowed |
|
| 653 | - if ($share->getPermissions() & Constants::PERMISSION_SHARE) { |
|
| 654 | - // the recipient of the initial share is now the initiator for the re-share |
|
| 655 | - $share->setSharedBy($share->getSharedWith()); |
|
| 656 | - $share->setSharedWith($shareWith); |
|
| 657 | - $result = $this->federatedShareProvider->create($share); |
|
| 658 | - $this->federatedShareProvider->storeRemoteId((int)$result->getId(), $senderId); |
|
| 659 | - return ['token' => $result->getToken(), 'providerId' => $result->getId()]; |
|
| 660 | - } else { |
|
| 661 | - throw new ProviderCouldNotAddShareException('resharing not allowed for share: ' . $id); |
|
| 662 | - } |
|
| 663 | - |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - /** |
|
| 667 | - * update permission of a re-share so that the share dialog shows the right |
|
| 668 | - * permission if the owner or the sender changes the permission |
|
| 669 | - * |
|
| 670 | - * @param string $id |
|
| 671 | - * @param array $notification |
|
| 672 | - * @return array |
|
| 673 | - * @throws AuthenticationFailedException |
|
| 674 | - * @throws BadRequestException |
|
| 675 | - */ |
|
| 676 | - protected function updateResharePermissions($id, array $notification) { |
|
| 677 | - |
|
| 678 | - if (!isset($notification['sharedSecret'])) { |
|
| 679 | - throw new BadRequestException(['sharedSecret']); |
|
| 680 | - } |
|
| 681 | - $token = $notification['sharedSecret']; |
|
| 682 | - |
|
| 683 | - if (!isset($notification['permission'])) { |
|
| 684 | - throw new BadRequestException(['permission']); |
|
| 685 | - } |
|
| 686 | - $ocmPermissions = $notification['permission']; |
|
| 687 | - |
|
| 688 | - $share = $this->federatedShareProvider->getShareById($id); |
|
| 689 | - |
|
| 690 | - $ncPermission = $this->ocmPermissions2ncPermissions($ocmPermissions); |
|
| 691 | - |
|
| 692 | - $this->verifyShare($share, $token); |
|
| 693 | - $this->updatePermissionsInDatabase($share, $ncPermission); |
|
| 694 | - |
|
| 695 | - return []; |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - /** |
|
| 699 | - * translate OCM Permissions to Nextcloud permissions |
|
| 700 | - * |
|
| 701 | - * @param array $ocmPermissions |
|
| 702 | - * @return int |
|
| 703 | - * @throws BadRequestException |
|
| 704 | - */ |
|
| 705 | - protected function ocmPermissions2ncPermissions(array $ocmPermissions) { |
|
| 706 | - $ncPermissions = 0; |
|
| 707 | - foreach($ocmPermissions as $permission) { |
|
| 708 | - switch (strtolower($permission)) { |
|
| 709 | - case 'read': |
|
| 710 | - $ncPermissions += Constants::PERMISSION_READ; |
|
| 711 | - break; |
|
| 712 | - case 'write': |
|
| 713 | - $ncPermissions += Constants::PERMISSION_CREATE + Constants::PERMISSION_UPDATE; |
|
| 714 | - break; |
|
| 715 | - case 'share': |
|
| 716 | - $ncPermissions += Constants::PERMISSION_SHARE; |
|
| 717 | - break; |
|
| 718 | - default: |
|
| 719 | - throw new BadRequestException(['permission']); |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - } |
|
| 723 | - |
|
| 724 | - return $ncPermissions; |
|
| 725 | - } |
|
| 726 | - |
|
| 727 | - /** |
|
| 728 | - * update permissions in database |
|
| 729 | - * |
|
| 730 | - * @param IShare $share |
|
| 731 | - * @param int $permissions |
|
| 732 | - */ |
|
| 733 | - protected function updatePermissionsInDatabase(IShare $share, $permissions) { |
|
| 734 | - $query = $this->connection->getQueryBuilder(); |
|
| 735 | - $query->update('share') |
|
| 736 | - ->where($query->expr()->eq('id', $query->createNamedParameter($share->getId()))) |
|
| 737 | - ->set('permissions', $query->createNamedParameter($permissions)) |
|
| 738 | - ->execute(); |
|
| 739 | - } |
|
| 740 | - |
|
| 741 | - |
|
| 742 | - /** |
|
| 743 | - * get file |
|
| 744 | - * |
|
| 745 | - * @param string $user |
|
| 746 | - * @param int $fileSource |
|
| 747 | - * @return array with internal path of the file and a absolute link to it |
|
| 748 | - */ |
|
| 749 | - private function getFile($user, $fileSource) { |
|
| 750 | - \OC_Util::setupFS($user); |
|
| 751 | - |
|
| 752 | - try { |
|
| 753 | - $file = Filesystem::getPath($fileSource); |
|
| 754 | - } catch (NotFoundException $e) { |
|
| 755 | - $file = null; |
|
| 756 | - } |
|
| 757 | - $args = Filesystem::is_dir($file) ? array('dir' => $file) : array('dir' => dirname($file), 'scrollto' => $file); |
|
| 758 | - $link = Util::linkToAbsolute('files', 'index.php', $args); |
|
| 759 | - |
|
| 760 | - return [$file, $link]; |
|
| 761 | - |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - /** |
|
| 765 | - * check if we are the initiator or the owner of a re-share and return the correct UID |
|
| 766 | - * |
|
| 767 | - * @param IShare $share |
|
| 768 | - * @return string |
|
| 769 | - */ |
|
| 770 | - protected function getCorrectUid(IShare $share) { |
|
| 771 | - if ($this->userManager->userExists($share->getShareOwner())) { |
|
| 772 | - return $share->getShareOwner(); |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - return $share->getSharedBy(); |
|
| 776 | - } |
|
| 777 | - |
|
| 778 | - |
|
| 779 | - |
|
| 780 | - /** |
|
| 781 | - * check if we got the right share |
|
| 782 | - * |
|
| 783 | - * @param IShare $share |
|
| 784 | - * @param string $token |
|
| 785 | - * @return bool |
|
| 786 | - * @throws AuthenticationFailedException |
|
| 787 | - */ |
|
| 788 | - protected function verifyShare(IShare $share, $token) { |
|
| 789 | - if ( |
|
| 790 | - $share->getShareType() === FederatedShareProvider::SHARE_TYPE_REMOTE && |
|
| 791 | - $share->getToken() === $token |
|
| 792 | - ) { |
|
| 793 | - return true; |
|
| 794 | - } |
|
| 795 | - |
|
| 796 | - throw new AuthenticationFailedException(); |
|
| 797 | - } |
|
| 798 | - |
|
| 799 | - |
|
| 800 | - |
|
| 801 | - /** |
|
| 802 | - * check if server-to-server sharing is enabled |
|
| 803 | - * |
|
| 804 | - * @param bool $incoming |
|
| 805 | - * @return bool |
|
| 806 | - */ |
|
| 807 | - private function isS2SEnabled($incoming = false) { |
|
| 808 | - |
|
| 809 | - $result = $this->appManager->isEnabledForUser('files_sharing'); |
|
| 810 | - |
|
| 811 | - if ($incoming) { |
|
| 812 | - $result = $result && $this->federatedShareProvider->isIncomingServer2serverShareEnabled(); |
|
| 813 | - } else { |
|
| 814 | - $result = $result && $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); |
|
| 815 | - } |
|
| 816 | - |
|
| 817 | - return $result; |
|
| 818 | - } |
|
| 819 | - |
|
| 820 | - |
|
| 821 | - /** |
|
| 822 | - * get the supported share types, e.g. "user", "group", etc. |
|
| 823 | - * |
|
| 824 | - * @return array |
|
| 825 | - * |
|
| 826 | - * @since 14.0.0 |
|
| 827 | - */ |
|
| 828 | - public function getSupportedShareTypes() { |
|
| 829 | - return ['user', 'group']; |
|
| 830 | - } |
|
| 55 | + /** @var IAppManager */ |
|
| 56 | + private $appManager; |
|
| 57 | + |
|
| 58 | + /** @var FederatedShareProvider */ |
|
| 59 | + private $federatedShareProvider; |
|
| 60 | + |
|
| 61 | + /** @var AddressHandler */ |
|
| 62 | + private $addressHandler; |
|
| 63 | + |
|
| 64 | + /** @var ILogger */ |
|
| 65 | + private $logger; |
|
| 66 | + |
|
| 67 | + /** @var IUserManager */ |
|
| 68 | + private $userManager; |
|
| 69 | + |
|
| 70 | + /** @var ICloudIdManager */ |
|
| 71 | + private $cloudIdManager; |
|
| 72 | + |
|
| 73 | + /** @var IActivityManager */ |
|
| 74 | + private $activityManager; |
|
| 75 | + |
|
| 76 | + /** @var INotificationManager */ |
|
| 77 | + private $notificationManager; |
|
| 78 | + |
|
| 79 | + /** @var IURLGenerator */ |
|
| 80 | + private $urlGenerator; |
|
| 81 | + |
|
| 82 | + /** @var ICloudFederationFactory */ |
|
| 83 | + private $cloudFederationFactory; |
|
| 84 | + |
|
| 85 | + /** @var ICloudFederationProviderManager */ |
|
| 86 | + private $cloudFederationProviderManager; |
|
| 87 | + |
|
| 88 | + /** @var IDBConnection */ |
|
| 89 | + private $connection; |
|
| 90 | + |
|
| 91 | + /** @var IGroupManager */ |
|
| 92 | + private $groupManager; |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * CloudFederationProvider constructor. |
|
| 96 | + * |
|
| 97 | + * @param IAppManager $appManager |
|
| 98 | + * @param FederatedShareProvider $federatedShareProvider |
|
| 99 | + * @param AddressHandler $addressHandler |
|
| 100 | + * @param ILogger $logger |
|
| 101 | + * @param IUserManager $userManager |
|
| 102 | + * @param ICloudIdManager $cloudIdManager |
|
| 103 | + * @param IActivityManager $activityManager |
|
| 104 | + * @param INotificationManager $notificationManager |
|
| 105 | + * @param IURLGenerator $urlGenerator |
|
| 106 | + * @param ICloudFederationFactory $cloudFederationFactory |
|
| 107 | + * @param ICloudFederationProviderManager $cloudFederationProviderManager |
|
| 108 | + * @param IDBConnection $connection |
|
| 109 | + * @param IGroupManager $groupManager |
|
| 110 | + */ |
|
| 111 | + public function __construct(IAppManager $appManager, |
|
| 112 | + FederatedShareProvider $federatedShareProvider, |
|
| 113 | + AddressHandler $addressHandler, |
|
| 114 | + ILogger $logger, |
|
| 115 | + IUserManager $userManager, |
|
| 116 | + ICloudIdManager $cloudIdManager, |
|
| 117 | + IActivityManager $activityManager, |
|
| 118 | + INotificationManager $notificationManager, |
|
| 119 | + IURLGenerator $urlGenerator, |
|
| 120 | + ICloudFederationFactory $cloudFederationFactory, |
|
| 121 | + ICloudFederationProviderManager $cloudFederationProviderManager, |
|
| 122 | + IDBConnection $connection, |
|
| 123 | + IGroupManager $groupManager |
|
| 124 | + ) { |
|
| 125 | + $this->appManager = $appManager; |
|
| 126 | + $this->federatedShareProvider = $federatedShareProvider; |
|
| 127 | + $this->addressHandler = $addressHandler; |
|
| 128 | + $this->logger = $logger; |
|
| 129 | + $this->userManager = $userManager; |
|
| 130 | + $this->cloudIdManager = $cloudIdManager; |
|
| 131 | + $this->activityManager = $activityManager; |
|
| 132 | + $this->notificationManager = $notificationManager; |
|
| 133 | + $this->urlGenerator = $urlGenerator; |
|
| 134 | + $this->cloudFederationFactory = $cloudFederationFactory; |
|
| 135 | + $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
| 136 | + $this->connection = $connection; |
|
| 137 | + $this->groupManager = $groupManager; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * @return string |
|
| 144 | + */ |
|
| 145 | + public function getShareType() { |
|
| 146 | + return 'file'; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * share received from another server |
|
| 151 | + * |
|
| 152 | + * @param ICloudFederationShare $share |
|
| 153 | + * @return string provider specific unique ID of the share |
|
| 154 | + * |
|
| 155 | + * @throws ProviderCouldNotAddShareException |
|
| 156 | + * @throws \OCP\AppFramework\QueryException |
|
| 157 | + * @throws \OC\HintException |
|
| 158 | + * @since 14.0.0 |
|
| 159 | + */ |
|
| 160 | + public function shareReceived(ICloudFederationShare $share) { |
|
| 161 | + |
|
| 162 | + if (!$this->isS2SEnabled(true)) { |
|
| 163 | + throw new ProviderCouldNotAddShareException('Server does not support federated cloud sharing', '', Http::STATUS_SERVICE_UNAVAILABLE); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + $protocol = $share->getProtocol(); |
|
| 167 | + if ($protocol['name'] !== 'webdav') { |
|
| 168 | + throw new ProviderCouldNotAddShareException('Unsupported protocol for data exchange.', '', Http::STATUS_NOT_IMPLEMENTED); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + list($ownerUid, $remote) = $this->addressHandler->splitUserRemote($share->getOwner()); |
|
| 172 | + // for backward compatibility make sure that the remote url stored in the |
|
| 173 | + // database ends with a trailing slash |
|
| 174 | + if (substr($remote, -1) !== '/') { |
|
| 175 | + $remote = $remote . '/'; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + $token = $share->getShareSecret(); |
|
| 179 | + $name = $share->getResourceName(); |
|
| 180 | + $owner = $share->getOwnerDisplayName(); |
|
| 181 | + $sharedBy = $share->getSharedByDisplayName(); |
|
| 182 | + $shareWith = $share->getShareWith(); |
|
| 183 | + $remoteId = $share->getProviderId(); |
|
| 184 | + $sharedByFederatedId = $share->getSharedBy(); |
|
| 185 | + $ownerFederatedId = $share->getOwner(); |
|
| 186 | + $shareType = $this->mapShareTypeToNextcloud($share->getShareType()); |
|
| 187 | + |
|
| 188 | + // if no explicit information about the person who created the share was send |
|
| 189 | + // we assume that the share comes from the owner |
|
| 190 | + if ($sharedByFederatedId === null) { |
|
| 191 | + $sharedBy = $owner; |
|
| 192 | + $sharedByFederatedId = $ownerFederatedId; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + if ($remote && $token && $name && $owner && $remoteId && $shareWith) { |
|
| 196 | + |
|
| 197 | + if (!Util::isValidFileName($name)) { |
|
| 198 | + throw new ProviderCouldNotAddShareException('The mountpoint name contains invalid characters.', '', Http::STATUS_BAD_REQUEST); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + // FIXME this should be a method in the user management instead |
|
| 202 | + if ($shareType === Share::SHARE_TYPE_USER) { |
|
| 203 | + $this->logger->debug('shareWith before, ' . $shareWith, ['app' => 'files_sharing']); |
|
| 204 | + Util::emitHook( |
|
| 205 | + '\OCA\Files_Sharing\API\Server2Server', |
|
| 206 | + 'preLoginNameUsedAsUserName', |
|
| 207 | + array('uid' => &$shareWith) |
|
| 208 | + ); |
|
| 209 | + $this->logger->debug('shareWith after, ' . $shareWith, ['app' => 'files_sharing']); |
|
| 210 | + |
|
| 211 | + if (!$this->userManager->userExists($shareWith)) { |
|
| 212 | + throw new ProviderCouldNotAddShareException('User does not exists', '',Http::STATUS_BAD_REQUEST); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + \OC_Util::setupFS($shareWith); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + if ($shareType === Share::SHARE_TYPE_GROUP && !$this->groupManager->groupExists($shareWith)) { |
|
| 219 | + throw new ProviderCouldNotAddShareException('Group does not exists', '',Http::STATUS_BAD_REQUEST); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + $externalManager = new \OCA\Files_Sharing\External\Manager( |
|
| 223 | + \OC::$server->getDatabaseConnection(), |
|
| 224 | + Filesystem::getMountManager(), |
|
| 225 | + Filesystem::getLoader(), |
|
| 226 | + \OC::$server->getHTTPClientService(), |
|
| 227 | + \OC::$server->getNotificationManager(), |
|
| 228 | + \OC::$server->query(\OCP\OCS\IDiscoveryService::class), |
|
| 229 | + \OC::$server->getCloudFederationProviderManager(), |
|
| 230 | + \OC::$server->getCloudFederationFactory(), |
|
| 231 | + $shareWith |
|
| 232 | + ); |
|
| 233 | + |
|
| 234 | + try { |
|
| 235 | + $externalManager->addShare($remote, $token, '', $name, $owner, $shareType,false, $shareWith, $remoteId); |
|
| 236 | + $shareId = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share_external'); |
|
| 237 | + |
|
| 238 | + if ($shareType === Share::SHARE_TYPE_USER) { |
|
| 239 | + $event = $this->activityManager->generateEvent(); |
|
| 240 | + $event->setApp('files_sharing') |
|
| 241 | + ->setType('remote_share') |
|
| 242 | + ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')]) |
|
| 243 | + ->setAffectedUser($shareWith) |
|
| 244 | + ->setObject('remote_share', (int)$shareId, $name); |
|
| 245 | + \OC::$server->getActivityManager()->publish($event); |
|
| 246 | + $this->notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name); |
|
| 247 | + } else { |
|
| 248 | + $groupMembers = $this->groupManager->get($shareWith)->getUsers(); |
|
| 249 | + foreach ($groupMembers as $user) { |
|
| 250 | + $event = $this->activityManager->generateEvent(); |
|
| 251 | + $event->setApp('files_sharing') |
|
| 252 | + ->setType('remote_share') |
|
| 253 | + ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')]) |
|
| 254 | + ->setAffectedUser($user->getUID()) |
|
| 255 | + ->setObject('remote_share', (int)$shareId, $name); |
|
| 256 | + \OC::$server->getActivityManager()->publish($event); |
|
| 257 | + $this->notifyAboutNewShare($user->getUID(), $shareId, $ownerFederatedId, $sharedByFederatedId, $name); |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | + return $shareId; |
|
| 261 | + } catch (\Exception $e) { |
|
| 262 | + $this->logger->logException($e, [ |
|
| 263 | + 'message' => 'Server can not add remote share.', |
|
| 264 | + 'level' => ILogger::ERROR, |
|
| 265 | + 'app' => 'files_sharing' |
|
| 266 | + ]); |
|
| 267 | + throw new ProviderCouldNotAddShareException('internal server error, was not able to add share from ' . $remote, '', HTTP::STATUS_INTERNAL_SERVER_ERROR); |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + throw new ProviderCouldNotAddShareException('server can not add remote share, missing parameter', '', HTTP::STATUS_BAD_REQUEST); |
|
| 272 | + |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * notification received from another server |
|
| 277 | + * |
|
| 278 | + * @param string $notificationType (e.g. SHARE_ACCEPTED) |
|
| 279 | + * @param string $providerId id of the share |
|
| 280 | + * @param array $notification payload of the notification |
|
| 281 | + * @return array data send back to the sender |
|
| 282 | + * |
|
| 283 | + * @throws ActionNotSupportedException |
|
| 284 | + * @throws AuthenticationFailedException |
|
| 285 | + * @throws BadRequestException |
|
| 286 | + * @throws \OC\HintException |
|
| 287 | + * @since 14.0.0 |
|
| 288 | + */ |
|
| 289 | + public function notificationReceived($notificationType, $providerId, array $notification) { |
|
| 290 | + |
|
| 291 | + switch ($notificationType) { |
|
| 292 | + case 'SHARE_ACCEPTED': |
|
| 293 | + return $this->shareAccepted($providerId, $notification); |
|
| 294 | + case 'SHARE_DECLINED': |
|
| 295 | + return $this->shareDeclined($providerId, $notification); |
|
| 296 | + case 'SHARE_UNSHARED': |
|
| 297 | + return $this->unshare($providerId, $notification); |
|
| 298 | + case 'REQUEST_RESHARE': |
|
| 299 | + return $this->reshareRequested($providerId, $notification); |
|
| 300 | + case 'RESHARE_UNDO': |
|
| 301 | + return $this->undoReshare($providerId, $notification); |
|
| 302 | + case 'RESHARE_CHANGE_PERMISSION': |
|
| 303 | + return $this->updateResharePermissions($providerId, $notification); |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + |
|
| 307 | + throw new BadRequestException([$notificationType]); |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * map OCM share type (strings) to Nextcloud internal share types (integer) |
|
| 312 | + * |
|
| 313 | + * @param string $shareType |
|
| 314 | + * @return int |
|
| 315 | + */ |
|
| 316 | + private function mapShareTypeToNextcloud($shareType) { |
|
| 317 | + $result = Share::SHARE_TYPE_USER; |
|
| 318 | + if ($shareType === 'group') { |
|
| 319 | + $result = Share::SHARE_TYPE_GROUP; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + return $result; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + /** |
|
| 326 | + * notify user about new federated share |
|
| 327 | + * |
|
| 328 | + * @param $shareWith |
|
| 329 | + * @param $shareId |
|
| 330 | + * @param $ownerFederatedId |
|
| 331 | + * @param $sharedByFederatedId |
|
| 332 | + * @param $name |
|
| 333 | + */ |
|
| 334 | + private function notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name) { |
|
| 335 | + $notification = $this->notificationManager->createNotification(); |
|
| 336 | + $notification->setApp('files_sharing') |
|
| 337 | + ->setUser($shareWith) |
|
| 338 | + ->setDateTime(new \DateTime()) |
|
| 339 | + ->setObject('remote_share', $shareId) |
|
| 340 | + ->setSubject('remote_share', [$ownerFederatedId, $sharedByFederatedId, trim($name, '/')]); |
|
| 341 | + |
|
| 342 | + $declineAction = $notification->createAction(); |
|
| 343 | + $declineAction->setLabel('decline') |
|
| 344 | + ->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'DELETE'); |
|
| 345 | + $notification->addAction($declineAction); |
|
| 346 | + |
|
| 347 | + $acceptAction = $notification->createAction(); |
|
| 348 | + $acceptAction->setLabel('accept') |
|
| 349 | + ->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'POST'); |
|
| 350 | + $notification->addAction($acceptAction); |
|
| 351 | + |
|
| 352 | + $this->notificationManager->notify($notification); |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * process notification that the recipient accepted a share |
|
| 357 | + * |
|
| 358 | + * @param string $id |
|
| 359 | + * @param array $notification |
|
| 360 | + * @return array |
|
| 361 | + * @throws ActionNotSupportedException |
|
| 362 | + * @throws AuthenticationFailedException |
|
| 363 | + * @throws BadRequestException |
|
| 364 | + * @throws \OC\HintException |
|
| 365 | + */ |
|
| 366 | + private function shareAccepted($id, array $notification) { |
|
| 367 | + |
|
| 368 | + if (!$this->isS2SEnabled()) { |
|
| 369 | + throw new ActionNotSupportedException('Server does not support federated cloud sharing'); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + if (!isset($notification['sharedSecret'])) { |
|
| 373 | + throw new BadRequestException(['sharedSecret']); |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + $token = $notification['sharedSecret']; |
|
| 377 | + |
|
| 378 | + $share = $this->federatedShareProvider->getShareById($id); |
|
| 379 | + |
|
| 380 | + $this->verifyShare($share, $token); |
|
| 381 | + $this->executeAcceptShare($share); |
|
| 382 | + if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
| 383 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
| 384 | + $remoteId = $this->federatedShareProvider->getRemoteId($share); |
|
| 385 | + $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
| 386 | + $notification->setMessage( |
|
| 387 | + 'SHARE_ACCEPTED', |
|
| 388 | + 'file', |
|
| 389 | + $remoteId, |
|
| 390 | + [ |
|
| 391 | + 'sharedSecret' => $token, |
|
| 392 | + 'message' => 'Recipient accepted the re-share' |
|
| 393 | + ] |
|
| 394 | + |
|
| 395 | + ); |
|
| 396 | + $this->cloudFederationProviderManager->sendNotification($remote, $notification); |
|
| 397 | + |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + return []; |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * @param IShare $share |
|
| 405 | + * @throws ShareNotFound |
|
| 406 | + */ |
|
| 407 | + protected function executeAcceptShare(IShare $share) { |
|
| 408 | + try { |
|
| 409 | + $fileId = (int)$share->getNode()->getId(); |
|
| 410 | + list($file, $link) = $this->getFile($this->getCorrectUid($share), $fileId); |
|
| 411 | + } catch (\Exception $e) { |
|
| 412 | + throw new ShareNotFound(); |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + $event = $this->activityManager->generateEvent(); |
|
| 416 | + $event->setApp('files_sharing') |
|
| 417 | + ->setType('remote_share') |
|
| 418 | + ->setAffectedUser($this->getCorrectUid($share)) |
|
| 419 | + ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_ACCEPTED, [$share->getSharedWith(), [$fileId => $file]]) |
|
| 420 | + ->setObject('files', $fileId, $file) |
|
| 421 | + ->setLink($link); |
|
| 422 | + $this->activityManager->publish($event); |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + /** |
|
| 426 | + * process notification that the recipient declined a share |
|
| 427 | + * |
|
| 428 | + * @param string $id |
|
| 429 | + * @param array $notification |
|
| 430 | + * @return array |
|
| 431 | + * @throws ActionNotSupportedException |
|
| 432 | + * @throws AuthenticationFailedException |
|
| 433 | + * @throws BadRequestException |
|
| 434 | + * @throws ShareNotFound |
|
| 435 | + * @throws \OC\HintException |
|
| 436 | + * |
|
| 437 | + */ |
|
| 438 | + protected function shareDeclined($id, array $notification) { |
|
| 439 | + |
|
| 440 | + if (!$this->isS2SEnabled()) { |
|
| 441 | + throw new ActionNotSupportedException('Server does not support federated cloud sharing'); |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + if (!isset($notification['sharedSecret'])) { |
|
| 445 | + throw new BadRequestException(['sharedSecret']); |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + $token = $notification['sharedSecret']; |
|
| 449 | + |
|
| 450 | + $share = $this->federatedShareProvider->getShareById($id); |
|
| 451 | + |
|
| 452 | + $this->verifyShare($share, $token); |
|
| 453 | + |
|
| 454 | + if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
| 455 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
| 456 | + $remoteId = $this->federatedShareProvider->getRemoteId($share); |
|
| 457 | + $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
| 458 | + $notification->setMessage( |
|
| 459 | + 'SHARE_DECLINED', |
|
| 460 | + 'file', |
|
| 461 | + $remoteId, |
|
| 462 | + [ |
|
| 463 | + 'sharedSecret' => $token, |
|
| 464 | + 'message' => 'Recipient declined the re-share' |
|
| 465 | + ] |
|
| 466 | + |
|
| 467 | + ); |
|
| 468 | + $this->cloudFederationProviderManager->sendNotification($remote, $notification); |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + $this->executeDeclineShare($share); |
|
| 472 | + |
|
| 473 | + return []; |
|
| 474 | + |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + /** |
|
| 478 | + * delete declined share and create a activity |
|
| 479 | + * |
|
| 480 | + * @param IShare $share |
|
| 481 | + * @throws ShareNotFound |
|
| 482 | + */ |
|
| 483 | + protected function executeDeclineShare(IShare $share) { |
|
| 484 | + $this->federatedShareProvider->removeShareFromTable($share); |
|
| 485 | + |
|
| 486 | + try { |
|
| 487 | + $fileId = (int)$share->getNode()->getId(); |
|
| 488 | + list($file, $link) = $this->getFile($this->getCorrectUid($share), $fileId); |
|
| 489 | + } catch (\Exception $e) { |
|
| 490 | + throw new ShareNotFound(); |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + $event = $this->activityManager->generateEvent(); |
|
| 494 | + $event->setApp('files_sharing') |
|
| 495 | + ->setType('remote_share') |
|
| 496 | + ->setAffectedUser($this->getCorrectUid($share)) |
|
| 497 | + ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_DECLINED, [$share->getSharedWith(), [$fileId => $file]]) |
|
| 498 | + ->setObject('files', $fileId, $file) |
|
| 499 | + ->setLink($link); |
|
| 500 | + $this->activityManager->publish($event); |
|
| 501 | + |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + /** |
|
| 505 | + * received the notification that the owner unshared a file from you |
|
| 506 | + * |
|
| 507 | + * @param string $id |
|
| 508 | + * @param array $notification |
|
| 509 | + * @return array |
|
| 510 | + * @throws AuthenticationFailedException |
|
| 511 | + * @throws BadRequestException |
|
| 512 | + */ |
|
| 513 | + private function undoReshare($id, array $notification) { |
|
| 514 | + if (!isset($notification['sharedSecret'])) { |
|
| 515 | + throw new BadRequestException(['sharedSecret']); |
|
| 516 | + } |
|
| 517 | + $token = $notification['sharedSecret']; |
|
| 518 | + |
|
| 519 | + $share = $this->federatedShareProvider->getShareById($id); |
|
| 520 | + |
|
| 521 | + $this->verifyShare($share, $token); |
|
| 522 | + $this->federatedShareProvider->removeShareFromTable($share); |
|
| 523 | + return []; |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + /** |
|
| 527 | + * unshare file from self |
|
| 528 | + * |
|
| 529 | + * @param string $id |
|
| 530 | + * @param array $notification |
|
| 531 | + * @return array |
|
| 532 | + * @throws ActionNotSupportedException |
|
| 533 | + * @throws BadRequestException |
|
| 534 | + */ |
|
| 535 | + private function unshare($id, array $notification) { |
|
| 536 | + |
|
| 537 | + if (!$this->isS2SEnabled(true)) { |
|
| 538 | + throw new ActionNotSupportedException("incoming shares disabled!"); |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + if (!isset($notification['sharedSecret'])) { |
|
| 542 | + throw new BadRequestException(['sharedSecret']); |
|
| 543 | + } |
|
| 544 | + $token = $notification['sharedSecret']; |
|
| 545 | + |
|
| 546 | + $qb = $this->connection->getQueryBuilder(); |
|
| 547 | + $qb->select('*') |
|
| 548 | + ->from('share_external') |
|
| 549 | + ->where( |
|
| 550 | + $qb->expr()->andX( |
|
| 551 | + $qb->expr()->eq('remote_id', $qb->createNamedParameter($id)), |
|
| 552 | + $qb->expr()->eq('share_token', $qb->createNamedParameter($token)) |
|
| 553 | + ) |
|
| 554 | + ); |
|
| 555 | + |
|
| 556 | + $result = $qb->execute(); |
|
| 557 | + $share = $result->fetch(); |
|
| 558 | + $result->closeCursor(); |
|
| 559 | + |
|
| 560 | + if ($token && $id && !empty($share)) { |
|
| 561 | + |
|
| 562 | + $remote = $this->cleanupRemote($share['remote']); |
|
| 563 | + |
|
| 564 | + $owner = $this->cloudIdManager->getCloudId($share['owner'], $remote); |
|
| 565 | + $mountpoint = $share['mountpoint']; |
|
| 566 | + $user = $share['user']; |
|
| 567 | + |
|
| 568 | + $qb = $this->connection->getQueryBuilder(); |
|
| 569 | + $qb->delete('share_external') |
|
| 570 | + ->where( |
|
| 571 | + $qb->expr()->andX( |
|
| 572 | + $qb->expr()->eq('remote_id', $qb->createNamedParameter($id)), |
|
| 573 | + $qb->expr()->eq('share_token', $qb->createNamedParameter($token)) |
|
| 574 | + ) |
|
| 575 | + ); |
|
| 576 | + |
|
| 577 | + $qb->execute(); |
|
| 578 | + |
|
| 579 | + if ($share['accepted']) { |
|
| 580 | + $path = trim($mountpoint, '/'); |
|
| 581 | + } else { |
|
| 582 | + $path = trim($share['name'], '/'); |
|
| 583 | + } |
|
| 584 | + |
|
| 585 | + $notification = $this->notificationManager->createNotification(); |
|
| 586 | + $notification->setApp('files_sharing') |
|
| 587 | + ->setUser($share['user']) |
|
| 588 | + ->setObject('remote_share', (int)$share['id']); |
|
| 589 | + $this->notificationManager->markProcessed($notification); |
|
| 590 | + |
|
| 591 | + $event = $this->activityManager->generateEvent(); |
|
| 592 | + $event->setApp('files_sharing') |
|
| 593 | + ->setType('remote_share') |
|
| 594 | + ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_UNSHARED, [$owner->getId(), $path]) |
|
| 595 | + ->setAffectedUser($user) |
|
| 596 | + ->setObject('remote_share', (int)$share['id'], $path); |
|
| 597 | + \OC::$server->getActivityManager()->publish($event); |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + return []; |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + private function cleanupRemote($remote) { |
|
| 604 | + $remote = substr($remote, strpos($remote, '://') + 3); |
|
| 605 | + |
|
| 606 | + return rtrim($remote, '/'); |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + /** |
|
| 610 | + * recipient of a share request to re-share the file with another user |
|
| 611 | + * |
|
| 612 | + * @param string $id |
|
| 613 | + * @param array $notification |
|
| 614 | + * @return array |
|
| 615 | + * @throws AuthenticationFailedException |
|
| 616 | + * @throws BadRequestException |
|
| 617 | + * @throws ProviderCouldNotAddShareException |
|
| 618 | + * @throws ShareNotFound |
|
| 619 | + */ |
|
| 620 | + protected function reshareRequested($id, array $notification) { |
|
| 621 | + |
|
| 622 | + if (!isset($notification['sharedSecret'])) { |
|
| 623 | + throw new BadRequestException(['sharedSecret']); |
|
| 624 | + } |
|
| 625 | + $token = $notification['sharedSecret']; |
|
| 626 | + |
|
| 627 | + if (!isset($notification['shareWith'])) { |
|
| 628 | + throw new BadRequestException(['shareWith']); |
|
| 629 | + } |
|
| 630 | + $shareWith = $notification['shareWith']; |
|
| 631 | + |
|
| 632 | + if (!isset($notification['senderId'])) { |
|
| 633 | + throw new BadRequestException(['senderId']); |
|
| 634 | + } |
|
| 635 | + $senderId = $notification['senderId']; |
|
| 636 | + |
|
| 637 | + $share = $this->federatedShareProvider->getShareById($id); |
|
| 638 | + // don't allow to share a file back to the owner |
|
| 639 | + try { |
|
| 640 | + list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith); |
|
| 641 | + $owner = $share->getShareOwner(); |
|
| 642 | + $currentServer = $this->addressHandler->generateRemoteURL(); |
|
| 643 | + if ($this->addressHandler->compareAddresses($user, $remote, $owner, $currentServer)) { |
|
| 644 | + throw new ProviderCouldNotAddShareException('Resharing back to the owner is not allowed: ' . $id); |
|
| 645 | + } |
|
| 646 | + } catch (\Exception $e) { |
|
| 647 | + throw new ProviderCouldNotAddShareException($e->getMessage()); |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + $this->verifyShare($share, $token); |
|
| 651 | + |
|
| 652 | + // check if re-sharing is allowed |
|
| 653 | + if ($share->getPermissions() & Constants::PERMISSION_SHARE) { |
|
| 654 | + // the recipient of the initial share is now the initiator for the re-share |
|
| 655 | + $share->setSharedBy($share->getSharedWith()); |
|
| 656 | + $share->setSharedWith($shareWith); |
|
| 657 | + $result = $this->federatedShareProvider->create($share); |
|
| 658 | + $this->federatedShareProvider->storeRemoteId((int)$result->getId(), $senderId); |
|
| 659 | + return ['token' => $result->getToken(), 'providerId' => $result->getId()]; |
|
| 660 | + } else { |
|
| 661 | + throw new ProviderCouldNotAddShareException('resharing not allowed for share: ' . $id); |
|
| 662 | + } |
|
| 663 | + |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + /** |
|
| 667 | + * update permission of a re-share so that the share dialog shows the right |
|
| 668 | + * permission if the owner or the sender changes the permission |
|
| 669 | + * |
|
| 670 | + * @param string $id |
|
| 671 | + * @param array $notification |
|
| 672 | + * @return array |
|
| 673 | + * @throws AuthenticationFailedException |
|
| 674 | + * @throws BadRequestException |
|
| 675 | + */ |
|
| 676 | + protected function updateResharePermissions($id, array $notification) { |
|
| 677 | + |
|
| 678 | + if (!isset($notification['sharedSecret'])) { |
|
| 679 | + throw new BadRequestException(['sharedSecret']); |
|
| 680 | + } |
|
| 681 | + $token = $notification['sharedSecret']; |
|
| 682 | + |
|
| 683 | + if (!isset($notification['permission'])) { |
|
| 684 | + throw new BadRequestException(['permission']); |
|
| 685 | + } |
|
| 686 | + $ocmPermissions = $notification['permission']; |
|
| 687 | + |
|
| 688 | + $share = $this->federatedShareProvider->getShareById($id); |
|
| 689 | + |
|
| 690 | + $ncPermission = $this->ocmPermissions2ncPermissions($ocmPermissions); |
|
| 691 | + |
|
| 692 | + $this->verifyShare($share, $token); |
|
| 693 | + $this->updatePermissionsInDatabase($share, $ncPermission); |
|
| 694 | + |
|
| 695 | + return []; |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + /** |
|
| 699 | + * translate OCM Permissions to Nextcloud permissions |
|
| 700 | + * |
|
| 701 | + * @param array $ocmPermissions |
|
| 702 | + * @return int |
|
| 703 | + * @throws BadRequestException |
|
| 704 | + */ |
|
| 705 | + protected function ocmPermissions2ncPermissions(array $ocmPermissions) { |
|
| 706 | + $ncPermissions = 0; |
|
| 707 | + foreach($ocmPermissions as $permission) { |
|
| 708 | + switch (strtolower($permission)) { |
|
| 709 | + case 'read': |
|
| 710 | + $ncPermissions += Constants::PERMISSION_READ; |
|
| 711 | + break; |
|
| 712 | + case 'write': |
|
| 713 | + $ncPermissions += Constants::PERMISSION_CREATE + Constants::PERMISSION_UPDATE; |
|
| 714 | + break; |
|
| 715 | + case 'share': |
|
| 716 | + $ncPermissions += Constants::PERMISSION_SHARE; |
|
| 717 | + break; |
|
| 718 | + default: |
|
| 719 | + throw new BadRequestException(['permission']); |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + } |
|
| 723 | + |
|
| 724 | + return $ncPermissions; |
|
| 725 | + } |
|
| 726 | + |
|
| 727 | + /** |
|
| 728 | + * update permissions in database |
|
| 729 | + * |
|
| 730 | + * @param IShare $share |
|
| 731 | + * @param int $permissions |
|
| 732 | + */ |
|
| 733 | + protected function updatePermissionsInDatabase(IShare $share, $permissions) { |
|
| 734 | + $query = $this->connection->getQueryBuilder(); |
|
| 735 | + $query->update('share') |
|
| 736 | + ->where($query->expr()->eq('id', $query->createNamedParameter($share->getId()))) |
|
| 737 | + ->set('permissions', $query->createNamedParameter($permissions)) |
|
| 738 | + ->execute(); |
|
| 739 | + } |
|
| 740 | + |
|
| 741 | + |
|
| 742 | + /** |
|
| 743 | + * get file |
|
| 744 | + * |
|
| 745 | + * @param string $user |
|
| 746 | + * @param int $fileSource |
|
| 747 | + * @return array with internal path of the file and a absolute link to it |
|
| 748 | + */ |
|
| 749 | + private function getFile($user, $fileSource) { |
|
| 750 | + \OC_Util::setupFS($user); |
|
| 751 | + |
|
| 752 | + try { |
|
| 753 | + $file = Filesystem::getPath($fileSource); |
|
| 754 | + } catch (NotFoundException $e) { |
|
| 755 | + $file = null; |
|
| 756 | + } |
|
| 757 | + $args = Filesystem::is_dir($file) ? array('dir' => $file) : array('dir' => dirname($file), 'scrollto' => $file); |
|
| 758 | + $link = Util::linkToAbsolute('files', 'index.php', $args); |
|
| 759 | + |
|
| 760 | + return [$file, $link]; |
|
| 761 | + |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + /** |
|
| 765 | + * check if we are the initiator or the owner of a re-share and return the correct UID |
|
| 766 | + * |
|
| 767 | + * @param IShare $share |
|
| 768 | + * @return string |
|
| 769 | + */ |
|
| 770 | + protected function getCorrectUid(IShare $share) { |
|
| 771 | + if ($this->userManager->userExists($share->getShareOwner())) { |
|
| 772 | + return $share->getShareOwner(); |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + return $share->getSharedBy(); |
|
| 776 | + } |
|
| 777 | + |
|
| 778 | + |
|
| 779 | + |
|
| 780 | + /** |
|
| 781 | + * check if we got the right share |
|
| 782 | + * |
|
| 783 | + * @param IShare $share |
|
| 784 | + * @param string $token |
|
| 785 | + * @return bool |
|
| 786 | + * @throws AuthenticationFailedException |
|
| 787 | + */ |
|
| 788 | + protected function verifyShare(IShare $share, $token) { |
|
| 789 | + if ( |
|
| 790 | + $share->getShareType() === FederatedShareProvider::SHARE_TYPE_REMOTE && |
|
| 791 | + $share->getToken() === $token |
|
| 792 | + ) { |
|
| 793 | + return true; |
|
| 794 | + } |
|
| 795 | + |
|
| 796 | + throw new AuthenticationFailedException(); |
|
| 797 | + } |
|
| 798 | + |
|
| 799 | + |
|
| 800 | + |
|
| 801 | + /** |
|
| 802 | + * check if server-to-server sharing is enabled |
|
| 803 | + * |
|
| 804 | + * @param bool $incoming |
|
| 805 | + * @return bool |
|
| 806 | + */ |
|
| 807 | + private function isS2SEnabled($incoming = false) { |
|
| 808 | + |
|
| 809 | + $result = $this->appManager->isEnabledForUser('files_sharing'); |
|
| 810 | + |
|
| 811 | + if ($incoming) { |
|
| 812 | + $result = $result && $this->federatedShareProvider->isIncomingServer2serverShareEnabled(); |
|
| 813 | + } else { |
|
| 814 | + $result = $result && $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); |
|
| 815 | + } |
|
| 816 | + |
|
| 817 | + return $result; |
|
| 818 | + } |
|
| 819 | + |
|
| 820 | + |
|
| 821 | + /** |
|
| 822 | + * get the supported share types, e.g. "user", "group", etc. |
|
| 823 | + * |
|
| 824 | + * @return array |
|
| 825 | + * |
|
| 826 | + * @since 14.0.0 |
|
| 827 | + */ |
|
| 828 | + public function getSupportedShareTypes() { |
|
| 829 | + return ['user', 'group']; |
|
| 830 | + } |
|
| 831 | 831 | } |