This commit is contained in:
Yuri Kuznetsov
2022-10-13 11:57:14 +03:00
parent b66ac6ce13
commit f236a72a1a
5 changed files with 28 additions and 30 deletions

View File

@@ -34,6 +34,7 @@ use Espo\Core\Job\Job\Status;
use Espo\Core\Job\Preparator;
use Espo\Core\Job\Preparator\Data;
use Espo\Entities\EmailAccount;
use Espo\ORM\EntityManager;
use Espo\Entities\Job as JobEntity;
@@ -42,7 +43,7 @@ use DateTimeImmutable;
class CheckEmailAccounts implements Preparator
{
private $entityManager;
private EntityManager $entityManager;
public function __construct(EntityManager $entityManager)
{
@@ -52,10 +53,10 @@ class CheckEmailAccounts implements Preparator
public function prepare(Data $data, DateTimeImmutable $executeTime): void
{
$collection = $this->entityManager
->getRDBRepository('EmailAccount')
->getRDBRepository(EmailAccount::ENTITY_TYPE)
->join('assignedUser', 'assignedUserAdditional')
->where([
'status' => 'Active',
'status' => EmailAccount::STATUS_ACTIVE,
'useImap' => true,
'assignedUserAdditional.isActive' => true,
])
@@ -70,7 +71,7 @@ class CheckEmailAccounts implements Preparator
Status::RUNNING,
Status::READY,
],
'targetType' => 'EmailAccount',
'targetType' => EmailAccount::ENTITY_TYPE,
'targetId' => $entity->getId(),
])
->findOne();
@@ -84,7 +85,7 @@ class CheckEmailAccounts implements Preparator
->where([
'scheduledJobId' => $data->getId(),
'status' => Status::PENDING,
'targetType' => 'EmailAccount',
'targetType' => EmailAccount::ENTITY_TYPE,
'targetId' => $entity->getId(),
])
->count();
@@ -99,7 +100,7 @@ class CheckEmailAccounts implements Preparator
'name' => $data->getName(),
'scheduledJobId' => $data->getId(),
'executeTime' => $executeTime->format(DateTime::SYSTEM_DATE_TIME_FORMAT),
'targetType' => 'EmailAccount',
'targetType' => EmailAccount::ENTITY_TYPE,
'targetId' => $entity->getId(),
]);

View File

@@ -31,6 +31,7 @@ namespace Espo\Classes\Select\EmailFilter\AccessControlFilters;
use Espo\{
Core\Select\AccessControl\Filter,
Entities\EmailAccount,
ORM\Query\SelectBuilder as QueryBuilder,
ORM\EntityManager,
Entities\User,
@@ -38,9 +39,8 @@ use Espo\{
class OnlyOwn implements Filter
{
private $user;
private $entityManager;
private User $user;
private EntityManager $entityManager;
public function __construct(User $user, EntityManager $entityManager)
{
@@ -53,14 +53,14 @@ class OnlyOwn implements Filter
$part = [];
$part[] = [
'parentType' => 'User',
'parentType' => User::ENTITY_TYPE,
'parentId' => $this->user->getId(),
];
$idList = [];
$emailAccountList = $this->entityManager
->getRDBRepository('EmailAccount')
->getRDBRepository(EmailAccount::ENTITY_TYPE)
->select('id')
->where([
'assignedUserId' => $this->user->getId(),
@@ -76,7 +76,7 @@ class OnlyOwn implements Filter
'OR' => [
$part,
[
'parentType' => 'EmailAccount',
'parentType' => EmailAccount::ENTITY_TYPE,
'parentId' => $idList,
],
]

View File

@@ -31,6 +31,7 @@ namespace Espo\Classes\Select\EmailFilter\BoolFilters;
use Espo\{
Core\Select\Bool\Filter,
Entities\EmailAccount,
ORM\Query\SelectBuilder as QueryBuilder,
ORM\Query\Part\WhereClause,
ORM\Query\Part\Where\OrGroupBuilder,
@@ -40,9 +41,8 @@ use Espo\{
class OnlyMy implements Filter
{
private $user;
private $entityManager;
private User $user;
private EntityManager $entityManager;
public function __construct(User $user, EntityManager $entityManager)
{
@@ -55,14 +55,14 @@ class OnlyMy implements Filter
$part = [];
$part[] = [
'parentType' => 'User',
'parentType' => User::ENTITY_TYPE,
'parentId' => $this->user->getId(),
];
$idList = [];
$emailAccountList = $this->entityManager
->getRDBRepository('EmailAccount')
->getRDBRepository(EmailAccount::ENTITY_TYPE)
->select('id')
->where([
'assignedUserId' => $this->user->getId(),
@@ -78,7 +78,7 @@ class OnlyMy implements Filter
'OR' => [
$part,
[
'parentType' => 'EmailAccount',
'parentType' => EmailAccount::ENTITY_TYPE,
'parentId' => $idList,
],
]

View File

@@ -84,21 +84,21 @@ class EmailAccount extends Record implements
{
if (!$this->user->isAdmin()) {
$count = $this->entityManager
->getRDBRepository('EmailAccount')
->getRDBRepository(EmailAccountEntity::ENTITY_TYPE)
->where([
'assignedUserId' => $this->getUser()->getId()
'assignedUserId' => $this->user->getId()
])
->count();
if ($count >= $this->getConfig()->get('maxEmailAccountCount', \PHP_INT_MAX)) {
if ($count >= $this->config->get('maxEmailAccountCount', \PHP_INT_MAX)) {
throw new Forbidden();
}
}
$entity = parent::create($data, $params);
if (!$this->getUser()->isAdmin()) {
$entity->set('assignedUserId', $this->getUser()->getId());
if (!$this->user->isAdmin()) {
$entity->set('assignedUserId', $this->user->getId());
}
$this->entityManager->saveEntity($entity);

View File

@@ -41,13 +41,10 @@ use Espo\Entities\User;
class Language
{
private $metadata;
private $acl;
private $user;
private $container;
private Metadata $metadata;
private Acl $acl;
private User $user;
private Container $container;
public function __construct(
Metadata $metadata,