1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 16:52:41 +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:
Andre Klapper 2024-05-12 10:15:37 +02:00
parent 899abf7a2b
commit 43d3fd9eac

View file

@ -6,6 +6,8 @@ final class PhabricatorBadgesAwardController
public function handleRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer(); $viewer = $request->getViewer();
$id = $request->getURIData('id'); $id = $request->getURIData('id');
$errors = array();
$e_badge = true;
$user = id(new PhabricatorPeopleQuery()) $user = id(new PhabricatorPeopleQuery())
->setViewer($viewer) ->setViewer($viewer)
@ -19,37 +21,41 @@ final class PhabricatorBadgesAwardController
if ($request->isFormPost()) { if ($request->isFormPost()) {
$badge_phids = $request->getArr('badgePHIDs'); $badge_phids = $request->getArr('badgePHIDs');
$badges = id(new PhabricatorBadgesQuery())
->setViewer($viewer) if (empty($badge_phids)) {
->withPHIDs($badge_phids) $errors[] = pht('Badge name is required.');
->requireCapabilities( $e_badge = pht('Required');
array(
PhabricatorPolicyCapability::CAN_EDIT,
PhabricatorPolicyCapability::CAN_VIEW,
))
->execute();
if (!$badges) {
return new Aphront404Response();
} }
$award_phids = array($user->getPHID()); if (!$errors) {
$badges = id(new PhabricatorBadgesQuery())
->setViewer($viewer)
->withPHIDs($badge_phids)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_EDIT,
PhabricatorPolicyCapability::CAN_VIEW,
))
->execute();
$award_phids = array($user->getPHID());
foreach ($badges as $badge) { foreach ($badges as $badge) {
$xactions = array(); $xactions = array();
$xactions[] = id(new PhabricatorBadgesTransaction()) $xactions[] = id(new PhabricatorBadgesTransaction())
->setTransactionType( ->setTransactionType(
PhabricatorBadgesBadgeAwardTransaction::TRANSACTIONTYPE) PhabricatorBadgesBadgeAwardTransaction::TRANSACTIONTYPE)
->setNewValue($award_phids); ->setNewValue($award_phids);
$editor = id(new PhabricatorBadgesEditor()) $editor = id(new PhabricatorBadgesEditor())
->setActor($viewer) ->setActor($viewer)
->setContentSourceFromRequest($request) ->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true) ->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true) ->setContinueOnMissingFields(true)
->applyTransactions($badge, $xactions); ->applyTransactions($badge, $xactions);
}
return id(new AphrontRedirectResponse())
->setURI($view_uri);
} }
return id(new AphrontRedirectResponse())
->setURI($view_uri);
} }
$form = id(new AphrontFormView()) $form = id(new AphrontFormView())
@ -58,6 +64,7 @@ final class PhabricatorBadgesAwardController
id(new AphrontFormTokenizerControl()) id(new AphrontFormTokenizerControl())
->setLabel(pht('Badge')) ->setLabel(pht('Badge'))
->setName('badgePHIDs') ->setName('badgePHIDs')
->setError($e_badge)
->setDatasource( ->setDatasource(
id(new PhabricatorBadgesDatasource()) id(new PhabricatorBadgesDatasource())
->setParameters( ->setParameters(