Skip to content

Commit

Permalink
emulate entity on Admin OCS API
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 Nov 23, 2022
1 parent 674ace2 commit 5b26f6c
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions lib/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@

namespace OCA\Circles\Controller;

use OCA\Circles\Tools\Traits\TDeserialize;
use OCA\Circles\Tools\Traits\TNCLogger;
use Exception;
use OCA\Circles\Exceptions\ContactAddressBookNotFoundException;
use OCA\Circles\Exceptions\ContactFormatException;
Expand All @@ -52,6 +50,8 @@
use OCA\Circles\Service\MemberService;
use OCA\Circles\Service\MembershipService;
use OCA\Circles\Service\SearchService;
use OCA\Circles\Tools\Traits\TDeserialize;
use OCA\Circles\Tools\Traits\TNCLogger;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSException;
use OCP\AppFramework\OCSController;
Expand Down Expand Up @@ -263,6 +263,7 @@ public function memberLevel(string $emulated, string $circleId, string $memberId
* @param string $emulated
* @param int $limit
* @param int $offset
*
* @return DataResponse
* @throws OCSException
*/
Expand Down Expand Up @@ -482,9 +483,6 @@ public function editSetting(string $emulated, string $circleId, string $setting,
}





/**
* @param string $emulated
* @param string $circleId
Expand Down Expand Up @@ -529,7 +527,7 @@ public function link(string $emulated, string $circleId, string $singleId): Data


/**
* @param string $emulated
* @param string $emulated by default, userId; can be an entity using singleId=<singleId>
*
* @throws FederatedUserException
* @throws FederatedUserNotFoundException
Expand All @@ -543,6 +541,18 @@ public function link(string $emulated, string $circleId, string $singleId): Data
private function setLocalFederatedUser(string $emulated): void {
$user = $this->userSession->getUser();
$this->federatedUserService->setCurrentPatron($user->getUID());

if (strpos($emulated, '=') > 0) {
[$type, $id] = explode('=', $emulated, 2);
switch (strtolower($type)) {
case 'singleid':
$federatedUser = $this->federatedUserService->getFederatedUser($id, Member::TYPE_SINGLE);
$this->federatedUserService->setCurrentUser($federatedUser);
break;
}

return;
}
$this->federatedUserService->setLocalCurrentUserId($emulated);
}
}

0 comments on commit 5b26f6c

Please sign in to comment.