mirror of
https://github.com/verdigado/organization_folders.git
synced 2024-11-23 21:20:28 +01:00
improved error handling
This commit is contained in:
parent
9f14ca2179
commit
ab378ea223
2 changed files with 19 additions and 8 deletions
|
@ -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);
|
||||
|
||||
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 {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue