Skip to content

Commit

Permalink
Attachments patches
Browse files Browse the repository at this point in the history
Included in CiviCRM version: N/A
Core PRs:
- civicrm#9875
- civicrm#10010
  • Loading branch information
davialexandre committed Jul 14, 2019
1 parent ac7af20 commit 99a0ecb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 26 deletions.
43 changes: 19 additions & 24 deletions Civi/API/Subscriber/DynamicFKAuthorization.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,32 +221,27 @@ public function authorizeDelegate($action, $entityTable, $entityId, $apiRequest)
throw new \Civi\API\Exception\UnauthorizedException("Authorization failed on ($entity): Missing entity_id");
}

/**
* @var \Exception $exception
*/
$exception = NULL;
$self = $this;
\CRM_Core_Transaction::create(TRUE)->run(function($tx) use ($entity, $action, $entityId, &$exception, $self) {
// Just to be safe.
$tx->rollback();

$params = [
'version' => 3,
'check_permissions' => 1,
'id' => $entityId,
];
if (!$this->isAuthorized($entity, $action, $entityId)) {
throw new \Civi\API\Exception\UnauthorizedException("Authorization failed on ($entity, $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)", [
'cause' => $result,
]);
}
});
/**
* @param string $entity
* @param string $action
* @param int $entityId
*
* @return bool
* @throws \Exception
*/
private function isAuthorized($entity, $action, $entityId) {
$params = [
'version' => 3,
'check_permissions' => 1,
'id' => $entityId
];

if ($exception) {
throw $exception;
}
return $this->kernel->runAuthorize($entity, $this->getDelegatedAction($action), $params);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions Civi/Core/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,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"
',
['civicrm_activity', 'civicrm_mailing', 'civicrm_contact', 'civicrm_grant']
'
));

$kernel->setApiProviders([
Expand Down

0 comments on commit 99a0ecb

Please sign in to comment.