From 7753eb32af33419ff565478a89ebf3c2a5fb882c Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Mon, 29 Jun 2020 14:29:33 +0300 Subject: [PATCH] controller refactoring --- application/Espo/Controllers/DataPrivacy.php | 22 +++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/application/Espo/Controllers/DataPrivacy.php b/application/Espo/Controllers/DataPrivacy.php index 7e1c9b66e4..a63a18e09a 100644 --- a/application/Espo/Controllers/DataPrivacy.php +++ b/application/Espo/Controllers/DataPrivacy.php @@ -29,27 +29,33 @@ namespace Espo\Controllers; -use Espo\Core\Exceptions\Error; use Espo\Core\Exceptions\Forbidden; -use Espo\Core\Exceptions\NotFound; use Espo\Core\Exceptions\BadRequest; -class DataPrivacy extends \Espo\Core\Controllers\Base +use Espo\Core\ServiceFactory; +use Espo\Core\Acl; + +class DataPrivacy { - protected function checkControllerAccess() + protected $serviceFactory; + protected $acl; + + public function __construct(ServiceFactory $serviceFactory, Acl $acl) { - if ($this->getAcl()->get('dataPrivacyPermission') === 'no') { + $this->serviceFactory = $serviceFactory; + $this->acl = $acl; + + if ($this->acl->get('dataPrivacyPermission') === 'no') { throw new Forbidden(); } } - public function postActionErase($params, $data) + public function postActionErase($params, \StdClass $data) { if (empty($data->entityType) || empty($data->id) || empty($data->fieldList) || !is_array($data->fieldList)) { throw new BadRequest(); } - return $this->getServiceFactory()->create('DataPrivacy')->erase($data->entityType, $data->id, $data->fieldList); + return $this->serviceFactory->create('DataPrivacy')->erase($data->entityType, $data->id, $data->fieldList); } - }