Skip to content

EspoCRM – Open Source CRM Application

Tests

Yurii40df0246dc0a
diff --git a/application/Espo/Core/Formula/Functions/RecordGroup/CreateType.php b/application/Espo/Core/Formula/Functions/RecordGroup/CreateType.php
index 70b7de49ba..6ab0520210 100644
--- a/application/Espo/Core/Formula/Functions/RecordGroup/CreateType.php
+++ b/application/Espo/Core/Formula/Functions/RecordGroup/CreateType.php
@@ -68,6 +68,8 @@ class CreateType implements Func
$this->getWriteRestrictedAttributeList($entityType),
);
+ $notAllowedAttributes = array_values($notAllowedAttributes);
+
if ($notAllowedAttributes) {
throw new NotAllowedUsage("Cannot write $entityType.$notAllowedAttributes[0].");
}
diff --git a/application/Espo/Core/Formula/Functions/RecordGroup/UpdateType.php b/application/Espo/Core/Formula/Functions/RecordGroup/UpdateType.php
index 1bf8be2568..c47c90ed08 100644
--- a/application/Espo/Core/Formula/Functions/RecordGroup/UpdateType.php
+++ b/application/Espo/Core/Formula/Functions/RecordGroup/UpdateType.php
@@ -73,6 +73,8 @@ class UpdateType implements Func
$this->getWriteRestrictedAttributeList($entityType),
);
+ $notAllowedAttributes = array_values($notAllowedAttributes);
+
if ($notAllowedAttributes) {
throw new NotAllowedUsage("Cannot write $entityType.$notAllowedAttributes[0].");
}
diff --git a/tests/integration/Espo/Core/Formula/FormulaTest.php b/tests/integration/Espo/Core/Formula/FormulaTest.php
index 4e6e8f5ec2..f091bf34d0 100644
--- a/tests/integration/Espo/Core/Formula/FormulaTest.php
+++ b/tests/integration/Espo/Core/Formula/FormulaTest.php
@@ -1561,5 +1561,67 @@ class FormulaTest extends BaseTestCase
$this->assertTrue($thrown);
//
+
+
+ $script = "
+ \$data = object\\create();
+ record\\create('Extension', \$data);
+ ";
+
+ $thrown = false;
+ try {
+ $fm->run($script, $user);
+ } catch (NotAllowedUsage) {
+ $thrown = true;
+ }
+
+ $this->assertTrue($thrown);
+
+ //
+ }
+
+ /**
+ * @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();
+
+ $script = <<<EOF
+ \$data = object\create();
+ \$data['lastName'] = 'Test';
+
+ \$id = record\create('Lead', \$data);
+
+ \$data['id'] = 'bad';
+
+ record\update('Lead', \$id, \$data);
+ EOF;
+
+ $this->expectException(NotAllowedUsage::class);
+
+ $fm->run($script);
}
}