From fb8a4b90ca0a6e695b2ed55441e76c8efa463ff8 Mon Sep 17 00:00:00 2001 From: yuri Date: Thu, 26 Feb 2015 11:16:57 +0200 Subject: [PATCH] maxEmailAccountCount --- application/Espo/Core/defaults/config.php | 1 + application/Espo/Core/defaults/systemConfig.php | 1 + application/Espo/Services/EmailAccount.php | 9 +++++++++ 3 files changed, 11 insertions(+) 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()) {