diff --git a/application/Espo/Core/Htmlizer/Htmlizer.php b/application/Espo/Core/Htmlizer/Htmlizer.php
index 4011195fbb..02a7d820d5 100644
--- a/application/Espo/Core/Htmlizer/Htmlizer.php
+++ b/application/Espo/Core/Htmlizer/Htmlizer.php
@@ -46,11 +46,19 @@ class Htmlizer
protected $config;
- public function __construct(FileManager $fileManager, DateTime $dateTime, Number $number)
+ protected $acl;
+
+ public function __construct(FileManager $fileManager, DateTime $dateTime, Number $number, $acl = null)
{
$this->fileManager = $fileManager;
$this->dateTime = $dateTime;
$this->number = $number;
+ $this->acl = $acl;
+ }
+
+ protected function getAcl()
+ {
+ return $this->acl;
}
protected function formatNumber($value)
@@ -68,16 +76,22 @@ class Htmlizer
return $value;
}
- protected function getDataFromEntity(Entity $entity)
+ protected function getDataFromEntity(Entity $entity, $notLinks = false)
{
$data = $entity->toArray();
-
-
$fieldDefs = $entity->getFields();
$fieldList = array_keys($fieldDefs);
+ $forbidenAttributeList = [];
+
+ if ($this->getAcl()) {
+ $forbidenAttributeList = $this->getAcl()->getScopeForbiddenAttributeList($entity->getEntityType(), 'read');
+ }
+
foreach ($fieldList as $field) {
+ if (in_array($field, $forbidenAttributeList)) continue;
+
$type = null;
if (!empty($fieldDefs[$field]['type'])) {
$type = $fieldDefs[$field]['type'];
@@ -123,6 +137,25 @@ class Htmlizer
}
}
+ if (!$notLinks) {
+ $relationDefs = $entity->getRelations();
+ foreach ($entity->getRelationList() as $relation) {
+ if (
+ !empty($relationDefs[$relation]['type'])
+ &&
+ ($entity->getRelationType($relation) === 'belongsTo' || $entity->getRelationType($relation) === 'belongsToParent')
+ ) {
+ $relatedEntity = $entity->get($relation);
+ if (!$relatedEntity) continue;
+ if ($this->getAcl()) {
+ if (!$this->getAcl()->check($relatedEntity, 'read')) continue;
+ }
+
+ $data[$relation] = $this->getDataFromEntity($relatedEntity, true);
+ }
+ }
+ }
+
return $data;
}
diff --git a/application/Espo/ORM/Entity.php b/application/Espo/ORM/Entity.php
index 385914d588..645646861e 100644
--- a/application/Espo/ORM/Entity.php
+++ b/application/Espo/ORM/Entity.php
@@ -280,6 +280,11 @@ abstract class Entity implements IEntity
return array_keys($this->getAttributes());
}
+ public function getRelationList()
+ {
+ return array_keys($this->getRelations());
+ }
+
public function getValues()
{
return $this->toArray();
diff --git a/application/Espo/Services/Pdf.php b/application/Espo/Services/Pdf.php
index 1c1922fbfb..9599793e91 100644
--- a/application/Espo/Services/Pdf.php
+++ b/application/Espo/Services/Pdf.php
@@ -88,7 +88,7 @@ class Pdf extends \Espo\Core\Services\Base
throw new Forbidden();
}
- $htmlizer = new Htmlizer($this->getFileManager(), $this->getInjection('dateTime'), $this->getInjection('number'));
+ $htmlizer = new Htmlizer($this->getFileManager(), $this->getInjection('dateTime'), $this->getInjection('number'), $this->getAcl());
$pdf = new \Espo\Core\Pdf\Tcpdf();