forked from littleredbutton/cloud_bbb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerController.php
More file actions
169 lines (127 loc) · 3.93 KB
/
ServerController.php
File metadata and controls
169 lines (127 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
namespace OCA\BigBlueButton\Controller;
use OCA\BigBlueButton\BigBlueButton\API;
use OCA\BigBlueButton\Permission;
use OCA\BigBlueButton\Service\RoomService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\IRequest;
class ServerController extends Controller {
/** @var RoomService */
private $service;
/** @var API */
private $server;
/** @var Permission */
private $permission;
/** @var string */
private $userId;
public function __construct(
$appName,
IRequest $request,
RoomService $service,
API $server,
Permission $permission,
$UserId
) {
parent::__construct($appName, $request);
$this->service = $service;
$this->server = $server;
$this->permission = $permission;
$this->userId = $UserId;
}
/**
* @NoAdminRequired
*/
public function isRunning(string $roomUid): DataResponse {
$room = $this->service->findByUid($roomUid);
if ($room === null) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
if (!$this->permission->isUser($room, $this->userId)) {
return new DataResponse([], Http::STATUS_FORBIDDEN);
}
$isRunning = $this->server->isRunning($room);
return new DataResponse($isRunning);
}
/**
* @NoAdminRequired
*/
public function insertDocument(string $roomUid, string $url, string $filename): DataResponse {
$room = $this->service->findByUid($roomUid);
if ($room === null) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
if (!$this->permission->isModerator($room, $this->userId)) {
return new DataResponse([], Http::STATUS_FORBIDDEN);
}
$success = $this->server->insertDocument($room, $url, $filename);
return new DataResponse($success);
}
/**
* @NoAdminRequired
*/
public function records(string $roomUid): DataResponse {
$room = $this->service->findByUid($roomUid);
if ($room === null) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
if (!$this->permission->isUser($room, $this->userId)) {
return new DataResponse([], Http::STATUS_FORBIDDEN);
}
$recordings = $this->server->getRecordings($room);
if (!$this->permission->isAdmin($room, $this->userId)) {
$recordings = array_values(array_filter($recordings, function ($recording) {
return $recording['published'];
}));
}
return new DataResponse($recordings);
}
/**
* @NoAdminRequired
*/
public function deleteRecord(string $recordId): DataResponse {
$record = $this->server->getRecording($recordId);
$room = $this->service->findByUid($record['meetingId']);
if ($room === null) {
return new DataResponse(false, Http::STATUS_NOT_FOUND);
}
if (!$this->permission->isAdmin($room, $this->userId)) {
return new DataResponse(false, Http::STATUS_FORBIDDEN);
}
$success = $this->server->deleteRecording($recordId);
return new DataResponse($success);
}
/**
* @NoAdminRequired
*/
public function publishRecord(string $recordId, bool $published): DataResponse {
$record = $this->server->getRecording($recordId);
$room = $this->service->findByUid($record['meetingId']);
if ($room === null) {
return new DataResponse(false, Http::STATUS_NOT_FOUND);
}
if (!$this->permission->isAdmin($room, $this->userId)) {
return new DataResponse(false, Http::STATUS_FORBIDDEN);
}
$success = $this->server->publishRecording($recordId, $published);
return new DataResponse($success);
}
public function check(?string $url, ?string $secret): DataResponse {
if ($url === null || empty($url) || $secret === null || empty($secret)) {
return new DataResponse(false);
}
return new DataResponse($this->server->check($url, $secret));
}
public function version(?string $url): DataResponse {
if ($url === null || empty($url)) {
return new DataResponse(false, Http::STATUS_NOT_FOUND);
}
try {
$version = $this->server->getVersion($url);
} catch (\Exception $e) {
return new DataResponse(false, Http::STATUS_NOT_FOUND);
}
return new DataResponse($version);
}
}