@@ -27,66 +27,66 @@ |
||
27 | 27 | use OCP\IUser; |
28 | 28 | |
29 | 29 | class SearchQuery implements ISearchQuery { |
30 | - /** @var ISearchOperator */ |
|
31 | - private $searchOperation; |
|
32 | - /** @var integer */ |
|
33 | - private $limit; |
|
34 | - /** @var integer */ |
|
35 | - private $offset; |
|
36 | - /** @var ISearchOrder[] */ |
|
37 | - private $order; |
|
38 | - /** @var IUser */ |
|
39 | - private $user; |
|
30 | + /** @var ISearchOperator */ |
|
31 | + private $searchOperation; |
|
32 | + /** @var integer */ |
|
33 | + private $limit; |
|
34 | + /** @var integer */ |
|
35 | + private $offset; |
|
36 | + /** @var ISearchOrder[] */ |
|
37 | + private $order; |
|
38 | + /** @var IUser */ |
|
39 | + private $user; |
|
40 | 40 | |
41 | - /** |
|
42 | - * SearchQuery constructor. |
|
43 | - * |
|
44 | - * @param ISearchOperator $searchOperation |
|
45 | - * @param int $limit |
|
46 | - * @param int $offset |
|
47 | - * @param array $order |
|
48 | - * @param IUser $user |
|
49 | - */ |
|
50 | - public function __construct(ISearchOperator $searchOperation, $limit, $offset, array $order, IUser $user) { |
|
51 | - $this->searchOperation = $searchOperation; |
|
52 | - $this->limit = $limit; |
|
53 | - $this->offset = $offset; |
|
54 | - $this->order = $order; |
|
55 | - $this->user = $user; |
|
56 | - } |
|
41 | + /** |
|
42 | + * SearchQuery constructor. |
|
43 | + * |
|
44 | + * @param ISearchOperator $searchOperation |
|
45 | + * @param int $limit |
|
46 | + * @param int $offset |
|
47 | + * @param array $order |
|
48 | + * @param IUser $user |
|
49 | + */ |
|
50 | + public function __construct(ISearchOperator $searchOperation, $limit, $offset, array $order, IUser $user) { |
|
51 | + $this->searchOperation = $searchOperation; |
|
52 | + $this->limit = $limit; |
|
53 | + $this->offset = $offset; |
|
54 | + $this->order = $order; |
|
55 | + $this->user = $user; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @return ISearchOperator |
|
60 | - */ |
|
61 | - public function getSearchOperation() { |
|
62 | - return $this->searchOperation; |
|
63 | - } |
|
58 | + /** |
|
59 | + * @return ISearchOperator |
|
60 | + */ |
|
61 | + public function getSearchOperation() { |
|
62 | + return $this->searchOperation; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @return int |
|
67 | - */ |
|
68 | - public function getLimit() { |
|
69 | - return $this->limit; |
|
70 | - } |
|
65 | + /** |
|
66 | + * @return int |
|
67 | + */ |
|
68 | + public function getLimit() { |
|
69 | + return $this->limit; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @return int |
|
74 | - */ |
|
75 | - public function getOffset() { |
|
76 | - return $this->offset; |
|
77 | - } |
|
72 | + /** |
|
73 | + * @return int |
|
74 | + */ |
|
75 | + public function getOffset() { |
|
76 | + return $this->offset; |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @return ISearchOrder[] |
|
81 | - */ |
|
82 | - public function getOrder() { |
|
83 | - return $this->order; |
|
84 | - } |
|
79 | + /** |
|
80 | + * @return ISearchOrder[] |
|
81 | + */ |
|
82 | + public function getOrder() { |
|
83 | + return $this->order; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * @return IUser |
|
88 | - */ |
|
89 | - public function getUser() { |
|
90 | - return $this->user; |
|
91 | - } |
|
86 | + /** |
|
87 | + * @return IUser |
|
88 | + */ |
|
89 | + public function getUser() { |
|
90 | + return $this->user; |
|
91 | + } |
|
92 | 92 | } |
@@ -29,38 +29,38 @@ |
||
29 | 29 | use ID3Parser\ID3Parser; |
30 | 30 | |
31 | 31 | class MP3 extends Provider { |
32 | - /** |
|
33 | - * {@inheritDoc} |
|
34 | - */ |
|
35 | - public function getMimeType() { |
|
36 | - return '/audio\/mpeg/'; |
|
37 | - } |
|
32 | + /** |
|
33 | + * {@inheritDoc} |
|
34 | + */ |
|
35 | + public function getMimeType() { |
|
36 | + return '/audio\/mpeg/'; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * {@inheritDoc} |
|
41 | - */ |
|
42 | - public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { |
|
43 | - $getID3 = new ID3Parser(); |
|
39 | + /** |
|
40 | + * {@inheritDoc} |
|
41 | + */ |
|
42 | + public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { |
|
43 | + $getID3 = new ID3Parser(); |
|
44 | 44 | |
45 | - $tmpPath = $fileview->toTmpFile($path); |
|
46 | - $tags = $getID3->analyze($tmpPath); |
|
47 | - unlink($tmpPath); |
|
48 | - $picture = isset($tags['id3v2']['APIC'][0]['data']) ? $tags['id3v2']['APIC'][0]['data'] : null; |
|
49 | - if(is_null($picture) && isset($tags['id3v2']['PIC'][0]['data'])) { |
|
50 | - $picture = $tags['id3v2']['PIC'][0]['data']; |
|
51 | - } |
|
45 | + $tmpPath = $fileview->toTmpFile($path); |
|
46 | + $tags = $getID3->analyze($tmpPath); |
|
47 | + unlink($tmpPath); |
|
48 | + $picture = isset($tags['id3v2']['APIC'][0]['data']) ? $tags['id3v2']['APIC'][0]['data'] : null; |
|
49 | + if(is_null($picture) && isset($tags['id3v2']['PIC'][0]['data'])) { |
|
50 | + $picture = $tags['id3v2']['PIC'][0]['data']; |
|
51 | + } |
|
52 | 52 | |
53 | - if(!is_null($picture)) { |
|
54 | - $image = new \OC_Image(); |
|
55 | - $image->loadFromData($picture); |
|
53 | + if(!is_null($picture)) { |
|
54 | + $image = new \OC_Image(); |
|
55 | + $image->loadFromData($picture); |
|
56 | 56 | |
57 | - if ($image->valid()) { |
|
58 | - $image->scaleDownToFit($maxX, $maxY); |
|
57 | + if ($image->valid()) { |
|
58 | + $image->scaleDownToFit($maxX, $maxY); |
|
59 | 59 | |
60 | - return $image; |
|
61 | - } |
|
62 | - } |
|
60 | + return $image; |
|
61 | + } |
|
62 | + } |
|
63 | 63 | |
64 | - return false; |
|
65 | - } |
|
64 | + return false; |
|
65 | + } |
|
66 | 66 | } |
@@ -46,11 +46,11 @@ |
||
46 | 46 | $tags = $getID3->analyze($tmpPath); |
47 | 47 | unlink($tmpPath); |
48 | 48 | $picture = isset($tags['id3v2']['APIC'][0]['data']) ? $tags['id3v2']['APIC'][0]['data'] : null; |
49 | - if(is_null($picture) && isset($tags['id3v2']['PIC'][0]['data'])) { |
|
49 | + if (is_null($picture) && isset($tags['id3v2']['PIC'][0]['data'])) { |
|
50 | 50 | $picture = $tags['id3v2']['PIC'][0]['data']; |
51 | 51 | } |
52 | 52 | |
53 | - if(!is_null($picture)) { |
|
53 | + if (!is_null($picture)) { |
|
54 | 54 | $image = new \OC_Image(); |
55 | 55 | $image->loadFromData($picture); |
56 | 56 |
@@ -23,18 +23,18 @@ |
||
23 | 23 | */ |
24 | 24 | |
25 | 25 | return [ |
26 | - 'routes' => [ |
|
27 | - ['name' => 'MountPublicLink#createFederatedShare', 'url' => '/createFederatedShare', 'verb' => 'POST'], |
|
28 | - ['name' => 'MountPublicLink#askForFederatedShare', 'url' => '/askForFederatedShare', 'verb' => 'POST'], |
|
29 | - ], |
|
30 | - 'ocs' => [ |
|
31 | - ['root' => '/cloud', 'name' => 'RequestHandler#createShare', 'url' => '/shares', 'verb' => 'POST'], |
|
32 | - ['root' => '/cloud', 'name' => 'RequestHandler#reShare', 'url' => '/shares/{id}/reshare', 'verb' => 'POST'], |
|
33 | - ['root' => '/cloud', 'name' => 'RequestHandler#updatePermissions', 'url' => '/shares/{id}/permissions', 'verb' => 'POST'], |
|
34 | - ['root' => '/cloud', 'name' => 'RequestHandler#acceptShare', 'url' => '/shares/{id}/accept', 'verb' => 'POST'], |
|
35 | - ['root' => '/cloud', 'name' => 'RequestHandler#declineShare', 'url' => '/shares/{id}/decline', 'verb' => 'POST'], |
|
36 | - ['root' => '/cloud', 'name' => 'RequestHandler#unshare', 'url' => '/shares/{id}/unshare', 'verb' => 'POST'], |
|
37 | - ['root' => '/cloud', 'name' => 'RequestHandler#revoke', 'url' => '/shares/{id}/revoke', 'verb' => 'POST'], |
|
38 | - ['root' => '/cloud', 'name' => 'RequestHandler#move', 'url' => '/shares/{id}/move', 'verb' => 'POST'], |
|
39 | - ], |
|
26 | + 'routes' => [ |
|
27 | + ['name' => 'MountPublicLink#createFederatedShare', 'url' => '/createFederatedShare', 'verb' => 'POST'], |
|
28 | + ['name' => 'MountPublicLink#askForFederatedShare', 'url' => '/askForFederatedShare', 'verb' => 'POST'], |
|
29 | + ], |
|
30 | + 'ocs' => [ |
|
31 | + ['root' => '/cloud', 'name' => 'RequestHandler#createShare', 'url' => '/shares', 'verb' => 'POST'], |
|
32 | + ['root' => '/cloud', 'name' => 'RequestHandler#reShare', 'url' => '/shares/{id}/reshare', 'verb' => 'POST'], |
|
33 | + ['root' => '/cloud', 'name' => 'RequestHandler#updatePermissions', 'url' => '/shares/{id}/permissions', 'verb' => 'POST'], |
|
34 | + ['root' => '/cloud', 'name' => 'RequestHandler#acceptShare', 'url' => '/shares/{id}/accept', 'verb' => 'POST'], |
|
35 | + ['root' => '/cloud', 'name' => 'RequestHandler#declineShare', 'url' => '/shares/{id}/decline', 'verb' => 'POST'], |
|
36 | + ['root' => '/cloud', 'name' => 'RequestHandler#unshare', 'url' => '/shares/{id}/unshare', 'verb' => 'POST'], |
|
37 | + ['root' => '/cloud', 'name' => 'RequestHandler#revoke', 'url' => '/shares/{id}/revoke', 'verb' => 'POST'], |
|
38 | + ['root' => '/cloud', 'name' => 'RequestHandler#move', 'url' => '/shares/{id}/move', 'verb' => 'POST'], |
|
39 | + ], |
|
40 | 40 | ]; |
@@ -33,280 +33,280 @@ |
||
33 | 33 | use OCP\OCS\IDiscoveryService; |
34 | 34 | |
35 | 35 | class Notifications { |
36 | - const RESPONSE_FORMAT = 'json'; // default response format for ocs calls |
|
37 | - |
|
38 | - /** @var AddressHandler */ |
|
39 | - private $addressHandler; |
|
40 | - |
|
41 | - /** @var IClientService */ |
|
42 | - private $httpClientService; |
|
43 | - |
|
44 | - /** @var IDiscoveryService */ |
|
45 | - private $discoveryService; |
|
46 | - |
|
47 | - /** @var IJobList */ |
|
48 | - private $jobList; |
|
49 | - |
|
50 | - /** |
|
51 | - * @param AddressHandler $addressHandler |
|
52 | - * @param IClientService $httpClientService |
|
53 | - * @param IDiscoveryService $discoveryService |
|
54 | - * @param IJobList $jobList |
|
55 | - */ |
|
56 | - public function __construct( |
|
57 | - AddressHandler $addressHandler, |
|
58 | - IClientService $httpClientService, |
|
59 | - IDiscoveryService $discoveryService, |
|
60 | - IJobList $jobList |
|
61 | - ) { |
|
62 | - $this->addressHandler = $addressHandler; |
|
63 | - $this->httpClientService = $httpClientService; |
|
64 | - $this->discoveryService = $discoveryService; |
|
65 | - $this->jobList = $jobList; |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * send server-to-server share to remote server |
|
70 | - * |
|
71 | - * @param string $token |
|
72 | - * @param string $shareWith |
|
73 | - * @param string $name |
|
74 | - * @param int $remote_id |
|
75 | - * @param string $owner |
|
76 | - * @param string $ownerFederatedId |
|
77 | - * @param string $sharedBy |
|
78 | - * @param string $sharedByFederatedId |
|
79 | - * @return bool |
|
80 | - * @throws \OC\HintException |
|
81 | - * @throws \OC\ServerNotAvailableException |
|
82 | - */ |
|
83 | - public function sendRemoteShare($token, $shareWith, $name, $remote_id, $owner, $ownerFederatedId, $sharedBy, $sharedByFederatedId) { |
|
84 | - |
|
85 | - list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith); |
|
86 | - |
|
87 | - if ($user && $remote) { |
|
88 | - $local = $this->addressHandler->generateRemoteURL(); |
|
89 | - |
|
90 | - $fields = array( |
|
91 | - 'shareWith' => $user, |
|
92 | - 'token' => $token, |
|
93 | - 'name' => $name, |
|
94 | - 'remoteId' => $remote_id, |
|
95 | - 'owner' => $owner, |
|
96 | - 'ownerFederatedId' => $ownerFederatedId, |
|
97 | - 'sharedBy' => $sharedBy, |
|
98 | - 'sharedByFederatedId' => $sharedByFederatedId, |
|
99 | - 'remote' => $local, |
|
100 | - ); |
|
101 | - |
|
102 | - $result = $this->tryHttpPostToShareEndpoint($remote, '', $fields); |
|
103 | - $status = json_decode($result['result'], true); |
|
104 | - |
|
105 | - if ($result['success'] && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200)) { |
|
106 | - \OC_Hook::emit('OCP\Share', 'federated_share_added', ['server' => $remote]); |
|
107 | - return true; |
|
108 | - } |
|
109 | - |
|
110 | - } |
|
111 | - |
|
112 | - return false; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * ask owner to re-share the file with the given user |
|
117 | - * |
|
118 | - * @param string $token |
|
119 | - * @param int $id remote Id |
|
120 | - * @param int $shareId internal share Id |
|
121 | - * @param string $remote remote address of the owner |
|
122 | - * @param string $shareWith |
|
123 | - * @param int $permission |
|
124 | - * @return bool |
|
125 | - * @throws \OC\HintException |
|
126 | - * @throws \OC\ServerNotAvailableException |
|
127 | - */ |
|
128 | - public function requestReShare($token, $id, $shareId, $remote, $shareWith, $permission) { |
|
129 | - |
|
130 | - $fields = array( |
|
131 | - 'shareWith' => $shareWith, |
|
132 | - 'token' => $token, |
|
133 | - 'permission' => $permission, |
|
134 | - 'remoteId' => $shareId |
|
135 | - ); |
|
136 | - |
|
137 | - $result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/' . $id . '/reshare', $fields); |
|
138 | - $status = json_decode($result['result'], true); |
|
139 | - |
|
140 | - $httpRequestSuccessful = $result['success']; |
|
141 | - $ocsCallSuccessful = $status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200; |
|
142 | - $validToken = isset($status['ocs']['data']['token']) && is_string($status['ocs']['data']['token']); |
|
143 | - $validRemoteId = isset($status['ocs']['data']['remoteId']); |
|
144 | - |
|
145 | - if ($httpRequestSuccessful && $ocsCallSuccessful && $validToken && $validRemoteId) { |
|
146 | - return [ |
|
147 | - $status['ocs']['data']['token'], |
|
148 | - (int)$status['ocs']['data']['remoteId'] |
|
149 | - ]; |
|
150 | - } |
|
151 | - |
|
152 | - return false; |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * send server-to-server unshare to remote server |
|
157 | - * |
|
158 | - * @param string $remote url |
|
159 | - * @param int $id share id |
|
160 | - * @param string $token |
|
161 | - * @return bool |
|
162 | - */ |
|
163 | - public function sendRemoteUnShare($remote, $id, $token) { |
|
164 | - $this->sendUpdateToRemote($remote, $id, $token, 'unshare'); |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * send server-to-server unshare to remote server |
|
169 | - * |
|
170 | - * @param string $remote url |
|
171 | - * @param int $id share id |
|
172 | - * @param string $token |
|
173 | - * @return bool |
|
174 | - */ |
|
175 | - public function sendRevokeShare($remote, $id, $token) { |
|
176 | - $this->sendUpdateToRemote($remote, $id, $token, 'revoke'); |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * send notification to remote server if the permissions was changed |
|
181 | - * |
|
182 | - * @param string $remote |
|
183 | - * @param int $remoteId |
|
184 | - * @param string $token |
|
185 | - * @param int $permissions |
|
186 | - * @return bool |
|
187 | - */ |
|
188 | - public function sendPermissionChange($remote, $remoteId, $token, $permissions) { |
|
189 | - $this->sendUpdateToRemote($remote, $remoteId, $token, 'permissions', ['permissions' => $permissions]); |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * forward accept reShare to remote server |
|
194 | - * |
|
195 | - * @param string $remote |
|
196 | - * @param int $remoteId |
|
197 | - * @param string $token |
|
198 | - */ |
|
199 | - public function sendAcceptShare($remote, $remoteId, $token) { |
|
200 | - $this->sendUpdateToRemote($remote, $remoteId, $token, 'accept'); |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * forward decline reShare to remote server |
|
205 | - * |
|
206 | - * @param string $remote |
|
207 | - * @param int $remoteId |
|
208 | - * @param string $token |
|
209 | - */ |
|
210 | - public function sendDeclineShare($remote, $remoteId, $token) { |
|
211 | - $this->sendUpdateToRemote($remote, $remoteId, $token, 'decline'); |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * inform remote server whether server-to-server share was accepted/declined |
|
216 | - * |
|
217 | - * @param string $remote |
|
218 | - * @param string $token |
|
219 | - * @param int $remoteId Share id on the remote host |
|
220 | - * @param string $action possible actions: accept, decline, unshare, revoke, permissions |
|
221 | - * @param array $data |
|
222 | - * @param int $try |
|
223 | - * @return boolean |
|
224 | - */ |
|
225 | - public function sendUpdateToRemote($remote, $remoteId, $token, $action, $data = [], $try = 0) { |
|
226 | - |
|
227 | - $fields = array('token' => $token); |
|
228 | - foreach ($data as $key => $value) { |
|
229 | - $fields[$key] = $value; |
|
230 | - } |
|
231 | - |
|
232 | - $result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/' . $remoteId . '/' . $action, $fields); |
|
233 | - $status = json_decode($result['result'], true); |
|
234 | - |
|
235 | - if ($result['success'] && |
|
236 | - ($status['ocs']['meta']['statuscode'] === 100 || |
|
237 | - $status['ocs']['meta']['statuscode'] === 200 |
|
238 | - ) |
|
239 | - ) { |
|
240 | - return true; |
|
241 | - } elseif ($try === 0) { |
|
242 | - // only add new job on first try |
|
243 | - $this->jobList->add('OCA\FederatedFileSharing\BackgroundJob\RetryJob', |
|
244 | - [ |
|
245 | - 'remote' => $remote, |
|
246 | - 'remoteId' => $remoteId, |
|
247 | - 'token' => $token, |
|
248 | - 'action' => $action, |
|
249 | - 'data' => json_encode($data), |
|
250 | - 'try' => $try, |
|
251 | - 'lastRun' => $this->getTimestamp() |
|
252 | - ] |
|
253 | - ); |
|
254 | - } |
|
255 | - |
|
256 | - return false; |
|
257 | - } |
|
258 | - |
|
259 | - |
|
260 | - /** |
|
261 | - * return current timestamp |
|
262 | - * |
|
263 | - * @return int |
|
264 | - */ |
|
265 | - protected function getTimestamp() { |
|
266 | - return time(); |
|
267 | - } |
|
268 | - |
|
269 | - /** |
|
270 | - * try http post with the given protocol, if no protocol is given we pick |
|
271 | - * the secure one (https) |
|
272 | - * |
|
273 | - * @param string $remoteDomain |
|
274 | - * @param string $urlSuffix |
|
275 | - * @param array $fields post parameters |
|
276 | - * @return array |
|
277 | - * @throws \Exception |
|
278 | - */ |
|
279 | - protected function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $fields) { |
|
280 | - $client = $this->httpClientService->newClient(); |
|
281 | - |
|
282 | - if ($this->addressHandler->urlContainProtocol($remoteDomain) === false) { |
|
283 | - $remoteDomain = 'https://' . $remoteDomain; |
|
284 | - } |
|
285 | - |
|
286 | - $result = [ |
|
287 | - 'success' => false, |
|
288 | - 'result' => '', |
|
289 | - ]; |
|
290 | - |
|
291 | - $federationEndpoints = $this->discoveryService->discover($remoteDomain, 'FEDERATED_SHARING'); |
|
292 | - $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; |
|
293 | - try { |
|
294 | - $response = $client->post($remoteDomain . $endpoint . $urlSuffix . '?format=' . self::RESPONSE_FORMAT, [ |
|
295 | - 'body' => $fields, |
|
296 | - 'timeout' => 10, |
|
297 | - 'connect_timeout' => 10, |
|
298 | - ]); |
|
299 | - $result['result'] = $response->getBody(); |
|
300 | - $result['success'] = true; |
|
301 | - } catch (\Exception $e) { |
|
302 | - // if flat re-sharing is not supported by the remote server |
|
303 | - // we re-throw the exception and fall back to the old behaviour. |
|
304 | - // (flat re-shares has been introduced in Nextcloud 9.1) |
|
305 | - if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) { |
|
306 | - throw $e; |
|
307 | - } |
|
308 | - } |
|
309 | - |
|
310 | - return $result; |
|
311 | - } |
|
36 | + const RESPONSE_FORMAT = 'json'; // default response format for ocs calls |
|
37 | + |
|
38 | + /** @var AddressHandler */ |
|
39 | + private $addressHandler; |
|
40 | + |
|
41 | + /** @var IClientService */ |
|
42 | + private $httpClientService; |
|
43 | + |
|
44 | + /** @var IDiscoveryService */ |
|
45 | + private $discoveryService; |
|
46 | + |
|
47 | + /** @var IJobList */ |
|
48 | + private $jobList; |
|
49 | + |
|
50 | + /** |
|
51 | + * @param AddressHandler $addressHandler |
|
52 | + * @param IClientService $httpClientService |
|
53 | + * @param IDiscoveryService $discoveryService |
|
54 | + * @param IJobList $jobList |
|
55 | + */ |
|
56 | + public function __construct( |
|
57 | + AddressHandler $addressHandler, |
|
58 | + IClientService $httpClientService, |
|
59 | + IDiscoveryService $discoveryService, |
|
60 | + IJobList $jobList |
|
61 | + ) { |
|
62 | + $this->addressHandler = $addressHandler; |
|
63 | + $this->httpClientService = $httpClientService; |
|
64 | + $this->discoveryService = $discoveryService; |
|
65 | + $this->jobList = $jobList; |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * send server-to-server share to remote server |
|
70 | + * |
|
71 | + * @param string $token |
|
72 | + * @param string $shareWith |
|
73 | + * @param string $name |
|
74 | + * @param int $remote_id |
|
75 | + * @param string $owner |
|
76 | + * @param string $ownerFederatedId |
|
77 | + * @param string $sharedBy |
|
78 | + * @param string $sharedByFederatedId |
|
79 | + * @return bool |
|
80 | + * @throws \OC\HintException |
|
81 | + * @throws \OC\ServerNotAvailableException |
|
82 | + */ |
|
83 | + public function sendRemoteShare($token, $shareWith, $name, $remote_id, $owner, $ownerFederatedId, $sharedBy, $sharedByFederatedId) { |
|
84 | + |
|
85 | + list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith); |
|
86 | + |
|
87 | + if ($user && $remote) { |
|
88 | + $local = $this->addressHandler->generateRemoteURL(); |
|
89 | + |
|
90 | + $fields = array( |
|
91 | + 'shareWith' => $user, |
|
92 | + 'token' => $token, |
|
93 | + 'name' => $name, |
|
94 | + 'remoteId' => $remote_id, |
|
95 | + 'owner' => $owner, |
|
96 | + 'ownerFederatedId' => $ownerFederatedId, |
|
97 | + 'sharedBy' => $sharedBy, |
|
98 | + 'sharedByFederatedId' => $sharedByFederatedId, |
|
99 | + 'remote' => $local, |
|
100 | + ); |
|
101 | + |
|
102 | + $result = $this->tryHttpPostToShareEndpoint($remote, '', $fields); |
|
103 | + $status = json_decode($result['result'], true); |
|
104 | + |
|
105 | + if ($result['success'] && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200)) { |
|
106 | + \OC_Hook::emit('OCP\Share', 'federated_share_added', ['server' => $remote]); |
|
107 | + return true; |
|
108 | + } |
|
109 | + |
|
110 | + } |
|
111 | + |
|
112 | + return false; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * ask owner to re-share the file with the given user |
|
117 | + * |
|
118 | + * @param string $token |
|
119 | + * @param int $id remote Id |
|
120 | + * @param int $shareId internal share Id |
|
121 | + * @param string $remote remote address of the owner |
|
122 | + * @param string $shareWith |
|
123 | + * @param int $permission |
|
124 | + * @return bool |
|
125 | + * @throws \OC\HintException |
|
126 | + * @throws \OC\ServerNotAvailableException |
|
127 | + */ |
|
128 | + public function requestReShare($token, $id, $shareId, $remote, $shareWith, $permission) { |
|
129 | + |
|
130 | + $fields = array( |
|
131 | + 'shareWith' => $shareWith, |
|
132 | + 'token' => $token, |
|
133 | + 'permission' => $permission, |
|
134 | + 'remoteId' => $shareId |
|
135 | + ); |
|
136 | + |
|
137 | + $result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/' . $id . '/reshare', $fields); |
|
138 | + $status = json_decode($result['result'], true); |
|
139 | + |
|
140 | + $httpRequestSuccessful = $result['success']; |
|
141 | + $ocsCallSuccessful = $status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200; |
|
142 | + $validToken = isset($status['ocs']['data']['token']) && is_string($status['ocs']['data']['token']); |
|
143 | + $validRemoteId = isset($status['ocs']['data']['remoteId']); |
|
144 | + |
|
145 | + if ($httpRequestSuccessful && $ocsCallSuccessful && $validToken && $validRemoteId) { |
|
146 | + return [ |
|
147 | + $status['ocs']['data']['token'], |
|
148 | + (int)$status['ocs']['data']['remoteId'] |
|
149 | + ]; |
|
150 | + } |
|
151 | + |
|
152 | + return false; |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * send server-to-server unshare to remote server |
|
157 | + * |
|
158 | + * @param string $remote url |
|
159 | + * @param int $id share id |
|
160 | + * @param string $token |
|
161 | + * @return bool |
|
162 | + */ |
|
163 | + public function sendRemoteUnShare($remote, $id, $token) { |
|
164 | + $this->sendUpdateToRemote($remote, $id, $token, 'unshare'); |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * send server-to-server unshare to remote server |
|
169 | + * |
|
170 | + * @param string $remote url |
|
171 | + * @param int $id share id |
|
172 | + * @param string $token |
|
173 | + * @return bool |
|
174 | + */ |
|
175 | + public function sendRevokeShare($remote, $id, $token) { |
|
176 | + $this->sendUpdateToRemote($remote, $id, $token, 'revoke'); |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * send notification to remote server if the permissions was changed |
|
181 | + * |
|
182 | + * @param string $remote |
|
183 | + * @param int $remoteId |
|
184 | + * @param string $token |
|
185 | + * @param int $permissions |
|
186 | + * @return bool |
|
187 | + */ |
|
188 | + public function sendPermissionChange($remote, $remoteId, $token, $permissions) { |
|
189 | + $this->sendUpdateToRemote($remote, $remoteId, $token, 'permissions', ['permissions' => $permissions]); |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * forward accept reShare to remote server |
|
194 | + * |
|
195 | + * @param string $remote |
|
196 | + * @param int $remoteId |
|
197 | + * @param string $token |
|
198 | + */ |
|
199 | + public function sendAcceptShare($remote, $remoteId, $token) { |
|
200 | + $this->sendUpdateToRemote($remote, $remoteId, $token, 'accept'); |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * forward decline reShare to remote server |
|
205 | + * |
|
206 | + * @param string $remote |
|
207 | + * @param int $remoteId |
|
208 | + * @param string $token |
|
209 | + */ |
|
210 | + public function sendDeclineShare($remote, $remoteId, $token) { |
|
211 | + $this->sendUpdateToRemote($remote, $remoteId, $token, 'decline'); |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * inform remote server whether server-to-server share was accepted/declined |
|
216 | + * |
|
217 | + * @param string $remote |
|
218 | + * @param string $token |
|
219 | + * @param int $remoteId Share id on the remote host |
|
220 | + * @param string $action possible actions: accept, decline, unshare, revoke, permissions |
|
221 | + * @param array $data |
|
222 | + * @param int $try |
|
223 | + * @return boolean |
|
224 | + */ |
|
225 | + public function sendUpdateToRemote($remote, $remoteId, $token, $action, $data = [], $try = 0) { |
|
226 | + |
|
227 | + $fields = array('token' => $token); |
|
228 | + foreach ($data as $key => $value) { |
|
229 | + $fields[$key] = $value; |
|
230 | + } |
|
231 | + |
|
232 | + $result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/' . $remoteId . '/' . $action, $fields); |
|
233 | + $status = json_decode($result['result'], true); |
|
234 | + |
|
235 | + if ($result['success'] && |
|
236 | + ($status['ocs']['meta']['statuscode'] === 100 || |
|
237 | + $status['ocs']['meta']['statuscode'] === 200 |
|
238 | + ) |
|
239 | + ) { |
|
240 | + return true; |
|
241 | + } elseif ($try === 0) { |
|
242 | + // only add new job on first try |
|
243 | + $this->jobList->add('OCA\FederatedFileSharing\BackgroundJob\RetryJob', |
|
244 | + [ |
|
245 | + 'remote' => $remote, |
|
246 | + 'remoteId' => $remoteId, |
|
247 | + 'token' => $token, |
|
248 | + 'action' => $action, |
|
249 | + 'data' => json_encode($data), |
|
250 | + 'try' => $try, |
|
251 | + 'lastRun' => $this->getTimestamp() |
|
252 | + ] |
|
253 | + ); |
|
254 | + } |
|
255 | + |
|
256 | + return false; |
|
257 | + } |
|
258 | + |
|
259 | + |
|
260 | + /** |
|
261 | + * return current timestamp |
|
262 | + * |
|
263 | + * @return int |
|
264 | + */ |
|
265 | + protected function getTimestamp() { |
|
266 | + return time(); |
|
267 | + } |
|
268 | + |
|
269 | + /** |
|
270 | + * try http post with the given protocol, if no protocol is given we pick |
|
271 | + * the secure one (https) |
|
272 | + * |
|
273 | + * @param string $remoteDomain |
|
274 | + * @param string $urlSuffix |
|
275 | + * @param array $fields post parameters |
|
276 | + * @return array |
|
277 | + * @throws \Exception |
|
278 | + */ |
|
279 | + protected function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $fields) { |
|
280 | + $client = $this->httpClientService->newClient(); |
|
281 | + |
|
282 | + if ($this->addressHandler->urlContainProtocol($remoteDomain) === false) { |
|
283 | + $remoteDomain = 'https://' . $remoteDomain; |
|
284 | + } |
|
285 | + |
|
286 | + $result = [ |
|
287 | + 'success' => false, |
|
288 | + 'result' => '', |
|
289 | + ]; |
|
290 | + |
|
291 | + $federationEndpoints = $this->discoveryService->discover($remoteDomain, 'FEDERATED_SHARING'); |
|
292 | + $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; |
|
293 | + try { |
|
294 | + $response = $client->post($remoteDomain . $endpoint . $urlSuffix . '?format=' . self::RESPONSE_FORMAT, [ |
|
295 | + 'body' => $fields, |
|
296 | + 'timeout' => 10, |
|
297 | + 'connect_timeout' => 10, |
|
298 | + ]); |
|
299 | + $result['result'] = $response->getBody(); |
|
300 | + $result['success'] = true; |
|
301 | + } catch (\Exception $e) { |
|
302 | + // if flat re-sharing is not supported by the remote server |
|
303 | + // we re-throw the exception and fall back to the old behaviour. |
|
304 | + // (flat re-shares has been introduced in Nextcloud 9.1) |
|
305 | + if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) { |
|
306 | + throw $e; |
|
307 | + } |
|
308 | + } |
|
309 | + |
|
310 | + return $result; |
|
311 | + } |
|
312 | 312 | } |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | 'remoteId' => $shareId |
135 | 135 | ); |
136 | 136 | |
137 | - $result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/' . $id . '/reshare', $fields); |
|
137 | + $result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/'.$id.'/reshare', $fields); |
|
138 | 138 | $status = json_decode($result['result'], true); |
139 | 139 | |
140 | 140 | $httpRequestSuccessful = $result['success']; |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | if ($httpRequestSuccessful && $ocsCallSuccessful && $validToken && $validRemoteId) { |
146 | 146 | return [ |
147 | 147 | $status['ocs']['data']['token'], |
148 | - (int)$status['ocs']['data']['remoteId'] |
|
148 | + (int) $status['ocs']['data']['remoteId'] |
|
149 | 149 | ]; |
150 | 150 | } |
151 | 151 | |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | $fields[$key] = $value; |
230 | 230 | } |
231 | 231 | |
232 | - $result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/' . $remoteId . '/' . $action, $fields); |
|
232 | + $result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/'.$remoteId.'/'.$action, $fields); |
|
233 | 233 | $status = json_decode($result['result'], true); |
234 | 234 | |
235 | 235 | if ($result['success'] && |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | $client = $this->httpClientService->newClient(); |
281 | 281 | |
282 | 282 | if ($this->addressHandler->urlContainProtocol($remoteDomain) === false) { |
283 | - $remoteDomain = 'https://' . $remoteDomain; |
|
283 | + $remoteDomain = 'https://'.$remoteDomain; |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | $result = [ |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | $federationEndpoints = $this->discoveryService->discover($remoteDomain, 'FEDERATED_SHARING'); |
292 | 292 | $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; |
293 | 293 | try { |
294 | - $response = $client->post($remoteDomain . $endpoint . $urlSuffix . '?format=' . self::RESPONSE_FORMAT, [ |
|
294 | + $response = $client->post($remoteDomain.$endpoint.$urlSuffix.'?format='.self::RESPONSE_FORMAT, [ |
|
295 | 295 | 'body' => $fields, |
296 | 296 | 'timeout' => 10, |
297 | 297 | 'connect_timeout' => 10, |
@@ -21,7 +21,7 @@ |
||
21 | 21 | */ |
22 | 22 | // no php execution timeout for webdav |
23 | 23 | if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
24 | - @set_time_limit(0); |
|
24 | + @set_time_limit(0); |
|
25 | 25 | } |
26 | 26 | ignore_user_abort(true); |
27 | 27 |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | } |
215 | 215 | |
216 | 216 | if ($provider === null) { |
217 | - throw new ProviderException('No provider with id .' . $id . ' found.'); |
|
217 | + throw new ProviderException('No provider with id .'.$id.' found.'); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | return $provider; |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | |
242 | 242 | |
243 | 243 | if ($provider === null) { |
244 | - throw new ProviderException('No share provider for share type ' . $shareType); |
|
244 | + throw new ProviderException('No share provider for share type '.$shareType); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | return $provider; |
@@ -176,7 +176,7 @@ |
||
176 | 176 | /** |
177 | 177 | * Create the circle share provider |
178 | 178 | * |
179 | - * @return FederatedShareProvider |
|
179 | + * @return null|\OCA\Circles\ShareByCircleProvider |
|
180 | 180 | * |
181 | 181 | * @suppress PhanUndeclaredClassMethod |
182 | 182 | */ |
@@ -43,233 +43,233 @@ |
||
43 | 43 | */ |
44 | 44 | class ProviderFactory implements IProviderFactory { |
45 | 45 | |
46 | - /** @var IServerContainer */ |
|
47 | - private $serverContainer; |
|
48 | - /** @var DefaultShareProvider */ |
|
49 | - private $defaultProvider = null; |
|
50 | - /** @var FederatedShareProvider */ |
|
51 | - private $federatedProvider = null; |
|
52 | - /** @var ShareByMailProvider */ |
|
53 | - private $shareByMailProvider; |
|
54 | - /** @var \OCA\Circles\ShareByCircleProvider */ |
|
55 | - private $shareByCircleProvider = null; |
|
56 | - /** @var bool */ |
|
57 | - private $circlesAreNotAvailable = false; |
|
58 | - |
|
59 | - /** |
|
60 | - * IProviderFactory constructor. |
|
61 | - * |
|
62 | - * @param IServerContainer $serverContainer |
|
63 | - */ |
|
64 | - public function __construct(IServerContainer $serverContainer) { |
|
65 | - $this->serverContainer = $serverContainer; |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Create the default share provider. |
|
70 | - * |
|
71 | - * @return DefaultShareProvider |
|
72 | - */ |
|
73 | - protected function defaultShareProvider() { |
|
74 | - if ($this->defaultProvider === null) { |
|
75 | - $this->defaultProvider = new DefaultShareProvider( |
|
76 | - $this->serverContainer->getDatabaseConnection(), |
|
77 | - $this->serverContainer->getUserManager(), |
|
78 | - $this->serverContainer->getGroupManager(), |
|
79 | - $this->serverContainer->getLazyRootFolder() |
|
80 | - ); |
|
81 | - } |
|
82 | - |
|
83 | - return $this->defaultProvider; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Create the federated share provider |
|
88 | - * |
|
89 | - * @return FederatedShareProvider |
|
90 | - */ |
|
91 | - protected function federatedShareProvider() { |
|
92 | - if ($this->federatedProvider === null) { |
|
93 | - /* |
|
46 | + /** @var IServerContainer */ |
|
47 | + private $serverContainer; |
|
48 | + /** @var DefaultShareProvider */ |
|
49 | + private $defaultProvider = null; |
|
50 | + /** @var FederatedShareProvider */ |
|
51 | + private $federatedProvider = null; |
|
52 | + /** @var ShareByMailProvider */ |
|
53 | + private $shareByMailProvider; |
|
54 | + /** @var \OCA\Circles\ShareByCircleProvider */ |
|
55 | + private $shareByCircleProvider = null; |
|
56 | + /** @var bool */ |
|
57 | + private $circlesAreNotAvailable = false; |
|
58 | + |
|
59 | + /** |
|
60 | + * IProviderFactory constructor. |
|
61 | + * |
|
62 | + * @param IServerContainer $serverContainer |
|
63 | + */ |
|
64 | + public function __construct(IServerContainer $serverContainer) { |
|
65 | + $this->serverContainer = $serverContainer; |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * Create the default share provider. |
|
70 | + * |
|
71 | + * @return DefaultShareProvider |
|
72 | + */ |
|
73 | + protected function defaultShareProvider() { |
|
74 | + if ($this->defaultProvider === null) { |
|
75 | + $this->defaultProvider = new DefaultShareProvider( |
|
76 | + $this->serverContainer->getDatabaseConnection(), |
|
77 | + $this->serverContainer->getUserManager(), |
|
78 | + $this->serverContainer->getGroupManager(), |
|
79 | + $this->serverContainer->getLazyRootFolder() |
|
80 | + ); |
|
81 | + } |
|
82 | + |
|
83 | + return $this->defaultProvider; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Create the federated share provider |
|
88 | + * |
|
89 | + * @return FederatedShareProvider |
|
90 | + */ |
|
91 | + protected function federatedShareProvider() { |
|
92 | + if ($this->federatedProvider === null) { |
|
93 | + /* |
|
94 | 94 | * Check if the app is enabled |
95 | 95 | */ |
96 | - $appManager = $this->serverContainer->getAppManager(); |
|
97 | - if (!$appManager->isEnabledForUser('federatedfilesharing')) { |
|
98 | - return null; |
|
99 | - } |
|
96 | + $appManager = $this->serverContainer->getAppManager(); |
|
97 | + if (!$appManager->isEnabledForUser('federatedfilesharing')) { |
|
98 | + return null; |
|
99 | + } |
|
100 | 100 | |
101 | - /* |
|
101 | + /* |
|
102 | 102 | * TODO: add factory to federated sharing app |
103 | 103 | */ |
104 | - $l = $this->serverContainer->getL10N('federatedfilessharing'); |
|
105 | - $addressHandler = new AddressHandler( |
|
106 | - $this->serverContainer->getURLGenerator(), |
|
107 | - $l, |
|
108 | - $this->serverContainer->getCloudIdManager() |
|
109 | - ); |
|
110 | - $notifications = new Notifications( |
|
111 | - $addressHandler, |
|
112 | - $this->serverContainer->getHTTPClientService(), |
|
113 | - $this->serverContainer->query(\OCP\OCS\IDiscoveryService::class), |
|
114 | - $this->serverContainer->getJobList() |
|
115 | - ); |
|
116 | - $tokenHandler = new TokenHandler( |
|
117 | - $this->serverContainer->getSecureRandom() |
|
118 | - ); |
|
119 | - |
|
120 | - $this->federatedProvider = new FederatedShareProvider( |
|
121 | - $this->serverContainer->getDatabaseConnection(), |
|
122 | - $addressHandler, |
|
123 | - $notifications, |
|
124 | - $tokenHandler, |
|
125 | - $l, |
|
126 | - $this->serverContainer->getLogger(), |
|
127 | - $this->serverContainer->getLazyRootFolder(), |
|
128 | - $this->serverContainer->getConfig(), |
|
129 | - $this->serverContainer->getUserManager(), |
|
130 | - $this->serverContainer->getCloudIdManager(), |
|
131 | - $this->serverContainer->query(Config::class) |
|
132 | - ); |
|
133 | - } |
|
134 | - |
|
135 | - return $this->federatedProvider; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Create the federated share provider |
|
140 | - * |
|
141 | - * @return ShareByMailProvider |
|
142 | - */ |
|
143 | - protected function getShareByMailProvider() { |
|
144 | - if ($this->shareByMailProvider === null) { |
|
145 | - /* |
|
104 | + $l = $this->serverContainer->getL10N('federatedfilessharing'); |
|
105 | + $addressHandler = new AddressHandler( |
|
106 | + $this->serverContainer->getURLGenerator(), |
|
107 | + $l, |
|
108 | + $this->serverContainer->getCloudIdManager() |
|
109 | + ); |
|
110 | + $notifications = new Notifications( |
|
111 | + $addressHandler, |
|
112 | + $this->serverContainer->getHTTPClientService(), |
|
113 | + $this->serverContainer->query(\OCP\OCS\IDiscoveryService::class), |
|
114 | + $this->serverContainer->getJobList() |
|
115 | + ); |
|
116 | + $tokenHandler = new TokenHandler( |
|
117 | + $this->serverContainer->getSecureRandom() |
|
118 | + ); |
|
119 | + |
|
120 | + $this->federatedProvider = new FederatedShareProvider( |
|
121 | + $this->serverContainer->getDatabaseConnection(), |
|
122 | + $addressHandler, |
|
123 | + $notifications, |
|
124 | + $tokenHandler, |
|
125 | + $l, |
|
126 | + $this->serverContainer->getLogger(), |
|
127 | + $this->serverContainer->getLazyRootFolder(), |
|
128 | + $this->serverContainer->getConfig(), |
|
129 | + $this->serverContainer->getUserManager(), |
|
130 | + $this->serverContainer->getCloudIdManager(), |
|
131 | + $this->serverContainer->query(Config::class) |
|
132 | + ); |
|
133 | + } |
|
134 | + |
|
135 | + return $this->federatedProvider; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Create the federated share provider |
|
140 | + * |
|
141 | + * @return ShareByMailProvider |
|
142 | + */ |
|
143 | + protected function getShareByMailProvider() { |
|
144 | + if ($this->shareByMailProvider === null) { |
|
145 | + /* |
|
146 | 146 | * Check if the app is enabled |
147 | 147 | */ |
148 | - $appManager = $this->serverContainer->getAppManager(); |
|
149 | - if (!$appManager->isEnabledForUser('sharebymail')) { |
|
150 | - return null; |
|
151 | - } |
|
152 | - |
|
153 | - $settingsManager = new SettingsManager($this->serverContainer->getConfig()); |
|
154 | - |
|
155 | - $this->shareByMailProvider = new ShareByMailProvider( |
|
156 | - $this->serverContainer->getDatabaseConnection(), |
|
157 | - $this->serverContainer->getSecureRandom(), |
|
158 | - $this->serverContainer->getUserManager(), |
|
159 | - $this->serverContainer->getLazyRootFolder(), |
|
160 | - $this->serverContainer->getL10N('sharebymail'), |
|
161 | - $this->serverContainer->getLogger(), |
|
162 | - $this->serverContainer->getMailer(), |
|
163 | - $this->serverContainer->getURLGenerator(), |
|
164 | - $this->serverContainer->getActivityManager(), |
|
165 | - $settingsManager, |
|
166 | - $this->serverContainer->query(Defaults::class), |
|
167 | - $this->serverContainer->getHasher(), |
|
168 | - $this->serverContainer->query(CapabilitiesManager::class) |
|
169 | - ); |
|
170 | - } |
|
171 | - |
|
172 | - return $this->shareByMailProvider; |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * Create the circle share provider |
|
178 | - * |
|
179 | - * @return FederatedShareProvider |
|
180 | - * |
|
181 | - * @suppress PhanUndeclaredClassMethod |
|
182 | - */ |
|
183 | - protected function getShareByCircleProvider() { |
|
184 | - |
|
185 | - if ($this->circlesAreNotAvailable) { |
|
186 | - return null; |
|
187 | - } |
|
188 | - |
|
189 | - if (!$this->serverContainer->getAppManager()->isEnabledForUser('circles') || |
|
190 | - !class_exists('\OCA\Circles\ShareByCircleProvider') |
|
191 | - ) { |
|
192 | - $this->circlesAreNotAvailable = true; |
|
193 | - return null; |
|
194 | - } |
|
195 | - |
|
196 | - if ($this->shareByCircleProvider === null) { |
|
197 | - |
|
198 | - $this->shareByCircleProvider = new \OCA\Circles\ShareByCircleProvider( |
|
199 | - $this->serverContainer->getDatabaseConnection(), |
|
200 | - $this->serverContainer->getSecureRandom(), |
|
201 | - $this->serverContainer->getUserManager(), |
|
202 | - $this->serverContainer->getLazyRootFolder(), |
|
203 | - $this->serverContainer->getL10N('circles'), |
|
204 | - $this->serverContainer->getLogger(), |
|
205 | - $this->serverContainer->getURLGenerator() |
|
206 | - ); |
|
207 | - } |
|
208 | - |
|
209 | - return $this->shareByCircleProvider; |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * @inheritdoc |
|
215 | - */ |
|
216 | - public function getProvider($id) { |
|
217 | - $provider = null; |
|
218 | - if ($id === 'ocinternal') { |
|
219 | - $provider = $this->defaultShareProvider(); |
|
220 | - } else if ($id === 'ocFederatedSharing') { |
|
221 | - $provider = $this->federatedShareProvider(); |
|
222 | - } else if ($id === 'ocMailShare') { |
|
223 | - $provider = $this->getShareByMailProvider(); |
|
224 | - } else if ($id === 'ocCircleShare') { |
|
225 | - $provider = $this->getShareByCircleProvider(); |
|
226 | - } |
|
227 | - |
|
228 | - if ($provider === null) { |
|
229 | - throw new ProviderException('No provider with id .' . $id . ' found.'); |
|
230 | - } |
|
231 | - |
|
232 | - return $provider; |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * @inheritdoc |
|
237 | - */ |
|
238 | - public function getProviderForType($shareType) { |
|
239 | - $provider = null; |
|
240 | - |
|
241 | - if ($shareType === \OCP\Share::SHARE_TYPE_USER || |
|
242 | - $shareType === \OCP\Share::SHARE_TYPE_GROUP || |
|
243 | - $shareType === \OCP\Share::SHARE_TYPE_LINK |
|
244 | - ) { |
|
245 | - $provider = $this->defaultShareProvider(); |
|
246 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
247 | - $provider = $this->federatedShareProvider(); |
|
248 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
249 | - $provider = $this->getShareByMailProvider(); |
|
250 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
251 | - $provider = $this->getShareByCircleProvider(); |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - if ($provider === null) { |
|
256 | - throw new ProviderException('No share provider for share type ' . $shareType); |
|
257 | - } |
|
258 | - |
|
259 | - return $provider; |
|
260 | - } |
|
261 | - |
|
262 | - public function getAllProviders() { |
|
263 | - $shares = [$this->defaultShareProvider(), $this->federatedShareProvider()]; |
|
264 | - $shareByMail = $this->getShareByMailProvider(); |
|
265 | - if ($shareByMail !== null) { |
|
266 | - $shares[] = $shareByMail; |
|
267 | - } |
|
268 | - $shareByCircle = $this->getShareByCircleProvider(); |
|
269 | - if ($shareByCircle !== null) { |
|
270 | - $shares[] = $shareByCircle; |
|
271 | - } |
|
272 | - |
|
273 | - return $shares; |
|
274 | - } |
|
148 | + $appManager = $this->serverContainer->getAppManager(); |
|
149 | + if (!$appManager->isEnabledForUser('sharebymail')) { |
|
150 | + return null; |
|
151 | + } |
|
152 | + |
|
153 | + $settingsManager = new SettingsManager($this->serverContainer->getConfig()); |
|
154 | + |
|
155 | + $this->shareByMailProvider = new ShareByMailProvider( |
|
156 | + $this->serverContainer->getDatabaseConnection(), |
|
157 | + $this->serverContainer->getSecureRandom(), |
|
158 | + $this->serverContainer->getUserManager(), |
|
159 | + $this->serverContainer->getLazyRootFolder(), |
|
160 | + $this->serverContainer->getL10N('sharebymail'), |
|
161 | + $this->serverContainer->getLogger(), |
|
162 | + $this->serverContainer->getMailer(), |
|
163 | + $this->serverContainer->getURLGenerator(), |
|
164 | + $this->serverContainer->getActivityManager(), |
|
165 | + $settingsManager, |
|
166 | + $this->serverContainer->query(Defaults::class), |
|
167 | + $this->serverContainer->getHasher(), |
|
168 | + $this->serverContainer->query(CapabilitiesManager::class) |
|
169 | + ); |
|
170 | + } |
|
171 | + |
|
172 | + return $this->shareByMailProvider; |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * Create the circle share provider |
|
178 | + * |
|
179 | + * @return FederatedShareProvider |
|
180 | + * |
|
181 | + * @suppress PhanUndeclaredClassMethod |
|
182 | + */ |
|
183 | + protected function getShareByCircleProvider() { |
|
184 | + |
|
185 | + if ($this->circlesAreNotAvailable) { |
|
186 | + return null; |
|
187 | + } |
|
188 | + |
|
189 | + if (!$this->serverContainer->getAppManager()->isEnabledForUser('circles') || |
|
190 | + !class_exists('\OCA\Circles\ShareByCircleProvider') |
|
191 | + ) { |
|
192 | + $this->circlesAreNotAvailable = true; |
|
193 | + return null; |
|
194 | + } |
|
195 | + |
|
196 | + if ($this->shareByCircleProvider === null) { |
|
197 | + |
|
198 | + $this->shareByCircleProvider = new \OCA\Circles\ShareByCircleProvider( |
|
199 | + $this->serverContainer->getDatabaseConnection(), |
|
200 | + $this->serverContainer->getSecureRandom(), |
|
201 | + $this->serverContainer->getUserManager(), |
|
202 | + $this->serverContainer->getLazyRootFolder(), |
|
203 | + $this->serverContainer->getL10N('circles'), |
|
204 | + $this->serverContainer->getLogger(), |
|
205 | + $this->serverContainer->getURLGenerator() |
|
206 | + ); |
|
207 | + } |
|
208 | + |
|
209 | + return $this->shareByCircleProvider; |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * @inheritdoc |
|
215 | + */ |
|
216 | + public function getProvider($id) { |
|
217 | + $provider = null; |
|
218 | + if ($id === 'ocinternal') { |
|
219 | + $provider = $this->defaultShareProvider(); |
|
220 | + } else if ($id === 'ocFederatedSharing') { |
|
221 | + $provider = $this->federatedShareProvider(); |
|
222 | + } else if ($id === 'ocMailShare') { |
|
223 | + $provider = $this->getShareByMailProvider(); |
|
224 | + } else if ($id === 'ocCircleShare') { |
|
225 | + $provider = $this->getShareByCircleProvider(); |
|
226 | + } |
|
227 | + |
|
228 | + if ($provider === null) { |
|
229 | + throw new ProviderException('No provider with id .' . $id . ' found.'); |
|
230 | + } |
|
231 | + |
|
232 | + return $provider; |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * @inheritdoc |
|
237 | + */ |
|
238 | + public function getProviderForType($shareType) { |
|
239 | + $provider = null; |
|
240 | + |
|
241 | + if ($shareType === \OCP\Share::SHARE_TYPE_USER || |
|
242 | + $shareType === \OCP\Share::SHARE_TYPE_GROUP || |
|
243 | + $shareType === \OCP\Share::SHARE_TYPE_LINK |
|
244 | + ) { |
|
245 | + $provider = $this->defaultShareProvider(); |
|
246 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
247 | + $provider = $this->federatedShareProvider(); |
|
248 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
249 | + $provider = $this->getShareByMailProvider(); |
|
250 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
251 | + $provider = $this->getShareByCircleProvider(); |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + if ($provider === null) { |
|
256 | + throw new ProviderException('No share provider for share type ' . $shareType); |
|
257 | + } |
|
258 | + |
|
259 | + return $provider; |
|
260 | + } |
|
261 | + |
|
262 | + public function getAllProviders() { |
|
263 | + $shares = [$this->defaultShareProvider(), $this->federatedShareProvider()]; |
|
264 | + $shareByMail = $this->getShareByMailProvider(); |
|
265 | + if ($shareByMail !== null) { |
|
266 | + $shares[] = $shareByMail; |
|
267 | + } |
|
268 | + $shareByCircle = $this->getShareByCircleProvider(); |
|
269 | + if ($shareByCircle !== null) { |
|
270 | + $shares[] = $shareByCircle; |
|
271 | + } |
|
272 | + |
|
273 | + return $shares; |
|
274 | + } |
|
275 | 275 | } |
@@ -65,7 +65,7 @@ |
||
65 | 65 | $eventDispatcher->addListener(MapperEvent::EVENT_ASSIGN, $mapperListener); |
66 | 66 | $eventDispatcher->addListener(MapperEvent::EVENT_UNASSIGN, $mapperListener); |
67 | 67 | |
68 | -\OCA\Files\App::getNavigationManager()->add(function () { |
|
68 | +\OCA\Files\App::getNavigationManager()->add(function() { |
|
69 | 69 | $l = \OC::$server->getL10N('systemtags'); |
70 | 70 | return [ |
71 | 71 | 'id' => 'systemtagsfilter', |
@@ -30,22 +30,22 @@ discard block |
||
30 | 30 | |
31 | 31 | $eventDispatcher = \OC::$server->getEventDispatcher(); |
32 | 32 | $eventDispatcher->addListener( |
33 | - 'OCA\Files::loadAdditionalScripts', |
|
34 | - function() { |
|
35 | - // FIXME: no public API for these ? |
|
36 | - \OCP\Util::addScript('oc-backbone-webdav'); |
|
37 | - \OCP\Util::addScript('systemtags/merged'); |
|
38 | - \OCP\Util::addScript('systemtags', 'merged'); |
|
39 | - \OCP\Util::addStyle('systemtags'); |
|
40 | - \OCP\Util::addStyle('systemtags', 'systemtagsfilelist'); |
|
41 | - } |
|
33 | + 'OCA\Files::loadAdditionalScripts', |
|
34 | + function() { |
|
35 | + // FIXME: no public API for these ? |
|
36 | + \OCP\Util::addScript('oc-backbone-webdav'); |
|
37 | + \OCP\Util::addScript('systemtags/merged'); |
|
38 | + \OCP\Util::addScript('systemtags', 'merged'); |
|
39 | + \OCP\Util::addStyle('systemtags'); |
|
40 | + \OCP\Util::addStyle('systemtags', 'systemtagsfilelist'); |
|
41 | + } |
|
42 | 42 | ); |
43 | 43 | |
44 | 44 | $managerListener = function(ManagerEvent $event) { |
45 | - $application = new \OCP\AppFramework\App('systemtags'); |
|
46 | - /** @var \OCA\SystemTags\Activity\Listener $listener */ |
|
47 | - $listener = $application->getContainer()->query(Listener::class); |
|
48 | - $listener->event($event); |
|
45 | + $application = new \OCP\AppFramework\App('systemtags'); |
|
46 | + /** @var \OCA\SystemTags\Activity\Listener $listener */ |
|
47 | + $listener = $application->getContainer()->query(Listener::class); |
|
48 | + $listener->event($event); |
|
49 | 49 | }; |
50 | 50 | |
51 | 51 | $eventDispatcher->addListener(ManagerEvent::EVENT_CREATE, $managerListener); |
@@ -53,23 +53,23 @@ discard block |
||
53 | 53 | $eventDispatcher->addListener(ManagerEvent::EVENT_UPDATE, $managerListener); |
54 | 54 | |
55 | 55 | $mapperListener = function(MapperEvent $event) { |
56 | - $application = new \OCP\AppFramework\App('systemtags'); |
|
57 | - /** @var \OCA\SystemTags\Activity\Listener $listener */ |
|
58 | - $listener = $application->getContainer()->query(Listener::class); |
|
59 | - $listener->mapperEvent($event); |
|
56 | + $application = new \OCP\AppFramework\App('systemtags'); |
|
57 | + /** @var \OCA\SystemTags\Activity\Listener $listener */ |
|
58 | + $listener = $application->getContainer()->query(Listener::class); |
|
59 | + $listener->mapperEvent($event); |
|
60 | 60 | }; |
61 | 61 | |
62 | 62 | $eventDispatcher->addListener(MapperEvent::EVENT_ASSIGN, $mapperListener); |
63 | 63 | $eventDispatcher->addListener(MapperEvent::EVENT_UNASSIGN, $mapperListener); |
64 | 64 | |
65 | 65 | \OCA\Files\App::getNavigationManager()->add(function () { |
66 | - $l = \OC::$server->getL10N('systemtags'); |
|
67 | - return [ |
|
68 | - 'id' => 'systemtagsfilter', |
|
69 | - 'appname' => 'systemtags', |
|
70 | - 'script' => 'list.php', |
|
71 | - 'order' => 25, |
|
72 | - 'name' => $l->t('Tags'), |
|
73 | - ]; |
|
66 | + $l = \OC::$server->getL10N('systemtags'); |
|
67 | + return [ |
|
68 | + 'id' => 'systemtagsfilter', |
|
69 | + 'appname' => 'systemtags', |
|
70 | + 'script' => 'list.php', |
|
71 | + 'order' => 25, |
|
72 | + 'name' => $l->t('Tags'), |
|
73 | + ]; |
|
74 | 74 | }); |
75 | 75 |
@@ -30,22 +30,22 @@ |
||
30 | 30 | |
31 | 31 | $manager = \OC::$server->getNotificationManager(); |
32 | 32 | $manager->registerNotifier(function() { |
33 | - return \OC::$server->query(Notifier::class); |
|
33 | + return \OC::$server->query(Notifier::class); |
|
34 | 34 | }, function() { |
35 | - $l = \OC::$server->getL10N('files_sharing'); |
|
36 | - return [ |
|
37 | - 'id' => 'files_sharing', |
|
38 | - 'name' => $l->t('Federated sharing'), |
|
39 | - ]; |
|
35 | + $l = \OC::$server->getL10N('files_sharing'); |
|
36 | + return [ |
|
37 | + 'id' => 'files_sharing', |
|
38 | + 'name' => $l->t('Federated sharing'), |
|
39 | + ]; |
|
40 | 40 | }); |
41 | 41 | |
42 | 42 | $federatedShareProvider = $app->getFederatedShareProvider(); |
43 | 43 | |
44 | 44 | $eventDispatcher->addListener( |
45 | - 'OCA\Files::loadAdditionalScripts', |
|
46 | - function() use ($federatedShareProvider) { |
|
47 | - if ($federatedShareProvider->isIncomingServer2serverShareEnabled()) { |
|
48 | - \OCP\Util::addScript('federatedfilesharing', 'external'); |
|
49 | - } |
|
50 | - } |
|
45 | + 'OCA\Files::loadAdditionalScripts', |
|
46 | + function() use ($federatedShareProvider) { |
|
47 | + if ($federatedShareProvider->isIncomingServer2serverShareEnabled()) { |
|
48 | + \OCP\Util::addScript('federatedfilesharing', 'external'); |
|
49 | + } |
|
50 | + } |
|
51 | 51 | ); |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | |
51 | 51 | $config = \OC::$server->getConfig(); |
52 | 52 | if ($config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes') { |
53 | - \OCA\Files\App::getNavigationManager()->add(function () { |
|
53 | + \OCA\Files\App::getNavigationManager()->add(function() { |
|
54 | 54 | $l = \OC::$server->getL10N('files_sharing'); |
55 | 55 | return [ |
56 | 56 | 'id' => 'sharingin', |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | }); |
63 | 63 | |
64 | 64 | if (\OCP\Util::isSharingDisabledForUser() === false) { |
65 | - \OCA\Files\App::getNavigationManager()->add(function () { |
|
65 | + \OCA\Files\App::getNavigationManager()->add(function() { |
|
66 | 66 | $l = \OC::$server->getL10N('files_sharing'); |
67 | 67 | return [ |
68 | 68 | 'id' => 'sharingout', |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | |
76 | 76 | // Check if sharing by link is enabled |
77 | 77 | if ($config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes') { |
78 | - \OCA\Files\App::getNavigationManager()->add(function () { |
|
78 | + \OCA\Files\App::getNavigationManager()->add(function() { |
|
79 | 79 | $l = \OC::$server->getL10N('files_sharing'); |
80 | 80 | return [ |
81 | 81 | 'id' => 'sharinglinks', |
@@ -36,50 +36,50 @@ |
||
36 | 36 | |
37 | 37 | $eventDispatcher = \OC::$server->getEventDispatcher(); |
38 | 38 | $eventDispatcher->addListener( |
39 | - 'OCA\Files::loadAdditionalScripts', |
|
40 | - function() { |
|
41 | - \OCP\Util::addStyle('files_sharing', 'mergedAdditionalStyles'); |
|
42 | - \OCP\Util::addScript('files_sharing', 'additionalScripts'); |
|
43 | - } |
|
39 | + 'OCA\Files::loadAdditionalScripts', |
|
40 | + function() { |
|
41 | + \OCP\Util::addStyle('files_sharing', 'mergedAdditionalStyles'); |
|
42 | + \OCP\Util::addScript('files_sharing', 'additionalScripts'); |
|
43 | + } |
|
44 | 44 | ); |
45 | 45 | |
46 | 46 | $config = \OC::$server->getConfig(); |
47 | 47 | if ($config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes') { |
48 | - \OCA\Files\App::getNavigationManager()->add(function () { |
|
49 | - $l = \OC::$server->getL10N('files_sharing'); |
|
50 | - return [ |
|
51 | - 'id' => 'sharingin', |
|
52 | - 'appname' => 'files_sharing', |
|
53 | - 'script' => 'list.php', |
|
54 | - 'order' => 15, |
|
55 | - 'name' => $l->t('Shared with you'), |
|
56 | - ]; |
|
57 | - }); |
|
48 | + \OCA\Files\App::getNavigationManager()->add(function () { |
|
49 | + $l = \OC::$server->getL10N('files_sharing'); |
|
50 | + return [ |
|
51 | + 'id' => 'sharingin', |
|
52 | + 'appname' => 'files_sharing', |
|
53 | + 'script' => 'list.php', |
|
54 | + 'order' => 15, |
|
55 | + 'name' => $l->t('Shared with you'), |
|
56 | + ]; |
|
57 | + }); |
|
58 | 58 | |
59 | - if (\OCP\Util::isSharingDisabledForUser() === false) { |
|
60 | - \OCA\Files\App::getNavigationManager()->add(function () { |
|
61 | - $l = \OC::$server->getL10N('files_sharing'); |
|
62 | - return [ |
|
63 | - 'id' => 'sharingout', |
|
64 | - 'appname' => 'files_sharing', |
|
65 | - 'script' => 'list.php', |
|
66 | - 'order' => 16, |
|
67 | - 'name' => $l->t('Shared with others'), |
|
68 | - ]; |
|
69 | - }); |
|
59 | + if (\OCP\Util::isSharingDisabledForUser() === false) { |
|
60 | + \OCA\Files\App::getNavigationManager()->add(function () { |
|
61 | + $l = \OC::$server->getL10N('files_sharing'); |
|
62 | + return [ |
|
63 | + 'id' => 'sharingout', |
|
64 | + 'appname' => 'files_sharing', |
|
65 | + 'script' => 'list.php', |
|
66 | + 'order' => 16, |
|
67 | + 'name' => $l->t('Shared with others'), |
|
68 | + ]; |
|
69 | + }); |
|
70 | 70 | |
71 | - // Check if sharing by link is enabled |
|
72 | - if ($config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes') { |
|
73 | - \OCA\Files\App::getNavigationManager()->add(function () { |
|
74 | - $l = \OC::$server->getL10N('files_sharing'); |
|
75 | - return [ |
|
76 | - 'id' => 'sharinglinks', |
|
77 | - 'appname' => 'files_sharing', |
|
78 | - 'script' => 'list.php', |
|
79 | - 'order' => 17, |
|
80 | - 'name' => $l->t('Shared by link'), |
|
81 | - ]; |
|
82 | - }); |
|
83 | - } |
|
84 | - } |
|
71 | + // Check if sharing by link is enabled |
|
72 | + if ($config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes') { |
|
73 | + \OCA\Files\App::getNavigationManager()->add(function () { |
|
74 | + $l = \OC::$server->getL10N('files_sharing'); |
|
75 | + return [ |
|
76 | + 'id' => 'sharinglinks', |
|
77 | + 'appname' => 'files_sharing', |
|
78 | + 'script' => 'list.php', |
|
79 | + 'order' => 17, |
|
80 | + 'name' => $l->t('Shared by link'), |
|
81 | + ]; |
|
82 | + }); |
|
83 | + } |
|
84 | + } |
|
85 | 85 | } |