Skip to content

Commit

Permalink
Added visibility for all users settings
Browse files Browse the repository at this point in the history
  • Loading branch information
vtsykun committed Jan 16, 2024
1 parent d65d2be commit 474fcab
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 7 deletions.
15 changes: 15 additions & 0 deletions src/Entity/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
13 changes: 9 additions & 4 deletions src/Form/Type/Package/SettingsPackageType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, [
Expand Down
19 changes: 17 additions & 2 deletions src/Repository/GroupRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand All @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions src/Security/Acl/PackagesAclChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion templates/package/viewPackage.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,11 @@
<p><span>Type:</span>{{ package.type }}</p>
{% endif %}

{% if groups is defined and groups is not empty and canEdit %}
{% if canEdit and package.fullVisibility %}
<p><span>Groups:</span>ALL USERS</p>
{% 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 %}
Expand Down

0 comments on commit 474fcab

Please sign in to comment.