Skip to content

Commit

Permalink
group can contains '@'
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 Jul 12, 2023
1 parent c7df971 commit d4284e1
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions lib/Service/FederatedUserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -721,14 +721,22 @@ public function getFederatedMember(string $userId, int $level = Member::LEVEL_ME
* @throws RequestBuilderException
*/
public function getFederatedUser(string $federatedId, int $type = Member::TYPE_SINGLE): FederatedUser {
// if type=user, we check that handle@domain is not an actual local user
if ($type === Member::TYPE_USER) {
try {
return $this->getLocalFederatedUser($federatedId);
} catch (Exception $e) {
// first testing federatedId string as a whole;
try {
switch ($type) {
case Member::TYPE_USER:
return $this->getLocalFederatedUser($federatedId);
case Member::TYPE_GROUP:
return $this->getFederatedUser_Group($federatedId);
case Member::TYPE_MAIL:
return $this->getFederatedUser_Mail($federatedId);
case Member::TYPE_CONTACT:
return $this->getFederatedUser_Contact($federatedId);
}
} catch (Exception $e) {
}

// then if nothing found, extract remote instance from string
[$singleId, $instance] = $this->extractIdAndInstance($federatedId);

switch ($type) {
Expand All @@ -739,10 +747,6 @@ public function getFederatedUser(string $federatedId, int $type = Member::TYPE_S
return $this->getFederatedUser_User($singleId, $instance);
case Member::TYPE_GROUP:
return $this->getFederatedUser_Group($singleId, $instance);
case Member::TYPE_MAIL:
return $this->getFederatedUser_Mail($federatedId);
case Member::TYPE_CONTACT:
return $this->getFederatedUser_Contact($federatedId);
}

throw new UserTypeNotFoundException();
Expand Down Expand Up @@ -879,14 +883,14 @@ private function getFederatedUser_User(string $userId, string $instance): Federa
* @throws UnknownRemoteException
* @throws RequestBuilderException
*/
public function getFederatedUser_Group(string $groupName, string $instance): FederatedUser {
public function getFederatedUser_Group(string $groupName, string $instance = ''): FederatedUser {
if ($this->configService->isLocalInstance($instance)) {
$circle = $this->getGroupCircle($groupName);
$federatedGroup = new FederatedUser();

return $federatedGroup->importFromCircle($circle);
} else {
// TODO: implement remote groups
throw new FederatedUserNotFoundException('remote group not supported yet. Use singleId');
}
}

Expand Down Expand Up @@ -948,11 +952,13 @@ public function getFederatedUser_Contact(string $contactPath): FederatedUser {
*/
public function extractIdAndInstance(string $federatedId): array {
$federatedId = trim($federatedId, '@');
if (strrpos($federatedId, '@') === false) {
$pos = strrpos($federatedId, '@');
if ($pos === false) {
$userId = $federatedId;
$instance = $this->interfaceService->getLocalInstance();
} else {
[$userId, $instance] = explode('@', $federatedId);
$userId = substr($federatedId, 0, $pos);
$instance = substr($federatedId, $pos + 1);
}

return [$userId, $instance];
Expand Down

0 comments on commit d4284e1

Please sign in to comment.