From ac8c37aedc9993d436910d78ee305ee98d39c1cc Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Tue, 29 Mar 2022 10:51:53 -0100 Subject: [PATCH] +runAsSuperSession Signed-off-by: Maxence Lange --- lib/CirclesManager.php | 44 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/lib/CirclesManager.php b/lib/CirclesManager.php index 3959ec0ff..94f5ec746 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,6 +61,7 @@ use OCA\Circles\Service\FederatedUserService; use OCA\Circles\Service\MemberService; use OCA\Circles\Service\MembershipService; +use OCA\Circles\Tools\Exceptions\InvalidItemException; use OCP\IUserSession; /** @@ -133,7 +133,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 +163,28 @@ public function startSuperSession(): void { } + /** + * Run a single method as Super, then Super level will be removed + */ + public function runAsSuperSession(string $method, array $params = []) { + $currentUser = $this->federatedUserService->getCurrentUser(); + $this->startSuperSession(); + + $result = call_user_func_array([$this, $method], $params); + if (is_null($currentUser)) { + return $result; + } + + $this->federatedUserService->bypassCurrentUserCondition(false); + try { + $this->federatedUserService->setCurrentUser($currentUser); + } catch (FederatedUserException $e) { + } + + return $result; + } + + /** * $userId - userId to emulate as initiator (can be empty) * $userType - specify if userIs not a singleId @@ -286,7 +310,9 @@ public function getCircles(?CircleProbe $probe = null): array { ->filterBackendCircles(); } - return $this->circleService->getCircles($probe); + $result = $this->circleService->getCircles($probe); + + return $result; } @@ -300,7 +326,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 +420,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 +432,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; }