Skip to content

EspoCRM – Open Source CRM Application

Revert ID restriction

Yuriif3dad81f05c4
diff --git a/application/Espo/Core/Formula/Functions/RecordGroup/CreateType.php b/application/Espo/Core/Formula/Functions/RecordGroup/CreateType.php
index 6ab0520210..081280725b 100644
--- a/application/Espo/Core/Formula/Functions/RecordGroup/CreateType.php
+++ b/application/Espo/Core/Formula/Functions/RecordGroup/CreateType.php
@@ -36,7 +36,6 @@ use Espo\Core\Formula\Exceptions\TooFewArguments;
use Espo\Core\Formula\Func;
use Espo\Core\Formula\Utils\EntityUtil;
use Espo\ORM\EntityManager;
-use Espo\ORM\Name\Attribute;
use stdClass;
/**
@@ -65,7 +64,7 @@ class CreateType implements Func
$notAllowedAttributes = array_intersect(
array_keys($data),
- $this->getWriteRestrictedAttributeList($entityType),
+ $this->entityUtil->getWriteRestrictedAttributeList($entityType),
);
$notAllowedAttributes = array_values($notAllowedAttributes);
@@ -91,7 +90,7 @@ class CreateType implements Func
private function getData(EvaluatedArgumentList $args, mixed $entityType): array
{
if (count($args) >= 2 && $args[1] instanceof stdClass) {
- return get_object_vars($args[1]);
+ return $this->filterData(get_object_vars($args[1]));
}
$data = [];
@@ -114,17 +113,15 @@ class CreateType implements Func
$i = $i + 2;
}
- return $data;
+ return $this->filterData($data);
}
/**
- * @return string[]
+ * @param array<string, mixed> $data
+ * @return array<string, mixed>
*/
- private function getWriteRestrictedAttributeList(string $entityType): array
+ private function filterData(array $data): array
{
- return [
- ...$this->entityUtil->getWriteRestrictedAttributeList($entityType),
- Attribute::ID,
- ];
+ return $data;
}
}
diff --git a/application/Espo/Core/Formula/Functions/RecordGroup/UpdateType.php b/application/Espo/Core/Formula/Functions/RecordGroup/UpdateType.php
index c47c90ed08..7150ae68ed 100644
--- a/application/Espo/Core/Formula/Functions/RecordGroup/UpdateType.php
+++ b/application/Espo/Core/Formula/Functions/RecordGroup/UpdateType.php
@@ -70,7 +70,7 @@ class UpdateType implements Func
$notAllowedAttributes = array_intersect(
array_keys($data),
- $this->getWriteRestrictedAttributeList($entityType),
+ $this->entityUtil->getWriteRestrictedAttributeList($entityType),
);
$notAllowedAttributes = array_values($notAllowedAttributes);
@@ -101,7 +101,7 @@ class UpdateType implements Func
private function getData(EvaluatedArgumentList $args, mixed $entityType): array
{
if (count($args) >= 3 && $args[2] instanceof stdClass) {
- return get_object_vars($args[2]);
+ return $this->filterData(get_object_vars($args[2]));
}
$data = [];
@@ -124,17 +124,17 @@ class UpdateType implements Func
$i = $i + 2;
}
- return $data;
+ return $this->filterData($data);
}
/**
- * @return string[]
+ * @param array<string, mixed> $data
+ * @return array<string, mixed>
*/
- private function getWriteRestrictedAttributeList(string $entityType): array
+ private function filterData(array $data): array
{
- return [
- ...$this->entityUtil->getWriteRestrictedAttributeList($entityType),
- Attribute::ID,
- ];
+ unset($data[Attribute::ID]);
+
+ return $data;
}
}
diff --git a/tests/integration/Espo/Core/Formula/FormulaTest.php b/tests/integration/Espo/Core/Formula/FormulaTest.php
index f091bf34d0..d62c5555c0 100644
--- a/tests/integration/Espo/Core/Formula/FormulaTest.php
+++ b/tests/integration/Espo/Core/Formula/FormulaTest.php
@@ -38,6 +38,7 @@ use Espo\Core\Formula\Manager;
use Espo\Entities\User;
use Espo\Modules\Crm\Entities\Account;
use Espo\Modules\Crm\Entities\Contact;
+use Espo\Modules\Crm\Entities\Lead;
use Espo\Modules\Crm\Entities\Meeting;
use Espo\Modules\Crm\Entities\Opportunity;
use Espo\ORM\EntityManager;
@@ -1580,34 +1581,13 @@ class FormulaTest extends BaseTestCase
//
}
- /**
- * @noinspection PhpUnhandledExceptionInspection
- */
- public function testRecordCreateIdRestriction(): void
- {
- $fm = $this->getContainer()->getByClass(Manager::class);
- $this->getEntityManager();
-
- $script = <<<EOF
- \$data = object\create();
- \$data['id'] = 'bad';
- \$data['lastName'] = 'Test';
-
- record\create('Lead', \$data);
- EOF;
-
- $this->expectException(NotAllowedUsage::class);
-
- $fm->run($script);
- }
-
/**
* @noinspection PhpUnhandledExceptionInspection
*/
public function testRecordUpdateIdRestriction(): void
{
$fm = $this->getContainer()->getByClass(Manager::class);
- $this->getEntityManager();
+ $em = $this->getEntityManager();
$script = <<<EOF
\$data = object\create();
@@ -1618,10 +1598,14 @@ class FormulaTest extends BaseTestCase
\$data['id'] = 'bad';
record\update('Lead', \$id, \$data);
+
+ \$id;
EOF;
- $this->expectException(NotAllowedUsage::class);
+ $id = $fm->run($script);
- $fm->run($script);
+ $lead = $em->getRDBRepositoryByClass(Lead::class)->getById($id);
+ $this->assertNotNull($lead);
+ $this->assertNotEquals('bad', $lead->getId());
}
}