diff --git a/src/applications/badges/controller/PhabricatorBadgesEditRecipientsController.php b/src/applications/badges/controller/PhabricatorBadgesEditRecipientsController.php --- a/src/applications/badges/controller/PhabricatorBadgesEditRecipientsController.php +++ b/src/applications/badges/controller/PhabricatorBadgesEditRecipientsController.php @@ -23,8 +23,6 @@ } $view_uri = $this->getApplicationURI('recipients/'.$badge->getID().'/'); - $awards = $badge->getAwards(); - $recipient_phids = mpull($awards, 'getRecipientPHID'); if ($request->isFormPost()) { $award_phids = array(); @@ -52,17 +50,6 @@ ->setURI($view_uri); } - $recipient_phids = array_reverse($recipient_phids); - $handles = $this->loadViewerHandles($recipient_phids); - - $state = array(); - foreach ($handles as $handle) { - $state[] = array( - 'phid' => $handle->getPHID(), - 'name' => $handle->getFullName(), - ); - } - $can_edit = PhabricatorPolicyFilter::hasCapability( $viewer, $badge, diff --git a/src/applications/badges/controller/PhabricatorBadgesRecipientsController.php b/src/applications/badges/controller/PhabricatorBadgesRecipientsController.php --- a/src/applications/badges/controller/PhabricatorBadgesRecipientsController.php +++ b/src/applications/badges/controller/PhabricatorBadgesRecipientsController.php @@ -15,6 +15,7 @@ ->setViewer($viewer) ->withIDs(array($id)) ->needRecipients(true) + ->setRecipientLimit(250) ->executeOne(); if (!$badge) { return new Aphront404Response(); diff --git a/src/applications/badges/controller/PhabricatorBadgesRemoveRecipientsController.php b/src/applications/badges/controller/PhabricatorBadgesRemoveRecipientsController.php --- a/src/applications/badges/controller/PhabricatorBadgesRemoveRecipientsController.php +++ b/src/applications/badges/controller/PhabricatorBadgesRemoveRecipientsController.php @@ -21,14 +21,7 @@ return new Aphront404Response(); } - $awards = $badge->getAwards(); - $recipient_phids = mpull($awards, 'getRecipientPHID'); $remove_phid = $request->getStr('phid'); - - if (!in_array($remove_phid, $recipient_phids)) { - return new Aphront404Response(); - } - $view_uri = $this->getApplicationURI('recipients/'.$badge->getID().'/'); if ($request->isFormPost()) { diff --git a/src/applications/badges/query/PhabricatorBadgesQuery.php b/src/applications/badges/query/PhabricatorBadgesQuery.php --- a/src/applications/badges/query/PhabricatorBadgesQuery.php +++ b/src/applications/badges/query/PhabricatorBadgesQuery.php @@ -8,6 +8,7 @@ private $qualities; private $statuses; private $recipientPHIDs; + private $recipientLimit = 0; private $needRecipients; @@ -47,6 +48,11 @@ return $this; } + public function setRecipientLimit($limit) { + $this->recipientLimit = $limit; + return $this; + } + protected function loadPage() { return $this->loadStandardPage($this->newResultObject()); } @@ -64,6 +70,7 @@ $query = id(new PhabricatorBadgesAwardQuery()) ->setViewer($this->getViewer()) ->withBadgePHIDs(mpull($badges, 'getPHID')) + ->setLimit($this->recipientLimit) ->execute(); $awards = mgroup($query, 'getBadgePHID'); diff --git a/src/applications/badges/xaction/PhabricatorBadgesBadgeAwardTransaction.php b/src/applications/badges/xaction/PhabricatorBadgesBadgeAwardTransaction.php --- a/src/applications/badges/xaction/PhabricatorBadgesBadgeAwardTransaction.php +++ b/src/applications/badges/xaction/PhabricatorBadgesBadgeAwardTransaction.php @@ -71,6 +71,7 @@ } foreach ($user_phids as $user_phid) { + // Check if a valid user $user = id(new PhabricatorPeopleQuery()) ->setViewer($this->getActor()) ->withPHIDs(array($user_phid)) @@ -81,6 +82,19 @@ 'Recipient PHID "%s" is not a valid user PHID.', $user_phid)); } + + // Check if already awarded + $award = id(new PhabricatorBadgesAwardQuery()) + ->setViewer($this->getActor()) + ->withRecipientPHIDs(array($user_phid)) + ->withBadgePHIDs(array($object->getPHID())) + ->executeOne(); + if ($award) { + $errors[] = $this->newInvalidError( + pht( + '%s has already been awarded this badge.', + $user->getUsername())); + } } }