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 57b333f
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion 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 @@ -161,6 +162,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

0 comments on commit 57b333f

Please sign in to comment.