diff --git a/lib/Manager/ACLManager.php b/lib/Manager/ACLManager.php index 6036fb8..bbb6aa2 100644 --- a/lib/Manager/ACLManager.php +++ b/lib/Manager/ACLManager.php @@ -16,6 +16,8 @@ use OCA\GroupFolders\Folder\FolderManager; use OCA\OrganizationFolders\OrganizationProvider\OrganizationProviderManager; use OCA\OrganizationFolders\Model\Principal; use OCA\OrganizationFolders\Enum\PrincipalType; +use OCA\OrganizationFolders\Errors\OrganizationProviderNotFound; +use OCA\OrganizationFolders\Errors\OrganizationRoleNotFound; class ACLManager { public function __construct( @@ -54,7 +56,7 @@ class ACLManager { return array_map($this->createRuleEntityFromRow(...), $rows); } - public function getMappingForPrincipal(Principal $principal): IUserMapping { + public function getMappingForPrincipal(Principal $principal): ?IUserMapping { if($principal->getType() === PrincipalType::USER) { return $this->userMappingManager->mappingFromId("user", $principal->getId()); } else if($principal->getType() === PrincipalType::GROUP) { @@ -62,8 +64,17 @@ class ACLManager { } else if($principal->getType() === PrincipalType::ROLE) { [$organizationProviderId, $roleId] = explode(":", $principal->getId(), 2); - $organizationProvider = $this->organizationProviderManager->getOrganizationProvider($organizationProviderId); - $role = $organizationProvider->getRole($roleId); + try { + $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()); } else { diff --git a/lib/Service/ResourceMemberService.php b/lib/Service/ResourceMemberService.php index 2ae7315..12a19e0 100644 --- a/lib/Service/ResourceMemberService.php +++ b/lib/Service/ResourceMemberService.php @@ -32,10 +32,10 @@ class ResourceMemberService { return $this->mapper->findAll($resourceId); } - private function handleException(Exception $e): void { + private function handleException(Exception $e, int $id): void { if ($e instanceof DoesNotExistException || $e instanceof MultipleObjectsReturnedException) { - throw new ResourceMemberNotFound($e->getMessage()); + throw new ResourceMemberNotFound($id); } else { throw $e; } @@ -45,7 +45,7 @@ class ResourceMemberService { try { return $this->mapper->find($id); } catch (Exception $e) { - $this->handleException($e); + $this->handleException($e, $id); } } @@ -96,7 +96,7 @@ class ResourceMemberService { return $member; } catch (Exception $e) { - $this->handleException($e); + $this->handleException($e, $id); } } @@ -111,7 +111,7 @@ class ResourceMemberService { return $member; } catch (Exception $e) { - $this->handleException($e); + $this->handleException($e, $id); } } } \ No newline at end of file