Skip to content

Commit ae99e38

Browse files
ArtificialOwlbackportbot[bot]
authored andcommitted
Managing external members tokens
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent 6cd0ea2 commit ae99e38

24 files changed

+771
-62
lines changed

lib/AppInfo/Application.php

+5-9
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
use OCA\Circles\Events\CircleMemberAddedEvent;
4242
use OCA\Circles\Events\MembershipsCreatedEvent;
4343
use OCA\Circles\Events\MembershipsRemovedEvent;
44+
use OCA\Circles\Events\RemovingCircleMemberEvent;
4445
use OCA\Circles\Events\RequestingCircleMemberEvent;
4546
use OCA\Circles\Handlers\WebfingerHandler;
4647
use OCA\Circles\Listeners\DeprecatedListener;
@@ -50,7 +51,7 @@
5051
use OCA\Circles\Listeners\Examples\ExampleRequestingCircleMember;
5152
use OCA\Circles\Listeners\Files\AddingMember as ListenerFilesAddingMember;
5253
use OCA\Circles\Listeners\Files\MemberAdded as ListenerFilesMemberAdded;
53-
use OCA\Circles\Listeners\Files\MembershipsRemoved as ListenerFilesMembershipsRemoved;
54+
use OCA\Circles\Listeners\Files\RemovingMember as ListenerFilesRemovingMember;
5455
use OCA\Circles\Listeners\GroupCreated;
5556
use OCA\Circles\Listeners\GroupDeleted;
5657
use OCA\Circles\Listeners\GroupMemberAdded;
@@ -62,13 +63,11 @@
6263
use OCA\Circles\Notification\Notifier;
6364
use OCA\Circles\Service\ConfigService;
6465
use OCA\Circles\Service\DavService;
65-
//use OCA\Files\App as FilesApp;
6666
use OCP\App\ManagerEvent;
6767
use OCP\AppFramework\App;
6868
use OCP\AppFramework\Bootstrap\IBootContext;
6969
use OCP\AppFramework\Bootstrap\IBootstrap;
7070
use OCP\AppFramework\Bootstrap\IRegistrationContext;
71-
use OCP\AppFramework\IAppContainer;
7271
use OCP\Files\Config\IMountProviderCollection;
7372
use OCP\Group\Events\GroupCreatedEvent;
7473
use OCP\Group\Events\GroupDeletedEvent;
@@ -81,6 +80,8 @@
8180
use Symfony\Component\EventDispatcher\GenericEvent;
8281
use Throwable;
8382

83+
//use OCA\Files\App as FilesApp;
84+
8485

8586
require_once __DIR__ . '/../../vendor/autoload.php';
8687

@@ -107,9 +108,6 @@ class Application extends App implements IBootstrap {
107108
/** @var ConfigService */
108109
private $configService;
109110

110-
/** @var IAppContainer */
111-
private $container;
112-
113111

114112
/**
115113
* Application constructor.
@@ -143,9 +141,7 @@ public function register(IRegistrationContext $context): void {
143141
// Local Events (for Files/Shares/Notifications management)
144142
$context->registerEventListener(AddingCircleMemberEvent::class, ListenerFilesAddingMember::class);
145143
$context->registerEventListener(CircleMemberAddedEvent::class, ListenerFilesMemberAdded::class);
146-
$context->registerEventListener(
147-
MembershipsRemovedEvent::class, ListenerFilesMembershipsRemoved::class
148-
);
144+
$context->registerEventListener(RemovingCircleMemberEvent::class, ListenerFilesRemovingMember::class);
149145
$context->registerEventListener(
150146
RequestingCircleMemberEvent::class, ListenerNotificationsRequestingMember::class
151147
);

lib/Command/CirclesMemberships.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ protected function configure() {
162162
->setDescription('index and display memberships for local and federated users')
163163
->addArgument('userId', InputArgument::OPTIONAL, 'userId to generate memberships', '')
164164
->addOption('display-name', '', InputOption::VALUE_NONE, 'display the displayName')
165-
->addOption('reset', '', InputOption::VALUE_NONE, 'reset memberships')
165+
// ->addOption('reset', '', InputOption::VALUE_NONE, 'reset memberships')
166166
->addOption('all', '', InputOption::VALUE_NONE, 'refresh memberships for all entities')
167167
->addOption(
168168
'type', '', InputOption::VALUE_REQUIRED, 'type of the user',
@@ -208,11 +208,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
208208
$type = Member::parseTypeString($input->getOption('type'));
209209
$federatedUser = $this->federatedUserService->getFederatedUser($userId, (int)$type);
210210

211-
if ($this->input->getOption('reset')) {
212-
$this->membershipsService->resetMemberships($federatedUser->getSingleId());
213-
214-
return 0;
215-
}
211+
// if ($this->input->getOption('reset')) {
212+
// $this->membershipsService->resetMemberships($federatedUser->getSingleId());
213+
//
214+
// return 0;
215+
// }
216216

217217
$output->writeln('Id: <info>' . $federatedUser->getUserId() . '</info>');
218218
$output->writeln('Instance: <info>' . $federatedUser->getInstance() . '</info>');
@@ -361,11 +361,11 @@ public function displayLeaf(SimpleDataStore $data, int $lineNumber): string {
361361
* @throws RequestBuilderException
362362
*/
363363
private function manageAllMemberships() {
364-
if ($this->input->getOption('reset')) {
365-
$this->membershipsService->resetMemberships('', true);
366-
367-
return;
368-
}
364+
// if ($this->input->getOption('reset')) {
365+
// $this->membershipsService->resetMemberships('', true);
366+
//
367+
// return;
368+
// }
369369

370370
$this->federatedUserService->bypassCurrentUserCondition(true);
371371

lib/Db/ShareTokenRequest.php

+29
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ public function save(ShareToken $token): void {
6565
}
6666

6767

68+
/**
69+
* @param ShareToken $shareToken
70+
*
71+
* @return ShareToken
72+
* @throws ShareTokenNotFoundException
73+
*/
74+
public function search(ShareToken $shareToken): ShareToken {
75+
$qb = $this->getTokenSelectSql();
76+
$qb->limitInt('share_id', $shareToken->getshareId());
77+
$qb->limitToCircleId($shareToken->getCircleId());
78+
$qb->limitToSingleId($shareToken->getSingleId());
79+
80+
return $this->getItemFromRequest($qb);
81+
}
82+
83+
6884
/**
6985
* @param string $token
7086
*
@@ -78,5 +94,18 @@ public function getByToken(string $token): ShareToken {
7894
return $this->getItemFromRequest($qb);
7995
}
8096

97+
98+
/**
99+
* @param string $singleId
100+
* @param string $circleId
101+
*/
102+
public function removeTokens(string $singleId, string $circleId) {
103+
$qb = $this->getTokenDeleteSql();
104+
$qb->limitToSingleId($singleId);
105+
$qb->limitToCircleId($circleId);
106+
107+
$qb->execute();
108+
}
109+
81110
}
82111

lib/Db/ShareWrapperRequest.php

+11-12
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ public function getSharesToCircle(
168168

169169
$qb->leftJoinCircle(CoreQueryBuilder::SHARE, null, 'share_with');
170170

171+
// TODO: filter direct-shares ?
171172
$aliasUpstreamMembership =
172173
$qb->generateAlias(CoreQueryBuilder::SHARE, CoreQueryBuilder::UPSTREAM_MEMBERSHIPS);
173174
$qb->limitToInheritedMemberships(CoreQueryBuilder::SHARE, $circleId, 'share_with');
@@ -176,20 +177,18 @@ public function getSharesToCircle(
176177
// $qb->limitToInitiator(CoreRequestBuilder::SHARE, $shareRecipient, 'share_with');
177178
// }
178179

179-
$qb->leftJoinInheritedMembers(
180-
$aliasUpstreamMembership,
181-
'circle_id',
182-
$qb->generateAlias(CoreQueryBuilder::SHARE, CoreQueryBuilder::INHERITED_BY)
183-
);
184-
185-
$aliasMembership = $qb->generateAlias($aliasUpstreamMembership, CoreQueryBuilder::MEMBERSHIPS);
186-
$qb->leftJoinFileCache(CoreQueryBuilder::SHARE);
187-
$qb->leftJoinShareChild(CoreQueryBuilder::SHARE, $aliasMembership);
180+
// TODO: add shareInitiator and shareRecipient to filter the request
181+
if (!is_null($shareRecipient) || $completeDetails) {
182+
$qb->leftJoinInheritedMembers(
183+
$aliasUpstreamMembership,
184+
'circle_id',
185+
$qb->generateAlias(CoreQueryBuilder::SHARE, CoreQueryBuilder::INHERITED_BY)
186+
);
188187

189-
if (!is_null($shareInitiator)) {
190-
}
188+
$aliasMembership = $qb->generateAlias($aliasUpstreamMembership, CoreQueryBuilder::MEMBERSHIPS);
189+
$qb->leftJoinFileCache(CoreQueryBuilder::SHARE);
190+
$qb->leftJoinShareChild(CoreQueryBuilder::SHARE, $aliasMembership);
191191

192-
if ($completeDetails) {
193192
$qb->generateGroupBy(
194193
self::$tables[self::TABLE_MEMBERSHIP],
195194
$aliasMembership,

lib/Events/AddingCircleMemberEvent.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
* This is a good place if anything needs to be executed when a new member have been added to a Circle.
4848
*
4949
* If anything needs to be managed on the master instance of the Circle (ie. CircleMemberAddedEvent), please use:
50-
* $event->getFederatedEvent()->addResult(string $key, array $data);
50+
* $event->getFederatedEvent()->setResultEntry(string $key, array $data);
5151
*
5252
* @package OCA\Circles\Events
5353
*/

lib/Events/CreatingCircleEvent.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
* This is a good place if anything needs to be executed when a new Circle has been created.
4949
*
5050
* If anything needs to be managed on the master instance of the Circle (ie. CircleCreatedEvent), please use:
51-
* $event->getFederatedEvent()->addResult(string $key, array $data);
51+
* $event->getFederatedEvent()->setResultEntry(string $key, array $data);
5252
*
5353
* @package OCA\Circles\Events
5454
*/

lib/Events/DestroyingCircleEvent.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
* This is a good place if anything needs to be executed when a Circle has been destroyed.
4949
*
5050
* If anything needs to be managed on the master instance of the Circle (ie. CircleDestroyedEvent), please use:
51-
* $event->getFederatedEvent()->addResult(string $key, array $data);
51+
* $event->getFederatedEvent()->setResultEntry(string $key, array $data);
5252
* *
5353
* @package OCA\Circles\Events
5454
*/

lib/Events/EditingCircleEvent.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
* This is a good place if anything needs to be executed when a circle is edited.
4848
*
4949
* If anything needs to be managed on the master instance of the Circle (ie. CircleEditedEvent), please use:
50-
* $event->getFederatedEvent()->addResult(string $key, array $data);
50+
* $event->getFederatedEvent()->setResultEntry(string $key, array $data);
5151
*
5252
* @package OCA\Circles\Events
5353
*/

lib/Events/EditingCircleMemberEvent.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
*
4949
* If anything needs to be managed on the master instance of the Circle (ie. CircleMemberEditedEvent), please
5050
* use:
51-
* $event->getFederatedEvent()->addResult(string $key, array $data);
51+
* $event->getFederatedEvent()->setResultEntry(string $key, array $data);
5252
*
5353
* @package OCA\Circles\Events
5454
*/

lib/Events/RemovingCircleMemberEvent.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
* This is a good place if anything needs to be executed when a member have been removed from a Circle.
4848
*
4949
* If anything needs to be managed on the master instance of the Circle (ie. CircleMemberRemovedEvent), please use:
50-
* $event->getFederatedEvent()->addResult(string $key, array $data);
50+
* $event->getFederatedEvent()->setResultEntry(string $key, array $data);
5151
*
5252
* @package OCA\Circles\Events
5353
*/

lib/Events/RequestingCircleMemberEvent.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
* This is a good place if anything needs to be executed when a member requests or is invited to a Circle.
4747
*
4848
* If anything needs to be managed on the master instance of the Circle (ie. CircleMemberRequestedEvent), please use:
49-
* $event->getFederatedEvent()->addResult(string $key, array $data);
49+
* $event->getFederatedEvent()->setResultEntry(string $key, array $data);
5050
*
5151
* @package OCA\Circles\Events
5252
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
6+
/**
7+
* Circles - Bring cloud-users closer together.
8+
*
9+
* This file is licensed under the Affero General Public License version 3 or
10+
* later. See the COPYING file.
11+
*
12+
* @author Maxence Lange <maxence@artificial-owl.com>
13+
* @copyright 2021
14+
* @license GNU AGPL version 3 or any later version
15+
*
16+
* This program is free software: you can redistribute it and/or modify
17+
* it under the terms of the GNU Affero General Public License as
18+
* published by the Free Software Foundation, either version 3 of the
19+
* License, or (at your option) any later version.
20+
*
21+
* This program is distributed in the hope that it will be useful,
22+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
23+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24+
* GNU Affero General Public License for more details.
25+
*
26+
* You should have received a copy of the GNU Affero General Public License
27+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
28+
*
29+
*/
30+
31+
namespace OCA\Circles\Exceptions;
32+
33+
34+
use Exception;
35+
36+
37+
/**
38+
* Class ShareTokenAlreadyExistException
39+
*
40+
* @package OCA\Circles\Exceptions
41+
*/
42+
class ShareTokenAlreadyExistException extends Exception {
43+
44+
}
45+

lib/FederatedItems/SingleMemberAdd.php

+1
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ private function memberIsMailbox(
633633
}
634634

635635
try {
636+
636637
$template = $this->generateMailExitingShares($author, $circle->getName());
637638
$this->fillMailExistingShares($template, $links);
638639
$this->sendMailExistingShares($template, $author, $recipient);

0 commit comments

Comments
 (0)