diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2021-08-23 14:33:07 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-23 14:33:07 +0300 |
commit | 72bda68191bc82c02b3a62c4f9260de8bad8fecf (patch) | |
tree | 56c4542c34ff71cf6b8ced1c5d161f1051ebbf6f | |
parent | e933c0f8c848815122330cbebac55a54b0363ad9 (diff) | |
parent | 55e30dae3537f7d4ca8556efd225d2919ca9b1ba (diff) |
Merge pull request #791 from nextcloud/backport/790/stable22v22.1.1rc2
[stable22] emulate initiator on CircleJoin
-rw-r--r-- | lib/Db/MemberRequest.php | 8 | ||||
-rw-r--r-- | lib/FederatedItems/CircleLeave.php | 17 | ||||
-rw-r--r-- | lib/Service/CircleService.php | 20 |
3 files changed, 36 insertions, 9 deletions
diff --git a/lib/Db/MemberRequest.php b/lib/Db/MemberRequest.php index 46372adf..1d548907 100644 --- a/lib/Db/MemberRequest.php +++ b/lib/Db/MemberRequest.php @@ -38,6 +38,7 @@ use OCA\Circles\IFederatedUser; use OCA\Circles\Model\Circle; use OCA\Circles\Model\FederatedUser; use OCA\Circles\Model\Member; +use OCA\Circles\Model\Probes\CircleProbe; use OCA\Circles\Model\Probes\MemberProbe; /** @@ -288,16 +289,21 @@ class MemberRequest extends MemberRequestBuilder { /** * @param string $circleId * @param string $singleId + * @param CircleProbe|null $probe * * @return Member * @throws MemberNotFoundException * @throws RequestBuilderException */ - public function getMember(string $circleId, string $singleId): Member { + public function getMember(string $circleId, string $singleId, ?CircleProbe $probe = null): Member { $qb = $this->getMemberSelectSql(); $qb->limitToCircleId($circleId); $qb->limitToSingleId($singleId); + if (!is_null($probe)) { + $qb->setOptions([CoreQueryBuilder::MEMBER], $probe->getAsOptions()); + } + return $this->getItemFromRequest($qb); } diff --git a/lib/FederatedItems/CircleLeave.php b/lib/FederatedItems/CircleLeave.php index 5b40d6df..d5d6c809 100644 --- a/lib/FederatedItems/CircleLeave.php +++ b/lib/FederatedItems/CircleLeave.php @@ -49,6 +49,7 @@ use OCA\Circles\Model\Federated\FederatedEvent; use OCA\Circles\Model\FederatedUser; use OCA\Circles\Model\Helpers\MemberHelper; use OCA\Circles\Model\Member; +use OCA\Circles\Model\Probes\CircleProbe; use OCA\Circles\Service\ConfigService; use OCA\Circles\Service\EventService; use OCA\Circles\Service\MembershipService; @@ -137,7 +138,13 @@ class CircleLeave implements if ($member->getId() === '') { try { // make it works for not-yet-members - $member = $this->memberRequest->getMember($circle->getSingleId(), $member->getSingleId()); + $probe = new CircleProbe(); + $probe->includeNonVisibleCircles(); + $member = $this->memberRequest->getMember( + $circle->getSingleId(), + $member->getSingleId(), + $probe + ); } catch (MemberNotFoundException $e) { throw new MemberNotFoundException(StatusCode::$CIRCLE_LEAVE[120], 120); } @@ -224,10 +231,10 @@ class CircleLeave implements if ($member->getLevel() > $newOwner->getLevel()) { $newOwner = $member; } elseif ($member->getLevel() === $newOwner->getLevel() - && ($member->getJoined() < $newOwner->getJoined() - || ($this->configService->isLocalInstance($member->getInstance()) - && !$this->configService->isLocalInstance($newOwner->getInstance())) - )) { + && ($member->getJoined() < $newOwner->getJoined() + || ($this->configService->isLocalInstance($member->getInstance()) + && !$this->configService->isLocalInstance($newOwner->getInstance())) + )) { $newOwner = $member; } } diff --git a/lib/Service/CircleService.php b/lib/Service/CircleService.php index 7aa51e93..90a5b317 100644 --- a/lib/Service/CircleService.php +++ b/lib/Service/CircleService.php @@ -378,9 +378,15 @@ class CircleService { $this->federatedUserService->mustHaveCurrentUser(); $probe = new CircleProbe(); - $probe->includeNonVisibleCircles(); + $probe->includeNonVisibleCircles() + ->emulateVisitor(); + + $circle = $this->circleRequest->getCircle( + $circleId, + $this->federatedUserService->getCurrentUser(), + $probe + ); - $circle = $this->circleRequest->getCircle($circleId, $this->federatedUserService->getCurrentUser(), $probe); if (!$circle->getInitiator()->hasInvitedBy()) { $this->federatedUserService->setMemberPatron($circle->getInitiator()); } @@ -414,7 +420,15 @@ class CircleService { public function circleLeave(string $circleId, bool $force = false): array { $this->federatedUserService->mustHaveCurrentUser(); - $circle = $this->circleRequest->getCircle($circleId, $this->federatedUserService->getCurrentUser()); + $probe = new CircleProbe(); + $probe->includeNonVisibleCircles() + ->emulateVisitor(); + + $circle = $this->circleRequest->getCircle( + $circleId, + $this->federatedUserService->getCurrentUser(), + $probe + ); $event = new FederatedEvent(CircleLeave::class); $event->setCircle($circle); |