0
0
Fork 0
mirror of https://github.com/verdigado/organization_folders.git synced 2024-11-24 13:40:27 +01:00

improved error handling

This commit is contained in:
Jonathan Treffler 2024-11-20 03:07:26 +01:00
parent 9f14ca2179
commit ab378ea223
2 changed files with 19 additions and 8 deletions

View file

@ -16,6 +16,8 @@ use OCA\GroupFolders\Folder\FolderManager;
use OCA\OrganizationFolders\OrganizationProvider\OrganizationProviderManager; use OCA\OrganizationFolders\OrganizationProvider\OrganizationProviderManager;
use OCA\OrganizationFolders\Model\Principal; use OCA\OrganizationFolders\Model\Principal;
use OCA\OrganizationFolders\Enum\PrincipalType; use OCA\OrganizationFolders\Enum\PrincipalType;
use OCA\OrganizationFolders\Errors\OrganizationProviderNotFound;
use OCA\OrganizationFolders\Errors\OrganizationRoleNotFound;
class ACLManager { class ACLManager {
public function __construct( public function __construct(
@ -54,7 +56,7 @@ class ACLManager {
return array_map($this->createRuleEntityFromRow(...), $rows); return array_map($this->createRuleEntityFromRow(...), $rows);
} }
public function getMappingForPrincipal(Principal $principal): IUserMapping { public function getMappingForPrincipal(Principal $principal): ?IUserMapping {
if($principal->getType() === PrincipalType::USER) { if($principal->getType() === PrincipalType::USER) {
return $this->userMappingManager->mappingFromId("user", $principal->getId()); return $this->userMappingManager->mappingFromId("user", $principal->getId());
} else if($principal->getType() === PrincipalType::GROUP) { } else if($principal->getType() === PrincipalType::GROUP) {
@ -62,8 +64,17 @@ class ACLManager {
} else if($principal->getType() === PrincipalType::ROLE) { } else if($principal->getType() === PrincipalType::ROLE) {
[$organizationProviderId, $roleId] = explode(":", $principal->getId(), 2); [$organizationProviderId, $roleId] = explode(":", $principal->getId(), 2);
$organizationProvider = $this->organizationProviderManager->getOrganizationProvider($organizationProviderId); try {
$role = $organizationProvider->getRole($roleId); $organizationProvider = $this->organizationProviderManager->getOrganizationProvider($organizationProviderId);
} catch (OrganizationProviderNotFound $e) {
return null;
}
try {
$role = $organizationProvider->getRole($roleId);
} catch (OrganizationRoleNotFound $e) {
return null;
}
return $this->userMappingManager->mappingFromId("group", $role->getMembersGroup()); return $this->userMappingManager->mappingFromId("group", $role->getMembersGroup());
} else { } else {

View file

@ -32,10 +32,10 @@ class ResourceMemberService {
return $this->mapper->findAll($resourceId); return $this->mapper->findAll($resourceId);
} }
private function handleException(Exception $e): void { private function handleException(Exception $e, int $id): void {
if ($e instanceof DoesNotExistException || if ($e instanceof DoesNotExistException ||
$e instanceof MultipleObjectsReturnedException) { $e instanceof MultipleObjectsReturnedException) {
throw new ResourceMemberNotFound($e->getMessage()); throw new ResourceMemberNotFound($id);
} else { } else {
throw $e; throw $e;
} }
@ -45,7 +45,7 @@ class ResourceMemberService {
try { try {
return $this->mapper->find($id); return $this->mapper->find($id);
} catch (Exception $e) { } catch (Exception $e) {
$this->handleException($e); $this->handleException($e, $id);
} }
} }
@ -96,7 +96,7 @@ class ResourceMemberService {
return $member; return $member;
} catch (Exception $e) { } catch (Exception $e) {
$this->handleException($e); $this->handleException($e, $id);
} }
} }
@ -111,7 +111,7 @@ class ResourceMemberService {
return $member; return $member;
} catch (Exception $e) { } catch (Exception $e) {
$this->handleException($e); $this->handleException($e, $id);
} }
} }
} }