diff --git a/application/Espo/Resources/layouts/EmailAccount/detail.json b/application/Espo/Resources/layouts/EmailAccount/detail.json index faaef4e10d..bf98da5057 100644 --- a/application/Espo/Resources/layouts/EmailAccount/detail.json +++ b/application/Espo/Resources/layouts/EmailAccount/detail.json @@ -8,14 +8,14 @@ ], [ {"name":"name"}, - {"name":"fetchSince"} + false ] ] }, { "label":"IMAP", "rows":[ - [{"name": "useImap"}, false], + [{"name": "useImap"}, {"name":"fetchSince"}], [ {"name":"host"},{"name":"ssl"} ], diff --git a/application/Espo/Resources/layouts/InboundEmail/detail.json b/application/Espo/Resources/layouts/InboundEmail/detail.json index 9127a0a004..19269ee87d 100644 --- a/application/Espo/Resources/layouts/InboundEmail/detail.json +++ b/application/Espo/Resources/layouts/InboundEmail/detail.json @@ -12,7 +12,7 @@ ], [ {"name":"teams"}, - {"name":"fetchSince"} + false ], [ {"name":"addAllTeamUsers"}, @@ -23,7 +23,7 @@ { "label": "IMAP", "rows": [ - [{"name": "useImap"}, false], + [{"name": "useImap"}, {"name":"fetchSince"}], [ {"name":"host"},{"name":"ssl"} ], diff --git a/application/Espo/Resources/metadata/clientDefs/EmailAccount.json b/application/Espo/Resources/metadata/clientDefs/EmailAccount.json index b189661ff0..853be96365 100644 --- a/application/Espo/Resources/metadata/clientDefs/EmailAccount.json +++ b/application/Espo/Resources/metadata/clientDefs/EmailAccount.json @@ -56,6 +56,32 @@ } ] } + }, + "fetchSince": { + "visible": { + "conditionGroup": [ + { + "type": "isTrue", + "attribute": "useImap" + } + ] + }, + "readOnly": { + "conditionGroup": [ + { + "type": "isNotEmpty", + "attribute": "fetchData" + } + ] + }, + "required": { + "conditionGroup": [ + { + "type": "isTrue", + "attribute": "useImap" + } + ] + } } } }, diff --git a/application/Espo/Resources/metadata/clientDefs/InboundEmail.json b/application/Espo/Resources/metadata/clientDefs/InboundEmail.json index 3e454825ca..eb310c3ee4 100644 --- a/application/Espo/Resources/metadata/clientDefs/InboundEmail.json +++ b/application/Espo/Resources/metadata/clientDefs/InboundEmail.json @@ -49,6 +49,32 @@ } ] } + }, + "fetchSince": { + "visible": { + "conditionGroup": [ + { + "type": "isTrue", + "attribute": "useImap" + } + ] + }, + "readOnly": { + "conditionGroup": [ + { + "type": "isNotEmpty", + "attribute": "fetchData" + } + ] + }, + "required": { + "conditionGroup": [ + { + "type": "isTrue", + "attribute": "useImap" + } + ] + } } } }, diff --git a/application/Espo/Resources/metadata/entityDefs/EmailAccount.json b/application/Espo/Resources/metadata/entityDefs/EmailAccount.json index 6eea6a548a..f13c0b5100 100644 --- a/application/Espo/Resources/metadata/entityDefs/EmailAccount.json +++ b/application/Espo/Resources/metadata/entityDefs/EmailAccount.json @@ -56,8 +56,7 @@ "type": "bool" }, "fetchSince": { - "type": "date", - "required": true + "type": "date" }, "fetchData": { "type": "jsonObject", diff --git a/application/Espo/Resources/metadata/entityDefs/InboundEmail.json b/application/Espo/Resources/metadata/entityDefs/InboundEmail.json index 9f37a3d61b..393e06867c 100644 --- a/application/Espo/Resources/metadata/entityDefs/InboundEmail.json +++ b/application/Espo/Resources/metadata/entityDefs/InboundEmail.json @@ -44,8 +44,7 @@ "tooltip": true }, "fetchSince": { - "type": "date", - "required": true + "type": "date" }, "fetchData": { "type": "jsonObject", diff --git a/application/Espo/Services/EmailAccount.php b/application/Espo/Services/EmailAccount.php index d8716dab2f..418fc9788f 100644 --- a/application/Espo/Services/EmailAccount.php +++ b/application/Espo/Services/EmailAccount.php @@ -29,11 +29,13 @@ namespace Espo\Services; -use \Espo\ORM\Entity; +use Espo\ORM\Entity; -use \Espo\Core\Exceptions\Error; -use \Espo\Core\Exceptions\Forbidden; -use \Zend\Mail\Storage; +use Espo\Core\Exceptions\Error; +use Espo\Core\Exceptions\Forbidden; +use Espo\Core\Exceptions\BadRequest; + +use Zend\Mail\Storage; class EmailAccount extends Record { @@ -64,6 +66,17 @@ class EmailAccount extends Record } } + public function processValidation(Entity $entity, $data) + { + parent::processValidation($entity, $data); + + if ($entity->get('useImap')) { + if (!$entity->get('fetchSince')) { + throw new BadRequest("EmailAccount validation: fetchSince is required."); + } + } + } + public function getFolders($params) { $userId = $params['userId'] ?? null; diff --git a/application/Espo/Services/InboundEmail.php b/application/Espo/Services/InboundEmail.php index e9176a300d..b9d50ca4ed 100644 --- a/application/Espo/Services/InboundEmail.php +++ b/application/Espo/Services/InboundEmail.php @@ -35,6 +35,7 @@ use Zend\Mail\Storage; use Espo\Core\Exceptions\Error; use Espo\Core\Exceptions\Forbidden; +use Espo\Core\Exceptions\BadRequest; class InboundEmail extends \Espo\Services\Record { @@ -74,6 +75,17 @@ class InboundEmail extends \Espo\Services\Record } } + public function processValidation(Entity $entity, $data) + { + parent::processValidation($entity, $data); + + if ($entity->get('useImap')) { + if (!$entity->get('fetchSince')) { + throw new BadRequest("EmailAccount validation: fetchSince is required."); + } + } + } + public function getFolders($params) { if (!empty($params['id'])) {