|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Circles - Bring cloud-users closer together. |
|
4
|
|
|
* |
|
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
6
|
|
|
* later. See the COPYING file. |
|
7
|
|
|
* |
|
8
|
|
|
* @author Maxence Lange <[email protected]> |
|
9
|
|
|
* @copyright 2017 |
|
10
|
|
|
* @license GNU AGPL version 3 or any later version |
|
11
|
|
|
* |
|
12
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
13
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
14
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
15
|
|
|
* License, or (at your option) any later version. |
|
16
|
|
|
* |
|
17
|
|
|
* This program is distributed in the hope that it will be useful, |
|
18
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20
|
|
|
* GNU Affero General Public License for more details. |
|
21
|
|
|
* |
|
22
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
23
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
24
|
|
|
* |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
namespace OCA\Circles\Controller; |
|
28
|
|
|
|
|
29
|
|
|
use Exception; |
|
30
|
|
|
use OCA\Circles\Model\SharingFrame; |
|
31
|
|
|
use OCP\AppFramework\Http\DataResponse; |
|
32
|
|
|
|
|
33
|
|
|
class SharesController extends BaseController { |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Called by the JavaScript API when creating a new Share item that will be |
|
38
|
|
|
* broadcasted to the circle itself, and any other circle linked to it. |
|
39
|
|
|
* |
|
40
|
|
|
* @NoAdminRequired |
|
41
|
|
|
* @NoSubAdminRequired |
|
42
|
|
|
* |
|
43
|
|
|
* @param string $circleUniqueId |
|
44
|
|
|
* @param string $source |
|
45
|
|
|
* @param string $type |
|
46
|
|
|
* @param array $payload |
|
47
|
|
|
* |
|
48
|
|
|
* @return DataResponse |
|
49
|
|
|
*/ |
|
50
|
|
|
public function create($circleUniqueId, $source, $type, $payload) { |
|
51
|
|
|
|
|
52
|
|
|
try { |
|
53
|
|
|
$share = new SharingFrame($source, $type); |
|
54
|
|
|
$share->setPayload($payload); |
|
55
|
|
|
|
|
56
|
|
|
$this->sharesService->createFrame($circleUniqueId, $share); |
|
57
|
|
|
} catch (\Exception $e) { |
|
58
|
|
|
return $this->fail( |
|
59
|
|
|
[ |
|
60
|
|
|
'circle_id' => $circleUniqueId, |
|
61
|
|
|
'source' => $source, |
|
62
|
|
|
'type' => $type, |
|
63
|
|
|
'payload' => $payload, |
|
64
|
|
|
'error' => $e->getMessage() |
|
65
|
|
|
] |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
return $this->success( |
|
70
|
|
|
[ |
|
71
|
|
|
'circle_id' => $circleUniqueId, |
|
72
|
|
|
'source' => $source, |
|
73
|
|
|
'type' => $type, |
|
74
|
|
|
'payload' => $payload |
|
75
|
|
|
] |
|
76
|
|
|
); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* initShareDelivery() |
|
82
|
|
|
* |
|
83
|
|
|
* Note: this function will close the request mid-run from the client but will still |
|
84
|
|
|
* running its process. |
|
85
|
|
|
* |
|
86
|
|
|
* Called by locally, the function will get the SharingFrame by its uniqueId from the database. |
|
87
|
|
|
* After closing the socket, will broadcast the Frame locally and - if Federated Shares are |
|
88
|
|
|
* enable - will deliver it to each remote circles linked to the circle the Payload belongs to. |
|
89
|
|
|
* |
|
90
|
|
|
* A status response is sent to free the client process before starting to broadcast the item |
|
91
|
|
|
* to other federated links. |
|
92
|
|
|
* |
|
93
|
|
|
* @PublicPage |
|
94
|
|
|
* @NoCSRFRequired |
|
95
|
|
|
* |
|
96
|
|
|
* @param string $circleId |
|
97
|
|
|
* @param string $frameId |
|
98
|
|
|
* |
|
99
|
|
|
* @return DataResponse |
|
|
|
|
|
|
100
|
|
|
*/ |
|
101
|
|
|
public function initShareDelivery($circleId, $frameId) { |
|
102
|
|
|
|
|
103
|
|
|
try { |
|
104
|
|
|
$frame = $this->sharesService->getFrameFromUniqueId($circleId, $frameId); |
|
105
|
|
|
} catch (Exception $e) { |
|
106
|
|
|
return $this->fail($e->getMessage()); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
// We don't want to keep the connection up |
|
110
|
|
|
$this->miscService->asyncAndLeaveClientOutOfThis('done'); |
|
111
|
|
|
|
|
112
|
|
|
$this->broadcastService->broadcastFrame($frame); |
|
|
|
|
|
|
113
|
|
|
|
|
114
|
|
|
// TODO - do not update cloudId to avoid duplicate, use it's own field and keep cloudId |
|
115
|
|
|
$this->federatedService->updateFrameWithCloudId($frame); |
|
|
|
|
|
|
116
|
|
|
if ($this->configService->isFederatedCirclesAllowed()) { |
|
117
|
|
|
$this->federatedService->sendRemoteShare($frame); |
|
|
|
|
|
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
exit(); |
|
|
|
|
|
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.