1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-09 16:32:39 +01:00

Disallow awarding a badge without selecting recipient

Summary:
Do not continue on missing fields (in this case: the badge recipient) in `PhabricatorBadgesEditRecipientsController`.

Closes T15827

Test Plan: See steps in T15827.

Reviewers: O1 Blessed Committers, valerio.bozzolan

Reviewed By: O1 Blessed Committers, valerio.bozzolan

Subscribers: tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Maniphest Tasks: T15827

Differential Revision: https://we.phorge.it/D25740
This commit is contained in:
Andre Klapper 2024-07-23 00:08:18 +02:00
parent f75b66b27a
commit 8793bdbaa8

View file

@ -7,6 +7,8 @@ final class PhabricatorBadgesEditRecipientsController
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$xactions = array();
$errors = array();
$e_recipient = true;
$badge = id(new PhabricatorBadgesQuery())
->setViewer($viewer)
@ -29,24 +31,29 @@ final class PhabricatorBadgesEditRecipientsController
$add_recipients = $request->getArr('phids');
if ($add_recipients) {
foreach ($add_recipients as $phid) {
$award_phids[] = $phid;
$award_phids[$phid] = $phid;
}
} else {
$errors[] = pht('Recipient name is required.');
$e_recipient = pht('Required');
}
$xactions[] = id(new PhabricatorBadgesTransaction())
->setTransactionType(
PhabricatorBadgesBadgeAwardTransaction::TRANSACTIONTYPE)
->setNewValue($award_phids);
if (!$errors) {
$xactions[] = id(new PhabricatorBadgesTransaction())
->setTransactionType(
PhabricatorBadgesBadgeAwardTransaction::TRANSACTIONTYPE)
->setNewValue($award_phids);
$editor = id(new PhabricatorBadgesEditor())
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true)
->applyTransactions($badge, $xactions);
$editor = id(new PhabricatorBadgesEditor())
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true)
->applyTransactions($badge, $xactions);
return id(new AphrontRedirectResponse())
->setURI($view_uri);
return id(new AphrontRedirectResponse())
->setURI($view_uri);
}
}
$form = new AphrontFormView();
@ -57,6 +64,7 @@ final class PhabricatorBadgesEditRecipientsController
id(new AphrontFormTokenizerControl())
->setName('phids')
->setLabel(pht('Recipients'))
->setError($e_recipient)
->setDatasource(new PhabricatorPeopleDatasource()));
$dialog = id(new AphrontDialogView())