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 Apr 1, 2022
1 parent c4a4e85 commit ba44a8c
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions lib/CirclesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
use OCA\Circles\Service\MemberService;
use OCA\Circles\Service\MembershipService;
use OCA\Circles\Tools\Exceptions\InvalidItemException;
use Throwable;

/**
* Class CirclesManager
Expand Down Expand Up @@ -206,6 +207,40 @@ public function startAppSession(string $appId, int $appSerial = Member::APP_DEFA
$this->federatedUserService->setLocalCurrentApp($appId, $appSerial);
}


/**
* Run a single method as Super, then Super level will be removed
*
* @throws Throwable
* @noinspection PhpUndefinedVariableInspection
*/
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

0 comments on commit ba44a8c

Please sign in to comment.