This commit is contained in:
Yuri Kuznetsov
2023-03-04 10:59:39 +02:00
parent e11e3d6168
commit 2655f0d9c5
7 changed files with 47 additions and 98 deletions
+5 -10
View File
@@ -100,32 +100,27 @@ class Application
protected function getInjectableFactory(): InjectableFactory
{
/** @var InjectableFactory */
return $this->container->get('injectableFactory');
return $this->container->getByClass(InjectableFactory::class);
}
protected function getApplicationUser(): ApplicationUser
{
/** @var ApplicationUser */
return $this->container->get('applicationUser');
return $this->container->getByClass(ApplicationUser::class);
}
protected function getClientManager(): ClientManager
{
/** @var ClientManager */
return $this->container->get('clientManager');
return $this->container->getByClass(ClientManager::class);
}
protected function getMetadata(): Metadata
{
/** @var Metadata */
return $this->container->get('metadata');
return $this->container->getByClass(Metadata::class);
}
protected function getConfig(): Config
{
/** @var Config */
return $this->container->get('config');
return $this->container->getByClass(Config::class);
}
protected function initAutoloads(): void
+8 -5
View File
@@ -39,6 +39,9 @@ use LogicException;
*/
class ApplicationState
{
private const KEY_USER = 'user';
private const KEY_PORTAL = 'portal';
public function __construct(private Container $container)
{}
@@ -47,7 +50,7 @@ class ApplicationState
*/
public function isPortal(): bool
{
return $this->container->has('portal');
return $this->container->has(self::KEY_PORTAL);
}
/**
@@ -72,7 +75,7 @@ class ApplicationState
}
/** @var PortalEntity */
return $this->container->get('portal');
return $this->container->get(self::KEY_PORTAL);
}
/**
@@ -80,7 +83,7 @@ class ApplicationState
*/
public function hasUser(): bool
{
return $this->container->has('user');
return $this->container->has(self::KEY_USER);
}
/**
@@ -93,7 +96,7 @@ class ApplicationState
}
/** @var UserEntity */
return $this->container->get('user');
return $this->container->get(self::KEY_USER);
}
/**
@@ -109,7 +112,7 @@ class ApplicationState
*/
public function isLogged(): bool
{
if (!$this->container->has('user')) {
if (!$this->container->has(self::KEY_USER)) {
return false;
}
@@ -30,25 +30,21 @@
namespace Espo\Core\Console\Commands;
use Espo\Entities\User;
use Espo\Core\AclManager;
use Espo\ORM\EntityManager;
use Espo\Core\AclManager;
use Espo\Core\Console\Command;
use Espo\Core\Console\Command\Params;
use Espo\Core\Console\IO;
use Espo\Core\Container;
use Espo\Core\Portal\Application as PortalApplication;
use Espo\Core\{
Portal\Application as PortalApplication,
Container,
Console\Command,
Console\Command\Params,
Console\IO,
};
/**
* Checks access for websocket topic subscription. Prints `true` if access allowed.
*/
class AclCheck implements Command
{
private Container $container;
public function __construct(Container $container)
{
$this->container = $container;
}
public function __construct(private Container $container)
{}
public function run(Params $params, IO $io): void
{
@@ -59,24 +55,14 @@ class AclCheck implements Command
$id = $options['id'] ?? null;
$action = $options['action'] ?? null;
if (empty($userId)) {
return;
}
if (empty($scope)) {
return;
}
if (empty($id)) {
if (!$userId || !$scope || !$id) {
return;
}
$container = $this->container;
$entityManager = $this->container->getByClass(EntityManager::class);
/** @var \Espo\ORM\EntityManager $entityManager */
$entityManager = $container->get('entityManager');
$user = $entityManager->getEntity('User', $userId);
$user = $entityManager->getEntityById(User::ENTITY_TYPE, $userId);
if (!$user) {
return;
@@ -88,13 +74,10 @@ class AclCheck implements Command
foreach ($portalIdList as $portalId) {
$application = new PortalApplication($portalId);
$containerPortal = $application->getContainer();
$entityManager = $containerPortal->getByClass(EntityManager::class);
/** @var \Espo\ORM\EntityManager $entityManager */
$entityManager = $containerPortal->get('entityManager');
$user = $entityManager->getEntity('User', $userId);
$user = $entityManager->getEntityById(User::ENTITY_TYPE, $userId);
if (!$user) {
return;
@@ -114,8 +97,6 @@ class AclCheck implements Command
if ($this->check($user, $scope, $id, $action, $container)) {
$io->write('true');
return;
}
}
@@ -127,22 +108,16 @@ class AclCheck implements Command
Container $container
): bool {
/** @var EntityManager $entityManager */
$entityManager = $container->get('entityManager');
$entityManager = $container->getByClass(EntityManager::class);
$entity = $entityManager->getEntity($scope, $id);
$entity = $entityManager->getEntityById($scope, $id);
if (!$entity) {
return false;
}
/** @var AclManager $aclManager */
$aclManager = $container->get('aclManager');
$aclManager = $container->getByClass(AclManager::class);
if ($aclManager->check($user, $entity, $action)) {
return true;
}
return false;
return $aclManager->check($user, $entity, $action);
}
}
@@ -29,24 +29,17 @@
namespace Espo\Core\Loaders;
use Espo\Core\{
Container\Loader,
Container,
AclManager as AclManagerService,
};
use Espo\Core\AclManager as AclManagerService;
use Espo\Core\Container;
use Espo\Core\Container\Loader;
class InternalAclManager implements Loader
{
private $container;
public function __construct(Container $container)
{
$this->container = $container;
}
public function __construct(private Container $container)
{}
public function load(): AclManagerService
{
/** @var AclManagerService */
return $this->container->get('aclManager');
return $this->container->getByClass(AclManagerService::class);
}
}
@@ -46,10 +46,7 @@ class EntityManagerProxy
private function getEntityManager(): EntityManager
{
if (!$this->entityManager) {
/** @var EntityManager $entityManager */
$entityManager = $this->container->get('entityManager');
$this->entityManager = $entityManager;
$this->entityManager = $this->container->getByClass(EntityManager::class);
}
return $this->entityManager;
@@ -71,7 +68,7 @@ class EntityManagerProxy
}
/**
* @param array<mixed,string> $options
* @param array<mixed, string> $options
* @return void
*/
public function saveEntity(Entity $entity, array $options = [])
+1 -4
View File
@@ -49,9 +49,7 @@ class Application extends BaseApplication
date_default_timezone_set('UTC');
$this->initContainer();
$this->initPortal($portalId);
$this->initAutoloads();
$this->initPreloads();
}
@@ -85,8 +83,7 @@ class Application extends BaseApplication
throw new Error("Portal ID was not passed to Portal\Application.");
}
/** @var EntityManager $entityManager */
$entityManager = $this->container->get('entityManager');
$entityManager = $this->container->getByClass(EntityManager::class);
$portal = $entityManager->getEntity(Portal::ENTITY_TYPE, $portalId);
+5 -16
View File
@@ -30,7 +30,6 @@
namespace Espo\Tools\App;
use Espo\Core\Utils\Language as LanguageUtil;
use Espo\Core\Acl;
use Espo\Core\Container;
use Espo\Core\Utils\Metadata;
@@ -39,22 +38,12 @@ use Espo\Entities\User;
class LanguageService
{
private Metadata $metadata;
private Acl $acl;
private User $user;
private Container $container;
public function __construct(
Metadata $metadata,
Acl $acl,
User $user,
Container $container
) {
$this->metadata = $metadata;
$this->acl = $acl;
$this->user = $user;
$this->container = $container;
}
private Metadata $metadata,
private Acl $acl,
private User $user,
private Container $container
) {}
// @todo Use proxy.
protected function getDefaultLanguage(): LanguageUtil