Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(meetings): Allow moderators to schedule a meeting #14073

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions appinfo/routes/routesRoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,7 @@
['name' => 'Room#unarchiveConversation', 'url' => '/api/{apiVersion}/room/{token}/archive', 'verb' => 'DELETE', 'requirements' => $requirementsWithToken],
/** @see \OCA\Talk\Controller\RoomController::importEmailsAsParticipants() */
['name' => 'Room#importEmailsAsParticipants', 'url' => '/api/{apiVersion}/room/{token}/import-emails', 'verb' => 'POST', 'requirements' => $requirementsWithToken],
/** @see \OCA\Talk\Controller\RoomController::scheduleMeeting() */
['name' => 'Room#scheduleMeeting', 'url' => '/api/{apiVersion}/room/{token}/meeting', 'verb' => 'POST', 'requirements' => $requirementsWithToken],
],
];
1 change: 1 addition & 0 deletions docs/capabilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,5 @@
* `config => conversations => force-passwords` - Whether passwords are enforced for public rooms
* `conversation-creation-password` - Whether the endpoints for creating public conversations or making a conversation public support setting a password
* `call-notification-state-api` (local) - Whether the endpoints exists for checking if a call notification should be dismissed
* `schedule-meeting` (local) - Whether logged-in participants can schedule meetings
* `config => chat => has-translation-task-providers` (local) - When true, translations can be done using the [OCS TaskProcessing API](https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/ocs-taskprocessing-api.html).
2 changes: 2 additions & 0 deletions lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class Capabilities implements IPublicCapability {
'email-csv-import',
'conversation-creation-password',
'call-notification-state-api',
'schedule-meeting',
];

public const CONDITIONAL_FEATURES = [
Expand All @@ -133,6 +134,7 @@ class Capabilities implements IPublicCapability {
'archived-conversations-v2',
'chat-summary-api',
'call-notification-state-api',
'schedule-meeting',
];

public const LOCAL_CONFIGS = [
Expand Down
100 changes: 100 additions & 0 deletions lib/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
use OCP\AppFramework\Http\Attribute\PublicPage;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Calendar\Exceptions\CalendarException;
use OCP\Calendar\ICreateFromString;
use OCP\Calendar\IManager as ICalendarManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Federation\ICloudIdManager;
use OCP\IConfig;
Expand All @@ -79,6 +82,7 @@
use OCP\IL10N;
use OCP\IPhoneNumberUtil;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Security\Bruteforce\IThrottler;
Expand Down Expand Up @@ -111,6 +115,7 @@ public function __construct(
protected SessionService $sessionService,
protected GuestManager $guestManager,
protected IUserStatusManager $statusManager,
protected ICalendarManager $calendarManager,
protected IEventDispatcher $dispatcher,
protected ITimeFactory $timeFactory,
protected ChecksumVerificationService $checksumVerificationService,
Expand All @@ -125,6 +130,7 @@ public function __construct(
protected Capabilities $capabilities,
protected FederationManager $federationManager,
protected BanService $banService,
protected IURLGenerator $url,
protected IL10N $l,
) {
parent::__construct($appName, $request);
Expand Down Expand Up @@ -2554,4 +2560,98 @@ public function getCapabilities(): DataResponse {

return new DataResponse($data, Http::STATUS_OK, $headers);
}

/**
* Schedule a meeting for a conversation
*
* Required capability: `schedule-meeting`
*
* @param string $calendarUri Last part of the calendar URI as seen by the participant e.g. 'personal' or 'company_shared_by_other_user'
* @param int $start Unix timestamp when the meeting starts
* @param ?int $end Unix timestamp when the meeting ends, falls back to 60 minutes after start
* @param ?string $title Title or summary of the event, falling back to the conversation name if none is given
* @param ?string $description Description of the event, falling back to the conversation description if none is given
* @return DataResponse<Http::STATUS_OK, null, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, array{error: 'calendar'|'email'|'end'|'start'}, array{}>
*
* 200: Meeting scheduled
* 400: Meeting could not be created successfully
*/
#[NoAdminRequired]
#[RequireLoggedInModeratorParticipant]
public function scheduleMeeting(string $calendarUri, int $start, ?int $end = null, ?string $title = null, ?string $description = null): DataResponse {
$eventBuilder = $this->calendarManager->createEventBuilder();
$calendars = $this->calendarManager->getCalendarsForPrincipal('principals/users/' . $this->userId, [$calendarUri]);

if (empty($calendars)) {
return new DataResponse(['error' => 'calendar'], Http::STATUS_BAD_REQUEST);
}

/** @var ICreateFromString $calendar */
$calendar = array_pop($calendars);

$user = $this->userManager->get($this->userId);
if (!$user instanceof IUser || $user->getEMailAddress() === null) {
return new DataResponse(['error' => 'email'], Http::STATUS_BAD_REQUEST);
}

$startDate = $this->timeFactory->getDateTime('@' . $start);
if ($start < $this->timeFactory->getTime()) {
return new DataResponse(['error' => 'start'], Http::STATUS_BAD_REQUEST);
}

if ($end !== null) {
$endDate = $this->timeFactory->getDateTime('@' . $end);
if ($start >= $end) {
return new DataResponse(['error' => 'end'], Http::STATUS_BAD_REQUEST);
}
} else {
$endDate = clone $startDate;
$endDate->add(new \DateInterval('PT1H'));
}

$eventBuilder->setLocation(
$this->url->linkToRouteAbsolute(
'spreed.Page.showCall',
['token' => $this->room->getToken()]
)
);
$eventBuilder->setSummary($title ?: $this->room->getDisplayName($this->userId));
$eventBuilder->setDescription($description ?: $this->room->getDescription());
$eventBuilder->setOrganizer($user->getEMailAddress(), $user->getDisplayName() ?: $this->userId);
$eventBuilder->setStartDate($startDate);
$eventBuilder->setEndDate($endDate);

$userIds = $this->participantService->getParticipantUserIds($this->room);
foreach ($userIds as $userId) {
$targetUser = $this->userManager->get($userId);
if (!$targetUser instanceof IUser) {
continue;
}
if ($targetUser->getEMailAddress() === null) {
continue;
}

$eventBuilder->addAttendee(
$targetUser->getEMailAddress(),
$targetUser->getDisplayName(),
);
}

$emailGuests = $this->participantService->getParticipantsByActorType($this->room, Attendee::ACTOR_EMAILS);
foreach ($emailGuests as $emailGuest) {
$eventBuilder->addAttendee(
$emailGuest->getAttendee()->getInvitedCloudId(),
$emailGuest->getAttendee()->getDisplayName(),
);
}

try {
$eventBuilder->createInCalendar($calendar);
} catch (\InvalidArgumentException|CalendarException $e) {
$this->logger->debug('Failed to get calendar to schedule a meeting', ['exception' => $e]);
return new DataResponse(['error' => 'calendar'], Http::STATUS_BAD_REQUEST);
}

return new DataResponse(null, Http::STATUS_OK);
}
}
168 changes: 168 additions & 0 deletions openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -17525,6 +17525,174 @@
}
}
},
"/ocs/v2.php/apps/spreed/api/{apiVersion}/room/{token}/meeting": {
"post": {
"operationId": "room-schedule-meeting",
"summary": "Schedule a meeting for a conversation",
"description": "Required capability: `schedule-meeting`",
"tags": [
"room"
],
"security": [
{
"bearer_auth": []
},
{
"basic_auth": []
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"calendarUri",
"start"
],
"properties": {
"calendarUri": {
"type": "string",
"description": "Last part of the calendar URI as seen by the participant e.g. 'personal' or 'company_shared_by_other_user'"
},
"start": {
"type": "integer",
"format": "int64",
"description": "Unix timestamp when the meeting starts"
},
"end": {
"type": "integer",
"format": "int64",
"nullable": true,
"description": "Unix timestamp when the meeting ends, falls back to 60 minutes after start"
},
"title": {
"type": "string",
"nullable": true,
"description": "Title or summary of the event, falling back to the conversation name if none is given"
},
"description": {
"type": "string",
"nullable": true,
"description": "Description of the event, falling back to the conversation description if none is given"
}
}
}
}
}
},
"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": "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": "Meeting scheduled",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"nullable": true
}
}
}
}
}
}
}
},
"400": {
"description": "Meeting could not be created successfully",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"type": "object",
"required": [
"error"
],
"properties": {
"error": {
"type": "string",
"enum": [
"calendar",
"email",
"end",
"start"
]
}
}
}
}
}
}
}
}
}
}
}
}
},
"/ocs/v2.php/apps/spreed/api/{apiVersion}/settings/user": {
"post": {
"operationId": "settings-set-user-setting",
Expand Down
Loading
Loading