Skip to content

EspoCRM – Open Source CRM Application

Mass update processor attachment handling ref

Yurii5be3e7ef2a01
diff --git a/application/Espo/Tools/MassUpdate/Processor.php b/application/Espo/Tools/MassUpdate/Processor.php
index 22c5e69662..3a8f608fe4 100644
--- a/application/Espo/Tools/MassUpdate/Processor.php
+++ b/application/Espo/Tools/MassUpdate/Processor.php
@@ -166,7 +166,7 @@ class Processor
Data $data,
int $i,
array $fieldToCopyList,
- Service $service
+ Service $service,
): bool {
$service->loadAdditionalFields($entity);
@@ -175,7 +175,16 @@ class Processor
return false;
}
- $values = $this->prepareItemValueMap($entity, $data, $i, $fieldToCopyList);
+ try {
+ $values = $this->prepareItemValueMap($entity, $data, $i, $fieldToCopyList);
+ } catch (Forbidden $e) {
+ $this->log->notice("Mass update forbidden. Record: {id}.", [
+ 'exception' => $e,
+ 'id' => $entity->getId(),
+ ]);
+
+ return false;
+ }
$service->filterInputReadOnlySaved($entity, $values);
@@ -223,6 +232,7 @@ class Processor
/**
* @param string[] $copyFieldList
+ * @throws Forbidden
*/
private function prepareItemValueMap(Entity $entity, Data $data, int $i, array $copyFieldList): stdClass
{
@@ -235,6 +245,7 @@ class Processor
/**
* @param string[] $copyFieldList
+ * @throws Forbidden
*/
private function copy(string $entityType, Data $data, int $i, array $copyFieldList): Data
{
@@ -265,6 +276,9 @@ class Processor
return $data;
}
+ /**
+ * @throws Forbidden
+ */
private function copyFileField(string $field, Data $data): Data
{
$attribute = $field . 'Id';
@@ -281,6 +295,10 @@ class Processor
return $data->with($attribute, null);
}
+ if (!$this->acl->checkEntityRead($attachment)) {
+ throw new Forbidden("No access to attachment $id.");
+ }
+
/** @var AttachmentRepository $attachmentRepository */
$attachmentRepository = $this->entityManager->getRepository(Attachment::ENTITY_TYPE);
@@ -289,6 +307,9 @@ class Processor
return $data->with($attribute, $copiedAttachment->getId());
}
+ /**
+ * @throws Forbidden
+ */
private function copyAttachmentMultipleField(string $field, Data $data): Data
{
$attribute = $field . 'Ids';
@@ -315,6 +336,10 @@ class Processor
continue;
}
+ if (!$this->acl->checkEntityRead($attachment)) {
+ throw new Forbidden("No access to attachment $id.");
+ }
+
$copiedIds[] = $attachmentRepository
->getCopiedAttachment($attachment)
->getId();