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: Ability to invite circles #5420

Merged
merged 1 commit into from
Dec 5, 2023
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
7 changes: 6 additions & 1 deletion appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
* 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
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
79 changes: 78 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 @@ -28,11 +30,16 @@
*/
namespace OCA\Calendar\Controller;

use OCA\Calendar\Service\ServiceException;
use OCA\Circles\Exceptions\CircleNotFoundException;
use OCP\App\IAppManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\QueryException;
use OCP\Contacts\IManager;
use OCP\IRequest;
use OCP\IUserManager;

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

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

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

/**
* ContactController constructor.
*
Expand All @@ -52,9 +65,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 +190,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
* @throws \OCP\AppFramework\QueryException
*
* @NoAdminRequired
*/
public function getCircleMembers(string $circleId):JSONResponse {
if (!$this->appManager->isEnabledForUser('circles') || !class_exists('\OCA\Circles\Api\v1\Circles')) {
return new JSONResponse();
}
if (!$this->contactsManager->isEnabled()) {
return new JSONResponse();
}

try {
$circle = \OCA\Circles\Api\v1\Circles::detailsCircle($circleId, true);
} catch (QueryException $ex) {
return new JSONResponse();
} catch (CircleNotFoundException $ex) {
return new JSONResponse();
}

if (!$circle) {
return new JSONResponse();
}

$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
14 changes: 14 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 @@ -25,6 +27,7 @@
*/
namespace OCA\Calendar\Controller;

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

/** @var CompareVersion */
private $compareVersion;

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

Expand All @@ -62,13 +68,15 @@ public function __construct(string $appName,
AppointmentConfigService $appointmentConfigService,
IInitialState $initialStateService,
IAppManager $appManager,
CompareVersion $compareVersion,
?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 +125,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');
onny marked this conversation as resolved.
Show resolved Hide resolved

$this->initialStateService->provideInitialState('app_version', $appVersion);
$this->initialStateService->provideInitialState('event_limit', $eventLimit);
$this->initialStateService->provideInitialState('first_run', $firstRun);
Expand All @@ -138,6 +151,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
8 changes: 8 additions & 0 deletions lib/Service/ServiceException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace OCA\Calendar\Service;

use Exception;

class ServiceException extends Exception {
}
7 changes: 7 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
<referencedClass name="Doctrine\DBAL\Types\Type" />
<referencedClass name="Doctrine\DBAL\Types\Types" />
<referencedClass name="OC\Security\CSP\ContentSecurityPolicyNonceManager" />
<referencedClass name="OC\App\CompareVersion" />
<referencedClass name="OCA\Circles\Api\v1\Circles" />
<referencedClass name="OCA\Circles\Exceptions\CircleNotFoundException" />
<referencedClass name="OCA\Calendar\Controller\Exception" />
onny marked this conversation as resolved.
Show resolved Hide resolved
<referencedClass name="Psr\Http\Client\ClientExceptionInterface" />
<referencedClass name="Sabre\VObject\Component\VCalendar" />
<referencedClass name="Sabre\VObject\Component\VTimezone" />
Expand All @@ -48,6 +52,9 @@
<referencedClass name="Doctrine\DBAL\Schema\Table" />
<referencedClass name="OC\Security\CSP\ContentSecurityPolicyNonceManager" />
<referencedClass name="Sabre\VObject\Component\VTimezone" />
<referencedClass name="OC\App\CompareVersion" />
<referencedClass name="OCA\Calendar\Controller\Exception" />
<referencedClass name="OCA\Circles\Api\v1\Circles" />
<referencedClass name="Symfony\Component\Console\Output\OutputInterface" />
</errorLevel>
</UndefinedDocblockClass>
Expand Down
50 changes: 22 additions & 28 deletions src/components/Editor/Invitees/InviteesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,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 @@ -133,8 +134,16 @@
})
},
groups() {
return this.calendarObjectInstance.attendees.filter(attendee => {
return attendee.attendeeProperty.userType === 'GROUP'
return this.invitees.filter(attendee => {
if (attendee.attendeeProperty.userType === 'GROUP') {
attendee.members = this.invitees.filter(invitee => {
return invitee.attendeeProperty.member
&& invitee.attendeeProperty.member.includes(attendee.uri)
&& attendee.attendeeProperty.userType === 'GROUP'
})
return attendee.members.length > 0

Check warning on line 144 in src/components/Editor/Invitees/InviteesList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/InviteesList.vue#L144

Added line #L144 was not covered by tests
}
return false
})
},
inviteesWithoutOrganizer() {
Expand All @@ -146,36 +155,20 @@
return this.invitees
.filter(attendee => {
// Filter attendees which are part of an invited group
let isMemberOfGroup = false
if (attendee.attendeeProperty.member) {
isMemberOfGroup = this.groups.some(function(group) {
return attendee.attendeeProperty.member.includes(group.uri)
&& attendee.attendeeProperty.userType === 'INDIVIDUAL'
})
if (this.groups.some(function(group) {

Check warning on line 158 in src/components/Editor/Invitees/InviteesList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/InviteesList.vue#L158

Added line #L158 was not covered by tests
return attendee.attendeeProperty.member
&& attendee.attendeeProperty.member.includes(group.uri)
&& attendee.attendeeProperty.userType === 'INDIVIDUAL'
})) {
return false

Check warning on line 163 in src/components/Editor/Invitees/InviteesList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/InviteesList.vue#L160-L163

Added lines #L160 - L163 were not covered by tests
}

// Add attendee to group member list
if (isMemberOfGroup) {
this.groups.forEach(group => {
if (attendee.member.includes(group.uri)) {
if (!group.members) {
group.members = []
}
group.members.push(attendee)
}
})
// Filter empty groups
if (attendee.attendeeProperty.userType === 'GROUP') {

Check warning on line 167 in src/components/Editor/Invitees/InviteesList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/InviteesList.vue#L167

Added line #L167 was not covered by tests
return attendee.members.length > 0
}

// Check if attendee is an empty group
let isEmptyGroup = attendee.attendeeProperty.userType === 'GROUP'
this.invitees.forEach(invitee => {
if (invitee.member && invitee.member.includes(attendee.uri)) {
isEmptyGroup = false
}
})

return attendee.uri !== this.calendarObjectInstance.organizer.uri
&& !isMemberOfGroup && !isEmptyGroup
})
},
isOrganizer() {
Expand Down Expand Up @@ -230,7 +223,7 @@
},
},
methods: {
addAttendee({ commonName, email, calendarUserType, language, timezoneId }) {
addAttendee({ commonName, email, calendarUserType, language, timezoneId, member }) {

Check warning on line 226 in src/components/Editor/Invitees/InviteesList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/InviteesList.vue#L226

Added line #L226 was not covered by tests
this.$store.commit('addAttendee', {
calendarObjectInstance: this.calendarObjectInstance,
commonName,
Expand All @@ -242,6 +235,7 @@
language,
timezoneId,
organizer: this.$store.getters.getCurrentUserPrincipal,
member,

Check warning on line 238 in src/components/Editor/Invitees/InviteesList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/InviteesList.vue#L238

Added line #L238 was not covered by tests
})
},
removeAttendee(attendee) {
Expand Down
Loading
Loading