mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 00:32:42 +01:00
Fix exception awarding empty badge to user
Summary: When awarding a badge to a user without having actually selected a batch to award, do not fail on running a database query with no parameter. Instead, silently fail without an error and reload the page, similar to the behavior of `Add Recipients` on `/badges/recipients/1/` in this case. Do not throw an Aphront404Response as it would make the `Award Badge` button in the dialog inaccessible and keep the dysfunctional overlay dialog displayed. ``` EXCEPTION: (AphrontParameterQueryException) Array for %Ls conversion is empty. Query: badges.phid IN (%Ls) at [<phorge>/src/infrastructure/storage/xsprintf/qsprintf.php:383] ``` Closes T15825 Test Plan: Go to a user's badges, click the `Award Badge` button, in the dialog do not select any Badge and click the `Award` button. Reviewers: O1 Blessed Committers, valerio.bozzolan Reviewed By: O1 Blessed Committers, valerio.bozzolan Subscribers: avivey, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15825 Differential Revision: https://we.phorge.it/D25636
This commit is contained in:
parent
899abf7a2b
commit
43d3fd9eac
1 changed files with 34 additions and 27 deletions
|
@ -6,6 +6,8 @@ final class PhabricatorBadgesAwardController
|
|||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $request->getViewer();
|
||||
$id = $request->getURIData('id');
|
||||
$errors = array();
|
||||
$e_badge = true;
|
||||
|
||||
$user = id(new PhabricatorPeopleQuery())
|
||||
->setViewer($viewer)
|
||||
|
@ -19,6 +21,12 @@ final class PhabricatorBadgesAwardController
|
|||
|
||||
if ($request->isFormPost()) {
|
||||
$badge_phids = $request->getArr('badgePHIDs');
|
||||
|
||||
if (empty($badge_phids)) {
|
||||
$errors[] = pht('Badge name is required.');
|
||||
$e_badge = pht('Required');
|
||||
}
|
||||
if (!$errors) {
|
||||
$badges = id(new PhabricatorBadgesQuery())
|
||||
->setViewer($viewer)
|
||||
->withPHIDs($badge_phids)
|
||||
|
@ -28,9 +36,6 @@ final class PhabricatorBadgesAwardController
|
|||
PhabricatorPolicyCapability::CAN_VIEW,
|
||||
))
|
||||
->execute();
|
||||
if (!$badges) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
$award_phids = array($user->getPHID());
|
||||
|
||||
foreach ($badges as $badge) {
|
||||
|
@ -51,6 +56,7 @@ final class PhabricatorBadgesAwardController
|
|||
return id(new AphrontRedirectResponse())
|
||||
->setURI($view_uri);
|
||||
}
|
||||
}
|
||||
|
||||
$form = id(new AphrontFormView())
|
||||
->setUser($viewer)
|
||||
|
@ -58,6 +64,7 @@ final class PhabricatorBadgesAwardController
|
|||
id(new AphrontFormTokenizerControl())
|
||||
->setLabel(pht('Badge'))
|
||||
->setName('badgePHIDs')
|
||||
->setError($e_badge)
|
||||
->setDatasource(
|
||||
id(new PhabricatorBadgesDatasource())
|
||||
->setParameters(
|
||||
|
|
Loading…
Reference in a new issue