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
2 changes: 1 addition & 1 deletion src/ArgumentResolver/UserResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function resolve(Request $request, ArgumentMetadata $argument): iterable

$user = $this->doctrine->getRepository(User::class)->findOneBy(['usernameCanonical' => $username]);

if (!$user && $this->security->isGranted('ROLE_ADMIN') && \filter_var($username, \FILTER_VALIDATE_EMAIL)) {
if (!$user && $this->security->isGranted('ROLE_ADMIN') && filter_var($username, \FILTER_VALIDATE_EMAIL)) {
$user = $this->doctrine->getRepository(User::class)->findOneBy(['emailCanonical' => $username]);
}

Expand Down
17 changes: 6 additions & 11 deletions src/Audit/AuditRecordType.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,17 @@ enum AuditRecordType: string

public function category(): string
{
return match($this) {
self::MaintainerAdded, self::MaintainerRemoved, self::PackageTransferred
=> 'ownership',
return match ($this) {
self::MaintainerAdded, self::MaintainerRemoved, self::PackageTransferred => 'ownership',
self::PackageCreated, self::PackageDeleted, self::CanonicalUrlChanged,
self::PackageAbandoned, self::PackageUnabandoned, self::PackageFrozen, self::PackageUnfrozen
=> 'package',
self::VersionCreated, self::VersionDeleted, self::VersionReferenceChanged
=> 'version',
self::PackageAbandoned, self::PackageUnabandoned, self::PackageFrozen, self::PackageUnfrozen => 'package',
self::VersionCreated, self::VersionDeleted, self::VersionReferenceChanged => 'version',
self::UserCreated, self::UserVerified, self::UserDeleted,
self::PasswordResetRequested, self::PasswordReset, self::PasswordChanged,
self::EmailChanged, self::UsernameChanged, self::GitHubLinkedWithUser,
self::GitHubDisconnectedFromUser, self::TwoFaAuthenticationActivated,
self::TwoFaAuthenticationDeactivated
=> 'user',
self::FilterListEntryAdded, self::FilterListEntryDeleted
=> 'filterlist',
self::TwoFaAuthenticationDeactivated => 'user',
self::FilterListEntryAdded, self::FilterListEntryDeleted => 'filterlist',
};
}
}
3 changes: 1 addition & 2 deletions src/Audit/Display/AbstractAuditLogDisplay.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public function getActor(): ActorDisplay

public function getTypeTranslationKey(): string
{
return 'audit_log.type.' . $this->getType()->value;
return 'audit_log.type.'.$this->getType()->value;
}

}
8 changes: 5 additions & 3 deletions src/Audit/Display/AuditLogDisplayFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ class AuditLogDisplayFactory
{
public function __construct(
private readonly Security $security,
) {}
) {
}

/**
* @param iterable<AuditRecord> $auditRecords
*
* @return array<AuditLogDisplayInterface>
*/
public function build(iterable $auditRecords): array
Expand Down Expand Up @@ -91,7 +93,7 @@ public function buildSingle(AuditRecord $record): AuditLogDisplayInterface
$record->attributes['name'],
$record->attributes['version'],
$record->attributes['metadata']['source']['reference'] ?? null,
$record->attributes['metadata']['dist']['reference'] ?? null,
$record->attributes['metadata']['dist']['reference'] ?? null,
$this->buildActor($record->attributes['actor']),
$record->ip,
),
Expand Down Expand Up @@ -245,7 +247,7 @@ private function buildActor(array|string|null $actor): ActorDisplay
return new ActorDisplay(null, 'unknown');
}

if (is_string($actor)) {
if (\is_string($actor)) {
return new ActorDisplay(null, $actor);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Audit/Display/PackageCreatedDisplay.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ public function getTemplateName(): string
{
return 'audit_log/display/package_created.html.twig';
}
}
}
1 change: 0 additions & 1 deletion src/Audit/Display/UserDeletedDisplay.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
namespace App\Audit\Display;

use App\Audit\AuditRecordType;
use App\Audit\UserRegistrationMethod;

readonly class UserDeletedDisplay extends AbstractAuditLogDisplay
{
Expand Down
1 change: 0 additions & 1 deletion src/Audit/Display/UserVerifiedDisplay.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
namespace App\Audit\Display;

use App\Audit\AuditRecordType;
use App\Audit\UserRegistrationMethod;

readonly class UserVerifiedDisplay extends AbstractAuditLogDisplay
{
Expand Down
2 changes: 1 addition & 1 deletion src/Audit/UserRegistrationMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ enum UserRegistrationMethod: string

public function translationKey(): string
{
return 'audit_log.enums.user-registration-method.' . $this->value;
return 'audit_log.enums.user-registration-method.'.$this->value;
}
}
7 changes: 3 additions & 4 deletions src/Command/DumpPackagesV2Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
use App\Package\V2Dumper;
use App\Service\Locker;
use Doctrine\Persistence\ManagerRegistry;
use Graze\DogStatsD\Client as StatsDClient;
use Monolog\Logger;
use Seld\Signal\SignalHandler;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Graze\DogStatsD\Client as StatsDClient;

/**
* @author Jordi Boggiano <j.boggiano@seld.be>
Expand All @@ -38,8 +38,7 @@ public function __construct(
private string $cacheDir,
private Logger $logger,
private StatsDClient $statsd,
)
{
) {
parent::__construct();
}

Expand Down Expand Up @@ -136,7 +135,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$ids = $this->getEM()->getRepository(Package::class)->getStalePackagesForDumpingV2($workerId, $numWorkers);
if (\count($ids) > 2000) {
$this->logger->emergency('Huge backlog in packages to be dumped is abnormal', ['count' => \count($ids), 'worker' => (string) $workerId]);
$ids = array_slice($ids, 0, 2000);
$ids = \array_slice($ids, 0, 2000);
}
}
$this->statsd->gauge('packagist.metadata_dump_queue', \count($ids), ['worker' => (string) $workerId]);
Expand Down
25 changes: 12 additions & 13 deletions src/Command/TransferOwnershipCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

namespace App\Command;

use App\Entity\AuditRecord;
use App\Entity\Package;
use App\Entity\User;
use App\Model\PackageManager;
Expand All @@ -32,8 +31,7 @@ class TransferOwnershipCommand extends Command
public function __construct(
private readonly ManagerRegistry $doctrine,
private readonly PackageManager $packageManager,
)
{
) {
parent::__construct();
}

Expand All @@ -43,8 +41,8 @@ protected function configure(): void
->setName('packagist:transfer-ownership')
->setDescription('Transfer all packages of a vendor')
->setDefinition([
new InputArgument('vendorOrPackage', InputArgument::REQUIRED,'Vendor or package name'),
new InputArgument('maintainers', InputArgument::IS_ARRAY|InputArgument::REQUIRED, 'The usernames of the new maintainers'),
new InputArgument('vendorOrPackage', InputArgument::REQUIRED, 'Vendor or package name'),
new InputArgument('maintainers', InputArgument::IS_ARRAY | InputArgument::REQUIRED, 'The usernames of the new maintainers'),
new InputOption('dry-run', null, InputOption::VALUE_NONE, 'Dry run'),
])
;
Expand All @@ -61,14 +59,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$vendorOrPackage = $input->getArgument('vendorOrPackage');
$maintainers = $this->queryAndValidateMaintainers($input, $output);

if (!count($maintainers)) {
if (!\count($maintainers)) {
return Command::FAILURE;
}

$packages = $this->queryPackages($vendorOrPackage);

if (!count($packages)) {
$output->writeln(sprintf('<error>No packages found for %s</error>', $vendorOrPackage));
if (!\count($packages)) {
$output->writeln(\sprintf('<error>No packages found for %s</error>', $vendorOrPackage));

return Command::FAILURE;
}

Expand Down Expand Up @@ -98,14 +97,14 @@ private function queryAndValidateMaintainers(InputInterface $input, OutputInterf
$notFound = [];

foreach ($usernames as $username) {
if (!array_key_exists($username, $maintainers)) {
if (!\array_key_exists($username, $maintainers)) {
$notFound[] = $username;
}
}

sort($notFound);

$output->writeln(sprintf('<error>%d maintainers could not be found: %s</error>', count($notFound), implode(', ', $notFound)));
$output->writeln(\sprintf('<error>%d maintainers could not be found: %s</error>', \count($notFound), implode(', ', $notFound)));

return [];
}
Expand All @@ -125,13 +124,13 @@ private function queryPackages(string $vendorOrPackage): array
}

return $repository->findBy([
'vendor' => $vendorOrPackage
'vendor' => $vendorOrPackage,
]);
}

/**
* @param Package[] $packages
* @param User[] $maintainers
* @param User[] $maintainers
*/
private function outputPackageTable(OutputInterface $output, array $packages, array $maintainers): void
{
Expand Down Expand Up @@ -163,7 +162,7 @@ private function outputPackageTable(OutputInterface $output, array $packages, ar

/**
* @param Package[] $packages
* @param User[] $maintainers
* @param User[] $maintainers
*/
private function transferOwnership(array $packages, array $maintainers): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/Command/UpdateFilterListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
try {
$list = FilterLists::from($input->getArgument('list'));
} catch (\ValueError) {
$output->writeln('list must be one of ' . implode(', ', array_map(fn (FilterLists $list) => $list->value, FilterLists::cases())));
$output->writeln('list must be one of '.implode(', ', array_map(fn (FilterLists $list) => $list->value, FilterLists::cases())));

return self::INVALID;
}
Expand Down
14 changes: 9 additions & 5 deletions src/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,12 @@ public function securityAdvisoryAction(Request $request, ProviderManager $provid
return $resp;
}

if ($request->headers->get('User-Agent') === 'GuzzleHttp/7' && in_array($request->getClientIp(), [
if ($request->headers->get('User-Agent') === 'GuzzleHttp/7' && \in_array($request->getClientIp(), [
'168.243.26.34', '52.20.173.197', '78.46.106.56', '178.79.183.158', '77.135.173.242', '139.255.192.18', '188.40.28.3', '18.157.117.165', '15.188.186.192', '54.72.75.192',
'81.196.171.134', '52.51.253.125', '138.199.6.240', '103.217.209.214', '3.75.82.169', '65.109.33.73', '185.118.121.6', '34.233.255.120', '2a01:4f8:c013:37fb::1', '23.21.44.77',
'4.182.131.232', '185.11.255.148', '3.65.203.52', '178.22.124.147', '131.175.200.52', '80.193.72.14', '2a02:4780:d:7d90::1', '34.200.24.102', '52.72.37.76', '116.203.120.12',
'80.65.238.52', '146.177.71.160', '18.153.179.13', '3.123.161.63', '54.147.71.92', '44.197.170.214', '51.15.252.215', '2a03:b0c0:2:d0::d4c:4001',
], true)
'81.196.171.134', '52.51.253.125', '138.199.6.240', '103.217.209.214', '3.75.82.169', '65.109.33.73', '185.118.121.6', '34.233.255.120', '2a01:4f8:c013:37fb::1', '23.21.44.77',
'4.182.131.232', '185.11.255.148', '3.65.203.52', '178.22.124.147', '131.175.200.52', '80.193.72.14', '2a02:4780:d:7d90::1', '34.200.24.102', '52.72.37.76', '116.203.120.12',
'80.65.238.52', '146.177.71.160', '18.153.179.13', '3.123.161.63', '54.147.71.92', '44.197.170.214', '51.15.252.215', '2a03:b0c0:2:d0::d4c:4001',
], true)
) {
return new JsonResponse('Please use a proper user agent with contact information to use our API', Response::HTTP_TOO_MANY_REQUESTS, ['Retry-After' => 31536000]);
}
Expand Down Expand Up @@ -491,6 +491,7 @@ protected function receiveUpdateRequest(Request $request, string $url, string $u
$statsd->increment('update_pkg_api.success', tags: ['mode' => 'github_user_secret']);
} else {
$statsd->increment('update_pkg_api.failed', tags: ['reason' => 'invalid_user_sig']);

return new JsonResponse(['status' => 'error', 'message' => 'Secret should be the Packagist API Token for the Packagist user "'.$username.'". Signature verification failed.'], 403);
}
} else {
Expand Down Expand Up @@ -520,6 +521,7 @@ protected function receiveUpdateRequest(Request $request, string $url, string $u
$statsd->increment('update_pkg_api.success', tags: ['mode' => 'github_auto']);
} else {
$statsd->increment('update_pkg_api.failed', tags: ['reason' => 'invalid_gh_sig']);

return new JsonResponse(['status' => 'error', 'message' => 'Invalid github signature. Delete this webhook and recreate it using the manual account sync trigger from https://packagist.org/about#how-to-update-packages'], 403);
}
}
Expand All @@ -528,6 +530,7 @@ protected function receiveUpdateRequest(Request $request, string $url, string $u
if (!$packages) {
if (!$user) {
$statsd->increment('update_pkg_api.failed', tags: ['reason' => 'no_user_found']);

return new JsonResponse(['status' => 'error', 'message' => 'Missing or invalid username/apiToken in request'], 403);
}

Expand All @@ -540,6 +543,7 @@ protected function receiveUpdateRequest(Request $request, string $url, string $u

if (!$packages) {
$statsd->increment('update_pkg_api.failed', tags: ['reason' => 'no_package_found']);

return new JsonResponse(['status' => 'error', 'message' => 'Could not find a package that matches this request (does user maintain the package?)'], 404);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Controller/FeedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ public function extensionReleasesAction(Request $req): Response

$feed = $this->buildFeed(
$req,
"New Extension Releases",
"Latest PIE extension releases on Packagist.org.",
'New Extension Releases',
'Latest PIE extension releases on Packagist.org.',
$this->generateUrl('browse_extensions', [], UrlGeneratorInterface::ABSOLUTE_URL),
$packages
);
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/GitHubLoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function connectCheck(Request $request, ClientRegistry $clientRegistry, S
}

$this->getEM()->persist($user);
$this->getEM()->persist(AuditRecord::gitHubLinkedWithUser($user, $user, $githubNickname??'', $ghUser->getId()));
$this->getEM()->persist(AuditRecord::gitHubLinkedWithUser($user, $user, $githubNickname ?? '', $ghUser->getId()));
$this->getEM()->flush();

$scheduler->scheduleUserScopeMigration($user->getId(), $oldScope, $user->getGithubScope() ?? '');
Expand Down
4 changes: 1 addition & 3 deletions src/Controller/PackageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\Requirement\EnumRequirement;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
Expand Down Expand Up @@ -986,7 +985,6 @@ public function removeMaintainerAction(Request $req, #[MapEntity] Package $packa
]);
}


#[Route(path: '/packages/{name:package}/transfer/', name: 'transfer_package', requirements: ['name' => Package::PACKAGE_NAME_REGEX], methods: ['GET', 'POST'])]
public function transferPackageAction(Request $req, #[MapEntity] Package $package, #[CurrentUser] User $user, LoggerInterface $logger): RedirectResponse
{
Expand Down Expand Up @@ -1014,7 +1012,7 @@ public function transferPackageAction(Request $req, #[MapEntity] Package $packag

if ($result) {
$usernames = array_map(fn (User $user) => $user->getUsername(), $newMaintainers);
$this->addFlash('success', sprintf('Package has been transferred to %s', implode(', ', $usernames)));
$this->addFlash('success', \sprintf('Package has been transferred to %s', implode(', ', $usernames)));
} else {
$this->addFlash('warning', 'Package maintainers are identical and have not been changed');
}
Expand Down
7 changes: 4 additions & 3 deletions src/Controller/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function publicProfile(Request $req, #[VarName('name')] User $user, Favor
// Admin email update form
$adminEmailForm = null;
if ($this->isGranted('ROLE_ADMIN')) {
assert($loggedUser !== null);
\assert($loggedUser !== null);
$adminUpdateEmailRequest = new AdminUpdateEmailRequest($user->getEmail());
$adminEmailForm = $this->createForm(AdminUpdateEmailType::class, $adminUpdateEmailRequest);
$adminEmailForm->handleRequest($req);
Expand Down Expand Up @@ -98,11 +98,12 @@ public function publicProfile(Request $req, #[VarName('name')] User $user, Favor
$this->getEM()->flush();

// Send notifications
$reason = 'Your email has been changed by an administrator from ' . $oldEmail . ' to ' . $newEmail;
$reason = 'Your email has been changed by an administrator from '.$oldEmail.' to '.$newEmail;
$userNotifier->notifyChange($oldEmail, $reason);
$userNotifier->notifyChange($newEmail, $reason);

$this->addFlash('success', 'Email address updated successfully.');

return $this->redirectToRoute('user_profile', ['name' => $user->getUsername()]);
} catch (\Exception $e) {
$logger->error('Failed to update user email', [
Expand Down Expand Up @@ -138,7 +139,7 @@ public function publicProfile(Request $req, #[VarName('name')] User $user, Favor
if ($this->isGranted('ROLE_ADMIN') && $user->getGithubId()) {
$githubUsername = null;
try {
$response = $httpClient->request('GET', 'https://api.github.com/user/' . $user->getGithubId());
$response = $httpClient->request('GET', 'https://api.github.com/user/'.$user->getGithubId());
if ($response->getStatusCode() === 200) {
$githubUsername = $response->toArray()['login'] ?? null;
}
Expand Down
Loading