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 bacc3d9
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 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,39 @@ public function startSuperSession(): void {
}


/**
* 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 bacc3d9

Please sign in to comment.