container = $container; } public function run(Params $params, IO $io): void { $options = $params->getOptions(); $userId = $options['userId'] ?? null; $scope = $options['scope'] ?? null; $id = $options['id'] ?? null; $action = $options['action'] ?? null; if (empty($userId)) { return; } if (empty($scope)) { return; } if (empty($id)) { return; } $container = $this->container; /** @var \Espo\ORM\EntityManager $entityManager */ $entityManager = $container->get('entityManager'); $user = $entityManager->getEntity('User', $userId); if (!$user) { return; } if ($user->isPortal()) { /** @var string[] $portalIdList */ $portalIdList = $user->getLinkMultipleIdList('portals'); foreach ($portalIdList as $portalId) { $application = new PortalApplication($portalId); $containerPortal = $application->getContainer(); /** @var \Espo\ORM\EntityManager $entityManager */ $entityManager = $containerPortal->get('entityManager'); $user = $entityManager->getEntity('User', $userId); if (!$user) { return; } $result = $this->check($user, $scope, $id, $action, $containerPortal); if ($result) { $io->write('true');; return; } } return; } if ($this->check($user, $scope, $id, $action, $container)) { $io->write('true'); return; } } private function check( User $user, string $scope, string $id, ?string $action, Container $container ): bool { /** @var EntityManager $entityManager */ $entityManager = $container->get('entityManager'); $entity = $entityManager->getEntity($scope, $id); if (!$entity) { return false; } /** @var AclManager $aclManager */ $aclManager = $container->get('aclManager'); if ($aclManager->check($user, $entity, $action)) { return true; } return false; } }