Skip to content

Commit

Permalink
feat(calls): Allow moderators to download a call participants list
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Oct 14, 2024
1 parent 2fa9f94 commit eea49d8
Show file tree
Hide file tree
Showing 6 changed files with 328 additions and 0 deletions.
2 changes: 2 additions & 0 deletions appinfo/routes/routesRoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
])],
/** @see \OCA\Talk\Controller\RoomController::getParticipants() */
['name' => 'Room#getParticipants', 'url' => '/api/{apiVersion}/room/{token}/participants', 'verb' => 'GET', 'requirements' => $requirementsWithToken],
/** @see \OCA\Talk\Controller\RoomController::downloadParticipants() */
['name' => 'Room#downloadParticipants', 'url' => '/api/{apiVersion}/room/{token}/participants/download', 'verb' => 'GET', 'requirements' => $requirementsWithToken],
/** @see \OCA\Talk\Controller\RoomController::getBreakoutRoomParticipants() */
['name' => 'Room#getBreakoutRoomParticipants', 'url' => '/api/{apiVersion}/room/{token}/breakout-rooms/participants', 'verb' => 'GET', 'requirements' => $requirementsWithToken],
/** @see \OCA\Talk\Controller\RoomController::addParticipantToRoom() */
Expand Down
46 changes: 46 additions & 0 deletions lib/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\Attribute\PublicPage;
use OCP\AppFramework\Http\DataDownloadResponse;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Federation\ICloudIdManager;
Expand Down Expand Up @@ -1103,6 +1105,50 @@ protected function formatParticipantList(array $participants, bool $includeStatu
return new DataResponse(array_values($results), Http::STATUS_OK, $headers);
}

/**
* Download the list of current call participants
*
* @param 'csv'|'pdf' $format Download format
* @return DataDownloadResponse<Http::STATUS_OK, 'text/csv'|'application/pdf', array{}>|Response<Http::STATUS_BAD_REQUEST, array{}>
*
* 200: List of participants in the call downloaded in the requested format
* 400: No call in progress
*/
#[PublicPage]
#[RequireModeratorParticipant]
public function downloadParticipants(string $format = 'csv'): DataDownloadResponse|Response {
$timeout = $this->timeFactory->getTime() - Session::SESSION_TIMEOUT;
$participants = $this->participantService->getParticipantsInCall($this->room, $timeout);

if (empty($participants)) {
return new Response(Http::STATUS_BAD_REQUEST);
}

if ($format !== 'csv' && $format !== 'pdf') {
// Unsupported format
return new Response(Http::STATUS_BAD_REQUEST);
}
if ($format !== 'csv') {
// FIXME Remove once pdf was implemented.
return new Response(Http::STATUS_BAD_REQUEST);
}

$output = fopen('php://memory', 'w');
fputcsv($output, [
'name',
'type',
'identifier',
]);

foreach ($participants as $participant) {
fputcsv($output, [$participant->getAttendee()->getDisplayName(), $participant->getAttendee()->getActorType(), $participant->getAttendee()->getActorId()]);
}

fseek($output, 0);

return new DataDownloadResponse(stream_get_contents($output), 'participants.csv', 'text/csv');
}

/**
* Add a participant to a room
*
Expand Down
86 changes: 86 additions & 0 deletions openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -12915,6 +12915,92 @@
}
}
},
"/ocs/v2.php/apps/spreed/api/{apiVersion}/room/{token}/participants/download": {
"get": {
"operationId": "room-download-participants",
"summary": "Download the list of current call participants",
"tags": [
"room"
],
"security": [
{},
{
"bearer_auth": []
},
{
"basic_auth": []
}
],
"parameters": [
{
"name": "apiVersion",
"in": "path",
"required": true,
"schema": {
"type": "string",
"enum": [
"v4"
],
"default": "v4"
}
},
{
"name": "token",
"in": "path",
"required": true,
"schema": {
"type": "string",
"pattern": "^[a-z0-9]{4,30}$"
}
},
{
"name": "format",
"in": "query",
"description": "Download format",
"schema": {
"type": "string",
"default": "csv",
"enum": [
"csv",
"pdf"
]
}
},
{
"name": "OCS-APIRequest",
"in": "header",
"description": "Required to be true for the API request to pass",
"required": true,
"schema": {
"type": "boolean",
"default": true
}
}
],
"responses": {
"200": {
"description": "List of participants in the call downloaded in the requested format",
"content": {
"text/csv": {
"schema": {
"type": "string",
"format": "binary"
}
},
"application/pdf": {
"schema": {
"type": "string",
"format": "binary"
}
}
}
},
"400": {
"description": "No call in progress"
}
}
}
},
"/ocs/v2.php/apps/spreed/api/{apiVersion}/room/{token}/breakout-rooms/participants": {
"get": {
"operationId": "room-get-breakout-room-participants",
Expand Down
86 changes: 86 additions & 0 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -13049,6 +13049,92 @@
}
}
},
"/ocs/v2.php/apps/spreed/api/{apiVersion}/room/{token}/participants/download": {
"get": {
"operationId": "room-download-participants",
"summary": "Download the list of current call participants",
"tags": [
"room"
],
"security": [
{},
{
"bearer_auth": []
},
{
"basic_auth": []
}
],
"parameters": [
{
"name": "apiVersion",
"in": "path",
"required": true,
"schema": {
"type": "string",
"enum": [
"v4"
],
"default": "v4"
}
},
{
"name": "token",
"in": "path",
"required": true,
"schema": {
"type": "string",
"pattern": "^[a-z0-9]{4,30}$"
}
},
{
"name": "format",
"in": "query",
"description": "Download format",
"schema": {
"type": "string",
"default": "csv",
"enum": [
"csv",
"pdf"
]
}
},
{
"name": "OCS-APIRequest",
"in": "header",
"description": "Required to be true for the API request to pass",
"required": true,
"schema": {
"type": "boolean",
"default": true
}
}
],
"responses": {
"200": {
"description": "List of participants in the call downloaded in the requested format",
"content": {
"text/csv": {
"schema": {
"type": "string",
"format": "binary"
}
},
"application/pdf": {
"schema": {
"type": "string",
"format": "binary"
}
}
}
},
"400": {
"description": "No call in progress"
}
}
}
},
"/ocs/v2.php/apps/spreed/api/{apiVersion}/room/{token}/breakout-rooms/participants": {
"get": {
"operationId": "room-get-breakout-room-participants",
Expand Down
54 changes: 54 additions & 0 deletions src/types/openapi/openapi-full.ts
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,23 @@ export type paths = {
patch?: never;
trace?: never;
};
"/ocs/v2.php/apps/spreed/api/{apiVersion}/room/{token}/participants/download": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
/** Download the list of current call participants */
get: operations["room-download-participants"];
put?: never;
post?: never;
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/ocs/v2.php/apps/spreed/api/{apiVersion}/room/{token}/breakout-rooms/participants": {
parameters: {
query?: never;
Expand Down Expand Up @@ -6814,6 +6831,43 @@ export interface operations {
};
};
};
"room-download-participants": {
parameters: {
query?: {
/** @description Download format */
format?: "csv" | "pdf";
};
header: {
/** @description Required to be true for the API request to pass */
"OCS-APIRequest": boolean;
};
path: {
apiVersion: "v4";
token: string;
};
cookie?: never;
};
requestBody?: never;
responses: {
/** @description List of participants in the call downloaded in the requested format */
200: {
headers: {
[name: string]: unknown;
};
content: {
"text/csv": string;
"application/pdf": string;
};
};
/** @description No call in progress */
400: {
headers: {
[name: string]: unknown;
};
content?: never;
};
};
};
"room-get-breakout-room-participants": {
parameters: {
query?: {
Expand Down
54 changes: 54 additions & 0 deletions src/types/openapi/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,23 @@ export type paths = {
patch?: never;
trace?: never;
};
"/ocs/v2.php/apps/spreed/api/{apiVersion}/room/{token}/participants/download": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
/** Download the list of current call participants */
get: operations["room-download-participants"];
put?: never;
post?: never;
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/ocs/v2.php/apps/spreed/api/{apiVersion}/room/{token}/breakout-rooms/participants": {
parameters: {
query?: never;
Expand Down Expand Up @@ -6395,6 +6412,43 @@ export interface operations {
};
};
};
"room-download-participants": {
parameters: {
query?: {
/** @description Download format */
format?: "csv" | "pdf";
};
header: {
/** @description Required to be true for the API request to pass */
"OCS-APIRequest": boolean;
};
path: {
apiVersion: "v4";
token: string;
};
cookie?: never;
};
requestBody?: never;
responses: {
/** @description List of participants in the call downloaded in the requested format */
200: {
headers: {
[name: string]: unknown;
};
content: {
"text/csv": string;
"application/pdf": string;
};
};
/** @description No call in progress */
400: {
headers: {
[name: string]: unknown;
};
content?: never;
};
};
};
"room-get-breakout-room-participants": {
parameters: {
query?: {
Expand Down

0 comments on commit eea49d8

Please sign in to comment.