Initial commit
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\RecordHooks\BpmnProcess;
|
||||
|
||||
use Espo\Core\Record\Hook\UpdateHook;
|
||||
use Espo\Core\Record\UpdateParams;
|
||||
use Espo\Modules\Advanced\Entities\BpmnProcess;
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
/**
|
||||
* @implements UpdateHook<BpmnProcess>
|
||||
*/
|
||||
class BeforeUpdate implements UpdateHook
|
||||
{
|
||||
public function process(Entity $entity, UpdateParams $params): void
|
||||
{
|
||||
$entity->clear('flowchartId');
|
||||
$entity->clear('targetId');
|
||||
$entity->clear('targetType');
|
||||
$entity->clear('startElementId');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\RecordHooks\BpmnUserTask;
|
||||
|
||||
use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Core\Record\Hook\UpdateHook;
|
||||
use Espo\Core\Record\UpdateParams;
|
||||
use Espo\Entities\User;
|
||||
use Espo\Modules\Advanced\Entities\BpmnUserTask;
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
/**
|
||||
* @implements UpdateHook<BpmnUserTask>
|
||||
*/
|
||||
class BeforeUpdate implements UpdateHook
|
||||
{
|
||||
private User $user;
|
||||
|
||||
public function __construct(
|
||||
User $user
|
||||
) {
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function process(Entity $entity, UpdateParams $params): void
|
||||
{
|
||||
if (!$this->user->isAdmin()) {
|
||||
if ($entity->getFetched('isResolved') && $entity->isAttributeChanged('resolution')) {
|
||||
throw new Forbidden("Can't change resolution. Already resolved.");
|
||||
}
|
||||
|
||||
if ($entity->getFetched('isCanceled') && $entity->isAttributeChanged('resolution')) {
|
||||
throw new Forbidden("Can't change resolution. Already canceled.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\RecordHooks\Report;
|
||||
|
||||
use Espo\Core\Acl;
|
||||
use Espo\Core\Acl\Table;
|
||||
use Espo\Core\Exceptions\BadRequest;
|
||||
use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Core\Record\CreateParams;
|
||||
use Espo\Core\Record\Hook\CreateHook;
|
||||
use Espo\Modules\Advanced\Entities\Report;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\EntityManager;
|
||||
|
||||
/**
|
||||
* @implements CreateHook<Report>
|
||||
*/
|
||||
class BeforeCreate implements CreateHook
|
||||
{
|
||||
private Acl $acl;
|
||||
private EntityManager $entityManager;
|
||||
|
||||
public function __construct(
|
||||
Acl $acl,
|
||||
EntityManager $entityManager
|
||||
) {
|
||||
$this->acl = $acl;
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
public function process(Entity $entity, CreateParams $params): void
|
||||
{
|
||||
$this->processJointGridBeforeSave($entity);
|
||||
|
||||
if (
|
||||
in_array('applyAcl', $this->acl->getScopeForbiddenFieldList(Report::ENTITY_TYPE, Table::ACTION_EDIT))
|
||||
) {
|
||||
$entity->setApplyAcl();
|
||||
}
|
||||
|
||||
if (!$this->acl->check($entity->getTargetEntityType(), Table::ACTION_READ)) {
|
||||
throw new Forbidden("No 'read' access to target entity type.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws BadRequest
|
||||
* @throws Forbidden
|
||||
*/
|
||||
public function processJointGridBeforeSave(Report $entity): void
|
||||
{
|
||||
if ($entity->getType() !== Report::TYPE_JOINT_GRID) {
|
||||
return;
|
||||
}
|
||||
|
||||
$joinedReportDataList = $entity->get('joinedReportDataList');
|
||||
|
||||
if (!is_array($joinedReportDataList) || !count($joinedReportDataList)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$groupCount = 0;
|
||||
|
||||
foreach ($joinedReportDataList as $i => $item) {
|
||||
if (empty($item->id)) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
/** @var ?Report $report */
|
||||
$report = $this->entityManager->getEntityById(Report::ENTITY_TYPE, $item->id);
|
||||
|
||||
if (!$report) {
|
||||
throw new Forbidden('Report not found.');
|
||||
}
|
||||
|
||||
if (!$this->acl->check($report->getTargetEntityType(), Table::ACTION_READ)) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$groupBy = $report->getGroupBy();
|
||||
|
||||
if (
|
||||
count($groupBy) > 1 ||
|
||||
$report->getType() !== Report::TYPE_GRID
|
||||
) {
|
||||
throw new Forbidden("Sub-report $item->id is not supported in joint report.");
|
||||
}
|
||||
|
||||
if ($i === 0) {
|
||||
$groupCount = count($groupBy);
|
||||
|
||||
$entityType = $report->getTargetEntityType();
|
||||
$entity->set('entityType', $entityType);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($groupCount !== count($groupBy)) {
|
||||
throw new BadRequest("Sub-reports must have the same Group By number.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/***********************************************************************************
|
||||
* The contents of this file are subject to the Extension License Agreement
|
||||
* ("Agreement") which can be viewed at
|
||||
* https://www.espocrm.com/extension-license-agreement/.
|
||||
* By copying, installing downloading, or using this file, You have unconditionally
|
||||
* agreed to the terms and conditions of the Agreement, and You may not use this
|
||||
* file except in compliance with the Agreement. Under the terms of the Agreement,
|
||||
* You shall not license, sublicense, sell, resell, rent, lease, lend, distribute,
|
||||
* redistribute, market, publish, commercialize, or otherwise transfer rights or
|
||||
* usage to the software or any modified version or derivative work of the software
|
||||
* created by or for you.
|
||||
*
|
||||
* Copyright (C) 2015-2025 EspoCRM, Inc.
|
||||
*
|
||||
* License ID: 19bc86a68a7bb01f458cb391d43a9212
|
||||
************************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Advanced\Classes\RecordHooks\Report;
|
||||
|
||||
use Espo\Core\Record\Hook\UpdateHook;
|
||||
use Espo\Core\Record\UpdateParams;
|
||||
use Espo\Modules\Advanced\Entities\Report;
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
/**
|
||||
* @implements UpdateHook<Report>
|
||||
*/
|
||||
class BeforeUpdate implements UpdateHook
|
||||
{
|
||||
private BeforeCreate $beforeCreate;
|
||||
|
||||
public function __construct(
|
||||
BeforeCreate $beforeCreate
|
||||
) {
|
||||
$this->beforeCreate = $beforeCreate;
|
||||
}
|
||||
|
||||
public function process(Entity $entity, UpdateParams $params): void
|
||||
{
|
||||
if ($entity->isAttributeChanged('type')) {
|
||||
$entity->set('type', $entity->getFetched('type'));
|
||||
}
|
||||
|
||||
if (
|
||||
$entity->getType() !== Report::TYPE_JOINT_GRID &&
|
||||
$entity->isAttributeChanged('entityType')
|
||||
) {
|
||||
$entity->set('entityType', $entity->getFetched('entityType'));
|
||||
}
|
||||
|
||||
$this->beforeCreate->processJointGridBeforeSave($entity);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user