Initial commit

This commit is contained in:
root
2026-01-19 17:44:46 +01:00
commit 823af8b11d
8721 changed files with 1130846 additions and 0 deletions

View File

@@ -0,0 +1,165 @@
<?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\AclPortal\Attachment;
use Espo\Entities\Attachment;
use Espo\Entities\Note;
use Espo\Entities\Settings;
use Espo\Entities\User;
use Espo\ORM\Entity;
use Espo\Core\Acl\AccessEntityCREDChecker;
use Espo\Core\Acl\ScopeData;
use Espo\Core\ORM\EntityManager;
use Espo\Core\Portal\Acl\DefaultAccessChecker;
use Espo\Core\Portal\Acl\Traits\DefaultAccessCheckerDependency;
use Espo\Core\Portal\AclManager;
/**
* @implements AccessEntityCREDChecker<Attachment>
*/
class AccessChecker implements AccessEntityCREDChecker
{
use DefaultAccessCheckerDependency;
private DefaultAccessChecker $defaultAccessChecker;
private AclManager $aclManager;
private EntityManager $entityManager;
public function __construct(
DefaultAccessChecker $defaultAccessChecker,
AclManager $aclManager,
EntityManager $entityManager
) {
$this->defaultAccessChecker = $defaultAccessChecker;
$this->aclManager = $aclManager;
$this->entityManager = $entityManager;
}
public function checkEntityRead(User $user, Entity $entity, ScopeData $data): bool
{
/** @var Attachment $entity */
if ($entity->get('parentType') === Settings::ENTITY_TYPE) {
// Allow the logo.
return true;
}
$parent = null;
$parentType = $entity->get('parentType');
$parentId = $entity->get('parentId');
$relatedType = $entity->get('relatedType');
$relatedId = $entity->get('relatedId');
if ($parentId && $parentType) {
$parent = $this->entityManager->getEntityById($parentType, $parentId);
} else if ($relatedId && $relatedType) {
$parent = $this->entityManager->getEntityById($relatedType, $relatedId);
}
if (!$parent) {
if ($entity->get('createdById') === $user->getId()) {
return true;
}
return false;
}
if ($parent->getEntityType() === Note::ENTITY_TYPE) {
/** @var Note $parent */
$result = $this->checkEntityReadNoteParent($user, $parent);
if ($result !== null) {
return $result;
}
} else if ($this->aclManager->checkEntity($user, $parent)) {
if (
$entity->getTargetField() &&
!$this->aclManager->checkField($user, $parent->getEntityType(), $entity->getTargetField())
) {
return false;
}
return true;
}
if ($this->defaultAccessChecker->checkEntityRead($user, $entity, $data)) {
return true;
}
return false;
}
private function checkEntityReadNoteParent(User $user, Note $note): ?bool
{
if ($note->isInternal()) {
return false;
}
if ($note->getTargetType() === Note::TARGET_PORTALS) {
$intersect = array_intersect(
$note->getLinkMultipleIdList('portals'),
$user->getLinkMultipleIdList('portals')
);
if (count($intersect)) {
return true;
}
return false;
}
if ($note->getTargetType() === Note::TARGET_USERS) {
$isRelated = $this->entityManager
->getRDBRepository(Note::ENTITY_TYPE)
->getRelation($note, 'users')
->isRelated($user);
if ($isRelated) {
return true;
}
return false;
}
if (!$note->getParentId() || !$note->getParentType()) {
return null;
}
$parent = $this->entityManager->getEntityById($note->getParentType(), $note->getParentId());
if ($parent && $this->aclManager->checkEntity($user, $parent)) {
return true;
}
return null;
}
}

View File

@@ -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\AclPortal\Attachment;
use Espo\Entities\Attachment;
use Espo\Entities\User;
use Espo\ORM\Entity;
use Espo\Core\Acl\OwnershipOwnChecker;
/**
* @implements OwnershipOwnChecker<Attachment>
*/
class OwnershipChecker implements OwnershipOwnChecker
{
private const ATTR_CREATED_BY_ID = 'createdById';
public function checkOwn(User $user, Entity $entity): bool
{
if ($user->getId() === $entity->get(self::ATTR_CREATED_BY_ID)) {
return true;
}
return false;
}
}

View File

@@ -0,0 +1,79 @@
<?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\AclPortal\Email;
use Espo\Entities\Email;
use Espo\Entities\User;
use Espo\ORM\Entity;
use Espo\Core\ORM\Entity as CoreEntity;
use Espo\Core\Acl\AccessEntityCREDSChecker;
use Espo\Core\Acl\ScopeData;
use Espo\Core\Acl\Table;
use Espo\Core\Portal\Acl\DefaultAccessChecker;
use Espo\Core\Portal\Acl\Traits\DefaultAccessCheckerDependency;
/**
* @implements AccessEntityCREDSChecker<Email>
*/
class AccessChecker implements AccessEntityCREDSChecker
{
use DefaultAccessCheckerDependency;
public function __construct(
DefaultAccessChecker $defaultAccessChecker
) {
$this->defaultAccessChecker = $defaultAccessChecker;
}
public function checkEntityRead(User $user, Entity $entity, ScopeData $data): bool
{
if ($this->defaultAccessChecker->checkEntityRead($user, $entity, $data)) {
return true;
}
if ($data->isFalse()) {
return false;
}
if ($data->getRead() === Table::LEVEL_NO) {
return false;
}
assert($entity instanceof CoreEntity);
$userIdList = $entity->getLinkMultipleIdList('users');
if (in_array($user->getId(), $userIdList)) {
return true;
}
return false;
}
}

View 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\AclPortal\Email;
use Espo\Entities\Email;
use Espo\Entities\User;
use Espo\ORM\Entity;
use Espo\Core\Acl\OwnershipOwnChecker;
/**
* @implements OwnershipOwnChecker<Email>
*/
class OwnershipChecker implements OwnershipOwnChecker
{
public function checkOwn(User $user, Entity $entity): bool
{
if ($user->getId() === $entity->get('createdById')) {
return true;
}
return false;
}
}

View File

@@ -0,0 +1,201 @@
<?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\AclPortal\Note;
use Espo\Core\Name\Field;
use Espo\Entities\Note;
use Espo\Entities\User;
use Espo\ORM\Entity;
use Espo\Core\Acl\AccessEntityCREDChecker;
use Espo\Core\Acl\ScopeData;
use Espo\Core\ORM\EntityManager;
use Espo\Core\Portal\Acl\DefaultAccessChecker;
use Espo\Core\Portal\Acl\Traits\DefaultAccessCheckerDependency;
use Espo\Core\Portal\AclManager;
use Espo\Core\Utils\Config;
use DateTime;
use Exception;
/**
* @implements AccessEntityCREDChecker<Note>
*/
class AccessChecker implements AccessEntityCREDChecker
{
use DefaultAccessCheckerDependency;
private const EDIT_PERIOD = '7 days';
private const DELETE_PERIOD = '1 month';
private DefaultAccessChecker $defaultAccessChecker;
private AclManager $aclManager;
private EntityManager $entityManager;
private Config $config;
public function __construct(
DefaultAccessChecker $defaultAccessChecker,
AclManager $aclManager,
EntityManager $entityManager,
Config $config
) {
$this->defaultAccessChecker = $defaultAccessChecker;
$this->aclManager = $aclManager;
$this->entityManager = $entityManager;
$this->config = $config;
}
/**
* @param Note $entity
*/
public function checkEntityCreate(User $user, Entity $entity, ScopeData $data): bool
{
$parentId = $entity->getParentId();
$parentType = $entity->getParentType();
if (!$parentId || !$parentType) {
return $this->defaultAccessChecker->checkEntityCreate($user, $entity, $data);
}
$parent = $this->entityManager->getEntityById($parentType, $parentId);
if ($parent && $this->aclManager->checkEntityStream($user, $parent)) {
return true;
}
return $this->defaultAccessChecker->checkEntityCreate($user, $entity, $data);
}
/**
* @param Note $entity
*/
public function checkEntityRead(User $user, Entity $entity, ScopeData $data): bool
{
$parentId = $entity->getParentId();
$parentType = $entity->getParentType();
if ($parentId && $parentType) {
$parent = $this->entityManager->getEntityById($parentType, $parentId);
if (!$parent) {
return false;
}
return $this->aclManager->checkEntityStream($user, $parent);
}
if ($entity->getType() !== Note::TYPE_POST) {
return false;
}
if ($entity->getCreatedById() === $user->getId()) {
return true;
}
if ($entity->getTargetType() === Note::TARGET_PORTALS) {
return in_array($user->getPortalId(), $entity->getLinkMultipleIdList('portals'));
}
return false;
}
/**
* @param Note $entity
*/
public function checkEntityEdit(User $user, Entity $entity, ScopeData $data): bool
{
if (!$this->defaultAccessChecker->checkEntityEdit($user, $entity, $data)) {
return false;
}
if (!$this->aclManager->checkOwnershipOwn($user, $entity)) {
return false;
}
$createdAt = $entity->get(Field::CREATED_AT);
if (!$createdAt) {
return true;
}
$noteEditThresholdPeriod =
'-' . $this->config->get('noteEditThresholdPeriod', self::EDIT_PERIOD);
$dt = new DateTime();
$dt->modify($noteEditThresholdPeriod);
try {
if ($dt->format('U') > (new DateTime($createdAt))->format('U')) {
return false;
}
} catch (Exception $e) {
return false;
}
return true;
}
/**
* @param Note $entity
*/
public function checkEntityDelete(User $user, Entity $entity, ScopeData $data): bool
{
if (!$this->defaultAccessChecker->checkEntityDelete($user, $entity, $data)) {
return false;
}
if (!$this->aclManager->checkOwnershipOwn($user, $entity)) {
return false;
}
$createdAt = $entity->get(Field::CREATED_AT);
if (!$createdAt) {
return true;
}
$deleteThresholdPeriod =
'-' . $this->config->get('noteDeleteThresholdPeriod', self::DELETE_PERIOD);
$dt = new DateTime();
$dt->modify($deleteThresholdPeriod);
try {
if ($dt->format('U') > (new DateTime($createdAt))->format('U')) {
return false;
}
} catch (Exception $e) {
return false;
}
return true;
}
}

View File

@@ -0,0 +1,53 @@
<?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\AclPortal\Note;
use Espo\Entities\Note;
use Espo\Entities\User;
use Espo\ORM\Entity;
use Espo\Core\Acl\OwnershipOwnChecker;
/**
* @implements OwnershipOwnChecker<Note>
*/
class OwnershipChecker implements OwnershipOwnChecker
{
/**
* @param Note $entity
*/
public function checkOwn(User $user, Entity $entity): bool
{
if ($entity->getType() === Note::TYPE_POST && $user->getId() === $entity->getCreatedById()) {
return true;
}
return false;
}
}

View 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\AclPortal\Notification;
use Espo\Entities\Notification;
use Espo\Entities\User;
use Espo\ORM\Entity;
use Espo\Core\Acl\OwnershipOwnChecker;
/**
* @implements OwnershipOwnChecker<Notification>
*/
class OwnershipChecker implements OwnershipOwnChecker
{
public function checkOwn(User $user, Entity $entity): bool
{
if ($user->getId() === $entity->get('userId')) {
return true;
}
return false;
}
}

View File

@@ -0,0 +1,45 @@
<?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\AclPortal\User;
use Espo\Entities\User;
use Espo\ORM\Entity;
use Espo\Core\Acl\OwnershipOwnChecker;
/**
* @implements OwnershipOwnChecker<User>
*/
class OwnershipChecker implements OwnershipOwnChecker
{
public function checkOwn(User $user, Entity $entity): bool
{
return $user->getId() === $entity->getId();
}
}