From d4169ca2257e3a78ce61bb8e5b05c353d2dbc0de Mon Sep 17 00:00:00 2001 From: Davi Alexandre Date: Thu, 5 Apr 2018 08:12:48 -0300 Subject: [PATCH] Attachments patches Included in CiviCRM version: N/A Core PRs: - https://github.com/civicrm/civicrm-core/pull/9875 - https://github.com/civicrm/civicrm-core/pull/10010 --- .../API/Subscriber/DynamicFKAuthorization.php | 44 ++++++++----------- Civi/Core/Container.php | 3 +- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/Civi/API/Subscriber/DynamicFKAuthorization.php b/Civi/API/Subscriber/DynamicFKAuthorization.php index 719e716c26d6..f6223d1ea975 100644 --- a/Civi/API/Subscriber/DynamicFKAuthorization.php +++ b/Civi/API/Subscriber/DynamicFKAuthorization.php @@ -217,34 +217,28 @@ public function authorizeDelegate($action, $entityTable, $entityId, $apiRequest) if ($this->isTrusted($apiRequest)) { return; } - - /** - * @var \Exception $exception - */ - $exception = NULL; - $self = $this; - \CRM_Core_Transaction::create(TRUE)->run(function($tx) use ($entity, $action, $entityId, &$exception, $self) { - $tx->rollback(); // Just to be safe. - - $params = array( - 'version' => 3, - 'check_permissions' => 1, - 'id' => $entityId, - ); - - $result = $self->kernel->run($entity, $self->getDelegatedAction($action), $params); - if ($result['is_error'] || empty($result['values'])) { - $exception = new \Civi\API\Exception\UnauthorizedException("Authorization failed on ($entity,$entityId)", array( - 'cause' => $result, - )); - } - }); - - if ($exception) { - throw $exception; + + if (!$this->isAuthorized($entity, $action, $entityId)) { + throw new \Civi\API\Exception\UnauthorizedException("Authorization failed on ($entity,$entityId)"); } } + /** + * @param string $entity + * @param string $action + * @param int $entityId + * + * @return bool + */ + private function isAuthorized($entity, $action, $entityId) { + $params = array( + 'version' => 3, + 'check_permissions' => 1, + 'id' => $entityId, + ); + return $this->kernel->runAuthorize($entity, $this->getDelegatedAction($action), $params); + } + /** * If the request attempts to change the entity_table/entity_id of an * existing record, then generate an error. diff --git a/Civi/Core/Container.php b/Civi/Core/Container.php index 6eb4a4d66a9f..e08c64227af7 100644 --- a/Civi/Core/Container.php +++ b/Civi/Core/Container.php @@ -397,8 +397,7 @@ public function createApiKernel($dispatcher, $magicFunctionProvider) { FROM civicrm_custom_field fld INNER JOIN civicrm_custom_group grp ON fld.custom_group_id = grp.id WHERE fld.data_type = "File" - ', - array('civicrm_activity', 'civicrm_mailing', 'civicrm_contact', 'civicrm_grant') + ' )); $kernel->setApiProviders(array(