@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.

Allow searching for Badge Awards by Badge status

Summary: Fixes T12398. This adds `withBadgeStatuses` as a query parameter when searching for Awards to show. In most (all?) cases we currently only show active badges.

Test Plan: Assign myself a badge, archive it and verify it does not appear on profile, comment form, or timeline.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T12398

Differential Revision: https://secure.phabricator.com/D17499

+52 -13
+44 -4
src/applications/badges/query/PhabricatorBadgesAwardQuery.php
··· 6 6 private $badgePHIDs; 7 7 private $recipientPHIDs; 8 8 private $awarderPHIDs; 9 - 9 + private $badgeStatuses = null; 10 10 11 11 protected function willFilterPage(array $awards) { 12 12 $badge_phids = array(); ··· 22 22 $badges = mpull($badges, null, 'getPHID'); 23 23 foreach ($awards as $key => $award) { 24 24 $award_badge = idx($badges, $award->getBadgePHID()); 25 + if (!$award_badge) { 26 + unset($awards[$key]); 27 + $this->didRejectResult($award); 28 + continue; 29 + } 25 30 $award->attachBadge($award_badge); 26 31 } 27 32 ··· 43 48 return $this; 44 49 } 45 50 51 + public function withBadgeStatuses(array $statuses) { 52 + $this->badgeStatuses = $statuses; 53 + return $this; 54 + } 55 + 56 + private function shouldJoinBadge() { 57 + return (bool)$this->badgeStatuses; 58 + } 59 + 46 60 protected function loadPage() { 47 61 return $this->loadStandardPage($this->newResultObject()); 48 62 } ··· 51 65 return new PhabricatorBadgesAward(); 52 66 } 53 67 68 + protected function getPrimaryTableAlias() { 69 + return 'badges_award'; 70 + } 71 + 54 72 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 55 73 $where = parent::buildWhereClauseParts($conn); 56 74 57 75 if ($this->badgePHIDs !== null) { 58 76 $where[] = qsprintf( 59 77 $conn, 60 - 'badgePHID IN (%Ls)', 78 + 'badges_award.badgePHID IN (%Ls)', 61 79 $this->badgePHIDs); 62 80 } 63 81 64 82 if ($this->recipientPHIDs !== null) { 65 83 $where[] = qsprintf( 66 84 $conn, 67 - 'recipientPHID IN (%Ls)', 85 + 'badges_award.recipientPHID IN (%Ls)', 68 86 $this->recipientPHIDs); 69 87 } 70 88 71 89 if ($this->awarderPHIDs !== null) { 72 90 $where[] = qsprintf( 73 91 $conn, 74 - 'awarderPHID IN (%Ls)', 92 + 'badges_award.awarderPHID IN (%Ls)', 75 93 $this->awarderPHIDs); 76 94 } 77 95 96 + if ($this->badgeStatuses !== null) { 97 + $where[] = qsprintf( 98 + $conn, 99 + 'badges_badge.status IN (%Ls)', 100 + $this->badgeStatuses); 101 + } 102 + 103 + 78 104 return $where; 105 + } 106 + 107 + protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) { 108 + $join = parent::buildJoinClauseParts($conn); 109 + $badges = new PhabricatorBadgesBadge(); 110 + 111 + if ($this->shouldJoinBadge()) { 112 + $join[] = qsprintf( 113 + $conn, 114 + 'JOIN %T badges_badge ON badges_award.badgePHID = badges_badge.phid', 115 + $badges->getTableName()); 116 + } 117 + 118 + return $join; 79 119 } 80 120 81 121 public function getQueryApplicationClass() {
+2 -3
src/applications/people/controller/PhabricatorPeopleProfileBadgesController.php
··· 84 84 $awards = id(new PhabricatorBadgesAwardQuery()) 85 85 ->setViewer($viewer) 86 86 ->withRecipientPHIDs(array($user->getPHID())) 87 + ->withBadgeStatuses(array(PhabricatorBadgesBadge::STATUS_ACTIVE)) 87 88 ->execute(); 88 89 $awards = mpull($awards, null, 'getBadgePHID'); 89 90 90 91 $badges = array(); 91 92 foreach ($awards as $award) { 92 93 $badge = $award->getBadge(); 93 - if ($badge->getStatus() == PhabricatorBadgesBadge::STATUS_ACTIVE) { 94 - $badges[$award->getBadgePHID()] = $badge; 95 - } 94 + $badges[$award->getBadgePHID()] = $badge; 96 95 } 97 96 98 97 if (count($badges)) {
+4 -2
src/applications/transactions/view/PhabricatorApplicationTransactionCommentView.php
··· 528 528 $awards = id(new PhabricatorBadgesAwardQuery()) 529 529 ->setViewer($this->getUser()) 530 530 ->withRecipientPHIDs(array($user->getPHID())) 531 + ->withBadgeStatuses(array(PhabricatorBadgesBadge::STATUS_ACTIVE)) 531 532 ->setLimit(2) 532 533 ->execute(); 534 + 535 + $badges = mpull($awards, 'getBadge'); 533 536 534 537 $badge_view = null; 535 - if ($awards) { 536 - $badges = mpull($awards, 'getBadge'); 538 + if ($badges) { 537 539 $badge_list = array(); 538 540 foreach ($badges as $badge) { 539 541 $badge_view = id(new PHUIBadgeMiniView())
+2 -4
src/view/phui/PHUITimelineView.php
··· 220 220 } 221 221 222 222 $user_phid_type = PhabricatorPeopleUserPHIDType::TYPECONST; 223 - $badge_edge_type = PhabricatorRecipientHasBadgeEdgeType::EDGECONST; 224 223 225 224 $user_phids = array(); 226 225 foreach ($events as $key => $event) { ··· 248 247 $awards = id(new PhabricatorBadgesAwardQuery()) 249 248 ->setViewer($this->getViewer()) 250 249 ->withRecipientPHIDs($user_phids) 250 + ->withBadgeStatuses(array(PhabricatorBadgesBadge::STATUS_ACTIVE)) 251 251 ->execute(); 252 252 253 253 $awards = mgroup($awards, 'getRecipientPHID'); ··· 259 259 $badges = array(); 260 260 foreach ($author_awards as $award) { 261 261 $badge = $award->getBadge(); 262 - if ($badge->getStatus() == PhabricatorBadgesBadge::STATUS_ACTIVE) { 263 - $badges[$award->getBadgePHID()] = $badge; 264 - } 262 + $badges[$award->getBadgePHID()] = $badge; 265 263 } 266 264 267 265 // TODO: Pick the "best" badges in some smart way. For now, just pick