diff --git a/lib/CirclesManager.php b/lib/CirclesManager.php index 3959ec0ff..26cd6094e 100644 --- a/lib/CirclesManager.php +++ b/lib/CirclesManager.php @@ -31,7 +31,6 @@ namespace OCA\Circles; -use OCA\Circles\Tools\Exceptions\InvalidItemException; use OCA\Circles\Exceptions\CircleNotFoundException; use OCA\Circles\Exceptions\ContactAddressBookNotFoundException; use OCA\Circles\Exceptions\ContactFormatException; @@ -62,7 +61,9 @@ use OCA\Circles\Service\FederatedUserService; use OCA\Circles\Service\MemberService; use OCA\Circles\Service\MembershipService; +use OCA\Circles\Tools\Exceptions\InvalidItemException; use OCP\IUserSession; +use Throwable; /** * Class CirclesManager @@ -133,7 +134,9 @@ public function __construct( * @throws UserTypeNotFoundException */ public function getFederatedUser(string $federatedId, int $type = Member::TYPE_SINGLE): FederatedUser { - return $this->federatedUserService->getFederatedUser($federatedId, $type); + $result = $this->federatedUserService->getFederatedUser($federatedId, $type); + + return $result; } @@ -161,6 +164,38 @@ public function startSuperSession(): void { } + /** + * Run a single method as Super, then Super level will be removed + * + * @throws Throwable + */ + public function runAsSuperSession(string $method, array $params = []) { + $currentUser = $this->federatedUserService->getCurrentUser(); + $this->startSuperSession(); + + $throwable = null; + try { + $result = call_user_func_array([$this, $method], $params); + } catch (Throwable $t) { + $throwable = $t; + } + + $this->federatedUserService->bypassCurrentUserCondition(false); + if (!is_null($currentUser)) { + try { + $this->federatedUserService->setCurrentUser($currentUser); + } catch (FederatedUserException $e) { + } + } + + if (!is_null($throwable)) { + throw $throwable; + } + + return $result; + } + + /** * $userId - userId to emulate as initiator (can be empty) * $userType - specify if userIs not a singleId @@ -286,7 +321,9 @@ public function getCircles(?CircleProbe $probe = null): array { ->filterBackendCircles(); } - return $this->circleService->getCircles($probe); + $result = $this->circleService->getCircles($probe); + + return $result; } @@ -300,7 +337,9 @@ public function getCircles(?CircleProbe $probe = null): array { * @throws RequestBuilderException */ public function getCircle(string $singleId, ?CircleProbe $probe = null): Circle { - return $this->circleService->getCircle($singleId, $probe); + $result = $this->circleService->getCircle($singleId, $probe); + + return $result; } @@ -392,7 +431,9 @@ public function removeMember(string $memberId): void { * @throws RequestBuilderException */ public function getLink(string $circleId, string $singleId, bool $detailed = false): Membership { - return $this->membershipService->getMembership($circleId, $singleId, $detailed); + $result = $this->membershipService->getMembership($circleId, $singleId, $detailed); + + return $result; } @@ -402,7 +443,9 @@ public function getLink(string $circleId, string $singleId, bool $detailed = fal * @return string */ public function getDefinition(IEntity $circle): string { - return $this->circleService->getDefinition($circle); + $result = $this->circleService->getDefinition($circle); + + return $result; }