From 6f9259b750b199eb088d7f80025049f99fe48a69 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Fri, 17 Jan 2020 13:16:35 +0200 Subject: [PATCH 1/5] fix test --- tests/integration/Espo/User/AclTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/Espo/User/AclTest.php b/tests/integration/Espo/User/AclTest.php index c7d9cc6d8e..b75442c382 100644 --- a/tests/integration/Espo/User/AclTest.php +++ b/tests/integration/Espo/User/AclTest.php @@ -185,7 +185,7 @@ class AclTest extends \tests\integration\Core\BaseTestCase $this->assertTrue(!property_exists($resultData, 'type') || $resultData->type !== 'admin'); $this->assertTrue( - !property_exists($resultData, 'teamsIds') || !is_array($resultData->teamsIds) || !in_array('id', $$resultData->teamsIds) + !property_exists($resultData, 'teamsIds') || !is_array($resultData->teamsIds) || !in_array('id', $resultData->teamsIds) ); } From 38dfa910585511bedd78a62c035179274c75102b Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Fri, 17 Jan 2020 16:41:46 +0200 Subject: [PATCH 2/5] fix link parent missing current entity type --- client/src/views/fields/link-parent.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/client/src/views/fields/link-parent.js b/client/src/views/fields/link-parent.js index 2113c88649..ea6613766f 100644 --- a/client/src/views/fields/link-parent.js +++ b/client/src/views/fields/link-parent.js @@ -106,6 +106,10 @@ define('views/fields/link-parent', 'views/fields/base', function (Dep) { this.foreignScope = this.model.get(this.typeName) || this.foreignScopeList[0]; + if (this.foreignScope && !~this.foreignScopeList.indexOf(this.foreignScope)) { + this.foreignScopeList.unshift(this.foreignScope); + } + this.listenTo(this.model, 'change:' + this.typeName, function () { this.foreignScope = this.model.get(this.typeName) || this.foreignScopeList[0]; }.bind(this)); From 6699e66c29a86278d21869a99c0f000bcbefa677 Mon Sep 17 00:00:00 2001 From: beppe9000 <6625123+beppe9000@users.noreply.github.com> Date: Tue, 21 Jan 2020 09:24:04 +0100 Subject: [PATCH 3/5] Increase logging of many-to-many relation operations and log invalid foreach parameter error for mid keys (#1579) closes #1577 --- .../Core/Utils/Database/Schema/Converter.php | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/application/Espo/Core/Utils/Database/Schema/Converter.php b/application/Espo/Core/Utils/Database/Schema/Converter.php index a2510953a3..a9e6b6294f 100644 --- a/application/Espo/Core/Utils/Database/Schema/Converter.php +++ b/application/Espo/Core/Utils/Database/Schema/Converter.php @@ -282,6 +282,9 @@ class Converter protected function prepareManyMany($entityName, $relationParams, $tables) { $tableName = Util::toUnderScore($relationParams['relationName']); + $GLOBALS['log']->debug('DBAL: prepareManyMany invoked for ' . $entityName, [ + 'tableName' => $tableName, 'parameters' => $relationParams + ]); if ($this->getSchema()->hasTable($tableName)) { $GLOBALS['log']->debug('DBAL: Table ['.$tableName.'] exists.'); @@ -297,17 +300,22 @@ class Converter //add midKeys to a schema $uniqueIndex = array(); - foreach($relationParams['midKeys'] as $index => $midKey) { - - $columnName = Util::toUnderScore($midKey); - $table->addColumn($columnName, $this->idParams['dbType'], $this->getDbFieldParams(array( - 'type' => 'foreignId', - 'len' => $this->idParams['len'], - ))); - $table->addIndex(array($columnName), SchemaUtils::generateIndexName($columnName)); - - $uniqueIndex[] = $columnName; - } + if (empty($relationParams['midKeys'])) { + $GLOBALS['log']->debug('REBUILD: midKeys are empty!', [ + 'scope' => $entityName, 'tableName' => $tableName, + 'parameters' => $relationParams + ]); + } else { + foreach($relationParams['midKeys'] as $index => $midKey) { + $columnName = Util::toUnderScore($midKey); + $table->addColumn($columnName, $this->idParams['dbType'], $this->getDbFieldParams(array( + 'type' => 'foreignId', + 'len' => $this->idParams['len'], + ))); + $table->addIndex(array($columnName), SchemaUtils::generateIndexName($columnName)); + $uniqueIndex[] = $columnName; + } + } //END: add midKeys to a schema //add additionalColumns From db334baa2edb1cea2096f163dc8997b6c221f110 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Tue, 21 Jan 2020 11:46:28 +0200 Subject: [PATCH 4/5] fix case portal user follow --- .../Espo/Modules/Crm/Repositories/CaseObj.php | 2 +- application/Espo/Services/Stream.php | 20 ++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/application/Espo/Modules/Crm/Repositories/CaseObj.php b/application/Espo/Modules/Crm/Repositories/CaseObj.php index 0ea402367a..b4a4db56a7 100644 --- a/application/Espo/Modules/Crm/Repositories/CaseObj.php +++ b/application/Espo/Modules/Crm/Repositories/CaseObj.php @@ -75,7 +75,7 @@ class CaseObj extends \Espo\Core\ORM\Repositories\RDB ])->findOne(); if ($portalUser) { - $this->getInjection('serviceFactory')->create('Stream')->followEntity($entity, $portalUser->id); + $this->getInjection('serviceFactory')->create('Stream')->followEntity($entity, $portalUser->id, true); } } diff --git a/application/Espo/Services/Stream.php b/application/Espo/Services/Stream.php index 9dc347bce5..3b86c07942 100644 --- a/application/Espo/Services/Stream.php +++ b/application/Espo/Services/Stream.php @@ -267,7 +267,7 @@ class Stream extends \Espo\Core\Services\Base $pdo->query($sql); } - public function followEntity(Entity $entity, $userId) + public function followEntity(Entity $entity, $userId, bool $skipAclCheck = false) { if ($userId == 'system') { return; @@ -276,15 +276,17 @@ class Stream extends \Espo\Core\Services\Base return false; } - $user = $this->getEntityManager()->getRepository('User') - ->select(['id', 'type', 'isActive']) - ->where([ - 'id' => $userId, - 'isActive' => true, - ])->findOne(); + if (!$skipAclCheck) { + $user = $this->getEntityManager()->getRepository('User') + ->select(['id', 'type', 'isActive']) + ->where([ + 'id' => $userId, + 'isActive' => true, + ])->findOne(); - if (!$user) return false; - if (!$this->getAclManager()->check($user, $entity, 'stream')) return false; + if (!$user) return false; + if (!$this->getAclManager()->check($user, $entity, 'stream')) return false; + } $pdo = $this->getEntityManager()->getPDO(); From 8fa65bc965efbd957fd3d35ac20401cbd7bba8e6 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Tue, 21 Jan 2020 11:47:14 +0200 Subject: [PATCH 5/5] fix naming --- application/Espo/Services/Stream.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/application/Espo/Services/Stream.php b/application/Espo/Services/Stream.php index 3b86c07942..e363374e58 100644 --- a/application/Espo/Services/Stream.php +++ b/application/Espo/Services/Stream.php @@ -186,7 +186,7 @@ class Stream extends \Espo\Core\Services\Base $sql = " SELECT id FROM subscription WHERE - entity_id = " . $pdo->quote($entity->id) . " AND entity_type = " . $pdo->quote($entity->getEntityName()) . " AND + entity_id = " . $pdo->quote($entity->id) . " AND entity_type = " . $pdo->quote($entity->getEntityType()) . " AND user_id = " . $pdo->quote($userId) . " "; @@ -272,7 +272,7 @@ class Stream extends \Espo\Core\Services\Base if ($userId == 'system') { return; } - if (!$this->getMetadata()->get('scopes.' . $entity->getEntityName() . '.stream')) { + if (!$this->getMetadata()->get('scopes.' . $entity->getEntityType() . '.stream')) { return false; } @@ -295,7 +295,7 @@ class Stream extends \Espo\Core\Services\Base INSERT INTO subscription (entity_id, entity_type, user_id) VALUES - (".$pdo->quote($entity->id) . ", " . $pdo->quote($entity->getEntityName()) . ", " . $pdo->quote($userId).") + (".$pdo->quote($entity->id) . ", " . $pdo->quote($entity->getEntityType()) . ", " . $pdo->quote($userId).") "; $sth = $pdo->prepare($sql)->execute(); } @@ -304,7 +304,7 @@ class Stream extends \Espo\Core\Services\Base public function unfollowEntity(Entity $entity, $userId) { - if (!$this->getMetadata()->get('scopes.' . $entity->getEntityName() . '.stream')) { + if (!$this->getMetadata()->get('scopes.' . $entity->getEntityType() . '.stream')) { return false; } @@ -313,7 +313,7 @@ class Stream extends \Espo\Core\Services\Base $sql = " DELETE FROM subscription WHERE - entity_id = " . $pdo->quote($entity->id) . " AND entity_type = " . $pdo->quote($entity->getEntityName()) . " AND + entity_id = " . $pdo->quote($entity->id) . " AND entity_type = " . $pdo->quote($entity->getEntityType()) . " AND user_id = " . $pdo->quote($userId) . " "; $sth = $pdo->prepare($sql)->execute(); @@ -1157,7 +1157,7 @@ class Stream extends \Espo\Core\Services\Base if ($from) { $person = $this->getEntityManager()->getRepository('EmailAddress')->getEntityByAddress($from); if ($person) { - $data['personEntityType'] = $person->getEntityName(); + $data['personEntityType'] = $person->getEntityType(); $data['personEntityName'] = $person->get('name'); $data['personEntityId'] = $person->id; } @@ -1214,7 +1214,7 @@ class Stream extends \Espo\Core\Services\Base } if ($person) { - $data['personEntityType'] = $person->getEntityName(); + $data['personEntityType'] = $person->getEntityType(); $data['personEntityName'] = $person->get('name'); $data['personEntityId'] = $person->id; }