Merge branch 'hotfix/5.7.12' of ssh://172.20.0.1/var/git/espo/backend into hotfix/5.7.12

This commit is contained in:
Taras Machyshyn
2020-01-21 14:56:26 +02:00
5 changed files with 43 additions and 29 deletions
@@ -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
@@ -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);
}
}
+18 -16
View File
@@ -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) . "
";
@@ -267,24 +267,26 @@ 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;
}
if (!$this->getMetadata()->get('scopes.' . $entity->getEntityName() . '.stream')) {
if (!$this->getMetadata()->get('scopes.' . $entity->getEntityType() . '.stream')) {
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();
@@ -293,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();
}
@@ -302,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;
}
@@ -311,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();
@@ -1155,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;
}
@@ -1212,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;
}
+4
View File
@@ -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));
+1 -1
View File
@@ -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)
);
}