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 Oct 23, 2018
1 parent 57b24ed commit d4169ca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 27 deletions.
44 changes: 19 additions & 25 deletions Civi/API/Subscriber/DynamicFKAuthorization.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions Civi/Core/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit d4169ca

Please sign in to comment.