@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+34 -27
+34 -27
src/applications/badges/controller/PhabricatorBadgesAwardController.php
··· 6 6 public function handleRequest(AphrontRequest $request) { 7 7 $viewer = $request->getViewer(); 8 8 $id = $request->getURIData('id'); 9 + $errors = array(); 10 + $e_badge = true; 9 11 10 12 $user = id(new PhabricatorPeopleQuery()) 11 13 ->setViewer($viewer) ··· 19 21 20 22 if ($request->isFormPost()) { 21 23 $badge_phids = $request->getArr('badgePHIDs'); 22 - $badges = id(new PhabricatorBadgesQuery()) 23 - ->setViewer($viewer) 24 - ->withPHIDs($badge_phids) 25 - ->requireCapabilities( 26 - array( 27 - PhabricatorPolicyCapability::CAN_EDIT, 28 - PhabricatorPolicyCapability::CAN_VIEW, 29 - )) 30 - ->execute(); 31 - if (!$badges) { 32 - return new Aphront404Response(); 24 + 25 + if (empty($badge_phids)) { 26 + $errors[] = pht('Badge name is required.'); 27 + $e_badge = pht('Required'); 33 28 } 34 - $award_phids = array($user->getPHID()); 29 + if (!$errors) { 30 + $badges = id(new PhabricatorBadgesQuery()) 31 + ->setViewer($viewer) 32 + ->withPHIDs($badge_phids) 33 + ->requireCapabilities( 34 + array( 35 + PhabricatorPolicyCapability::CAN_EDIT, 36 + PhabricatorPolicyCapability::CAN_VIEW, 37 + )) 38 + ->execute(); 39 + $award_phids = array($user->getPHID()); 40 + 41 + foreach ($badges as $badge) { 42 + $xactions = array(); 43 + $xactions[] = id(new PhabricatorBadgesTransaction()) 44 + ->setTransactionType( 45 + PhabricatorBadgesBadgeAwardTransaction::TRANSACTIONTYPE) 46 + ->setNewValue($award_phids); 35 47 36 - foreach ($badges as $badge) { 37 - $xactions = array(); 38 - $xactions[] = id(new PhabricatorBadgesTransaction()) 39 - ->setTransactionType( 40 - PhabricatorBadgesBadgeAwardTransaction::TRANSACTIONTYPE) 41 - ->setNewValue($award_phids); 48 + $editor = id(new PhabricatorBadgesEditor()) 49 + ->setActor($viewer) 50 + ->setContentSourceFromRequest($request) 51 + ->setContinueOnNoEffect(true) 52 + ->setContinueOnMissingFields(true) 53 + ->applyTransactions($badge, $xactions); 54 + } 42 55 43 - $editor = id(new PhabricatorBadgesEditor()) 44 - ->setActor($viewer) 45 - ->setContentSourceFromRequest($request) 46 - ->setContinueOnNoEffect(true) 47 - ->setContinueOnMissingFields(true) 48 - ->applyTransactions($badge, $xactions); 56 + return id(new AphrontRedirectResponse()) 57 + ->setURI($view_uri); 49 58 } 50 - 51 - return id(new AphrontRedirectResponse()) 52 - ->setURI($view_uri); 53 59 } 54 60 55 61 $form = id(new AphrontFormView()) ··· 58 64 id(new AphrontFormTokenizerControl()) 59 65 ->setLabel(pht('Badge')) 60 66 ->setName('badgePHIDs') 67 + ->setError($e_badge) 61 68 ->setDatasource( 62 69 id(new PhabricatorBadgesDatasource()) 63 70 ->setParameters(