@@ -106,7 +106,6 @@ |
||
106 | 106 | * @param string $ownerDisplayName display name of the user who shared the item |
107 | 107 | * @param string $sharedBy provider specific UID of the user who shared the resource |
108 | 108 | * @param string $sharedByDisplayName display name of the user who shared the resource |
109 | - * @param string $sharedSecret use to authenticate accross servers |
|
110 | 109 | * @param array $protocol (e,.g. ['name' => 'webdav', 'options' => ['username' => 'john', 'permissions' => 31]]) |
111 | 110 | * @param string $shareType ('group' or 'user' share) |
112 | 111 | * @param $resourceType ('file', 'calendar',...) |
@@ -51,233 +51,233 @@ |
||
51 | 51 | */ |
52 | 52 | class RequestHandlerController extends Controller { |
53 | 53 | |
54 | - /** @var ILogger */ |
|
55 | - private $logger; |
|
54 | + /** @var ILogger */ |
|
55 | + private $logger; |
|
56 | 56 | |
57 | - /** @var IUserManager */ |
|
58 | - private $userManager; |
|
57 | + /** @var IUserManager */ |
|
58 | + private $userManager; |
|
59 | 59 | |
60 | - /** @var IURLGenerator */ |
|
61 | - private $urlGenerator; |
|
60 | + /** @var IURLGenerator */ |
|
61 | + private $urlGenerator; |
|
62 | 62 | |
63 | - /** @var ICloudFederationProviderManager */ |
|
64 | - private $cloudFederationProviderManager; |
|
63 | + /** @var ICloudFederationProviderManager */ |
|
64 | + private $cloudFederationProviderManager; |
|
65 | 65 | |
66 | - /** @var Config */ |
|
67 | - private $config; |
|
66 | + /** @var Config */ |
|
67 | + private $config; |
|
68 | 68 | |
69 | - /** @var ICloudFederationFactory */ |
|
70 | - private $factory; |
|
69 | + /** @var ICloudFederationFactory */ |
|
70 | + private $factory; |
|
71 | 71 | |
72 | - /** @var ICloudIdManager */ |
|
73 | - private $cloudIdManager; |
|
72 | + /** @var ICloudIdManager */ |
|
73 | + private $cloudIdManager; |
|
74 | 74 | |
75 | - public function __construct($appName, |
|
76 | - IRequest $request, |
|
77 | - ILogger $logger, |
|
78 | - IUserManager $userManager, |
|
79 | - IURLGenerator $urlGenerator, |
|
80 | - ICloudFederationProviderManager $cloudFederationProviderManager, |
|
81 | - Config $config, |
|
82 | - ICloudFederationFactory $factory, |
|
83 | - ICloudIdManager $cloudIdManager |
|
84 | - ) { |
|
85 | - parent::__construct($appName, $request); |
|
75 | + public function __construct($appName, |
|
76 | + IRequest $request, |
|
77 | + ILogger $logger, |
|
78 | + IUserManager $userManager, |
|
79 | + IURLGenerator $urlGenerator, |
|
80 | + ICloudFederationProviderManager $cloudFederationProviderManager, |
|
81 | + Config $config, |
|
82 | + ICloudFederationFactory $factory, |
|
83 | + ICloudIdManager $cloudIdManager |
|
84 | + ) { |
|
85 | + parent::__construct($appName, $request); |
|
86 | 86 | |
87 | - $this->logger = $logger; |
|
88 | - $this->userManager = $userManager; |
|
89 | - $this->urlGenerator = $urlGenerator; |
|
90 | - $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
91 | - $this->config = $config; |
|
92 | - $this->factory = $factory; |
|
93 | - $this->cloudIdManager = $cloudIdManager; |
|
94 | - } |
|
87 | + $this->logger = $logger; |
|
88 | + $this->userManager = $userManager; |
|
89 | + $this->urlGenerator = $urlGenerator; |
|
90 | + $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
91 | + $this->config = $config; |
|
92 | + $this->factory = $factory; |
|
93 | + $this->cloudIdManager = $cloudIdManager; |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * add share |
|
98 | - * |
|
99 | - * @NoCSRFRequired |
|
100 | - * @PublicPage |
|
101 | - * @BruteForceProtection(action=receiveFederatedShare) |
|
102 | - * |
|
103 | - * @param string $shareWith |
|
104 | - * @param string $name resource name (e.g. document.odt) |
|
105 | - * @param string $description share description (optional) |
|
106 | - * @param string $providerId resource UID on the provider side |
|
107 | - * @param string $owner provider specific UID of the user who owns the resource |
|
108 | - * @param string $ownerDisplayName display name of the user who shared the item |
|
109 | - * @param string $sharedBy provider specific UID of the user who shared the resource |
|
110 | - * @param string $sharedByDisplayName display name of the user who shared the resource |
|
111 | - * @param string $sharedSecret use to authenticate accross servers |
|
112 | - * @param array $protocol (e,.g. ['name' => 'webdav', 'options' => ['username' => 'john', 'permissions' => 31]]) |
|
113 | - * @param string $shareType ('group' or 'user' share) |
|
114 | - * @param $resourceType ('file', 'calendar',...) |
|
115 | - * @return Http\DataResponse|JSONResponse |
|
116 | - * |
|
117 | - * 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 |
|
118 | - */ |
|
119 | - public function addShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $protocol, $shareType, $resourceType) { |
|
120 | - if (!$this->config->incomingRequestsEnabled()) { |
|
121 | - return new JSONResponse( |
|
122 | - ['message' => 'This server doesn\'t support outgoing federated shares'], |
|
123 | - Http::STATUS_NOT_IMPLEMENTED |
|
124 | - ); |
|
125 | - } |
|
96 | + /** |
|
97 | + * add share |
|
98 | + * |
|
99 | + * @NoCSRFRequired |
|
100 | + * @PublicPage |
|
101 | + * @BruteForceProtection(action=receiveFederatedShare) |
|
102 | + * |
|
103 | + * @param string $shareWith |
|
104 | + * @param string $name resource name (e.g. document.odt) |
|
105 | + * @param string $description share description (optional) |
|
106 | + * @param string $providerId resource UID on the provider side |
|
107 | + * @param string $owner provider specific UID of the user who owns the resource |
|
108 | + * @param string $ownerDisplayName display name of the user who shared the item |
|
109 | + * @param string $sharedBy provider specific UID of the user who shared the resource |
|
110 | + * @param string $sharedByDisplayName display name of the user who shared the resource |
|
111 | + * @param string $sharedSecret use to authenticate accross servers |
|
112 | + * @param array $protocol (e,.g. ['name' => 'webdav', 'options' => ['username' => 'john', 'permissions' => 31]]) |
|
113 | + * @param string $shareType ('group' or 'user' share) |
|
114 | + * @param $resourceType ('file', 'calendar',...) |
|
115 | + * @return Http\DataResponse|JSONResponse |
|
116 | + * |
|
117 | + * 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 |
|
118 | + */ |
|
119 | + public function addShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $protocol, $shareType, $resourceType) { |
|
120 | + if (!$this->config->incomingRequestsEnabled()) { |
|
121 | + return new JSONResponse( |
|
122 | + ['message' => 'This server doesn\'t support outgoing federated shares'], |
|
123 | + Http::STATUS_NOT_IMPLEMENTED |
|
124 | + ); |
|
125 | + } |
|
126 | 126 | |
127 | - // check if all required parameters are set |
|
128 | - if ($shareWith === null || |
|
129 | - $name === null || |
|
130 | - $providerId === null || |
|
131 | - $owner === null || |
|
132 | - $resourceType === null || |
|
133 | - $shareType === null || |
|
134 | - !is_array($protocol) || |
|
135 | - !isset($protocol['name']) || |
|
136 | - !isset ($protocol['options']) || |
|
137 | - !is_array($protocol['options']) || |
|
138 | - !isset($protocol['options']['sharedSecret']) |
|
139 | - ) { |
|
140 | - return new JSONResponse( |
|
141 | - ['message' => 'Missing arguments'], |
|
142 | - Http::STATUS_BAD_REQUEST |
|
143 | - ); |
|
144 | - } |
|
127 | + // check if all required parameters are set |
|
128 | + if ($shareWith === null || |
|
129 | + $name === null || |
|
130 | + $providerId === null || |
|
131 | + $owner === null || |
|
132 | + $resourceType === null || |
|
133 | + $shareType === null || |
|
134 | + !is_array($protocol) || |
|
135 | + !isset($protocol['name']) || |
|
136 | + !isset ($protocol['options']) || |
|
137 | + !is_array($protocol['options']) || |
|
138 | + !isset($protocol['options']['sharedSecret']) |
|
139 | + ) { |
|
140 | + return new JSONResponse( |
|
141 | + ['message' => 'Missing arguments'], |
|
142 | + Http::STATUS_BAD_REQUEST |
|
143 | + ); |
|
144 | + } |
|
145 | 145 | |
146 | - $cloudId = $this->cloudIdManager->resolveCloudId($shareWith); |
|
147 | - $shareWithLocalId = $cloudId->getUser(); |
|
148 | - $shareWith = $this->mapUid($shareWithLocalId); |
|
146 | + $cloudId = $this->cloudIdManager->resolveCloudId($shareWith); |
|
147 | + $shareWithLocalId = $cloudId->getUser(); |
|
148 | + $shareWith = $this->mapUid($shareWithLocalId); |
|
149 | 149 | |
150 | - if (!$this->userManager->userExists($shareWith)) { |
|
151 | - return new JSONResponse( |
|
152 | - ['message' => 'User "' . $shareWith . '" does not exists at ' . $this->urlGenerator->getBaseUrl()], |
|
153 | - Http::STATUS_BAD_REQUEST |
|
154 | - ); |
|
155 | - } |
|
150 | + if (!$this->userManager->userExists($shareWith)) { |
|
151 | + return new JSONResponse( |
|
152 | + ['message' => 'User "' . $shareWith . '" does not exists at ' . $this->urlGenerator->getBaseUrl()], |
|
153 | + Http::STATUS_BAD_REQUEST |
|
154 | + ); |
|
155 | + } |
|
156 | 156 | |
157 | - // if no explicit display name is given, we use the uid as display name |
|
158 | - $ownerDisplayName = $ownerDisplayName === null ? $owner : $ownerDisplayName; |
|
159 | - $sharedByDisplayName = $sharedByDisplayName === null ? $sharedBy : $sharedByDisplayName; |
|
157 | + // if no explicit display name is given, we use the uid as display name |
|
158 | + $ownerDisplayName = $ownerDisplayName === null ? $owner : $ownerDisplayName; |
|
159 | + $sharedByDisplayName = $sharedByDisplayName === null ? $sharedBy : $sharedByDisplayName; |
|
160 | 160 | |
161 | - // sharedBy* parameter is optional, if nothing is set we assume that it is the same user as the owner |
|
162 | - if ($sharedBy === null) { |
|
163 | - $sharedBy = $owner; |
|
164 | - $sharedByDisplayName = $ownerDisplayName; |
|
165 | - } |
|
161 | + // sharedBy* parameter is optional, if nothing is set we assume that it is the same user as the owner |
|
162 | + if ($sharedBy === null) { |
|
163 | + $sharedBy = $owner; |
|
164 | + $sharedByDisplayName = $ownerDisplayName; |
|
165 | + } |
|
166 | 166 | |
167 | - try { |
|
168 | - $provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType); |
|
169 | - $share = $this->factory->getCloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, '', $shareType, $resourceType); |
|
170 | - $share->setProtocol($protocol); |
|
171 | - $id = $provider->shareReceived($share); |
|
172 | - } catch (ProviderDoesNotExistsException $e) { |
|
173 | - return new JSONResponse( |
|
174 | - ['message' => $e->getMessage()], |
|
175 | - Http::STATUS_NOT_IMPLEMENTED |
|
176 | - ); |
|
177 | - } catch (ProviderCouldNotAddShareException $e) { |
|
178 | - return new JSONResponse( |
|
179 | - ['message' => $e->getMessage()], |
|
180 | - $e->getCode() |
|
181 | - ); |
|
182 | - } catch (\Exception $e) { |
|
183 | - return new JSONResponse( |
|
184 | - ['message' => 'Internal error at ' . $this->urlGenerator->getBaseUrl()], |
|
185 | - Http::STATUS_BAD_REQUEST |
|
186 | - ); |
|
187 | - } |
|
167 | + try { |
|
168 | + $provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType); |
|
169 | + $share = $this->factory->getCloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, '', $shareType, $resourceType); |
|
170 | + $share->setProtocol($protocol); |
|
171 | + $id = $provider->shareReceived($share); |
|
172 | + } catch (ProviderDoesNotExistsException $e) { |
|
173 | + return new JSONResponse( |
|
174 | + ['message' => $e->getMessage()], |
|
175 | + Http::STATUS_NOT_IMPLEMENTED |
|
176 | + ); |
|
177 | + } catch (ProviderCouldNotAddShareException $e) { |
|
178 | + return new JSONResponse( |
|
179 | + ['message' => $e->getMessage()], |
|
180 | + $e->getCode() |
|
181 | + ); |
|
182 | + } catch (\Exception $e) { |
|
183 | + return new JSONResponse( |
|
184 | + ['message' => 'Internal error at ' . $this->urlGenerator->getBaseUrl()], |
|
185 | + Http::STATUS_BAD_REQUEST |
|
186 | + ); |
|
187 | + } |
|
188 | 188 | |
189 | - return new JSONResponse( |
|
190 | - ['id' => $id, 'createdAt' => time()], |
|
191 | - Http::STATUS_CREATED); |
|
189 | + return new JSONResponse( |
|
190 | + ['id' => $id, 'createdAt' => time()], |
|
191 | + Http::STATUS_CREATED); |
|
192 | 192 | |
193 | - } |
|
193 | + } |
|
194 | 194 | |
195 | - /** |
|
196 | - * receive notification about existing share |
|
197 | - * |
|
198 | - * @NoCSRFRequired |
|
199 | - * @PublicPage |
|
200 | - * @BruteForceProtection(action=receiveFederatedShareNotification) |
|
201 | - * |
|
202 | - * @param string $notificationType (notification type, e.g. SHARE_ACCEPTED) |
|
203 | - * @param string $resourceType (calendar, file, contact,...) |
|
204 | - * @param string $providerId id of the share |
|
205 | - * @param array $notification the actual payload of the notification |
|
206 | - * @return JSONResponse |
|
207 | - */ |
|
208 | - public function receiveNotification($notificationType, $resourceType, $providerId, array $notification) { |
|
209 | - if (!$this->config->incomingRequestsEnabled()) { |
|
210 | - return new JSONResponse( |
|
211 | - ['message' => 'This server doesn\'t support outgoing federated shares'], |
|
212 | - Http::STATUS_NOT_IMPLEMENTED |
|
213 | - ); |
|
214 | - } |
|
195 | + /** |
|
196 | + * receive notification about existing share |
|
197 | + * |
|
198 | + * @NoCSRFRequired |
|
199 | + * @PublicPage |
|
200 | + * @BruteForceProtection(action=receiveFederatedShareNotification) |
|
201 | + * |
|
202 | + * @param string $notificationType (notification type, e.g. SHARE_ACCEPTED) |
|
203 | + * @param string $resourceType (calendar, file, contact,...) |
|
204 | + * @param string $providerId id of the share |
|
205 | + * @param array $notification the actual payload of the notification |
|
206 | + * @return JSONResponse |
|
207 | + */ |
|
208 | + public function receiveNotification($notificationType, $resourceType, $providerId, array $notification) { |
|
209 | + if (!$this->config->incomingRequestsEnabled()) { |
|
210 | + return new JSONResponse( |
|
211 | + ['message' => 'This server doesn\'t support outgoing federated shares'], |
|
212 | + Http::STATUS_NOT_IMPLEMENTED |
|
213 | + ); |
|
214 | + } |
|
215 | 215 | |
216 | - // check if all required parameters are set |
|
217 | - if ($notificationType === null || |
|
218 | - $resourceType === null || |
|
219 | - $providerId === null || |
|
220 | - !is_array($notification) |
|
221 | - ) { |
|
222 | - return new JSONResponse( |
|
223 | - ['message' => 'Missing arguments'], |
|
224 | - Http::STATUS_BAD_REQUEST |
|
225 | - ); |
|
226 | - } |
|
216 | + // check if all required parameters are set |
|
217 | + if ($notificationType === null || |
|
218 | + $resourceType === null || |
|
219 | + $providerId === null || |
|
220 | + !is_array($notification) |
|
221 | + ) { |
|
222 | + return new JSONResponse( |
|
223 | + ['message' => 'Missing arguments'], |
|
224 | + Http::STATUS_BAD_REQUEST |
|
225 | + ); |
|
226 | + } |
|
227 | 227 | |
228 | - try { |
|
229 | - $provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType); |
|
230 | - $provider->notificationReceived($notificationType, $providerId, $notification); |
|
231 | - } catch (ProviderDoesNotExistsException $e) { |
|
232 | - return new JSONResponse( |
|
233 | - ['message' => $e->getMessage()], |
|
234 | - Http::STATUS_BAD_REQUEST |
|
235 | - ); |
|
236 | - } catch (ShareNotFoundException $e) { |
|
237 | - return new JSONResponse( |
|
238 | - ['message' => $e->getMessage()], |
|
239 | - Http::STATUS_BAD_REQUEST |
|
240 | - ); |
|
241 | - } catch (ActionNotSupportedException $e) { |
|
242 | - return new JSONResponse( |
|
243 | - ['message' => $e->getMessage()], |
|
244 | - Http::STATUS_NOT_IMPLEMENTED |
|
245 | - ); |
|
246 | - } catch (BadRequestException $e) { |
|
247 | - return new JSONResponse($e->getReturnMessage(), Http::STATUS_BAD_REQUEST); |
|
248 | - } catch (AuthenticationFailedException $e) { |
|
249 | - return new JSONResponse(["message" => "RESOURCE_NOT_FOUND"], Http::STATUS_FORBIDDEN); |
|
250 | - } |
|
251 | - catch (\Exception $e) { |
|
252 | - return new JSONResponse( |
|
253 | - ['message' => 'Internal error at ' . $this->urlGenerator->getBaseUrl()], |
|
254 | - Http::STATUS_BAD_REQUEST |
|
255 | - ); |
|
256 | - } |
|
228 | + try { |
|
229 | + $provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType); |
|
230 | + $provider->notificationReceived($notificationType, $providerId, $notification); |
|
231 | + } catch (ProviderDoesNotExistsException $e) { |
|
232 | + return new JSONResponse( |
|
233 | + ['message' => $e->getMessage()], |
|
234 | + Http::STATUS_BAD_REQUEST |
|
235 | + ); |
|
236 | + } catch (ShareNotFoundException $e) { |
|
237 | + return new JSONResponse( |
|
238 | + ['message' => $e->getMessage()], |
|
239 | + Http::STATUS_BAD_REQUEST |
|
240 | + ); |
|
241 | + } catch (ActionNotSupportedException $e) { |
|
242 | + return new JSONResponse( |
|
243 | + ['message' => $e->getMessage()], |
|
244 | + Http::STATUS_NOT_IMPLEMENTED |
|
245 | + ); |
|
246 | + } catch (BadRequestException $e) { |
|
247 | + return new JSONResponse($e->getReturnMessage(), Http::STATUS_BAD_REQUEST); |
|
248 | + } catch (AuthenticationFailedException $e) { |
|
249 | + return new JSONResponse(["message" => "RESOURCE_NOT_FOUND"], Http::STATUS_FORBIDDEN); |
|
250 | + } |
|
251 | + catch (\Exception $e) { |
|
252 | + return new JSONResponse( |
|
253 | + ['message' => 'Internal error at ' . $this->urlGenerator->getBaseUrl()], |
|
254 | + Http::STATUS_BAD_REQUEST |
|
255 | + ); |
|
256 | + } |
|
257 | 257 | |
258 | 258 | |
259 | - return new JSONResponse([],Http::STATUS_CREATED); |
|
259 | + return new JSONResponse([],Http::STATUS_CREATED); |
|
260 | 260 | |
261 | - } |
|
261 | + } |
|
262 | 262 | |
263 | - /** |
|
264 | - * map login name to internal LDAP UID if a LDAP backend is in use |
|
265 | - * |
|
266 | - * @param string $uid |
|
267 | - * @return string mixed |
|
268 | - */ |
|
269 | - private function mapUid($uid) { |
|
270 | - \OC::$server->getURLGenerator()->linkToDocs('key'); |
|
271 | - // FIXME this should be a method in the user management instead |
|
272 | - $this->logger->debug('shareWith before, ' . $uid, ['app' => $this->appName]); |
|
273 | - \OCP\Util::emitHook( |
|
274 | - '\OCA\Files_Sharing\API\Server2Server', |
|
275 | - 'preLoginNameUsedAsUserName', |
|
276 | - array('uid' => &$uid) |
|
277 | - ); |
|
278 | - $this->logger->debug('shareWith after, ' . $uid, ['app' => $this->appName]); |
|
263 | + /** |
|
264 | + * map login name to internal LDAP UID if a LDAP backend is in use |
|
265 | + * |
|
266 | + * @param string $uid |
|
267 | + * @return string mixed |
|
268 | + */ |
|
269 | + private function mapUid($uid) { |
|
270 | + \OC::$server->getURLGenerator()->linkToDocs('key'); |
|
271 | + // FIXME this should be a method in the user management instead |
|
272 | + $this->logger->debug('shareWith before, ' . $uid, ['app' => $this->appName]); |
|
273 | + \OCP\Util::emitHook( |
|
274 | + '\OCA\Files_Sharing\API\Server2Server', |
|
275 | + 'preLoginNameUsedAsUserName', |
|
276 | + array('uid' => &$uid) |
|
277 | + ); |
|
278 | + $this->logger->debug('shareWith after, ' . $uid, ['app' => $this->appName]); |
|
279 | 279 | |
280 | - return $uid; |
|
281 | - } |
|
280 | + return $uid; |
|
281 | + } |
|
282 | 282 | |
283 | 283 | } |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | |
150 | 150 | if (!$this->userManager->userExists($shareWith)) { |
151 | 151 | return new JSONResponse( |
152 | - ['message' => 'User "' . $shareWith . '" does not exists at ' . $this->urlGenerator->getBaseUrl()], |
|
152 | + ['message' => 'User "'.$shareWith.'" does not exists at '.$this->urlGenerator->getBaseUrl()], |
|
153 | 153 | Http::STATUS_BAD_REQUEST |
154 | 154 | ); |
155 | 155 | } |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | ); |
182 | 182 | } catch (\Exception $e) { |
183 | 183 | return new JSONResponse( |
184 | - ['message' => 'Internal error at ' . $this->urlGenerator->getBaseUrl()], |
|
184 | + ['message' => 'Internal error at '.$this->urlGenerator->getBaseUrl()], |
|
185 | 185 | Http::STATUS_BAD_REQUEST |
186 | 186 | ); |
187 | 187 | } |
@@ -250,13 +250,13 @@ discard block |
||
250 | 250 | } |
251 | 251 | catch (\Exception $e) { |
252 | 252 | return new JSONResponse( |
253 | - ['message' => 'Internal error at ' . $this->urlGenerator->getBaseUrl()], |
|
253 | + ['message' => 'Internal error at '.$this->urlGenerator->getBaseUrl()], |
|
254 | 254 | Http::STATUS_BAD_REQUEST |
255 | 255 | ); |
256 | 256 | } |
257 | 257 | |
258 | 258 | |
259 | - return new JSONResponse([],Http::STATUS_CREATED); |
|
259 | + return new JSONResponse([], Http::STATUS_CREATED); |
|
260 | 260 | |
261 | 261 | } |
262 | 262 | |
@@ -269,13 +269,13 @@ discard block |
||
269 | 269 | private function mapUid($uid) { |
270 | 270 | \OC::$server->getURLGenerator()->linkToDocs('key'); |
271 | 271 | // FIXME this should be a method in the user management instead |
272 | - $this->logger->debug('shareWith before, ' . $uid, ['app' => $this->appName]); |
|
272 | + $this->logger->debug('shareWith before, '.$uid, ['app' => $this->appName]); |
|
273 | 273 | \OCP\Util::emitHook( |
274 | 274 | '\OCA\Files_Sharing\API\Server2Server', |
275 | 275 | 'preLoginNameUsedAsUserName', |
276 | 276 | array('uid' => &$uid) |
277 | 277 | ); |
278 | - $this->logger->debug('shareWith after, ' . $uid, ['app' => $this->appName]); |
|
278 | + $this->logger->debug('shareWith after, '.$uid, ['app' => $this->appName]); |
|
279 | 279 | |
280 | 280 | return $uid; |
281 | 281 | } |
@@ -247,8 +247,7 @@ |
||
247 | 247 | return new JSONResponse($e->getReturnMessage(), Http::STATUS_BAD_REQUEST); |
248 | 248 | } catch (AuthenticationFailedException $e) { |
249 | 249 | return new JSONResponse(["message" => "RESOURCE_NOT_FOUND"], Http::STATUS_FORBIDDEN); |
250 | - } |
|
251 | - catch (\Exception $e) { |
|
250 | + } catch (\Exception $e) { |
|
252 | 251 | return new JSONResponse( |
253 | 252 | ['message' => 'Internal error at ' . $this->urlGenerator->getBaseUrl()], |
254 | 253 | Http::STATUS_BAD_REQUEST |
@@ -23,221 +23,221 @@ |
||
23 | 23 | |
24 | 24 | interface ICloudFederationShare { |
25 | 25 | |
26 | - /** |
|
27 | - * set uid of the recipient |
|
28 | - * |
|
29 | - * @param string $user |
|
30 | - * |
|
31 | - * @since 14.0.0 |
|
32 | - */ |
|
33 | - public function setShareWith($user); |
|
34 | - |
|
35 | - /** |
|
36 | - * set resource name (e.g. file, calendar, contact,...) |
|
37 | - * |
|
38 | - * @param string $name |
|
39 | - * |
|
40 | - * @since 14.0.0 |
|
41 | - */ |
|
42 | - public function setResourceName($name); |
|
43 | - |
|
44 | - /** |
|
45 | - * set resource type (e.g. file, calendar, contact,...) |
|
46 | - * |
|
47 | - * @param string $resourceType |
|
48 | - * |
|
49 | - * @since 14.0.0 |
|
50 | - */ |
|
51 | - public function setResourceType($resourceType); |
|
52 | - |
|
53 | - /** |
|
54 | - * set resource description (optional) |
|
55 | - * |
|
56 | - * @param string $description |
|
57 | - * |
|
58 | - * @since 14.0.0 |
|
59 | - */ |
|
60 | - public function setDescription($description); |
|
61 | - |
|
62 | - /** |
|
63 | - * set provider ID (e.g. file ID) |
|
64 | - * |
|
65 | - * @param string $providerId |
|
66 | - * |
|
67 | - * @since 14.0.0 |
|
68 | - */ |
|
69 | - public function setProviderId($providerId); |
|
70 | - |
|
71 | - /** |
|
72 | - * set owner UID |
|
73 | - * |
|
74 | - * @param string $owner |
|
75 | - * |
|
76 | - * @since 14.0.0 |
|
77 | - */ |
|
78 | - public function setOwner($owner); |
|
79 | - |
|
80 | - /** |
|
81 | - * set owner display name |
|
82 | - * |
|
83 | - * @param string $ownerDisplayName |
|
84 | - * |
|
85 | - * @since 14.0.0 |
|
86 | - */ |
|
87 | - public function setOwnerDisplayName($ownerDisplayName); |
|
88 | - |
|
89 | - /** |
|
90 | - * set UID of the user who sends the share |
|
91 | - * |
|
92 | - * @param string $sharedBy |
|
93 | - * |
|
94 | - * @since 14.0.0 |
|
95 | - */ |
|
96 | - public function setSharedBy($sharedBy); |
|
97 | - |
|
98 | - /** |
|
99 | - * set display name of the user who sends the share |
|
100 | - * |
|
101 | - * @param $sharedByDisplayName |
|
102 | - * |
|
103 | - * @since 14.0.0 |
|
104 | - */ |
|
105 | - public function setSharedByDisplayName($sharedByDisplayName); |
|
106 | - |
|
107 | - /** |
|
108 | - * set protocol specification |
|
109 | - * |
|
110 | - * @param array $protocol |
|
111 | - * |
|
112 | - * @since 14.0.0 |
|
113 | - */ |
|
114 | - public function setProtocol(array $protocol); |
|
115 | - |
|
116 | - /** |
|
117 | - * share type (group or user) |
|
118 | - * |
|
119 | - * @param string $shareType |
|
120 | - * |
|
121 | - * @since 14.0.0 |
|
122 | - */ |
|
123 | - public function setShareType($shareType); |
|
124 | - |
|
125 | - /** |
|
126 | - * get the whole share, ready to send out |
|
127 | - * |
|
128 | - * @return array |
|
129 | - * |
|
130 | - * @since 14.0.0 |
|
131 | - */ |
|
132 | - public function getShare(); |
|
133 | - |
|
134 | - /** |
|
135 | - * get uid of the recipient |
|
136 | - * |
|
137 | - * @return string |
|
138 | - * |
|
139 | - * @since 14.0.0 |
|
140 | - */ |
|
141 | - public function getShareWith(); |
|
142 | - |
|
143 | - /** |
|
144 | - * get resource name (e.g. file, calendar, contact,...) |
|
145 | - * |
|
146 | - * @return string |
|
147 | - * |
|
148 | - * @since 14.0.0 |
|
149 | - */ |
|
150 | - public function getResourceName(); |
|
151 | - |
|
152 | - /** |
|
153 | - * get resource type (e.g. file, calendar, contact,...) |
|
154 | - * |
|
155 | - * @return string |
|
156 | - * |
|
157 | - * @since 14.0.0 |
|
158 | - */ |
|
159 | - public function getResourceType(); |
|
160 | - |
|
161 | - /** |
|
162 | - * get resource description (optional) |
|
163 | - * |
|
164 | - * @return string |
|
165 | - * |
|
166 | - * @since 14.0.0 |
|
167 | - */ |
|
168 | - public function getDescription(); |
|
169 | - |
|
170 | - /** |
|
171 | - * get provider ID (e.g. file ID) |
|
172 | - * |
|
173 | - * @return string |
|
174 | - * |
|
175 | - * @since 14.0.0 |
|
176 | - */ |
|
177 | - public function getProviderId(); |
|
178 | - |
|
179 | - /** |
|
180 | - * get owner UID |
|
181 | - * |
|
182 | - * @return string |
|
183 | - * |
|
184 | - * @since 14.0.0 |
|
185 | - */ |
|
186 | - public function getOwner(); |
|
187 | - |
|
188 | - /** |
|
189 | - * get owner display name |
|
190 | - * |
|
191 | - * @return string |
|
192 | - * |
|
193 | - * @since 14.0.0 |
|
194 | - */ |
|
195 | - public function getOwnerDisplayName(); |
|
196 | - |
|
197 | - /** |
|
198 | - * get UID of the user who sends the share |
|
199 | - * |
|
200 | - * @return string |
|
201 | - * |
|
202 | - * @since 14.0.0 |
|
203 | - */ |
|
204 | - public function getSharedBy(); |
|
205 | - |
|
206 | - /** |
|
207 | - * get display name of the user who sends the share |
|
208 | - * |
|
209 | - * @return string |
|
210 | - * |
|
211 | - * @since 14.0.0 |
|
212 | - */ |
|
213 | - public function getSharedByDisplayName(); |
|
214 | - |
|
215 | - /** |
|
216 | - * get share type (group or user) |
|
217 | - * |
|
218 | - * @return string |
|
219 | - * |
|
220 | - * @since 14.0.0 |
|
221 | - */ |
|
222 | - public function getShareType(); |
|
223 | - |
|
224 | - /** |
|
225 | - * get share Secret |
|
226 | - * |
|
227 | - * @return string |
|
228 | - * |
|
229 | - * @since 14.0.0 |
|
230 | - */ |
|
231 | - public function getShareSecret(); |
|
232 | - |
|
233 | - |
|
234 | - /** |
|
235 | - * get protocol specification |
|
236 | - * |
|
237 | - * @return array |
|
238 | - * |
|
239 | - * @since 14.0.0 |
|
240 | - */ |
|
241 | - public function getProtocol(); |
|
26 | + /** |
|
27 | + * set uid of the recipient |
|
28 | + * |
|
29 | + * @param string $user |
|
30 | + * |
|
31 | + * @since 14.0.0 |
|
32 | + */ |
|
33 | + public function setShareWith($user); |
|
34 | + |
|
35 | + /** |
|
36 | + * set resource name (e.g. file, calendar, contact,...) |
|
37 | + * |
|
38 | + * @param string $name |
|
39 | + * |
|
40 | + * @since 14.0.0 |
|
41 | + */ |
|
42 | + public function setResourceName($name); |
|
43 | + |
|
44 | + /** |
|
45 | + * set resource type (e.g. file, calendar, contact,...) |
|
46 | + * |
|
47 | + * @param string $resourceType |
|
48 | + * |
|
49 | + * @since 14.0.0 |
|
50 | + */ |
|
51 | + public function setResourceType($resourceType); |
|
52 | + |
|
53 | + /** |
|
54 | + * set resource description (optional) |
|
55 | + * |
|
56 | + * @param string $description |
|
57 | + * |
|
58 | + * @since 14.0.0 |
|
59 | + */ |
|
60 | + public function setDescription($description); |
|
61 | + |
|
62 | + /** |
|
63 | + * set provider ID (e.g. file ID) |
|
64 | + * |
|
65 | + * @param string $providerId |
|
66 | + * |
|
67 | + * @since 14.0.0 |
|
68 | + */ |
|
69 | + public function setProviderId($providerId); |
|
70 | + |
|
71 | + /** |
|
72 | + * set owner UID |
|
73 | + * |
|
74 | + * @param string $owner |
|
75 | + * |
|
76 | + * @since 14.0.0 |
|
77 | + */ |
|
78 | + public function setOwner($owner); |
|
79 | + |
|
80 | + /** |
|
81 | + * set owner display name |
|
82 | + * |
|
83 | + * @param string $ownerDisplayName |
|
84 | + * |
|
85 | + * @since 14.0.0 |
|
86 | + */ |
|
87 | + public function setOwnerDisplayName($ownerDisplayName); |
|
88 | + |
|
89 | + /** |
|
90 | + * set UID of the user who sends the share |
|
91 | + * |
|
92 | + * @param string $sharedBy |
|
93 | + * |
|
94 | + * @since 14.0.0 |
|
95 | + */ |
|
96 | + public function setSharedBy($sharedBy); |
|
97 | + |
|
98 | + /** |
|
99 | + * set display name of the user who sends the share |
|
100 | + * |
|
101 | + * @param $sharedByDisplayName |
|
102 | + * |
|
103 | + * @since 14.0.0 |
|
104 | + */ |
|
105 | + public function setSharedByDisplayName($sharedByDisplayName); |
|
106 | + |
|
107 | + /** |
|
108 | + * set protocol specification |
|
109 | + * |
|
110 | + * @param array $protocol |
|
111 | + * |
|
112 | + * @since 14.0.0 |
|
113 | + */ |
|
114 | + public function setProtocol(array $protocol); |
|
115 | + |
|
116 | + /** |
|
117 | + * share type (group or user) |
|
118 | + * |
|
119 | + * @param string $shareType |
|
120 | + * |
|
121 | + * @since 14.0.0 |
|
122 | + */ |
|
123 | + public function setShareType($shareType); |
|
124 | + |
|
125 | + /** |
|
126 | + * get the whole share, ready to send out |
|
127 | + * |
|
128 | + * @return array |
|
129 | + * |
|
130 | + * @since 14.0.0 |
|
131 | + */ |
|
132 | + public function getShare(); |
|
133 | + |
|
134 | + /** |
|
135 | + * get uid of the recipient |
|
136 | + * |
|
137 | + * @return string |
|
138 | + * |
|
139 | + * @since 14.0.0 |
|
140 | + */ |
|
141 | + public function getShareWith(); |
|
142 | + |
|
143 | + /** |
|
144 | + * get resource name (e.g. file, calendar, contact,...) |
|
145 | + * |
|
146 | + * @return string |
|
147 | + * |
|
148 | + * @since 14.0.0 |
|
149 | + */ |
|
150 | + public function getResourceName(); |
|
151 | + |
|
152 | + /** |
|
153 | + * get resource type (e.g. file, calendar, contact,...) |
|
154 | + * |
|
155 | + * @return string |
|
156 | + * |
|
157 | + * @since 14.0.0 |
|
158 | + */ |
|
159 | + public function getResourceType(); |
|
160 | + |
|
161 | + /** |
|
162 | + * get resource description (optional) |
|
163 | + * |
|
164 | + * @return string |
|
165 | + * |
|
166 | + * @since 14.0.0 |
|
167 | + */ |
|
168 | + public function getDescription(); |
|
169 | + |
|
170 | + /** |
|
171 | + * get provider ID (e.g. file ID) |
|
172 | + * |
|
173 | + * @return string |
|
174 | + * |
|
175 | + * @since 14.0.0 |
|
176 | + */ |
|
177 | + public function getProviderId(); |
|
178 | + |
|
179 | + /** |
|
180 | + * get owner UID |
|
181 | + * |
|
182 | + * @return string |
|
183 | + * |
|
184 | + * @since 14.0.0 |
|
185 | + */ |
|
186 | + public function getOwner(); |
|
187 | + |
|
188 | + /** |
|
189 | + * get owner display name |
|
190 | + * |
|
191 | + * @return string |
|
192 | + * |
|
193 | + * @since 14.0.0 |
|
194 | + */ |
|
195 | + public function getOwnerDisplayName(); |
|
196 | + |
|
197 | + /** |
|
198 | + * get UID of the user who sends the share |
|
199 | + * |
|
200 | + * @return string |
|
201 | + * |
|
202 | + * @since 14.0.0 |
|
203 | + */ |
|
204 | + public function getSharedBy(); |
|
205 | + |
|
206 | + /** |
|
207 | + * get display name of the user who sends the share |
|
208 | + * |
|
209 | + * @return string |
|
210 | + * |
|
211 | + * @since 14.0.0 |
|
212 | + */ |
|
213 | + public function getSharedByDisplayName(); |
|
214 | + |
|
215 | + /** |
|
216 | + * get share type (group or user) |
|
217 | + * |
|
218 | + * @return string |
|
219 | + * |
|
220 | + * @since 14.0.0 |
|
221 | + */ |
|
222 | + public function getShareType(); |
|
223 | + |
|
224 | + /** |
|
225 | + * get share Secret |
|
226 | + * |
|
227 | + * @return string |
|
228 | + * |
|
229 | + * @since 14.0.0 |
|
230 | + */ |
|
231 | + public function getShareSecret(); |
|
232 | + |
|
233 | + |
|
234 | + /** |
|
235 | + * get protocol specification |
|
236 | + * |
|
237 | + * @return array |
|
238 | + * |
|
239 | + * @since 14.0.0 |
|
240 | + */ |
|
241 | + public function getProtocol(); |
|
242 | 242 | |
243 | 243 | } |
@@ -23,33 +23,33 @@ |
||
23 | 23 | |
24 | 24 | interface ICloudFederationFactory { |
25 | 25 | |
26 | - /** |
|
27 | - * get a CloudFederationShare Object to prepare a share you want to send |
|
28 | - * |
|
29 | - * @param string $shareWith |
|
30 | - * @param string $name resource name (e.g. document.odt) |
|
31 | - * @param string $description share description (optional) |
|
32 | - * @param string $providerId resource UID on the provider side |
|
33 | - * @param string $owner provider specific UID of the user who owns the resource |
|
34 | - * @param string $ownerDisplayName display name of the user who shared the item |
|
35 | - * @param string $sharedBy provider specific UID of the user who shared the resource |
|
36 | - * @param string $sharedByDisplayName display name of the user who shared the resource |
|
37 | - * @param string $sharedSecret used to authenticate requests across servers |
|
38 | - * @param string $shareType ('group' or 'user' share) |
|
39 | - * @param $resourceType ('file', 'calendar',...) |
|
40 | - * @return ICloudFederationShare |
|
41 | - * |
|
42 | - * @since 14.0.0 |
|
43 | - */ |
|
44 | - public function getCloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $sharedSecret, $shareType, $resourceType); |
|
26 | + /** |
|
27 | + * get a CloudFederationShare Object to prepare a share you want to send |
|
28 | + * |
|
29 | + * @param string $shareWith |
|
30 | + * @param string $name resource name (e.g. document.odt) |
|
31 | + * @param string $description share description (optional) |
|
32 | + * @param string $providerId resource UID on the provider side |
|
33 | + * @param string $owner provider specific UID of the user who owns the resource |
|
34 | + * @param string $ownerDisplayName display name of the user who shared the item |
|
35 | + * @param string $sharedBy provider specific UID of the user who shared the resource |
|
36 | + * @param string $sharedByDisplayName display name of the user who shared the resource |
|
37 | + * @param string $sharedSecret used to authenticate requests across servers |
|
38 | + * @param string $shareType ('group' or 'user' share) |
|
39 | + * @param $resourceType ('file', 'calendar',...) |
|
40 | + * @return ICloudFederationShare |
|
41 | + * |
|
42 | + * @since 14.0.0 |
|
43 | + */ |
|
44 | + public function getCloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $sharedSecret, $shareType, $resourceType); |
|
45 | 45 | |
46 | - /** |
|
47 | - * get a Cloud FederationNotification object to prepare a notification you |
|
48 | - * want to send |
|
49 | - * |
|
50 | - * @return ICloudFederationNotification |
|
51 | - * |
|
52 | - * @since 14.0.0 |
|
53 | - */ |
|
54 | - public function getCloudFederationNotification(); |
|
46 | + /** |
|
47 | + * get a Cloud FederationNotification object to prepare a notification you |
|
48 | + * want to send |
|
49 | + * |
|
50 | + * @return ICloudFederationNotification |
|
51 | + * |
|
52 | + * @since 14.0.0 |
|
53 | + */ |
|
54 | + public function getCloudFederationNotification(); |
|
55 | 55 | } |
@@ -23,25 +23,25 @@ |
||
23 | 23 | |
24 | 24 | interface ICloudFederationNotification { |
25 | 25 | |
26 | - /** |
|
27 | - * add a message to the notification |
|
28 | - * |
|
29 | - * @param string $notificationType (e.g. SHARE_ACCEPTED) |
|
30 | - * @param string $resourceType (e.g. file, calendar, contact,...) |
|
31 | - * @param $providerId id of the share |
|
32 | - * @param array $notification , payload of the notification |
|
33 | - * |
|
34 | - * @return |
|
35 | - * @since 14.0.0 |
|
36 | - */ |
|
37 | - public function setMessage($notificationType, $resourceType, $providerId, array $notification); |
|
26 | + /** |
|
27 | + * add a message to the notification |
|
28 | + * |
|
29 | + * @param string $notificationType (e.g. SHARE_ACCEPTED) |
|
30 | + * @param string $resourceType (e.g. file, calendar, contact,...) |
|
31 | + * @param $providerId id of the share |
|
32 | + * @param array $notification , payload of the notification |
|
33 | + * |
|
34 | + * @return |
|
35 | + * @since 14.0.0 |
|
36 | + */ |
|
37 | + public function setMessage($notificationType, $resourceType, $providerId, array $notification); |
|
38 | 38 | |
39 | - /** |
|
40 | - * get message, ready to send out |
|
41 | - * |
|
42 | - * @return string |
|
43 | - * |
|
44 | - * @since 14.0.0 |
|
45 | - */ |
|
46 | - public function getMessage(); |
|
39 | + /** |
|
40 | + * get message, ready to send out |
|
41 | + * |
|
42 | + * @return string |
|
43 | + * |
|
44 | + * @since 14.0.0 |
|
45 | + */ |
|
46 | + public function getMessage(); |
|
47 | 47 | } |
@@ -25,328 +25,328 @@ |
||
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-collaboration-services.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-collaboration-services.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 | - $this->share['shareType'] = $shareType; |
|
208 | - } |
|
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 | + $this->share['shareType'] = $shareType; |
|
208 | + } |
|
209 | 209 | |
210 | - /** |
|
211 | - * get the whole share, ready to send out |
|
212 | - * |
|
213 | - * @return array |
|
214 | - * |
|
215 | - * @since 14.0.0 |
|
216 | - */ |
|
217 | - public function getShare() { |
|
218 | - return $this->share; |
|
219 | - } |
|
210 | + /** |
|
211 | + * get the whole share, ready to send out |
|
212 | + * |
|
213 | + * @return array |
|
214 | + * |
|
215 | + * @since 14.0.0 |
|
216 | + */ |
|
217 | + public function getShare() { |
|
218 | + return $this->share; |
|
219 | + } |
|
220 | 220 | |
221 | - /** |
|
222 | - * get uid of the recipient |
|
223 | - * |
|
224 | - * @return string |
|
225 | - * |
|
226 | - * @since 14.0.0 |
|
227 | - */ |
|
228 | - public function getShareWith() { |
|
229 | - return $this->share['shareWith']; |
|
230 | - } |
|
221 | + /** |
|
222 | + * get uid of the recipient |
|
223 | + * |
|
224 | + * @return string |
|
225 | + * |
|
226 | + * @since 14.0.0 |
|
227 | + */ |
|
228 | + public function getShareWith() { |
|
229 | + return $this->share['shareWith']; |
|
230 | + } |
|
231 | 231 | |
232 | - /** |
|
233 | - * get resource name (e.g. file, calendar, contact,...) |
|
234 | - * |
|
235 | - * @return string |
|
236 | - * |
|
237 | - * @since 14.0.0 |
|
238 | - */ |
|
239 | - public function getResourceName() { |
|
240 | - return $this->share['name']; |
|
241 | - } |
|
232 | + /** |
|
233 | + * get resource name (e.g. file, calendar, contact,...) |
|
234 | + * |
|
235 | + * @return string |
|
236 | + * |
|
237 | + * @since 14.0.0 |
|
238 | + */ |
|
239 | + public function getResourceName() { |
|
240 | + return $this->share['name']; |
|
241 | + } |
|
242 | 242 | |
243 | - /** |
|
244 | - * get resource type (e.g. file, calendar, contact,...) |
|
245 | - * |
|
246 | - * @return string |
|
247 | - * |
|
248 | - * @since 14.0.0 |
|
249 | - */ |
|
250 | - public function getResourceType() { |
|
251 | - return $this->share['resourceType']; |
|
252 | - } |
|
243 | + /** |
|
244 | + * get resource type (e.g. file, calendar, contact,...) |
|
245 | + * |
|
246 | + * @return string |
|
247 | + * |
|
248 | + * @since 14.0.0 |
|
249 | + */ |
|
250 | + public function getResourceType() { |
|
251 | + return $this->share['resourceType']; |
|
252 | + } |
|
253 | 253 | |
254 | - /** |
|
255 | - * get resource description (optional) |
|
256 | - * |
|
257 | - * @return string |
|
258 | - * |
|
259 | - * @since 14.0.0 |
|
260 | - */ |
|
261 | - public function getDescription() { |
|
262 | - return $this->share['description']; |
|
263 | - } |
|
254 | + /** |
|
255 | + * get resource description (optional) |
|
256 | + * |
|
257 | + * @return string |
|
258 | + * |
|
259 | + * @since 14.0.0 |
|
260 | + */ |
|
261 | + public function getDescription() { |
|
262 | + return $this->share['description']; |
|
263 | + } |
|
264 | 264 | |
265 | - /** |
|
266 | - * get provider ID (e.g. file ID) |
|
267 | - * |
|
268 | - * @return string |
|
269 | - * |
|
270 | - * @since 14.0.0 |
|
271 | - */ |
|
272 | - public function getProviderId() { |
|
273 | - return $this->share['providerId']; |
|
274 | - } |
|
265 | + /** |
|
266 | + * get provider ID (e.g. file ID) |
|
267 | + * |
|
268 | + * @return string |
|
269 | + * |
|
270 | + * @since 14.0.0 |
|
271 | + */ |
|
272 | + public function getProviderId() { |
|
273 | + return $this->share['providerId']; |
|
274 | + } |
|
275 | 275 | |
276 | - /** |
|
277 | - * get owner UID |
|
278 | - * |
|
279 | - * @return string |
|
280 | - * |
|
281 | - * @since 14.0.0 |
|
282 | - */ |
|
283 | - public function getOwner() { |
|
284 | - return $this->share['owner']; |
|
285 | - } |
|
276 | + /** |
|
277 | + * get owner UID |
|
278 | + * |
|
279 | + * @return string |
|
280 | + * |
|
281 | + * @since 14.0.0 |
|
282 | + */ |
|
283 | + public function getOwner() { |
|
284 | + return $this->share['owner']; |
|
285 | + } |
|
286 | 286 | |
287 | - /** |
|
288 | - * get owner display name |
|
289 | - * |
|
290 | - * @return string |
|
291 | - * |
|
292 | - * @since 14.0.0 |
|
293 | - */ |
|
294 | - public function getOwnerDisplayName() { |
|
295 | - return $this->share['ownerDisplayName']; |
|
296 | - } |
|
287 | + /** |
|
288 | + * get owner display name |
|
289 | + * |
|
290 | + * @return string |
|
291 | + * |
|
292 | + * @since 14.0.0 |
|
293 | + */ |
|
294 | + public function getOwnerDisplayName() { |
|
295 | + return $this->share['ownerDisplayName']; |
|
296 | + } |
|
297 | 297 | |
298 | - /** |
|
299 | - * get UID of the user who sends the share |
|
300 | - * |
|
301 | - * @return string |
|
302 | - * |
|
303 | - * @since 14.0.0 |
|
304 | - */ |
|
305 | - public function getSharedBy() { |
|
306 | - return $this->share['sharedBy']; |
|
307 | - } |
|
298 | + /** |
|
299 | + * get UID of the user who sends the share |
|
300 | + * |
|
301 | + * @return string |
|
302 | + * |
|
303 | + * @since 14.0.0 |
|
304 | + */ |
|
305 | + public function getSharedBy() { |
|
306 | + return $this->share['sharedBy']; |
|
307 | + } |
|
308 | 308 | |
309 | - /** |
|
310 | - * get display name of the user who sends the share |
|
311 | - * |
|
312 | - * @return string |
|
313 | - * |
|
314 | - * @since 14.0.0 |
|
315 | - */ |
|
316 | - public function getSharedByDisplayName() { |
|
317 | - return $this->share['sharedByDisplayName']; |
|
318 | - } |
|
309 | + /** |
|
310 | + * get display name of the user who sends the share |
|
311 | + * |
|
312 | + * @return string |
|
313 | + * |
|
314 | + * @since 14.0.0 |
|
315 | + */ |
|
316 | + public function getSharedByDisplayName() { |
|
317 | + return $this->share['sharedByDisplayName']; |
|
318 | + } |
|
319 | 319 | |
320 | - /** |
|
321 | - * get share type (group or user) |
|
322 | - * |
|
323 | - * @return string |
|
324 | - * |
|
325 | - * @since 14.0.0 |
|
326 | - */ |
|
327 | - public function getShareType() { |
|
328 | - return $this->share['shareType']; |
|
329 | - } |
|
320 | + /** |
|
321 | + * get share type (group or user) |
|
322 | + * |
|
323 | + * @return string |
|
324 | + * |
|
325 | + * @since 14.0.0 |
|
326 | + */ |
|
327 | + public function getShareType() { |
|
328 | + return $this->share['shareType']; |
|
329 | + } |
|
330 | 330 | |
331 | - /** |
|
332 | - * get share Secret |
|
333 | - * |
|
334 | - * @return string |
|
335 | - * |
|
336 | - * @since 14.0.0 |
|
337 | - */ |
|
338 | - public function getShareSecret() { |
|
339 | - return $this->share['protocol']['options']['sharedSecret']; |
|
340 | - } |
|
331 | + /** |
|
332 | + * get share Secret |
|
333 | + * |
|
334 | + * @return string |
|
335 | + * |
|
336 | + * @since 14.0.0 |
|
337 | + */ |
|
338 | + public function getShareSecret() { |
|
339 | + return $this->share['protocol']['options']['sharedSecret']; |
|
340 | + } |
|
341 | 341 | |
342 | - /** |
|
343 | - * get protocol specification |
|
344 | - * |
|
345 | - * @return array |
|
346 | - * |
|
347 | - * @since 14.0.0 |
|
348 | - */ |
|
349 | - public function getProtocol() { |
|
350 | - return $this->share['protocol']; |
|
351 | - } |
|
342 | + /** |
|
343 | + * get protocol specification |
|
344 | + * |
|
345 | + * @return array |
|
346 | + * |
|
347 | + * @since 14.0.0 |
|
348 | + */ |
|
349 | + public function getProtocol() { |
|
350 | + return $this->share['protocol']; |
|
351 | + } |
|
352 | 352 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | IClientService $httpClientService, |
72 | 72 | ICloudIdManager $cloudIdManager, |
73 | 73 | ILogger $logger) { |
74 | - $this->cloudFederationProvider= []; |
|
74 | + $this->cloudFederationProvider = []; |
|
75 | 75 | $this->appManager = $appManager; |
76 | 76 | $this->httpClientService = $httpClientService; |
77 | 77 | $this->cloudIdManager = $cloudIdManager; |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | |
141 | 141 | $client = $this->httpClientService->newClient(); |
142 | 142 | try { |
143 | - $response = $client->post($ocmEndPoint . '/shares', [ |
|
143 | + $response = $client->post($ocmEndPoint.'/shares', [ |
|
144 | 144 | 'body' => $share->getShare(), |
145 | 145 | 'timeout' => 10, |
146 | 146 | 'connect_timeout' => 10, |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | |
178 | 178 | $client = $this->httpClientService->newClient(); |
179 | 179 | try { |
180 | - $response = $client->post($ocmEndPoint . '/notifications', [ |
|
180 | + $response = $client->post($ocmEndPoint.'/notifications', [ |
|
181 | 181 | 'body' => $notification->getMessage(), |
182 | 182 | 'timeout' => 10, |
183 | 183 | 'connect_timeout' => 10, |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | } |
188 | 188 | } catch (\Exception $e) { |
189 | 189 | // log the error and return false |
190 | - $this->logger->error('error while sending notification for federated share: ' . $e->getMessage()); |
|
190 | + $this->logger->error('error while sending notification for federated share: '.$e->getMessage()); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | return false; |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | protected function getOCMEndPoint($url) { |
211 | 211 | $client = $this->httpClientService->newClient(); |
212 | 212 | try { |
213 | - $response = $client->get($url . '/ocm-provider/', ['timeout' => 10, 'connect_timeout' => 10]); |
|
213 | + $response = $client->get($url.'/ocm-provider/', ['timeout' => 10, 'connect_timeout' => 10]); |
|
214 | 214 | } catch (\Exception $e) { |
215 | 215 | return ''; |
216 | 216 | } |
@@ -42,190 +42,190 @@ |
||
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 $shareType which share 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($shareType, $displayName, callable $callback) { |
|
90 | - \OC::$server->getRemoteApiFactory(); |
|
91 | - |
|
92 | - $this->cloudFederationProvider[$shareType] = [ |
|
93 | - 'shareType' => $shareType, |
|
94 | - 'displayName' => $displayName, |
|
95 | - 'callback' => $callback, |
|
96 | - ]; |
|
97 | - |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * remove cloud federation provider |
|
102 | - * |
|
103 | - * @param string $providerId |
|
104 | - */ |
|
105 | - public function removeCloudFederationProvider($providerId) { |
|
106 | - unset($this->cloudFederationProvider[$providerId]); |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * get a list of all cloudFederationProviders |
|
111 | - * |
|
112 | - * @return array [id => ['id' => $id, 'displayName' => $displayName, 'callback' => callback]] |
|
113 | - */ |
|
114 | - public function getAllCloudFederationProviders() { |
|
115 | - return $this->cloudFederationProvider; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * get a specific cloud federation provider |
|
120 | - * |
|
121 | - * @param string $shareType |
|
122 | - * @return ICloudFederationProvider |
|
123 | - * @throws ProviderDoesNotExistsException |
|
124 | - */ |
|
125 | - public function getCloudFederationProvider($shareType) { |
|
126 | - if (isset($this->cloudFederationProvider[$shareType])) { |
|
127 | - return call_user_func($this->cloudFederationProvider[$shareType]['callback']); |
|
128 | - } else { |
|
129 | - throw new ProviderDoesNotExistsException($shareType); |
|
130 | - } |
|
131 | - } |
|
132 | - |
|
133 | - public function sendShare(ICloudFederationShare $share) { |
|
134 | - $cloudID = $this->cloudIdManager->resolveCloudId($share->getShareWith()); |
|
135 | - $ocmEndPoint = $this->getOCMEndPoint($cloudID->getRemote()); |
|
136 | - |
|
137 | - if (empty($ocmEndPoint)) { |
|
138 | - return false; |
|
139 | - } |
|
140 | - |
|
141 | - $client = $this->httpClientService->newClient(); |
|
142 | - try { |
|
143 | - $response = $client->post($ocmEndPoint . '/shares', [ |
|
144 | - 'body' => $share->getShare(), |
|
145 | - 'timeout' => 10, |
|
146 | - 'connect_timeout' => 10, |
|
147 | - ]); |
|
148 | - |
|
149 | - if ($response->getStatusCode() === Http::STATUS_CREATED) { |
|
150 | - return true; |
|
151 | - } |
|
152 | - |
|
153 | - } catch (\Exception $e) { |
|
154 | - // if flat re-sharing is not supported by the remote server |
|
155 | - // we re-throw the exception and fall back to the old behaviour. |
|
156 | - // (flat re-shares has been introduced in Nextcloud 9.1) |
|
157 | - if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) { |
|
158 | - throw $e; |
|
159 | - } |
|
160 | - } |
|
161 | - |
|
162 | - return false; |
|
163 | - |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * @param string $url |
|
168 | - * @param ICloudFederationNotification $notification |
|
169 | - * @return bool |
|
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_OK) { |
|
186 | - return true; |
|
187 | - } |
|
188 | - } catch (\Exception $e) { |
|
189 | - // log the error and return false |
|
190 | - $this->logger->error('error while sending notification for federated share: ' . $e->getMessage()); |
|
191 | - } |
|
192 | - |
|
193 | - return false; |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * check if the new cloud federation API is ready to be used |
|
198 | - * |
|
199 | - * @return bool |
|
200 | - */ |
|
201 | - public function isReady() { |
|
202 | - return $this->appManager->isEnabledForUser('cloud_federation_api', false); |
|
203 | - } |
|
204 | - /** |
|
205 | - * check if server supports the new OCM api and ask for the correct end-point |
|
206 | - * |
|
207 | - * @param string $url full base URL of the cloud server |
|
208 | - * @return string |
|
209 | - */ |
|
210 | - protected function getOCMEndPoint($url) { |
|
211 | - $client = $this->httpClientService->newClient(); |
|
212 | - try { |
|
213 | - $response = $client->get($url . '/ocm-provider/', ['timeout' => 10, 'connect_timeout' => 10]); |
|
214 | - } catch (\Exception $e) { |
|
215 | - return ''; |
|
216 | - } |
|
217 | - |
|
218 | - $result = $response->getBody(); |
|
219 | - $result = json_decode($result, true); |
|
220 | - |
|
221 | - $supportedVersion = isset($result['apiVersion']) && $result['apiVersion'] === $this->supportedAPIVersion; |
|
222 | - |
|
223 | - if (isset($result['endPoint']) && $supportedVersion) { |
|
224 | - return $result['endPoint']; |
|
225 | - } |
|
226 | - |
|
227 | - return ''; |
|
228 | - } |
|
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 $shareType which share 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($shareType, $displayName, callable $callback) { |
|
90 | + \OC::$server->getRemoteApiFactory(); |
|
91 | + |
|
92 | + $this->cloudFederationProvider[$shareType] = [ |
|
93 | + 'shareType' => $shareType, |
|
94 | + 'displayName' => $displayName, |
|
95 | + 'callback' => $callback, |
|
96 | + ]; |
|
97 | + |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * remove cloud federation provider |
|
102 | + * |
|
103 | + * @param string $providerId |
|
104 | + */ |
|
105 | + public function removeCloudFederationProvider($providerId) { |
|
106 | + unset($this->cloudFederationProvider[$providerId]); |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * get a list of all cloudFederationProviders |
|
111 | + * |
|
112 | + * @return array [id => ['id' => $id, 'displayName' => $displayName, 'callback' => callback]] |
|
113 | + */ |
|
114 | + public function getAllCloudFederationProviders() { |
|
115 | + return $this->cloudFederationProvider; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * get a specific cloud federation provider |
|
120 | + * |
|
121 | + * @param string $shareType |
|
122 | + * @return ICloudFederationProvider |
|
123 | + * @throws ProviderDoesNotExistsException |
|
124 | + */ |
|
125 | + public function getCloudFederationProvider($shareType) { |
|
126 | + if (isset($this->cloudFederationProvider[$shareType])) { |
|
127 | + return call_user_func($this->cloudFederationProvider[$shareType]['callback']); |
|
128 | + } else { |
|
129 | + throw new ProviderDoesNotExistsException($shareType); |
|
130 | + } |
|
131 | + } |
|
132 | + |
|
133 | + public function sendShare(ICloudFederationShare $share) { |
|
134 | + $cloudID = $this->cloudIdManager->resolveCloudId($share->getShareWith()); |
|
135 | + $ocmEndPoint = $this->getOCMEndPoint($cloudID->getRemote()); |
|
136 | + |
|
137 | + if (empty($ocmEndPoint)) { |
|
138 | + return false; |
|
139 | + } |
|
140 | + |
|
141 | + $client = $this->httpClientService->newClient(); |
|
142 | + try { |
|
143 | + $response = $client->post($ocmEndPoint . '/shares', [ |
|
144 | + 'body' => $share->getShare(), |
|
145 | + 'timeout' => 10, |
|
146 | + 'connect_timeout' => 10, |
|
147 | + ]); |
|
148 | + |
|
149 | + if ($response->getStatusCode() === Http::STATUS_CREATED) { |
|
150 | + return true; |
|
151 | + } |
|
152 | + |
|
153 | + } catch (\Exception $e) { |
|
154 | + // if flat re-sharing is not supported by the remote server |
|
155 | + // we re-throw the exception and fall back to the old behaviour. |
|
156 | + // (flat re-shares has been introduced in Nextcloud 9.1) |
|
157 | + if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) { |
|
158 | + throw $e; |
|
159 | + } |
|
160 | + } |
|
161 | + |
|
162 | + return false; |
|
163 | + |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * @param string $url |
|
168 | + * @param ICloudFederationNotification $notification |
|
169 | + * @return bool |
|
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_OK) { |
|
186 | + return true; |
|
187 | + } |
|
188 | + } catch (\Exception $e) { |
|
189 | + // log the error and return false |
|
190 | + $this->logger->error('error while sending notification for federated share: ' . $e->getMessage()); |
|
191 | + } |
|
192 | + |
|
193 | + return false; |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * check if the new cloud federation API is ready to be used |
|
198 | + * |
|
199 | + * @return bool |
|
200 | + */ |
|
201 | + public function isReady() { |
|
202 | + return $this->appManager->isEnabledForUser('cloud_federation_api', false); |
|
203 | + } |
|
204 | + /** |
|
205 | + * check if server supports the new OCM api and ask for the correct end-point |
|
206 | + * |
|
207 | + * @param string $url full base URL of the cloud server |
|
208 | + * @return string |
|
209 | + */ |
|
210 | + protected function getOCMEndPoint($url) { |
|
211 | + $client = $this->httpClientService->newClient(); |
|
212 | + try { |
|
213 | + $response = $client->get($url . '/ocm-provider/', ['timeout' => 10, 'connect_timeout' => 10]); |
|
214 | + } catch (\Exception $e) { |
|
215 | + return ''; |
|
216 | + } |
|
217 | + |
|
218 | + $result = $response->getBody(); |
|
219 | + $result = json_decode($result, true); |
|
220 | + |
|
221 | + $supportedVersion = isset($result['apiVersion']) && $result['apiVersion'] === $this->supportedAPIVersion; |
|
222 | + |
|
223 | + if (isset($result['endPoint']) && $supportedVersion) { |
|
224 | + return $result['endPoint']; |
|
225 | + } |
|
226 | + |
|
227 | + return ''; |
|
228 | + } |
|
229 | 229 | |
230 | 230 | |
231 | 231 | } |
@@ -25,36 +25,36 @@ |
||
25 | 25 | |
26 | 26 | class CloudFederationNotification implements ICloudFederationNotification { |
27 | 27 | |
28 | - private $message = []; |
|
28 | + private $message = []; |
|
29 | 29 | |
30 | - /** |
|
31 | - * add a message to the notification |
|
32 | - * |
|
33 | - * @param string $notificationType (e.g. SHARE_ACCEPTED) |
|
34 | - * @param string $resourceType (e.g. file, calendar, contact,...) |
|
35 | - * @param string $providerId id of the share |
|
36 | - * @param array $notification payload of the notification |
|
37 | - * |
|
38 | - * @since 14.0.0 |
|
39 | - */ |
|
40 | - public function setMessage($notificationType, $resourceType, $providerId, array $notification) { |
|
41 | - $this->message = [ |
|
42 | - 'notificationType' => $notificationType, |
|
43 | - 'resourceType' => $resourceType, |
|
44 | - 'providerId' => $providerId, |
|
45 | - 'notification' => $notification, |
|
46 | - ]; |
|
30 | + /** |
|
31 | + * add a message to the notification |
|
32 | + * |
|
33 | + * @param string $notificationType (e.g. SHARE_ACCEPTED) |
|
34 | + * @param string $resourceType (e.g. file, calendar, contact,...) |
|
35 | + * @param string $providerId id of the share |
|
36 | + * @param array $notification payload of the notification |
|
37 | + * |
|
38 | + * @since 14.0.0 |
|
39 | + */ |
|
40 | + public function setMessage($notificationType, $resourceType, $providerId, array $notification) { |
|
41 | + $this->message = [ |
|
42 | + 'notificationType' => $notificationType, |
|
43 | + 'resourceType' => $resourceType, |
|
44 | + 'providerId' => $providerId, |
|
45 | + 'notification' => $notification, |
|
46 | + ]; |
|
47 | 47 | |
48 | - } |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * get message, ready to send out |
|
52 | - * |
|
53 | - * @return array |
|
54 | - * |
|
55 | - * @since 14.0.0 |
|
56 | - */ |
|
57 | - public function getMessage() { |
|
58 | - return $this->message; |
|
59 | - } |
|
50 | + /** |
|
51 | + * get message, ready to send out |
|
52 | + * |
|
53 | + * @return array |
|
54 | + * |
|
55 | + * @since 14.0.0 |
|
56 | + */ |
|
57 | + public function getMessage() { |
|
58 | + return $this->message; |
|
59 | + } |
|
60 | 60 | } |
@@ -27,37 +27,37 @@ |
||
27 | 27 | |
28 | 28 | class CloudFederationFactory implements ICloudFederationFactory { |
29 | 29 | |
30 | - /** |
|
31 | - * get a CloudFederationShare Object to prepare a share you want to send |
|
32 | - * |
|
33 | - * @param string $shareWith |
|
34 | - * @param string $name resource name (e.g. document.odt) |
|
35 | - * @param string $description share description (optional) |
|
36 | - * @param string $providerId resource UID on the provider side |
|
37 | - * @param string $owner provider specific UID of the user who owns the resource |
|
38 | - * @param string $ownerDisplayName display name of the user who shared the item |
|
39 | - * @param string $sharedBy provider specific UID of the user who shared the resource |
|
40 | - * @param string $sharedByDisplayName display name of the user who shared the resource |
|
41 | - * @param string $sharedSecret used to authenticate requests across servers |
|
42 | - * @param string $shareType ('group' or 'user' share) |
|
43 | - * @param $resourceType ('file', 'calendar',...) |
|
44 | - * @return ICloudFederationShare |
|
45 | - * |
|
46 | - * @since 14.0.0 |
|
47 | - */ |
|
48 | - public function getCloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $sharedSecret, $shareType, $resourceType) { |
|
49 | - return new CloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $shareType, $resourceType, $sharedSecret); |
|
50 | - } |
|
30 | + /** |
|
31 | + * get a CloudFederationShare Object to prepare a share you want to send |
|
32 | + * |
|
33 | + * @param string $shareWith |
|
34 | + * @param string $name resource name (e.g. document.odt) |
|
35 | + * @param string $description share description (optional) |
|
36 | + * @param string $providerId resource UID on the provider side |
|
37 | + * @param string $owner provider specific UID of the user who owns the resource |
|
38 | + * @param string $ownerDisplayName display name of the user who shared the item |
|
39 | + * @param string $sharedBy provider specific UID of the user who shared the resource |
|
40 | + * @param string $sharedByDisplayName display name of the user who shared the resource |
|
41 | + * @param string $sharedSecret used to authenticate requests across servers |
|
42 | + * @param string $shareType ('group' or 'user' share) |
|
43 | + * @param $resourceType ('file', 'calendar',...) |
|
44 | + * @return ICloudFederationShare |
|
45 | + * |
|
46 | + * @since 14.0.0 |
|
47 | + */ |
|
48 | + public function getCloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $sharedSecret, $shareType, $resourceType) { |
|
49 | + return new CloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $shareType, $resourceType, $sharedSecret); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * get a Cloud FederationNotification object to prepare a notification you |
|
54 | - * want to send |
|
55 | - * |
|
56 | - * @return ICloudFederationNotification |
|
57 | - * |
|
58 | - * @since 14.0.0 |
|
59 | - */ |
|
60 | - public function getCloudFederationNotification() { |
|
61 | - return new CloudFederationNotification(); |
|
62 | - } |
|
52 | + /** |
|
53 | + * get a Cloud FederationNotification object to prepare a notification you |
|
54 | + * want to send |
|
55 | + * |
|
56 | + * @return ICloudFederationNotification |
|
57 | + * |
|
58 | + * @since 14.0.0 |
|
59 | + */ |
|
60 | + public function getCloudFederationNotification() { |
|
61 | + return new CloudFederationNotification(); |
|
62 | + } |
|
63 | 63 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | * share received from another server |
123 | 123 | * |
124 | 124 | * @param ICloudFederationShare $share |
125 | - * @return string provider specific unique ID of the share |
|
125 | + * @return integer provider specific unique ID of the share |
|
126 | 126 | * |
127 | 127 | * @throws ProviderCouldNotAddShareException |
128 | 128 | * @throws \OCP\AppFramework\QueryException |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | } |
266 | 266 | |
267 | 267 | /** |
268 | - * @param $id |
|
268 | + * @param string $id |
|
269 | 269 | * @param $notification |
270 | 270 | * @return bool |
271 | 271 | * @throws ActionNotSupportedException |
@@ -27,7 +27,6 @@ discard block |
||
27 | 27 | use OCA\FederatedFileSharing\AddressHandler; |
28 | 28 | use OCA\FederatedFileSharing\FederatedShareProvider; |
29 | 29 | use OCP\Activity\IManager as IActivityManager; |
30 | -use OCP\Activity\IManager; |
|
31 | 30 | use OCP\App\IAppManager; |
32 | 31 | use OCP\Federation\Exceptions\ActionNotSupportedException; |
33 | 32 | use OCP\Federation\Exceptions\AuthenticationFailedException; |
@@ -42,7 +41,6 @@ discard block |
||
42 | 41 | use OCP\IURLGenerator; |
43 | 42 | use OCP\IUserManager; |
44 | 43 | use OCP\Notification\IManager as INotificationManager; |
45 | -use OCP\Share\Exceptions\ShareNotFound; |
|
46 | 44 | use OCP\Share\IShare; |
47 | 45 | use OCP\Util; |
48 | 46 |
@@ -48,357 +48,357 @@ |
||
48 | 48 | |
49 | 49 | class CloudFederationProviderFiles implements ICloudFederationProvider { |
50 | 50 | |
51 | - /** @var IAppManager */ |
|
52 | - private $appManager; |
|
53 | - |
|
54 | - /** @var FederatedShareProvider */ |
|
55 | - private $federatedShareProvider; |
|
56 | - |
|
57 | - /** @var AddressHandler */ |
|
58 | - private $addressHandler; |
|
59 | - |
|
60 | - /** @var ILogger */ |
|
61 | - private $logger; |
|
62 | - |
|
63 | - /** @var IUserManager */ |
|
64 | - private $userManager; |
|
65 | - |
|
66 | - /** @var ICloudIdManager */ |
|
67 | - private $cloudIdManager; |
|
68 | - |
|
69 | - /** @var IActivityManager */ |
|
70 | - private $activityManager; |
|
71 | - |
|
72 | - /** @var INotificationManager */ |
|
73 | - private $notificationManager; |
|
74 | - |
|
75 | - /** @var IURLGenerator */ |
|
76 | - private $urlGenerator; |
|
77 | - |
|
78 | - /** |
|
79 | - * CloudFederationProvider constructor. |
|
80 | - * |
|
81 | - * @param IAppManager $appManager |
|
82 | - * @param FederatedShareProvider $federatedShareProvider |
|
83 | - * @param AddressHandler $addressHandler |
|
84 | - * @param ILogger $logger |
|
85 | - * @param IUserManager $userManager |
|
86 | - * @param ICloudIdManager $cloudIdManager |
|
87 | - * @param IActivityManager $activityManager |
|
88 | - * @param INotificationManager $notificationManager |
|
89 | - * @param IURLGenerator $urlGenerator |
|
90 | - */ |
|
91 | - public function __construct(IAppManager $appManager, |
|
92 | - FederatedShareProvider $federatedShareProvider, |
|
93 | - AddressHandler $addressHandler, |
|
94 | - ILogger $logger, |
|
95 | - IUserManager $userManager, |
|
96 | - ICloudIdManager $cloudIdManager, |
|
97 | - IActivityManager $activityManager, |
|
98 | - INotificationManager $notificationManager, |
|
99 | - IURLGenerator $urlGenerator |
|
100 | - ) { |
|
101 | - $this->appManager = $appManager; |
|
102 | - $this->federatedShareProvider = $federatedShareProvider; |
|
103 | - $this->addressHandler = $addressHandler; |
|
104 | - $this->logger = $logger; |
|
105 | - $this->userManager = $userManager; |
|
106 | - $this->cloudIdManager = $cloudIdManager; |
|
107 | - $this->activityManager = $activityManager; |
|
108 | - $this->notificationManager = $notificationManager; |
|
109 | - $this->urlGenerator = $urlGenerator; |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * @return string |
|
116 | - */ |
|
117 | - public function getShareType() { |
|
118 | - return 'file'; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * share received from another server |
|
123 | - * |
|
124 | - * @param ICloudFederationShare $share |
|
125 | - * @return string provider specific unique ID of the share |
|
126 | - * |
|
127 | - * @throws ProviderCouldNotAddShareException |
|
128 | - * @throws \OCP\AppFramework\QueryException |
|
129 | - * @throws \OC\HintException |
|
130 | - * @since 14.0.0 |
|
131 | - */ |
|
132 | - public function shareReceived(ICloudFederationShare $share) { |
|
133 | - |
|
134 | - if (!$this->isS2SEnabled(true)) { |
|
135 | - throw new ProviderCouldNotAddShareException('Server does not support federated cloud sharing', '', Http::STATUS_SERVICE_UNAVAILABLE); |
|
136 | - } |
|
137 | - |
|
138 | - $protocol = $share->getProtocol(); |
|
139 | - if ($protocol['name'] !== 'webdav') { |
|
140 | - throw new ProviderCouldNotAddShareException('Unsupported protocol for data exchange.', '', Http::STATUS_NOT_IMPLEMENTED); |
|
141 | - } |
|
142 | - |
|
143 | - list($ownerUid, $remote) = $this->addressHandler->splitUserRemote($share->getOwner()); |
|
144 | - |
|
145 | - $remote = $remote; |
|
146 | - $token = $share->getShareSecret(); |
|
147 | - $name = $share->getResourceName(); |
|
148 | - $owner = $share->getOwnerDisplayName(); |
|
149 | - $sharedBy = $share->getSharedByDisplayName(); |
|
150 | - $shareWith = $share->getShareWith(); |
|
151 | - $remoteId = $share->getProviderId(); |
|
152 | - $sharedByFederatedId = $share->getSharedBy(); |
|
153 | - $ownerFederatedId = $share->getOwner(); |
|
154 | - |
|
155 | - // if no explicit information about the person who created the share was send |
|
156 | - // we assume that the share comes from the owner |
|
157 | - if ($sharedByFederatedId === null) { |
|
158 | - $sharedBy = $owner; |
|
159 | - $sharedByFederatedId = $ownerFederatedId; |
|
160 | - } |
|
161 | - |
|
162 | - if ($remote && $token && $name && $owner && $remoteId && $shareWith) { |
|
163 | - |
|
164 | - if (!Util::isValidFileName($name)) { |
|
165 | - throw new ProviderCouldNotAddShareException('The mountpoint name contains invalid characters.', '', Http::STATUS_BAD_REQUEST); |
|
166 | - } |
|
167 | - |
|
168 | - // FIXME this should be a method in the user management instead |
|
169 | - $this->logger->debug('shareWith before, ' . $shareWith, ['app' => 'files_sharing']); |
|
170 | - Util::emitHook( |
|
171 | - '\OCA\Files_Sharing\API\Server2Server', |
|
172 | - 'preLoginNameUsedAsUserName', |
|
173 | - array('uid' => &$shareWith) |
|
174 | - ); |
|
175 | - $this->logger->debug('shareWith after, ' . $shareWith, ['app' => 'files_sharing']); |
|
176 | - |
|
177 | - if (!$this->userManager->userExists($shareWith)) { |
|
178 | - throw new ProviderCouldNotAddShareException('User does not exists', '',Http::STATUS_BAD_REQUEST); |
|
179 | - } |
|
180 | - |
|
181 | - \OC_Util::setupFS($shareWith); |
|
182 | - |
|
183 | - $externalManager = new \OCA\Files_Sharing\External\Manager( |
|
184 | - \OC::$server->getDatabaseConnection(), |
|
185 | - Filesystem::getMountManager(), |
|
186 | - Filesystem::getLoader(), |
|
187 | - \OC::$server->getHTTPClientService(), |
|
188 | - \OC::$server->getNotificationManager(), |
|
189 | - \OC::$server->query(\OCP\OCS\IDiscoveryService::class), |
|
190 | - \OC::$server->getCloudFederationProviderManager(), |
|
191 | - \OC::$server->getCloudFederationFactory(), |
|
192 | - $shareWith |
|
193 | - ); |
|
194 | - |
|
195 | - try { |
|
196 | - $externalManager->addShare($remote, $token, '', $name, $owner, false, $shareWith, $remoteId); |
|
197 | - $shareId = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share_external'); |
|
198 | - |
|
199 | - $event = $this->activityManager->generateEvent(); |
|
200 | - $event->setApp('files_sharing') |
|
201 | - ->setType('remote_share') |
|
202 | - ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')]) |
|
203 | - ->setAffectedUser($shareWith) |
|
204 | - ->setObject('remote_share', (int)$shareId, $name); |
|
205 | - \OC::$server->getActivityManager()->publish($event); |
|
206 | - |
|
207 | - $notification = $this->notificationManager->createNotification(); |
|
208 | - $notification->setApp('files_sharing') |
|
209 | - ->setUser($shareWith) |
|
210 | - ->setDateTime(new \DateTime()) |
|
211 | - ->setObject('remote_share', $shareId) |
|
212 | - ->setSubject('remote_share', [$ownerFederatedId, $sharedByFederatedId, trim($name, '/')]); |
|
213 | - |
|
214 | - $declineAction = $notification->createAction(); |
|
215 | - $declineAction->setLabel('decline') |
|
216 | - ->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'DELETE'); |
|
217 | - $notification->addAction($declineAction); |
|
218 | - |
|
219 | - $acceptAction = $notification->createAction(); |
|
220 | - $acceptAction->setLabel('accept') |
|
221 | - ->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'POST'); |
|
222 | - $notification->addAction($acceptAction); |
|
223 | - |
|
224 | - $this->notificationManager->notify($notification); |
|
225 | - |
|
226 | - return $shareId; |
|
227 | - } catch (\Exception $e) { |
|
228 | - $this->logger->logException($e, [ |
|
229 | - 'message' => 'Server can not add remote share.', |
|
230 | - 'level' => Util::ERROR, |
|
231 | - 'app' => 'files_sharing' |
|
232 | - ]); |
|
233 | - throw new ProviderCouldNotAddShareException('internal server error, was not able to add share from ' . $remote, '', HTTP::STATUS_INTERNAL_SERVER_ERROR); |
|
234 | - } |
|
235 | - } |
|
236 | - |
|
237 | - throw new ProviderCouldNotAddShareException('server can not add remote share, missing parameter', '', HTTP::STATUS_BAD_REQUEST); |
|
238 | - |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * notification received from another server |
|
243 | - * |
|
244 | - * @param string $notificationType (e.g. SHARE_ACCEPTED) |
|
245 | - * @param string $providerId id of the share |
|
246 | - * @param array $notification payload of the notification |
|
247 | - * |
|
248 | - * @throws ActionNotSupportedException |
|
249 | - * @throws AuthenticationFailedException |
|
250 | - * @throws BadRequestException |
|
251 | - * @throws ShareNotFoundException |
|
252 | - * @throws \OC\HintException |
|
253 | - * @since 14.0.0 |
|
254 | - */ |
|
255 | - public function notificationReceived($notificationType, $providerId, array $notification) { |
|
256 | - |
|
257 | - switch ($notificationType) { |
|
258 | - case 'SHARE_ACCEPTED': |
|
259 | - $this->shareAccepted($providerId, $notification); |
|
260 | - return; |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - throw new ActionNotSupportedException($notification); |
|
265 | - } |
|
266 | - |
|
267 | - /** |
|
268 | - * @param $id |
|
269 | - * @param $notification |
|
270 | - * @return bool |
|
271 | - * @throws ActionNotSupportedException |
|
272 | - * @throws AuthenticationFailedException |
|
273 | - * @throws BadRequestException |
|
274 | - * @throws ShareNotFoundException |
|
275 | - * @throws \OC\HintException |
|
276 | - */ |
|
277 | - private function shareAccepted($id, $notification) { |
|
278 | - |
|
279 | - if (!$this->isS2SEnabled(true)) { |
|
280 | - throw new ActionNotSupportedException('Server does not support federated cloud sharing', '', Http::STATUS_SERVICE_UNAVAILABLE); |
|
281 | - } |
|
282 | - |
|
283 | - if (!isset($notification['sharedSecret'])) { |
|
284 | - throw new BadRequestException(['sharedSecret']); |
|
285 | - } |
|
286 | - |
|
287 | - $token = $notification['sharedSecret']; |
|
288 | - |
|
289 | - $share = $this->federatedShareProvider->getShareById($id); |
|
290 | - |
|
291 | - $this->verifyShare($share, $token); |
|
292 | - $this->executeAcceptShare($share); |
|
293 | - if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
294 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
295 | - $remoteId = $this->federatedShareProvider->getRemoteId($share); |
|
296 | - $this->notifications->sendAcceptShare($remote, $remoteId, $share->getToken()); |
|
297 | - } |
|
298 | - |
|
299 | - return true; |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - /** |
|
304 | - * @param IShare $share |
|
305 | - * @throws ShareNotFoundException |
|
306 | - */ |
|
307 | - protected function executeAcceptShare(IShare $share) { |
|
308 | - try { |
|
309 | - $fileId = (int)$share->getNode()->getId(); |
|
310 | - list($file, $link) = $this->getFile($this->getCorrectUid($share), $fileId); |
|
311 | - } catch (\Exception $e) { |
|
312 | - throw new ShareNotFoundException(); |
|
313 | - } |
|
314 | - |
|
315 | - $event = $this->activityManager->generateEvent(); |
|
316 | - $event->setApp('files_sharing') |
|
317 | - ->setType('remote_share') |
|
318 | - ->setAffectedUser($this->getCorrectUid($share)) |
|
319 | - ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_ACCEPTED, [$share->getSharedWith(), [$fileId => $file]]) |
|
320 | - ->setObject('files', $fileId, $file) |
|
321 | - ->setLink($link); |
|
322 | - $this->activityManager->publish($event); |
|
323 | - } |
|
324 | - |
|
325 | - /** |
|
326 | - * get file |
|
327 | - * |
|
328 | - * @param string $user |
|
329 | - * @param int $fileSource |
|
330 | - * @return array with internal path of the file and a absolute link to it |
|
331 | - */ |
|
332 | - private function getFile($user, $fileSource) { |
|
333 | - \OC_Util::setupFS($user); |
|
334 | - |
|
335 | - try { |
|
336 | - $file = Filesystem::getPath($fileSource); |
|
337 | - } catch (NotFoundException $e) { |
|
338 | - $file = null; |
|
339 | - } |
|
340 | - $args = Filesystem::is_dir($file) ? array('dir' => $file) : array('dir' => dirname($file), 'scrollto' => $file); |
|
341 | - $link = Util::linkToAbsolute('files', 'index.php', $args); |
|
342 | - |
|
343 | - return array($file, $link); |
|
344 | - |
|
345 | - } |
|
346 | - |
|
347 | - /** |
|
348 | - * check if we are the initiator or the owner of a re-share and return the correct UID |
|
349 | - * |
|
350 | - * @param IShare $share |
|
351 | - * @return string |
|
352 | - */ |
|
353 | - protected function getCorrectUid(IShare $share) { |
|
354 | - if ($this->userManager->userExists($share->getShareOwner())) { |
|
355 | - return $share->getShareOwner(); |
|
356 | - } |
|
357 | - |
|
358 | - return $share->getSharedBy(); |
|
359 | - } |
|
360 | - |
|
361 | - |
|
362 | - |
|
363 | - /** |
|
364 | - * check if we got the right share |
|
365 | - * |
|
366 | - * @param IShare $share |
|
367 | - * @param string $token |
|
368 | - * @return bool |
|
369 | - * @throws AuthenticationFailedException |
|
370 | - */ |
|
371 | - protected function verifyShare(IShare $share, $token) { |
|
372 | - if ( |
|
373 | - $share->getShareType() === FederatedShareProvider::SHARE_TYPE_REMOTE && |
|
374 | - $share->getToken() === $token |
|
375 | - ) { |
|
376 | - return true; |
|
377 | - } |
|
378 | - |
|
379 | - throw new AuthenticationFailedException(); |
|
380 | - } |
|
381 | - |
|
382 | - |
|
383 | - |
|
384 | - /** |
|
385 | - * check if server-to-server sharing is enabled |
|
386 | - * |
|
387 | - * @param bool $incoming |
|
388 | - * @return bool |
|
389 | - */ |
|
390 | - private function isS2SEnabled($incoming = false) { |
|
391 | - |
|
392 | - $result = $this->appManager->isEnabledForUser('files_sharing'); |
|
393 | - |
|
394 | - if ($incoming) { |
|
395 | - $result = $result && $this->federatedShareProvider->isIncomingServer2serverShareEnabled(); |
|
396 | - } else { |
|
397 | - $result = $result && $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); |
|
398 | - } |
|
399 | - |
|
400 | - return $result; |
|
401 | - } |
|
51 | + /** @var IAppManager */ |
|
52 | + private $appManager; |
|
53 | + |
|
54 | + /** @var FederatedShareProvider */ |
|
55 | + private $federatedShareProvider; |
|
56 | + |
|
57 | + /** @var AddressHandler */ |
|
58 | + private $addressHandler; |
|
59 | + |
|
60 | + /** @var ILogger */ |
|
61 | + private $logger; |
|
62 | + |
|
63 | + /** @var IUserManager */ |
|
64 | + private $userManager; |
|
65 | + |
|
66 | + /** @var ICloudIdManager */ |
|
67 | + private $cloudIdManager; |
|
68 | + |
|
69 | + /** @var IActivityManager */ |
|
70 | + private $activityManager; |
|
71 | + |
|
72 | + /** @var INotificationManager */ |
|
73 | + private $notificationManager; |
|
74 | + |
|
75 | + /** @var IURLGenerator */ |
|
76 | + private $urlGenerator; |
|
77 | + |
|
78 | + /** |
|
79 | + * CloudFederationProvider constructor. |
|
80 | + * |
|
81 | + * @param IAppManager $appManager |
|
82 | + * @param FederatedShareProvider $federatedShareProvider |
|
83 | + * @param AddressHandler $addressHandler |
|
84 | + * @param ILogger $logger |
|
85 | + * @param IUserManager $userManager |
|
86 | + * @param ICloudIdManager $cloudIdManager |
|
87 | + * @param IActivityManager $activityManager |
|
88 | + * @param INotificationManager $notificationManager |
|
89 | + * @param IURLGenerator $urlGenerator |
|
90 | + */ |
|
91 | + public function __construct(IAppManager $appManager, |
|
92 | + FederatedShareProvider $federatedShareProvider, |
|
93 | + AddressHandler $addressHandler, |
|
94 | + ILogger $logger, |
|
95 | + IUserManager $userManager, |
|
96 | + ICloudIdManager $cloudIdManager, |
|
97 | + IActivityManager $activityManager, |
|
98 | + INotificationManager $notificationManager, |
|
99 | + IURLGenerator $urlGenerator |
|
100 | + ) { |
|
101 | + $this->appManager = $appManager; |
|
102 | + $this->federatedShareProvider = $federatedShareProvider; |
|
103 | + $this->addressHandler = $addressHandler; |
|
104 | + $this->logger = $logger; |
|
105 | + $this->userManager = $userManager; |
|
106 | + $this->cloudIdManager = $cloudIdManager; |
|
107 | + $this->activityManager = $activityManager; |
|
108 | + $this->notificationManager = $notificationManager; |
|
109 | + $this->urlGenerator = $urlGenerator; |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * @return string |
|
116 | + */ |
|
117 | + public function getShareType() { |
|
118 | + return 'file'; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * share received from another server |
|
123 | + * |
|
124 | + * @param ICloudFederationShare $share |
|
125 | + * @return string provider specific unique ID of the share |
|
126 | + * |
|
127 | + * @throws ProviderCouldNotAddShareException |
|
128 | + * @throws \OCP\AppFramework\QueryException |
|
129 | + * @throws \OC\HintException |
|
130 | + * @since 14.0.0 |
|
131 | + */ |
|
132 | + public function shareReceived(ICloudFederationShare $share) { |
|
133 | + |
|
134 | + if (!$this->isS2SEnabled(true)) { |
|
135 | + throw new ProviderCouldNotAddShareException('Server does not support federated cloud sharing', '', Http::STATUS_SERVICE_UNAVAILABLE); |
|
136 | + } |
|
137 | + |
|
138 | + $protocol = $share->getProtocol(); |
|
139 | + if ($protocol['name'] !== 'webdav') { |
|
140 | + throw new ProviderCouldNotAddShareException('Unsupported protocol for data exchange.', '', Http::STATUS_NOT_IMPLEMENTED); |
|
141 | + } |
|
142 | + |
|
143 | + list($ownerUid, $remote) = $this->addressHandler->splitUserRemote($share->getOwner()); |
|
144 | + |
|
145 | + $remote = $remote; |
|
146 | + $token = $share->getShareSecret(); |
|
147 | + $name = $share->getResourceName(); |
|
148 | + $owner = $share->getOwnerDisplayName(); |
|
149 | + $sharedBy = $share->getSharedByDisplayName(); |
|
150 | + $shareWith = $share->getShareWith(); |
|
151 | + $remoteId = $share->getProviderId(); |
|
152 | + $sharedByFederatedId = $share->getSharedBy(); |
|
153 | + $ownerFederatedId = $share->getOwner(); |
|
154 | + |
|
155 | + // if no explicit information about the person who created the share was send |
|
156 | + // we assume that the share comes from the owner |
|
157 | + if ($sharedByFederatedId === null) { |
|
158 | + $sharedBy = $owner; |
|
159 | + $sharedByFederatedId = $ownerFederatedId; |
|
160 | + } |
|
161 | + |
|
162 | + if ($remote && $token && $name && $owner && $remoteId && $shareWith) { |
|
163 | + |
|
164 | + if (!Util::isValidFileName($name)) { |
|
165 | + throw new ProviderCouldNotAddShareException('The mountpoint name contains invalid characters.', '', Http::STATUS_BAD_REQUEST); |
|
166 | + } |
|
167 | + |
|
168 | + // FIXME this should be a method in the user management instead |
|
169 | + $this->logger->debug('shareWith before, ' . $shareWith, ['app' => 'files_sharing']); |
|
170 | + Util::emitHook( |
|
171 | + '\OCA\Files_Sharing\API\Server2Server', |
|
172 | + 'preLoginNameUsedAsUserName', |
|
173 | + array('uid' => &$shareWith) |
|
174 | + ); |
|
175 | + $this->logger->debug('shareWith after, ' . $shareWith, ['app' => 'files_sharing']); |
|
176 | + |
|
177 | + if (!$this->userManager->userExists($shareWith)) { |
|
178 | + throw new ProviderCouldNotAddShareException('User does not exists', '',Http::STATUS_BAD_REQUEST); |
|
179 | + } |
|
180 | + |
|
181 | + \OC_Util::setupFS($shareWith); |
|
182 | + |
|
183 | + $externalManager = new \OCA\Files_Sharing\External\Manager( |
|
184 | + \OC::$server->getDatabaseConnection(), |
|
185 | + Filesystem::getMountManager(), |
|
186 | + Filesystem::getLoader(), |
|
187 | + \OC::$server->getHTTPClientService(), |
|
188 | + \OC::$server->getNotificationManager(), |
|
189 | + \OC::$server->query(\OCP\OCS\IDiscoveryService::class), |
|
190 | + \OC::$server->getCloudFederationProviderManager(), |
|
191 | + \OC::$server->getCloudFederationFactory(), |
|
192 | + $shareWith |
|
193 | + ); |
|
194 | + |
|
195 | + try { |
|
196 | + $externalManager->addShare($remote, $token, '', $name, $owner, false, $shareWith, $remoteId); |
|
197 | + $shareId = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share_external'); |
|
198 | + |
|
199 | + $event = $this->activityManager->generateEvent(); |
|
200 | + $event->setApp('files_sharing') |
|
201 | + ->setType('remote_share') |
|
202 | + ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')]) |
|
203 | + ->setAffectedUser($shareWith) |
|
204 | + ->setObject('remote_share', (int)$shareId, $name); |
|
205 | + \OC::$server->getActivityManager()->publish($event); |
|
206 | + |
|
207 | + $notification = $this->notificationManager->createNotification(); |
|
208 | + $notification->setApp('files_sharing') |
|
209 | + ->setUser($shareWith) |
|
210 | + ->setDateTime(new \DateTime()) |
|
211 | + ->setObject('remote_share', $shareId) |
|
212 | + ->setSubject('remote_share', [$ownerFederatedId, $sharedByFederatedId, trim($name, '/')]); |
|
213 | + |
|
214 | + $declineAction = $notification->createAction(); |
|
215 | + $declineAction->setLabel('decline') |
|
216 | + ->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'DELETE'); |
|
217 | + $notification->addAction($declineAction); |
|
218 | + |
|
219 | + $acceptAction = $notification->createAction(); |
|
220 | + $acceptAction->setLabel('accept') |
|
221 | + ->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'POST'); |
|
222 | + $notification->addAction($acceptAction); |
|
223 | + |
|
224 | + $this->notificationManager->notify($notification); |
|
225 | + |
|
226 | + return $shareId; |
|
227 | + } catch (\Exception $e) { |
|
228 | + $this->logger->logException($e, [ |
|
229 | + 'message' => 'Server can not add remote share.', |
|
230 | + 'level' => Util::ERROR, |
|
231 | + 'app' => 'files_sharing' |
|
232 | + ]); |
|
233 | + throw new ProviderCouldNotAddShareException('internal server error, was not able to add share from ' . $remote, '', HTTP::STATUS_INTERNAL_SERVER_ERROR); |
|
234 | + } |
|
235 | + } |
|
236 | + |
|
237 | + throw new ProviderCouldNotAddShareException('server can not add remote share, missing parameter', '', HTTP::STATUS_BAD_REQUEST); |
|
238 | + |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * notification received from another server |
|
243 | + * |
|
244 | + * @param string $notificationType (e.g. SHARE_ACCEPTED) |
|
245 | + * @param string $providerId id of the share |
|
246 | + * @param array $notification payload of the notification |
|
247 | + * |
|
248 | + * @throws ActionNotSupportedException |
|
249 | + * @throws AuthenticationFailedException |
|
250 | + * @throws BadRequestException |
|
251 | + * @throws ShareNotFoundException |
|
252 | + * @throws \OC\HintException |
|
253 | + * @since 14.0.0 |
|
254 | + */ |
|
255 | + public function notificationReceived($notificationType, $providerId, array $notification) { |
|
256 | + |
|
257 | + switch ($notificationType) { |
|
258 | + case 'SHARE_ACCEPTED': |
|
259 | + $this->shareAccepted($providerId, $notification); |
|
260 | + return; |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + throw new ActionNotSupportedException($notification); |
|
265 | + } |
|
266 | + |
|
267 | + /** |
|
268 | + * @param $id |
|
269 | + * @param $notification |
|
270 | + * @return bool |
|
271 | + * @throws ActionNotSupportedException |
|
272 | + * @throws AuthenticationFailedException |
|
273 | + * @throws BadRequestException |
|
274 | + * @throws ShareNotFoundException |
|
275 | + * @throws \OC\HintException |
|
276 | + */ |
|
277 | + private function shareAccepted($id, $notification) { |
|
278 | + |
|
279 | + if (!$this->isS2SEnabled(true)) { |
|
280 | + throw new ActionNotSupportedException('Server does not support federated cloud sharing', '', Http::STATUS_SERVICE_UNAVAILABLE); |
|
281 | + } |
|
282 | + |
|
283 | + if (!isset($notification['sharedSecret'])) { |
|
284 | + throw new BadRequestException(['sharedSecret']); |
|
285 | + } |
|
286 | + |
|
287 | + $token = $notification['sharedSecret']; |
|
288 | + |
|
289 | + $share = $this->federatedShareProvider->getShareById($id); |
|
290 | + |
|
291 | + $this->verifyShare($share, $token); |
|
292 | + $this->executeAcceptShare($share); |
|
293 | + if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
294 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
295 | + $remoteId = $this->federatedShareProvider->getRemoteId($share); |
|
296 | + $this->notifications->sendAcceptShare($remote, $remoteId, $share->getToken()); |
|
297 | + } |
|
298 | + |
|
299 | + return true; |
|
300 | + } |
|
301 | + |
|
302 | + |
|
303 | + /** |
|
304 | + * @param IShare $share |
|
305 | + * @throws ShareNotFoundException |
|
306 | + */ |
|
307 | + protected function executeAcceptShare(IShare $share) { |
|
308 | + try { |
|
309 | + $fileId = (int)$share->getNode()->getId(); |
|
310 | + list($file, $link) = $this->getFile($this->getCorrectUid($share), $fileId); |
|
311 | + } catch (\Exception $e) { |
|
312 | + throw new ShareNotFoundException(); |
|
313 | + } |
|
314 | + |
|
315 | + $event = $this->activityManager->generateEvent(); |
|
316 | + $event->setApp('files_sharing') |
|
317 | + ->setType('remote_share') |
|
318 | + ->setAffectedUser($this->getCorrectUid($share)) |
|
319 | + ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_ACCEPTED, [$share->getSharedWith(), [$fileId => $file]]) |
|
320 | + ->setObject('files', $fileId, $file) |
|
321 | + ->setLink($link); |
|
322 | + $this->activityManager->publish($event); |
|
323 | + } |
|
324 | + |
|
325 | + /** |
|
326 | + * get file |
|
327 | + * |
|
328 | + * @param string $user |
|
329 | + * @param int $fileSource |
|
330 | + * @return array with internal path of the file and a absolute link to it |
|
331 | + */ |
|
332 | + private function getFile($user, $fileSource) { |
|
333 | + \OC_Util::setupFS($user); |
|
334 | + |
|
335 | + try { |
|
336 | + $file = Filesystem::getPath($fileSource); |
|
337 | + } catch (NotFoundException $e) { |
|
338 | + $file = null; |
|
339 | + } |
|
340 | + $args = Filesystem::is_dir($file) ? array('dir' => $file) : array('dir' => dirname($file), 'scrollto' => $file); |
|
341 | + $link = Util::linkToAbsolute('files', 'index.php', $args); |
|
342 | + |
|
343 | + return array($file, $link); |
|
344 | + |
|
345 | + } |
|
346 | + |
|
347 | + /** |
|
348 | + * check if we are the initiator or the owner of a re-share and return the correct UID |
|
349 | + * |
|
350 | + * @param IShare $share |
|
351 | + * @return string |
|
352 | + */ |
|
353 | + protected function getCorrectUid(IShare $share) { |
|
354 | + if ($this->userManager->userExists($share->getShareOwner())) { |
|
355 | + return $share->getShareOwner(); |
|
356 | + } |
|
357 | + |
|
358 | + return $share->getSharedBy(); |
|
359 | + } |
|
360 | + |
|
361 | + |
|
362 | + |
|
363 | + /** |
|
364 | + * check if we got the right share |
|
365 | + * |
|
366 | + * @param IShare $share |
|
367 | + * @param string $token |
|
368 | + * @return bool |
|
369 | + * @throws AuthenticationFailedException |
|
370 | + */ |
|
371 | + protected function verifyShare(IShare $share, $token) { |
|
372 | + if ( |
|
373 | + $share->getShareType() === FederatedShareProvider::SHARE_TYPE_REMOTE && |
|
374 | + $share->getToken() === $token |
|
375 | + ) { |
|
376 | + return true; |
|
377 | + } |
|
378 | + |
|
379 | + throw new AuthenticationFailedException(); |
|
380 | + } |
|
381 | + |
|
382 | + |
|
383 | + |
|
384 | + /** |
|
385 | + * check if server-to-server sharing is enabled |
|
386 | + * |
|
387 | + * @param bool $incoming |
|
388 | + * @return bool |
|
389 | + */ |
|
390 | + private function isS2SEnabled($incoming = false) { |
|
391 | + |
|
392 | + $result = $this->appManager->isEnabledForUser('files_sharing'); |
|
393 | + |
|
394 | + if ($incoming) { |
|
395 | + $result = $result && $this->federatedShareProvider->isIncomingServer2serverShareEnabled(); |
|
396 | + } else { |
|
397 | + $result = $result && $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); |
|
398 | + } |
|
399 | + |
|
400 | + return $result; |
|
401 | + } |
|
402 | 402 | |
403 | 403 | |
404 | 404 | } |
@@ -166,16 +166,16 @@ discard block |
||
166 | 166 | } |
167 | 167 | |
168 | 168 | // FIXME this should be a method in the user management instead |
169 | - $this->logger->debug('shareWith before, ' . $shareWith, ['app' => 'files_sharing']); |
|
169 | + $this->logger->debug('shareWith before, '.$shareWith, ['app' => 'files_sharing']); |
|
170 | 170 | Util::emitHook( |
171 | 171 | '\OCA\Files_Sharing\API\Server2Server', |
172 | 172 | 'preLoginNameUsedAsUserName', |
173 | 173 | array('uid' => &$shareWith) |
174 | 174 | ); |
175 | - $this->logger->debug('shareWith after, ' . $shareWith, ['app' => 'files_sharing']); |
|
175 | + $this->logger->debug('shareWith after, '.$shareWith, ['app' => 'files_sharing']); |
|
176 | 176 | |
177 | 177 | if (!$this->userManager->userExists($shareWith)) { |
178 | - throw new ProviderCouldNotAddShareException('User does not exists', '',Http::STATUS_BAD_REQUEST); |
|
178 | + throw new ProviderCouldNotAddShareException('User does not exists', '', Http::STATUS_BAD_REQUEST); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | \OC_Util::setupFS($shareWith); |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | ->setType('remote_share') |
202 | 202 | ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')]) |
203 | 203 | ->setAffectedUser($shareWith) |
204 | - ->setObject('remote_share', (int)$shareId, $name); |
|
204 | + ->setObject('remote_share', (int) $shareId, $name); |
|
205 | 205 | \OC::$server->getActivityManager()->publish($event); |
206 | 206 | |
207 | 207 | $notification = $this->notificationManager->createNotification(); |
@@ -213,12 +213,12 @@ discard block |
||
213 | 213 | |
214 | 214 | $declineAction = $notification->createAction(); |
215 | 215 | $declineAction->setLabel('decline') |
216 | - ->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'DELETE'); |
|
216 | + ->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/'.$shareId)), 'DELETE'); |
|
217 | 217 | $notification->addAction($declineAction); |
218 | 218 | |
219 | 219 | $acceptAction = $notification->createAction(); |
220 | 220 | $acceptAction->setLabel('accept') |
221 | - ->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'POST'); |
|
221 | + ->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/'.$shareId)), 'POST'); |
|
222 | 222 | $notification->addAction($acceptAction); |
223 | 223 | |
224 | 224 | $this->notificationManager->notify($notification); |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | 'level' => Util::ERROR, |
231 | 231 | 'app' => 'files_sharing' |
232 | 232 | ]); |
233 | - throw new ProviderCouldNotAddShareException('internal server error, was not able to add share from ' . $remote, '', HTTP::STATUS_INTERNAL_SERVER_ERROR); |
|
233 | + throw new ProviderCouldNotAddShareException('internal server error, was not able to add share from '.$remote, '', HTTP::STATUS_INTERNAL_SERVER_ERROR); |
|
234 | 234 | } |
235 | 235 | } |
236 | 236 | |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | */ |
307 | 307 | protected function executeAcceptShare(IShare $share) { |
308 | 308 | try { |
309 | - $fileId = (int)$share->getNode()->getId(); |
|
309 | + $fileId = (int) $share->getNode()->getId(); |
|
310 | 310 | list($file, $link) = $this->getFile($this->getCorrectUid($share), $fileId); |
311 | 311 | } catch (\Exception $e) { |
312 | 312 | throw new ShareNotFoundException(); |