Merge branch 'hotfix/5.6.2' of ssh://172.20.0.1/var/git/espo/backend into hotfix/5.6.2

This commit is contained in:
Taras Machyshyn
2019-05-09 11:41:08 +03:00
7 changed files with 126 additions and 49 deletions
+2 -2
View File
@@ -115,7 +115,7 @@ class Container
$rotation = $config->get('logger.rotation', true);
$log = new \Espo\Core\Utils\Log('Espo');
$levelCode = $log->getLevelCode($config->get('logger.level', 'WARNING'));
$levelCode = $log::toMonologLevel($config->get('logger.level', 'WARNING'));
if ($rotation) {
$maxFileNumber = $config->get('logger.maxFileNumber', 30);
@@ -127,7 +127,7 @@ class Container
$errorHandler = new \Monolog\ErrorHandler($log);
$errorHandler->registerExceptionHandler(null, false);
$errorHandler->registerErrorHandler(array(), false);
$errorHandler->registerErrorHandler([], false);
return $log;
}
@@ -0,0 +1,35 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2019 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
* Website: https://www.espocrm.com
*
* EspoCRM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EspoCRM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\Exceptions;
class ForbiddenSilent extends Forbidden
{
public $logLevel = 'notice';
}
@@ -0,0 +1,35 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2019 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
* Website: https://www.espocrm.com
*
* EspoCRM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EspoCRM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\Exceptions;
class NotFoundSilent extends NotFound
{
public $logLevel = 'notice';
}
+30 -4
View File
@@ -71,22 +71,48 @@ class Output
echo $data;
}
public function processError(string $message = 'Error', int $code = 500, bool $toPrint = false, $exception = null)
public function processError(string $message = 'Error', int $statusCode = 500, bool $toPrint = false, $exception = null)
{
$currentRoute = $this->getSlim()->router()->getCurrentRoute();
if (isset($currentRoute)) {
$inputData = $this->getSlim()->request()->getBody();
$inputData = $this->clearPasswords($inputData);
$GLOBALS['log']->error('API ['.$this->getSlim()->request()->getMethod().']:'.$currentRoute->getPattern().', Params:'.print_r($currentRoute->getParams(), true).', InputData: '.$inputData.' - '.$message);
$routePattern = $currentRoute->getPattern();
$routeParams = $currentRoute->getParams();
$method = $this->getSlim()->request()->getMethod();
$logMessage = "API ($statusCode) ";
$logMessageItemList = [];
if ($message) $logMessageItemList[] = $message;
$logMessageItemList[] .= "$method " . $_SERVER['REQUEST_URI'];
if ($inputData) $logMessageItemList[] = "Input data: " . $inputData;
if ($routePattern) $logMessageItemList[] = "Route pattern: ". $routePattern;
if (!empty($routeParams)) $logMessageItemList[] = "Route params: ". print_r($routeParams, true);
$logMessage .= implode("; ", $logMessageItemList);
$GLOBALS['log']->log('debug', $logMessage);
}
$this->displayError($message, $code, $toPrint, $exception);
$this->displayError($message, $statusCode, $toPrint, $exception);
}
public function displayError(string $text, int $statusCode = 500, bool $toPrint = false, $exception = null)
{
$GLOBALS['log']->error('Display Error: '.$text.', Code: '.$statusCode.' URL: '.$_SERVER['REQUEST_URI']);
$logLevel = 'error';
if ($exception && !empty($exception->logLevel)) {
$logLevel = $exception->logLevel;
}
$logMessageItemList = [];
if ($text) $logMessageItemList[] = "{$text}";
if (!empty($this->slim)) {
$logMessageItemList[] = $this->getSlim()->request()->getMethod() . ' ' .$_SERVER['REQUEST_URI'];
}
$logMessage = "($statusCode) " . implode("; ", $logMessageItemList);
$GLOBALS['log']->log($logLevel, $logMessage);
ob_clean();
@@ -28,28 +28,11 @@
************************************************************************/
namespace Espo\Core\Utils\Log\Monolog;
class Logger extends \Monolog\Logger
{
protected $defaultLevelName = 'DEBUG';
/**
* Get Level Code
* @param string $level Ex. DEBUG, ...
* @return int
*/
public function getLevelCode($levelName)
{
$levelName = strtoupper($levelName);
$levels = $this->getLevels();
if (isset($levels[$levelName])) {
return $levels[$levelName];
}
return $levels[$this->defaultLevelName];
}
public function setLevel($levelName)
{
$level = static::toMonologLevel($levelName);
+10 -13
View File
@@ -36,7 +36,8 @@ use \Espo\Core\Exceptions\Forbidden;
use \Espo\Core\Exceptions\BadRequest;
use \Espo\Core\Exceptions\Conflict;
use \Espo\Core\Exceptions\NotFound;
use \Espo\Core\Exceptions\NotFoundSilent;
use \Espo\Core\Exceptions\ForbiddenSilent;
use \Espo\Core\Utils\Util;
@@ -282,7 +283,7 @@ class Record extends \Espo\Core\Services\Base
}
$entity = $this->getEntity($id);
if (!$entity) throw new NotFound();
if (!$entity) throw new NotFoundSilent("Record does not exist.");
$this->processActionHistoryRecord('read', $entity);
@@ -303,11 +304,7 @@ class Record extends \Espo\Core\Services\Base
if ($entity && !is_null($id)) {
$this->loadAdditionalFields($entity);
if (!$this->getAcl()->check($entity, 'read')) {
throw new Forbidden();
}
if (!$this->getAcl()->check($entity, 'read')) throw new ForbiddenSilent();
$this->prepareEntityForOutput($entity);
}
@@ -882,7 +879,7 @@ class Record extends \Espo\Core\Services\Base
public function create($data)
{
if (!$this->getAcl()->check($this->getEntityType(), 'create')) throw new Forbidden();
if (!$this->getAcl()->check($this->getEntityType(), 'create')) throw new ForbiddenSilent();
$entity = $this->getRepository()->get();
@@ -902,11 +899,11 @@ class Record extends \Espo\Core\Services\Base
$this->populateDefaults($entity, $data);
if (!$this->getAcl()->check($entity, 'create')) throw new Forbidden();
if (!$this->getAcl()->check($entity, 'create')) throw new ForbiddenSilent();
$this->processValidation($entity, $data);
if (!$this->checkAssignment($entity)) throw new Forbidden('Assignment permission failure');
if (!$this->checkAssignment($entity)) throw new Forbidden('Assignment permission failure.');
$this->processDuplicateCheck($entity, $data);
@@ -954,13 +951,13 @@ class Record extends \Espo\Core\Services\Base
if (!$entity) throw new NotFound();
if (!$this->getAcl()->check($entity, 'edit')) throw new Forbidden();
if (!$this->getAcl()->check($entity, 'edit')) throw new ForbiddenSilent();
$entity->set($data);
$this->processValidation($entity, $data);
if (!$this->checkAssignment($entity)) throw new Forbidden();
if (!$this->checkAssignment($entity)) throw new Forbidden("Assignment permission failure.");
$this->beforeUpdateEntity($entity, $data);
@@ -1023,7 +1020,7 @@ class Record extends \Espo\Core\Services\Base
if (!$entity) throw new NotFound();
if (!$this->getAcl()->check($entity, 'delete')) throw new Forbidden();
if (!$this->getAcl()->check($entity, 'delete')) throw new ForbiddenSilent();
$this->beforeDeleteEntity($entity);
+13 -12
View File
@@ -45,19 +45,20 @@ Espo.define('views/admin/field-manager/list', 'view', function (Dep) {
var field = $(e.currentTarget).data('name');
this.confirm(this.translate('confirmation', 'messages'), function () {
this.notify('Removing...');
$.ajax({
url: 'Admin/fieldManager/' + this.scope + '/' + field,
type: 'DELETE',
success: function () {
this.notify('Removed', 'success');
var data = this.getMetadata().data;
delete data['entityDefs'][this.scope]['fields'][field];
Espo.Ui.notify(this.translate('Removing...'));
Espo.Ajax.request('Admin/fieldManager/' + this.scope + '/' + field, 'delete').then(function () {
Espo.Ui.success(this.translate('Removed'));
$(e.currentTarget).closest('tr').remove();
var data = this.getMetadata().data;
delete data['entityDefs'][this.scope]['fields'][field];
this.getMetadata().load(function () {
this.getMetadata().storeToCache();
$(e.currentTarget).closest('tr').remove();
}.bind(this),
});
}, this);
}.bind(this), true);
}.bind(this));
}.bind(this));
}
},