Skip to content

Commit 046caa0

Browse files
Remove href attributes and fix form processing
1 parent 3ba8134 commit 046caa0

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

src/Controller/PackageController.php

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -998,28 +998,34 @@ public function transferPackageAction(Request $req, #[MapEntity] Package $packag
998998
$form = $this->createTransferPackageForm($package);
999999
$form->handleRequest($req);
10001000

1001-
if ($form->isSubmitted() && $form->isValid()) {
1002-
try {
1003-
$newMaintainers = $form->getData()->getMaintainers()->toArray();
1004-
$result = $this->packageManager->transferPackage($package, $newMaintainers);
1005-
$this->getEM()->flush();
1006-
1007-
if ($result) {
1008-
$usernames = array_map(fn (User $user) => $user->getUsername(), $newMaintainers);
1009-
$this->addFlash('success', sprintf('Package has been transferred to %s', implode(', ', $usernames)));
1010-
} else {
1011-
$this->addFlash('warning', 'Package maintainers are identical and have not been changed');
1012-
}
1001+
if (!$form->isSubmitted()) {
1002+
return $this->redirectToRoute('view_package', ['name' => $package->getName()]);
1003+
}
10131004

1014-
return $this->redirectToRoute('view_package', ['name' => $package->getName()]);
1015-
} catch (\Exception $e) {
1016-
$logger->critical($e->getMessage(), ['exception', $e]);
1017-
$this->addFlash('error', 'The package could not be transferred.');
1018-
}
1019-
} elseif (!$form->isValid()) {
1005+
if (!$form->isValid()) {
10201006
foreach ($form->getErrors(true, true) as $error) {
10211007
$this->addFlash('error', $error->getMessage());
10221008
}
1009+
1010+
return $this->redirectToRoute('view_package', ['name' => $package->getName()]);
1011+
}
1012+
1013+
try {
1014+
$newMaintainers = $form->getData()->getMaintainers()->toArray();
1015+
$result = $this->packageManager->transferPackage($package, $newMaintainers);
1016+
$this->getEM()->flush();
1017+
1018+
if ($result) {
1019+
$usernames = array_map(fn (User $user) => $user->getUsername(), $newMaintainers);
1020+
$this->addFlash('success', sprintf('Package has been transferred to %s', implode(', ', $usernames)));
1021+
} else {
1022+
$this->addFlash('warning', 'Package maintainers are identical and have not been changed');
1023+
}
1024+
1025+
return $this->redirectToRoute('view_package', ['name' => $package->getName()]);
1026+
} catch (\Exception $e) {
1027+
$logger->critical($e->getMessage(), ['exception', $e]);
1028+
$this->addFlash('error', 'The package could not be transferred.');
10231029
}
10241030

10251031
return $this->redirectToRoute('view_package', ['name' => $package->getName()]);

templates/package/view_package.html.twig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,12 @@
145145
<a href="{{ path('user_profile', {'name': maintainer.username}) }}"><img width="48" height="48" title="{{ maintainer.username }}" src="https://www.gravatar.com/avatar/{{ maintainer.email|gravatar_hash }}?s=48&amp;d=identicon" srcset="https://www.gravatar.com/avatar/{{ maintainer.email|gravatar_hash }}?s=96&amp;d=identicon 2x"></a>
146146
{% endfor %}
147147
</p>
148-
148+
149149
{% if is_granted('remove_maintainer', package) or is_granted('add_maintainer', package) or is_granted('transfer_package', package) %}
150150
<h5>Maintainer actions</h5>
151-
{% if is_granted('add_maintainer', package) %}<a title="Add Maintainer" id="add-maintainer" href="{{ path('add_maintainer', {'name': package.name}) }}"><i class="glyphicon glyphicon-plus"></i></a>{% endif %}
152-
{% if is_granted('remove_maintainer', package) %}<a title="Remove Maintainer" id="remove-maintainer" href="{{ path('remove_maintainer', {'name': package.name}) }}"><i class="glyphicon glyphicon-remove"></i></a>{% endif %}
153-
{% if is_granted('transfer_package', package) %}<a title="Transfer Package" id="transfer-package" href="{{ path('transfer_package', {'name': package.name}) }}"><i class="glyphicon glyphicon-transfer"></i></a>{% endif %}
151+
{% if is_granted('add_maintainer', package) %}<a title="Add Maintainer" id="add-maintainer"><i class="glyphicon glyphicon-plus"></i></a>{% endif %}
152+
{% if is_granted('remove_maintainer', package) %}<a title="Remove Maintainer" id="remove-maintainer"><i class="glyphicon glyphicon-remove"></i></a>{% endif %}
153+
{% if is_granted('transfer_package', package) %}<a title="Transfer Package" id="transfer-package"><i class="glyphicon glyphicon-transfer"></i></a>{% endif %}
154154
{% endif %}
155155

156156
<h5>Details</h5>

0 commit comments

Comments
 (0)