diff --git a/application/Espo/Core/defaults/config.php b/application/Espo/Core/defaults/config.php index dd80c8a975..c067e864af 100644 --- a/application/Espo/Core/defaults/config.php +++ b/application/Espo/Core/defaults/config.php @@ -96,6 +96,7 @@ return array ( 'emailMessageMaxSize' => 10, 'notificationsCheckInterval' => 10, 'disabledCountQueryEntityList' => array('Email'), + 'maxEmailAccountCount' => 2, 'isInstalled' => false, ); diff --git a/application/Espo/Core/defaults/systemConfig.php b/application/Espo/Core/defaults/systemConfig.php index fc7bb2d0c2..bc1605c4b2 100644 --- a/application/Espo/Core/defaults/systemConfig.php +++ b/application/Espo/Core/defaults/systemConfig.php @@ -115,6 +115,7 @@ return array ( 'ldapTryUsernameSplit', 'ldapOptReferrals', 'ldapCreateEspoUser', + 'maxEmailAccountCount' ), 'isInstalled' => false, ); diff --git a/application/Espo/Services/EmailAccount.php b/application/Espo/Services/EmailAccount.php index 7480bd83a3..9fc0f3cfee 100644 --- a/application/Espo/Services/EmailAccount.php +++ b/application/Espo/Services/EmailAccount.php @@ -94,6 +94,15 @@ class EmailAccount extends Record public function createEntity($data) { + if (!$this->getUser()->isAdmin()) { + $count = $this->getEntityManager()->getRepository('EmailAccount')->where(array( + 'assignedUserId' => $this->getUser()->id + ))->count(); + if ($count >= $this->getConfig()->get('maxEmailAccountCount', \PHP_INT_MAX)) { + throw new Forbidden(); + } + } + $entity = parent::createEntity($data); if ($entity) { if (!$this->getUser()->isAdmin()) {