diff --git a/src/Entity/Package.php b/src/Entity/Package.php index 31e13b95..7d630c61 100644 --- a/src/Entity/Package.php +++ b/src/Entity/Package.php @@ -110,6 +110,9 @@ class Package #[ORM\Column(name: 'external_ref', length: 255, nullable: true)] private ?string $externalRef = null; + #[ORM\Column(name: 'full_visibility', type: 'boolean', nullable: true)] + private ?bool $fullVisibility = null; + /** * @internal * @var \Composer\Repository\Vcs\VcsDriverInterface @@ -802,6 +805,18 @@ public function setExternalRef(?string $externalRef): self return $this; } + public function isFullVisibility(): ?bool + { + return $this->fullVisibility; + } + + public function setFullVisibility(?bool $fullVisibility): self + { + $this->fullVisibility = $fullVisibility; + + return $this; + } + public static function sortVersions(Version $a, Version $b) { $aVersion = $a->getNormalizedVersion(); diff --git a/src/Form/Type/Package/SettingsPackageType.php b/src/Form/Type/Package/SettingsPackageType.php index 71a2e260..43159ecb 100644 --- a/src/Form/Type/Package/SettingsPackageType.php +++ b/src/Form/Type/Package/SettingsPackageType.php @@ -24,10 +24,15 @@ public function __construct(private ManagerRegistry $registry) */ public function buildForm(FormBuilderInterface $builder, array $options): void { - $builder->add('disabledUpdate', CheckboxType::class, [ - 'required' => false, - 'label' => 'Disable cron auto-updates', - ]); + $builder + ->add('disabledUpdate', CheckboxType::class, [ + 'required' => false, + 'label' => 'Disable cron auto-updates', + ]) + ->add('fullVisibility', CheckboxType::class, [ + 'required' => false, + 'label' => 'Visible for all users', + ]); if ($options['has_active_integration']) { $builder->add('pullRequestReview', ChoiceType::class, [ diff --git a/src/Repository/GroupRepository.php b/src/Repository/GroupRepository.php index cc962dc9..3d1b218e 100644 --- a/src/Repository/GroupRepository.php +++ b/src/Repository/GroupRepository.php @@ -28,6 +28,9 @@ class GroupRepository extends \Doctrine\ORM\EntityRepository public function getAllowedVersionByPackage(?UserInterface $user, Package $package) { $qb = $this->getEntityManager()->createQueryBuilder(); + if ($package->isFullVisibility()) { + return [null]; // all versions + } if ($user instanceof User) { $qb @@ -93,12 +96,13 @@ public function getAllowedPackagesForUser(?UserInterface $user, bool|int $hydrat ->setParameter('gid', $user->getAclGroups() ? : [-1]); } - $result = $qb->getQuery()->getResult(); + $result = $qb->getQuery()->getSingleColumnResult(); + $result = array_merge($result, $this->getFullVisiblePackages()); + if (empty($result)) { return []; } - $result = array_column($result, 'id'); if (true === $hydration) { $qb = $this->getEntityManager()->createQueryBuilder(); $qb->select('p') @@ -121,6 +125,17 @@ public function getAllowedPackagesForUser(?UserInterface $user, bool|int $hydrat return $result; } + public function getFullVisiblePackages(): array + { + $qb = $this->getEntityManager()->createQueryBuilder(); + + return $qb->select('p.id') + ->from(Package::class, 'p') + ->where('p.fullVisibility = :visibility') + ->setParameter('visibility', true) + ->getQuery()->getSingleColumnResult(); + } + public function getGroupsData(Group|int $group): array { $qb = $this->getEntityManager()->createQueryBuilder(); diff --git a/src/Security/Acl/PackagesAclChecker.php b/src/Security/Acl/PackagesAclChecker.php index f3ff91ec..e886ab81 100644 --- a/src/Security/Acl/PackagesAclChecker.php +++ b/src/Security/Acl/PackagesAclChecker.php @@ -52,6 +52,10 @@ public function isGrantedAccessForPackage(PUI $user, Package $package) public function isGrantedAccessForAllVersions(PUI $user, Package $package) { + if ($package->isFullVisibility()) { + return true; + } + $versionConstraints = $this->getVersions($user, $package); foreach ($versionConstraints as $constraint) { if ($constraint === null) { diff --git a/templates/package/viewPackage.html.twig b/templates/package/viewPackage.html.twig index ae447aed..6d366f99 100644 --- a/templates/package/viewPackage.html.twig +++ b/templates/package/viewPackage.html.twig @@ -262,7 +262,11 @@

Type:{{ package.type }}

{% endif %} - {% if groups is defined and groups is not empty and canEdit %} + {% if canEdit and package.fullVisibility %} +

Groups:ALL USERS

+ {% endif %} + + {% if groups is defined and groups is not empty and canEdit and package.fullVisibility is empty %} {%- set listGroups -%} {%- for group in groups -%} {% if _key != 0 or groups|length > 4 %}