Skip to content

Commit

Permalink
+runAsSuperSession
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
  • Loading branch information
ArtificialOwl committed Mar 29, 2022
1 parent 69c2f79 commit b34f273
Showing 1 changed file with 49 additions and 6 deletions.
55 changes: 49 additions & 6 deletions lib/CirclesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -286,7 +321,9 @@ public function getCircles(?CircleProbe $probe = null): array {
->filterBackendCircles();
}

return $this->circleService->getCircles($probe);
$result = $this->circleService->getCircles($probe);

return $result;
}


Expand All @@ -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;
}


Expand Down Expand Up @@ -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;
}


Expand All @@ -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;
}


Expand Down

0 comments on commit b34f273

Please sign in to comment.