Skip to content

Commit

Permalink
feat: Ability to invite circles
Browse files Browse the repository at this point in the history
This commit adds support for adding circles as attendees to a calendar event.
The relationship between the imported group and members will be compliant with
the iCal specification.

A circle with the title "testcircle" will be added as an attendee with iCal
attributes "CUTYPE=GROUP` and uri "mailto:circle+CIRCLEID@CIRCLE_INSTANCE".

Members of the circle will be imported as standard attendees. Each member gets
assigned to the circle group entry by assigning them to the group uri using the
iCal member property: "MEMBER='mailto:circle+CIRCLEID@CIRCLE_INSTANCE'".

Searching for circles is only enabled if the circles app is activated.

Circles added to the list of attendees get imported only once and are not
synced yet. While adding a circle, a notice about this is shown to the user.
Only members of local circles which are local users get imported.

Rendering groups in the frontend is done in a separate PR
#5396

Signed-off-by: Jonas Heinrich <[email protected]>
  • Loading branch information
Jonas Heinrich committed Oct 27, 2023
1 parent 26fe5f1 commit 4bea3c5
Show file tree
Hide file tree
Showing 9 changed files with 320 additions and 9 deletions.
9 changes: 7 additions & 2 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
* Calendar App
*
* @author Georg Ehrke
* @copyright 2018 Georg Ehrke <[email protected]>
* @author Thomas Müller
* @author Jonas Heinrich
*
* @copyright 2018 Georg Ehrke <[email protected]>
* @copyright 2016 Thomas Müller <[email protected]>
*
* @copyright 2023 Jonas Heinrich <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
Expand Down Expand Up @@ -54,6 +57,8 @@
['name' => 'contact#searchAttendee', 'url' => '/v1/autocompletion/attendee', 'verb' => 'POST'],
['name' => 'contact#searchLocation', 'url' => '/v1/autocompletion/location', 'verb' => 'POST'],
['name' => 'contact#searchPhoto', 'url' => '/v1/autocompletion/photo', 'verb' => 'POST'],
// Circles
['name' => 'contact#getCircleMembers', 'url' => '/v1/circles/getmembers', 'verb' => 'GET'],
// Settings
['name' => 'settings#setConfig', 'url' => '/v1/config/{key}', 'verb' => 'POST'],
// Tools
Expand Down
78 changes: 77 additions & 1 deletion lib/Controller/ContactController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
* @author Georg Ehrke
* @author Jakob Röhrl
* @author Christoph Wurst
* @author Jonas Heinrich
*
* @copyright 2019 Georg Ehrke <[email protected]>
* @copyright 2019 Jakob Röhrl <[email protected]>
* @copyright 2019 Christoph Wurst <[email protected]>
* @copyright 2023 Jonas Heinrich <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
Expand All @@ -31,8 +33,12 @@
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\QueryException;
use OCP\App\IAppManager;
use OCA\Circles\Exceptions\CircleNotFoundException;
use OCP\Contacts\IManager;
use OCP\IRequest;
use OCP\IUserManager;

/**
* Class ContactController
Expand All @@ -43,6 +49,12 @@ class ContactController extends Controller {
/** @var IManager */
private $contactsManager;

/** @var IAppManager */
private $appManager;

/** @var IUserManager */
private $userManager;

/**
* ContactController constructor.
*
Expand All @@ -52,9 +64,13 @@ class ContactController extends Controller {
*/
public function __construct(string $appName,
IRequest $request,
IManager $contacts) {
IManager $contacts,
IAppManager $appManager,
IUserManager $userManager) {
parent::__construct($appName, $request);
$this->contactsManager = $contacts;
$this->appManager = $appManager;
$this->userManager = $userManager;
}

/**
Expand Down Expand Up @@ -173,6 +189,66 @@ public function searchAttendee(string $search):JSONResponse {
return new JSONResponse($contacts);
}

/**
* Query members of a circle by circleId
*
* @param string $circleId CircleId to query for members
* @return JSONResponse
* @throws Exception

Check failure on line 197 in lib/Controller/ContactController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable25

UndefinedDocblockClass

lib/Controller/ContactController.php:197:13: UndefinedDocblockClass: Docblock-defined class, interface or enum named OCA\Calendar\Controller\Exception does not exist (see https://psalm.dev/200)

Check failure on line 197 in lib/Controller/ContactController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable27

UndefinedDocblockClass

lib/Controller/ContactController.php:197:13: UndefinedDocblockClass: Docblock-defined class, interface or enum named OCA\Calendar\Controller\Exception does not exist (see https://psalm.dev/200)

Check failure on line 197 in lib/Controller/ContactController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-master

UndefinedDocblockClass

lib/Controller/ContactController.php:197:13: UndefinedDocblockClass: Docblock-defined class, interface or enum named OCA\Calendar\Controller\Exception does not exist (see https://psalm.dev/200)

Check failure on line 197 in lib/Controller/ContactController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable26

UndefinedDocblockClass

lib/Controller/ContactController.php:197:13: UndefinedDocblockClass: Docblock-defined class, interface or enum named OCA\Calendar\Controller\Exception does not exist (see https://psalm.dev/200)
* @throws \OCP\AppFramework\QueryException
*
* @NoAdminRequired
*/
public function getCircleMembers(string $circleId):JSONResponse {
if (!$this->appManager->isEnabledForUser('circles') || !class_exists('\OCA\Circles\Api\v1\Circles')) {
return [];

Check failure on line 204 in lib/Controller/ContactController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable25

InvalidReturnStatement

lib/Controller/ContactController.php:204:11: InvalidReturnStatement: The inferred type 'array<never, never>' does not match the declared return type 'OCP\AppFramework\Http\JSONResponse' for OCA\Calendar\Controller\ContactController::getCircleMembers (see https://psalm.dev/128)

Check failure on line 204 in lib/Controller/ContactController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable27

InvalidReturnStatement

lib/Controller/ContactController.php:204:11: InvalidReturnStatement: The inferred type 'array<never, never>' does not match the declared return type 'OCP\AppFramework\Http\JSONResponse' for OCA\Calendar\Controller\ContactController::getCircleMembers (see https://psalm.dev/128)

Check failure on line 204 in lib/Controller/ContactController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-master

InvalidReturnStatement

lib/Controller/ContactController.php:204:11: InvalidReturnStatement: The inferred type 'array<never, never>' does not match the declared return type 'OCP\AppFramework\Http\JSONResponse' for OCA\Calendar\Controller\ContactController::getCircleMembers (see https://psalm.dev/128)

Check failure on line 204 in lib/Controller/ContactController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable26

InvalidReturnStatement

lib/Controller/ContactController.php:204:11: InvalidReturnStatement: The inferred type 'array<never, never>' does not match the declared return type 'OCP\AppFramework\Http\JSONResponse' for OCA\Calendar\Controller\ContactController::getCircleMembers (see https://psalm.dev/128)
}
if (!$this->contactsManager->isEnabled()) {
return new JSONResponse();
}

try {
$circle = \OCA\Circles\Api\v1\Circles::detailsCircle($circleId, true);

Check failure on line 211 in lib/Controller/ContactController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable25

UndefinedClass

lib/Controller/ContactController.php:211:14: UndefinedClass: Class, interface or enum named OCA\Circles\Api\v1\Circles does not exist (see https://psalm.dev/019)

Check failure on line 211 in lib/Controller/ContactController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable27

UndefinedClass

lib/Controller/ContactController.php:211:14: UndefinedClass: Class, interface or enum named OCA\Circles\Api\v1\Circles does not exist (see https://psalm.dev/019)

Check failure on line 211 in lib/Controller/ContactController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-master

UndefinedClass

lib/Controller/ContactController.php:211:14: UndefinedClass: Class, interface or enum named OCA\Circles\Api\v1\Circles does not exist (see https://psalm.dev/019)

Check failure on line 211 in lib/Controller/ContactController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable26

UndefinedClass

lib/Controller/ContactController.php:211:14: UndefinedClass: Class, interface or enum named OCA\Circles\Api\v1\Circles does not exist (see https://psalm.dev/019)
} catch (QueryException $ex) {
return null;
} catch (CircleNotFoundException $ex) {
return null;
}

if (!$circle) {
return null;
}

$circleMembers = $circle->getInheritedMembers();

foreach ($circleMembers as $circleMember) {
if ($circleMember->isLocal()) {

$circleMemberUserId = $circleMember->getUserId();

$user = $this->userManager->get($circleMemberUserId);

if ($user === null) {
throw new ServiceException('Could not find organizer');
}

$contacts[] = [
'commonName' => $circleMember->getDisplayName(),
'calendarUserType' => 'INDIVIDUAL',
'email' => $user->getEMailAddress(),
'isUser' => true,
'avatar' => $circleMemberUserId,
'hasMultipleEMails' => false,
'dropdownName' => $circleMember->getDisplayName(),
'member' => 'mailto:circle+' . $circleId . '@' . $circleMember->getInstance(),
];
}
}

return new JSONResponse($contacts);
}


/**
* Get a contact's photo based on their email-address
*
Expand Down
15 changes: 15 additions & 0 deletions lib/Controller/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
*
* @author Georg Ehrke
* @author Richard Steinmetz <[email protected]>
* @author Jonas Heinrich <[email protected]>
* @copyright 2019 Georg Ehrke <[email protected]>
* @copyright Copyright (c) 2022 Informatyka Boguslawski sp. z o.o. sp.k., http://www.ib.pl/
* @copyright 2023 Jonas Heinrich <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
Expand All @@ -26,6 +28,8 @@
namespace OCA\Calendar\Controller;

use OCA\Calendar\Service\Appointments\AppointmentConfigService;
use OCA\Calendar\Service\CategoriesService;
use OC\App\CompareVersion;
use OCP\App\IAppManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\FileDisplayResponse;
Expand All @@ -51,6 +55,9 @@ class ViewController extends Controller {
/** @var IAppManager */
private $appManager;

/** @var CompareVersion */

Check failure on line 58 in lib/Controller/ViewController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable25

UndefinedDocblockClass

lib/Controller/ViewController.php:58:14: UndefinedDocblockClass: Docblock-defined class, interface or enum named OC\App\CompareVersion does not exist (see https://psalm.dev/200)

Check failure on line 58 in lib/Controller/ViewController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable27

UndefinedDocblockClass

lib/Controller/ViewController.php:58:14: UndefinedDocblockClass: Docblock-defined class, interface or enum named OC\App\CompareVersion does not exist (see https://psalm.dev/200)

Check failure on line 58 in lib/Controller/ViewController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-master

UndefinedDocblockClass

lib/Controller/ViewController.php:58:14: UndefinedDocblockClass: Docblock-defined class, interface or enum named OC\App\CompareVersion does not exist (see https://psalm.dev/200)

Check failure on line 58 in lib/Controller/ViewController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable26

UndefinedDocblockClass

lib/Controller/ViewController.php:58:14: UndefinedDocblockClass: Docblock-defined class, interface or enum named OC\App\CompareVersion does not exist (see https://psalm.dev/200)
private $compareVersion;

/** @var string */
private $userId;

Expand All @@ -62,13 +69,15 @@ public function __construct(string $appName,
AppointmentConfigService $appointmentConfigService,
IInitialState $initialStateService,
IAppManager $appManager,
CompareVersion $compareVersion,

Check failure on line 72 in lib/Controller/ViewController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable25

UndefinedClass

lib/Controller/ViewController.php:72:3: UndefinedClass: Class, interface or enum named OC\App\CompareVersion does not exist (see https://psalm.dev/019)

Check failure on line 72 in lib/Controller/ViewController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable27

UndefinedClass

lib/Controller/ViewController.php:72:3: UndefinedClass: Class, interface or enum named OC\App\CompareVersion does not exist (see https://psalm.dev/019)

Check failure on line 72 in lib/Controller/ViewController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-master

UndefinedClass

lib/Controller/ViewController.php:72:3: UndefinedClass: Class, interface or enum named OC\App\CompareVersion does not exist (see https://psalm.dev/019)

Check failure on line 72 in lib/Controller/ViewController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable26

UndefinedClass

lib/Controller/ViewController.php:72:3: UndefinedClass: Class, interface or enum named OC\App\CompareVersion does not exist (see https://psalm.dev/019)
?string $userId,
IAppData $appData) {
parent::__construct($appName, $request);
$this->config = $config;
$this->appointmentConfigService = $appointmentConfigService;
$this->initialStateService = $initialStateService;
$this->appManager = $appManager;
$this->compareVersion = $compareVersion;
$this->userId = $userId;
$this->appData = $appData;
}
Expand Down Expand Up @@ -117,6 +126,11 @@ public function index():TemplateResponse {
$talkApiVersion = version_compare($this->appManager->getAppVersion('spreed'), '12.0.0', '>=') ? 'v4' : 'v1';
$tasksEnabled = $this->appManager->isEnabledForUser('tasks');

$circleVersion = $this->appManager->getAppVersion('circles');
$isCirclesEnabled = $this->appManager->isEnabledForUser('circles') === true;
// if circles is not installed, we use 0.0.0
$isCircleVersionCompatible = $this->compareVersion->isCompatible($circleVersion ? $circleVersion : '0.0.0', '22');

Check failure on line 132 in lib/Controller/ViewController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable25

UndefinedDocblockClass

lib/Controller/ViewController.php:132:32: UndefinedDocblockClass: Docblock-defined class, interface or enum named OC\App\CompareVersion does not exist (see https://psalm.dev/200)

Check failure on line 132 in lib/Controller/ViewController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable27

UndefinedDocblockClass

lib/Controller/ViewController.php:132:32: UndefinedDocblockClass: Docblock-defined class, interface or enum named OC\App\CompareVersion does not exist (see https://psalm.dev/200)

Check failure on line 132 in lib/Controller/ViewController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-master

UndefinedDocblockClass

lib/Controller/ViewController.php:132:32: UndefinedDocblockClass: Docblock-defined class, interface or enum named OC\App\CompareVersion does not exist (see https://psalm.dev/200)

Check failure on line 132 in lib/Controller/ViewController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable26

UndefinedDocblockClass

lib/Controller/ViewController.php:132:32: UndefinedDocblockClass: Docblock-defined class, interface or enum named OC\App\CompareVersion does not exist (see https://psalm.dev/200)

$this->initialStateService->provideInitialState('app_version', $appVersion);
$this->initialStateService->provideInitialState('event_limit', $eventLimit);
$this->initialStateService->provideInitialState('first_run', $firstRun);
Expand All @@ -138,6 +152,7 @@ public function index():TemplateResponse {
$this->initialStateService->provideInitialState('disable_appointments', $disableAppointments);
$this->initialStateService->provideInitialState('can_subscribe_link', $canSubscribeLink);
$this->initialStateService->provideInitialState('show_resources', $showResources);
$this->initialStateService->provideInitialState('isCirclesEnabled', $isCirclesEnabled && $isCircleVersionCompatible);

return new TemplateResponse($this->appName, 'main');
}
Expand Down
6 changes: 5 additions & 1 deletion src/components/Editor/Invitees/InviteesList.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<!--
- @copyright Copyright (c) 2019 Georg Ehrke <[email protected]>
- @copyright Copyright (c) 2023 Jonas Heinrich <[email protected]>
-
- @author Georg Ehrke <[email protected]>
- @author Richard Steinmetz <[email protected]>
- @author Jonas Heinrich <[email protected]>
-
- @license AGPL-3.0-or-later
-
Expand All @@ -25,6 +27,7 @@
<div>
<InviteesListSearch v-if="!isReadOnly && !isSharedWithMe && hasUserEmailAddress"
:already-invited-emails="alreadyInvitedEmails"
:organizer="calendarObjectInstance.organizer"
@add-attendee="addAttendee" />
<OrganizerListItem v-if="hasOrganizer"
:is-read-only="isReadOnly || isSharedWithMe"
Expand Down Expand Up @@ -189,7 +192,7 @@ export default {
},
},
methods: {
addAttendee({ commonName, email, calendarUserType, language, timezoneId }) {
addAttendee({ commonName, email, calendarUserType, language, timezoneId, member }) {
this.$store.commit('addAttendee', {
calendarObjectInstance: this.calendarObjectInstance,
commonName,
Expand All @@ -201,6 +204,7 @@ export default {
language,
timezoneId,
organizer: this.$store.getters.getCurrentUserPrincipal,
member,
})
},
removeAttendee(attendee) {
Expand Down
Loading

0 comments on commit 4bea3c5

Please sign in to comment.