Initial commit
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Classes\Record\AppSecret;
|
||||
|
||||
use Espo\Core\Exceptions\BadRequest;
|
||||
use Espo\Core\Record\Input\Data;
|
||||
use Espo\Core\Record\Input\Filter;
|
||||
use Espo\Core\Utils\Crypt;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class ValueInputFilter implements Filter
|
||||
{
|
||||
private const ATTR_VALUE = 'value';
|
||||
|
||||
public function __construct(private Crypt $crypt) {}
|
||||
|
||||
/**
|
||||
* @throws BadRequest
|
||||
*/
|
||||
public function filter(Data $data): void
|
||||
{
|
||||
$value = $data->get(self::ATTR_VALUE);
|
||||
|
||||
if ($value !== null) {
|
||||
if (!is_string($value)) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
$data->set(self::ATTR_VALUE, $this->crypt->encrypt($value));
|
||||
}
|
||||
}
|
||||
}
|
||||
156
application/Espo/Classes/Record/Attachment/CreateInputFilter.php
Normal file
156
application/Espo/Classes/Record/Attachment/CreateInputFilter.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Classes\Record\Attachment;
|
||||
|
||||
use Espo\Core\Exceptions\BadRequest;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Core\Record\Input\Data;
|
||||
use Espo\Core\Record\Input\Filter;
|
||||
use Espo\Entities\Attachment;
|
||||
use Espo\ORM\EntityManager;
|
||||
use Espo\Tools\Attachment\AccessChecker;
|
||||
use Espo\Tools\Attachment\DetailsObtainer;
|
||||
use Espo\Tools\Attachment\FieldData;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class CreateInputFilter implements Filter
|
||||
{
|
||||
public function __construct(
|
||||
private EntityManager $entityManager,
|
||||
private AccessChecker $accessChecker,
|
||||
private DetailsObtainer $detailsObtainer
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws BadRequest
|
||||
* @throws Error
|
||||
* @throws Forbidden
|
||||
*/
|
||||
public function filter(Data $data): void
|
||||
{
|
||||
$data->clear('parentId');
|
||||
$data->clear('relatedId');
|
||||
|
||||
$contents = $this->handleContents($data);
|
||||
|
||||
$relatedEntityType = $this->getRelatedEntityType($data);
|
||||
|
||||
$field = $data->get('field');
|
||||
$role = $data->get('role') ?? Attachment::ROLE_ATTACHMENT;
|
||||
|
||||
if (!$relatedEntityType || !$field) {
|
||||
throw new BadRequest("No `field` and `parentType`.");
|
||||
}
|
||||
|
||||
$fieldData = new FieldData($field, $data->get('parentType'), $data->get('relatedType'));
|
||||
|
||||
$this->accessChecker->check($fieldData, $role);
|
||||
$this->checkMaxSize($contents, $data, $field, $role);
|
||||
}
|
||||
|
||||
private function getRelatedEntityType(Data $data): ?string
|
||||
{
|
||||
if ($data->get('parentType') !== null) {
|
||||
$data->clear('relatedType');
|
||||
|
||||
return $data->get('parentType');
|
||||
}
|
||||
|
||||
if ($data->get('relatedType') !== null) {
|
||||
return $data->get('relatedType');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws BadRequest
|
||||
*/
|
||||
private function handleContents(Data $data): string
|
||||
{
|
||||
$isBeingUploaded = $data->get('isBeingUploaded') ?? false;
|
||||
|
||||
$contents = '';
|
||||
|
||||
if (!$isBeingUploaded) {
|
||||
if (!$data->has('file')) {
|
||||
throw new BadRequest("No file contents.");
|
||||
}
|
||||
|
||||
$file = $data->get('file');
|
||||
|
||||
if (!is_string($file)) {
|
||||
throw new BadRequest("Non-string file contents.");
|
||||
}
|
||||
|
||||
$arr = explode(',', $file);
|
||||
|
||||
if (count($arr) < 2) {
|
||||
throw new BadRequest("Bad file contents.");
|
||||
}
|
||||
|
||||
$contents = base64_decode($arr[1]);
|
||||
|
||||
if ($contents === false) {
|
||||
throw new BadRequest("Could not decode file contents.");
|
||||
}
|
||||
}
|
||||
|
||||
$data->set('contents', $contents);
|
||||
|
||||
return $contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws BadRequest
|
||||
*/
|
||||
private function checkMaxSize(string $contents, Data $data, mixed $field, mixed $role): void
|
||||
{
|
||||
$size = mb_strlen($contents, '8bit');
|
||||
|
||||
$dummy = $this->entityManager->getRepositoryByClass(Attachment::class)->getNew();
|
||||
|
||||
$dummy->set([
|
||||
'parentType' => $data->get('parentType'),
|
||||
'relatedType' => $data->get('relatedType'),
|
||||
'field' => $field,
|
||||
'role' => $role,
|
||||
]);
|
||||
|
||||
$maxSize = $this->detailsObtainer->getUploadMaxSize($dummy);
|
||||
|
||||
if ($maxSize && $size > $maxSize * 1024 * 1024) {
|
||||
throw new BadRequest("File size should not exceed $maxSize Mb.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Classes\Record\Attachment;
|
||||
|
||||
use Espo\Core\Record\Input\Data;
|
||||
use Espo\Core\Record\Input\Filter;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class UpdateInputFilter implements Filter
|
||||
{
|
||||
public function filter(Data $data): void
|
||||
{
|
||||
$data->clear('parentId');
|
||||
$data->clear('parentType');
|
||||
$data->clear('relatedId');
|
||||
$data->clear('relatedType');
|
||||
$data->clear('isBeingUploaded');
|
||||
$data->clear('storage');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Classes\Record\AuthToken;
|
||||
|
||||
use Espo\Core\Record\Input\Data;
|
||||
use Espo\Core\Record\Input\Filter;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class UpdateInputFilter implements Filter
|
||||
{
|
||||
public function filter(Data $data): void
|
||||
{
|
||||
foreach ($data->getAttributeList() as $attribute) {
|
||||
if ($attribute !== 'isActive') {
|
||||
$data->clear($attribute);
|
||||
}
|
||||
}
|
||||
|
||||
if ($data->get('isActive')) {
|
||||
$data->clear('isActive');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Classes\Record\InboundEmail;
|
||||
|
||||
use Espo\Core\Exceptions\BadRequest;
|
||||
use Espo\Core\Record\Input\Data;
|
||||
use Espo\Core\Record\Input\Filter;
|
||||
use Espo\Core\Utils\Crypt;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class PasswordsInputFilter implements Filter
|
||||
{
|
||||
public function __construct(
|
||||
private Crypt $crypt
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws BadRequest
|
||||
*/
|
||||
public function filter(Data $data): void
|
||||
{
|
||||
$password = $data->get('password');
|
||||
|
||||
if ($password !== null) {
|
||||
if (!is_string($password)) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
$data->set('password', $this->crypt->encrypt($password));
|
||||
}
|
||||
|
||||
$smtpPassword = $data->get('smtpPassword');
|
||||
|
||||
if ($smtpPassword !== null) {
|
||||
if (!is_string($smtpPassword)) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
$data->set('smtpPassword', $this->crypt->encrypt($smtpPassword));
|
||||
}
|
||||
}
|
||||
}
|
||||
50
application/Espo/Classes/Record/Note/UpdateInputFilter.php
Normal file
50
application/Espo/Classes/Record/Note/UpdateInputFilter.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Classes\Record\Note;
|
||||
|
||||
use Espo\Core\Record\Input\Data;
|
||||
use Espo\Core\Record\Input\Filter;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class UpdateInputFilter implements Filter
|
||||
{
|
||||
public function filter(Data $data): void
|
||||
{
|
||||
$data->clear('parentId');
|
||||
$data->clear('parentType');
|
||||
$data->clear('targetType');
|
||||
$data->clear('usersIds');
|
||||
$data->clear('teamsIds');
|
||||
$data->clear('portalsIds');
|
||||
$data->clear('isGlobal');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Classes\Record\OAuthProvider;
|
||||
|
||||
use Espo\Core\Exceptions\BadRequest;
|
||||
use Espo\Core\Record\Input\Data;
|
||||
use Espo\Core\Record\Input\Filter;
|
||||
use Espo\Core\Utils\Crypt;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class GeneralFilter implements Filter
|
||||
{
|
||||
private const ATTR_CLIENT_SECRET = 'clientSecret';
|
||||
|
||||
public function __construct(private Crypt $crypt) {}
|
||||
|
||||
/**
|
||||
* @throws BadRequest
|
||||
*/
|
||||
public function filter(Data $data): void
|
||||
{
|
||||
$this->processClientSecret($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws BadRequest
|
||||
*/
|
||||
private function processClientSecret(Data $data): void
|
||||
{
|
||||
$value = $data->get(self::ATTR_CLIENT_SECRET);
|
||||
|
||||
if ($value === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_string($value)) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
$data->set(self::ATTR_CLIENT_SECRET, $this->crypt->encrypt($value));
|
||||
}
|
||||
}
|
||||
59
application/Espo/Classes/Record/Portal/InputFilter.php
Normal file
59
application/Espo/Classes/Record/Portal/InputFilter.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Classes\Record\Portal;
|
||||
|
||||
use Espo\Core\Record\Input\Data;
|
||||
use Espo\Core\Record\Input\Filter;
|
||||
use Espo\Core\Utils\Config;
|
||||
use Espo\Entities\User;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class InputFilter implements Filter
|
||||
{
|
||||
public function __construct(
|
||||
private User $user,
|
||||
private Config $config
|
||||
) {}
|
||||
|
||||
public function filter(Data $data): void
|
||||
{
|
||||
if (!$this->config->get('restrictedMode')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->user->isSuperAdmin()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data->clear('customUrl');
|
||||
}
|
||||
}
|
||||
69
application/Espo/Classes/Record/User/DeletedRestorer.php
Normal file
69
application/Espo/Classes/Record/User/DeletedRestorer.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Classes\Record\User;
|
||||
|
||||
use Espo\Core\Exceptions\Conflict;
|
||||
use Espo\Core\Record\Deleted\DefaultRestorer;
|
||||
use Espo\Core\Record\Deleted\Restorer;
|
||||
use Espo\Entities\User;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\Tools\User\UserUtil;
|
||||
|
||||
/**
|
||||
* @implements Restorer<User>
|
||||
*/
|
||||
class DeletedRestorer implements Restorer
|
||||
{
|
||||
public function __construct(
|
||||
private DefaultRestorer $defaultRestorer,
|
||||
private UserUtil $userUtil,
|
||||
) {}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function restore(Entity $entity): void
|
||||
{
|
||||
$this->processUserExistsChecking($entity);
|
||||
|
||||
$this->defaultRestorer->restore($entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Conflict
|
||||
*/
|
||||
private function processUserExistsChecking(User $user): void
|
||||
{
|
||||
if ($this->userUtil->checkExists($user)) {
|
||||
throw new Conflict('userNameExists');
|
||||
}
|
||||
}
|
||||
}
|
||||
58
application/Espo/Classes/Record/User/InputFilter.php
Normal file
58
application/Espo/Classes/Record/User/InputFilter.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Classes\Record\User;
|
||||
|
||||
use Espo\Core\Acl;
|
||||
use Espo\Core\Record\Input\Data;
|
||||
use Espo\Core\Record\Input\Filter;
|
||||
use Espo\Entities\Team as TeamEntity;
|
||||
use Espo\Entities\User;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class InputFilter implements Filter
|
||||
{
|
||||
public function __construct(
|
||||
private User $user,
|
||||
private Acl $acl,
|
||||
) {}
|
||||
|
||||
public function filter(Data $data): void
|
||||
{
|
||||
if (!$this->user->isSuperAdmin()) {
|
||||
$data->clear('isSuperAdmin');
|
||||
}
|
||||
|
||||
if (!$this->user->isAdmin() && !$this->acl->checkScope(TeamEntity::ENTITY_TYPE)) {
|
||||
$data->clear('defaultTeamId');
|
||||
}
|
||||
}
|
||||
}
|
||||
74
application/Espo/Classes/Record/User/OutputFilter.php
Normal file
74
application/Espo/Classes/Record/User/OutputFilter.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Classes\Record\User;
|
||||
|
||||
use Espo\Core\Authentication\Logins\Hmac;
|
||||
use Espo\Core\Record\Output\Filter;
|
||||
use Espo\Core\Utils\ApiKey;
|
||||
use Espo\Entities\User;
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
/**
|
||||
* @implements Filter<User>
|
||||
*/
|
||||
class OutputFilter implements Filter
|
||||
{
|
||||
public function __construct(
|
||||
private User $user,
|
||||
private ApiKey $apiKey
|
||||
) {}
|
||||
|
||||
public function filter(Entity $entity): void
|
||||
{
|
||||
$entity->clear('sendAccessInfo');
|
||||
|
||||
$this->filterApiUser($entity);
|
||||
}
|
||||
|
||||
private function filterApiUser(User $entity): void
|
||||
{
|
||||
if (!$entity->isApi()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->user->isAdmin()) {
|
||||
if ($entity->getAuthMethod() === Hmac::NAME) {
|
||||
$secretKey = $this->apiKey->getSecretKeyForUserId($entity->getId());
|
||||
|
||||
$entity->set('secretKey', $secretKey);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$entity->clear('apiKey');
|
||||
$entity->clear('secretKey');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Classes\Record\Webhook;
|
||||
|
||||
use Espo\Core\Record\Defaults\DefaultPopulator;
|
||||
use Espo\Core\Record\Defaults\Populator;
|
||||
use Espo\Entities\User;
|
||||
use Espo\Entities\Webhook;
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
/**
|
||||
* @implements Populator<Webhook>
|
||||
*/
|
||||
class DefaultsPopulator implements Populator
|
||||
{
|
||||
public function __construct(
|
||||
private DefaultPopulator $defaultsDefaultsPopulator,
|
||||
private User $user
|
||||
) {}
|
||||
|
||||
public function populate(Entity $entity): void
|
||||
{
|
||||
$this->defaultsDefaultsPopulator->populate($entity);
|
||||
|
||||
if ($this->user->isApi()) {
|
||||
$entity->set('userId', $this->user->getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Classes\Record\Webhook;
|
||||
|
||||
use Espo\Core\Record\Input\Data;
|
||||
use Espo\Core\Record\Input\Filter;
|
||||
use Espo\Entities\User;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class UpdateInputFilter implements Filter
|
||||
{
|
||||
public function __construct(
|
||||
private User $user
|
||||
) {}
|
||||
|
||||
public function filter(Data $data): void
|
||||
{
|
||||
if (!$this->user->isAdmin()) {
|
||||
$data->clear('event');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user