Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/V1Module/security/ACLModuleBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace App\Security;

use Nette\PhpGenerator\ClassType;
use Nette\PhpGenerator\PhpLiteral;
use Nette\PhpGenerator\Literal;
use Nette\Utils\Strings;
use ReflectionClass;
use ReflectionMethod;
Expand Down Expand Up @@ -72,7 +72,7 @@ public function build($interfaceName, $name, $uniqueId): ClassType
'return $this->check(?, ?);',
[
$action,
new PhpLiteral("[" . implode(", ", $contextStrings) . "]")
new Literal("[" . implode(", ", $contextStrings) . "]")
]
);
}
Expand Down
28 changes: 13 additions & 15 deletions app/V1Module/security/AuthorizatorBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
use LogicException;
use Nette\PhpGenerator\ClassType;
use Nette\PhpGenerator\Dumper;
use Nette\PhpGenerator\PhpLiteral;
use Nette\PhpGenerator\Helpers;
use Nette\Security\Permission;
use Nette\PhpGenerator\Literal;
use Nette\Utils\Arrays;
use ReflectionClass;
use ReflectionException;
Expand Down Expand Up @@ -48,7 +46,7 @@ public function build($aclInterfaces, array $permissions, $uniqueId): ClassType
$allow = Arrays::get($rule, "allow", true);
$role = Arrays::get($rule, "role", null);
$resource = Arrays::get($rule, "resource", null);
$interface = $resource !== null ? new ReflectionClass(Arrays::get($aclInterfaces, $resource)) : null;
$interface = $resource !== null ? new ReflectionClass(Arrays::get($aclInterfaces, $resource) ?? '') : null;
$actions = (array)Arrays::get($rule, "actions", []);

$assertion = null;
Expand All @@ -61,21 +59,21 @@ public function build($aclInterfaces, array $permissions, $uniqueId): ClassType
$condition = $this->loadConditionClauses($conditions, $interface, $actions, $checkVariables);

foreach ($checkVariables as $variableName => $variableValue) {
$assertion->addBody("? = ?;", [new PhpLiteral($variableName), new PhpLiteral($variableValue)]);
$assertion->addBody("? = ?;", [new Literal($variableName), new Literal($variableValue)]);
}

$assertion->addBody("return ?;", [new PhpLiteral($condition)]);
$assertion->addBody("return ?;", [new Literal($condition)]);
}

$actionsString = '"' . implode('", "', $actions) . '"';

$check->addBody(
'if (? && ? && ? && ?) {',
[
$role !== null ? new PhpLiteral(sprintf('$this->isInRole($role, "%s")', $role)) : true,
$resource !== null ? new PhpLiteral(sprintf('$resource === "%s"', $resource)) : true,
count($actions) > 0 ? new PhpLiteral(sprintf('in_array($privilege, [%s])', $actionsString)) : true,
$assertion !== null ? new PhpLiteral(sprintf('$this->%s()', $assertion->getName())) : true
$role !== null ? new Literal(sprintf('$this->isInRole($role, "%s")', $role)) : true,
$resource !== null ? new Literal(sprintf('$resource === "%s"', $resource)) : true,
count($actions) > 0 ? new Literal(sprintf('in_array($privilege, [%s])', $actionsString)) : true,
$assertion !== null ? new Literal(sprintf('$this->%s()', $assertion->getName())) : true
]
);
$check->addBody('return ?;', [$allow]);
Expand Down Expand Up @@ -108,7 +106,7 @@ private function loadConditionClauses($conditions, $interface, &$actions, array
$checkVariable = "\$check_" . $this->checkCounter++;
$checkValues[$checkVariable] = $this->dumper->format(
'$this->policy->check(?, ?, $this->queriedIdentity)',
$conditionTarget ? new PhpLiteral(sprintf('$this->queriedContext["%s"]', $conditionTarget)) : null,
$conditionTarget ? new Literal(sprintf('$this->queriedContext["%s"]', $conditionTarget)) : null,
$condition
);

Expand Down Expand Up @@ -136,11 +134,11 @@ private function loadConditionClauses($conditions, $interface, &$actions, array
}

if ($type === "and") {
return $this->dumper->format("(?)", new PhpLiteral(join(" && ", $children)));
} elseif ($type === "or") {
return $this->dumper->format("(?)", new PhpLiteral(join(" || ", $children)));
return $this->dumper->format("(?)", new Literal(join(" && ", $children)));
} /* @phpstan-ignore identical.alwaysTrue */ elseif ($type === "or") {
return $this->dumper->format("(?)", new Literal(join(" || ", $children)));
} else {
return new PhpLiteral("true");
return new Literal("true");
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/V1Module/security/UserStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function setExpiration(?string $expire, bool $clearIdentity): void
/**
* @inheritDoc
*/
public function saveAuthentication(IIdentity $identity): void
public function saveAuthentication(?IIdentity $identity): void
{
if ($identity !== null && !($identity instanceof Identity)) {
throw new InvalidArgumentException("Wrong identity class");
Expand Down
2 changes: 2 additions & 0 deletions app/async/Notify.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static function isAvailable(): bool
{
$requirements = ['inotify_init', 'inotify_add_watch', 'inotify_read', 'inotify_queue_len', 'stream_select'];
foreach ($requirements as $reqFnc) {
// @phpstan-ignore-next-line
if (!function_exists($reqFnc)) {
return false;
}
Expand All @@ -31,6 +32,7 @@ public static function isAvailable(): bool
/**
* @var string|null path to the inotify file used to wake up the worker (null = no inotify)
*/
// @phpstan-ignore property.unusedType
private $inotifyFile = null;

/**
Expand Down
16 changes: 6 additions & 10 deletions app/commands/AsyncJobsUpkeep.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
namespace App\Console;

use App\Helpers\Notifications\AsyncJobsStuckEmailsSender;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\ORM\EntityManagerInterface;
use Nette\Utils\Arrays;
use DateTime;

#[AsCommand(
name: 'asyncJobs:upkeep',
description: 'Performs periodic upkeep for async jobs (cleanup, send warning emails)'
)]
class AsyncJobsUpkeep extends Command
{
protected static $defaultName = 'asyncJobs:upkeep';

/** @var AsyncJobsStuckEmailsSender */
private $sender;

Expand Down Expand Up @@ -46,13 +49,6 @@ public function __construct(
$this->entityManager = $entityManager;
}

protected function configure()
{
$this->setName(self::$defaultName)->setDescription(
'Performs periodic upkeep for async jobs (cleanup, send warning emails)'
);
}

/**
* Delete all async jobs that match given clause and are passed given threshold.
* @param string $additionalErrorClause raw SQL WHERE clause fragment
Expand Down Expand Up @@ -110,7 +106,7 @@ protected function sendStuckNotifications()
}
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->cleanupOldCompleted();
$this->sendStuckNotifications();
Expand Down
8 changes: 5 additions & 3 deletions app/commands/DoctrineFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Id\AssignedGenerator;
use Nette\Utils\Finder;
use Nette\Utils\FileInfo;
use SplFileInfo;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -20,6 +22,7 @@
* in add/fixtures directory. Also, 'db:fill' command is registered to provide
* convenient usage of this function.
*/
#[AsCommand(name: 'db:fill', description: 'Clear the database and fill it with initial data.')]
class DoctrineFixtures extends Command
{
protected static $defaultName = 'db:fill';
Expand Down Expand Up @@ -64,7 +67,6 @@ public function __construct(
*/
protected function configure()
{
$this->setName('db:fill')->setDescription('Clear the database and fill it with initial data.');
$this->addOption(
'test',
't',
Expand All @@ -81,7 +83,7 @@ protected function configure()
* @param OutputInterface $output Console output for logging
* @return int 0 on success, 1 on error
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->clearDatabase();

Expand All @@ -97,7 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
foreach ($input->getArgument("groups") as $group) {
$groupFiles = [];

/** @var SplFileInfo $file */
/** @var FileInfo $file */
foreach (
Finder::findFiles("*.neon", "*.yml", "*.yaml", "*.json")
->in($fixtureDir . "/" . $group) as $file
Expand Down
14 changes: 3 additions & 11 deletions app/commands/ExportDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use App\Model\Repository\RuntimeEnvironments;
use Nette\Neon\Neon;
use Nette\Utils\FileSystem;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -20,10 +21,9 @@
* YAML file in fixtures/generated directory. Also, 'db:export' command is
* registered to provide convenient usage of this function.
*/
#[AsCommand(name: 'db:export', description: 'Export some of the data from database.')]
class ExportDatabase extends Command
{
protected static $defaultName = 'db:export';

private const EXTENSION = ".neon";
private const PARAMETERS_KEY = "parameters";

Expand Down Expand Up @@ -59,21 +59,13 @@ public function __construct(
$this->hardwareGroups = $hardwareGroups;
}

/**
* Register the 'db:export' command in the framework
*/
protected function configure()
{
$this->setName('db:export')->setDescription('Export some of the data from database.');
}

/**
* Execute the database exporting.
* @param InputInterface $input Console input, not used
* @param OutputInterface $output Console output for logging
* @return int 0 on success, 1 on error
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$fixtureDir = __DIR__ . '/../../fixtures/generated/';
FileSystem::createDir($fixtureDir);
Expand Down
16 changes: 6 additions & 10 deletions app/commands/GeneralStatsNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@

use App\Helpers\Notifications\GeneralStatsEmailsSender;
use App\Helpers\GeneralStatsHelper;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
name: 'notifications:general-stats',
description: 'Send notifications with general statistics overview for the administrator.'
)]
class GeneralStatsNotification extends Command
{
protected static $defaultName = 'notifications:general-stats';

/** @var GeneralStatsEmailsSender */
private $emailSender;

Expand All @@ -25,14 +28,7 @@ public function __construct(GeneralStatsEmailsSender $emailSender, GeneralStatsH
$this->generalStats = $generalStats;
}

protected function configure()
{
$this->setName('notifications:general-stats')->setDescription(
'Send notifications with general statistics overview for the administrator.'
);
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->emailSender->send($this->generalStats);
return 0;
Expand Down
18 changes: 7 additions & 11 deletions app/commands/GenerateSwagger.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Console;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -10,19 +11,14 @@
/**
* Command that consumes a temporary file containing endpoint annotations and generates a swagger documentation.
*/
#[AsCommand(
name: 'swagger:generate',
description: 'Generate an OpenAPI documentation from the temporary file created by the swagger:annotate command. '
. 'The temporary file is deleted afterwards.'
)]
class GenerateSwagger extends Command
{
protected static $defaultName = 'swagger:generate';

protected function configure()
{
$this->setName(self::$defaultName)->setDescription(
'Generate an OpenAPI documentation from the temporary file created by the swagger:annotate command.'
. ' The temporary file is deleted afterwards.'
);
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$path = __DIR__ . '/../V1Module/presenters/_autogenerated_annotations_temp.php';

Expand Down
13 changes: 3 additions & 10 deletions app/commands/MetaConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Console;

use App\Helpers\MetaFormats\AnnotationConversion\AnnotationToAttributeConverter;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -12,18 +13,10 @@
* parameter annotations are converted into attributes.
* The new folder is named 'presenters2'.
*/
#[AsCommand(name: 'meta:convert', description: 'Convert endpoint parameter annotations to attributes.')]
class MetaConverter extends Command
{
protected static $defaultName = 'meta:convert';

protected function configure()
{
$this->setName(self::$defaultName)->setDescription(
'Convert endpoint parameter annotations to attributes..'
);
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->generatePresenters();
return Command::SUCCESS;
Expand Down
11 changes: 6 additions & 5 deletions app/commands/PlagiarismDetectionAccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Security\AccessManager;
use App\Security\TokenScope;
use App\Security\Roles;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -18,10 +19,12 @@
* A console command that generates token restricted for plagiarism detection tools.
* This token can be used to create plagiarism detection batches and upload their data regarding detected similarities.
*/
#[AsCommand(
name: 'plagiarism:create-access-token',
description: 'Generate token restricted for plagiarism scope (for 3rd party tools).'
)]
class PlagiarismDetectionAccessToken extends Command
{
protected static $defaultName = 'plagiarism:create-access-token';

/** @var AccessManager */
public $accessManager;

Expand All @@ -37,8 +40,6 @@ public function __construct(AccessManager $accessManager, Users $users)

protected function configure()
{
$this->setName(self::$defaultName)
->setDescription('Generate token restricted for plagiarism scope (for 3rd party tools).');
$this->addArgument('userId', InputArgument::REQUIRED, 'ID of the admin owning the token.');
$this->addOption(
'expiration',
Expand All @@ -49,7 +50,7 @@ protected function configure()
);
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
// get user by given ID
$userId = $input->getArgument('userId');
Expand Down
Loading