@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 awarding Badges from the profile

Summary:
[WIP] Allows awarding a badge from a user profile. Unsure of the interactions here if a user can't award any badges, or if we should just hide this.

Fixes T10688
Fixes T10318

Test Plan: Award some badges. Steal them back.

Reviewers: lpriestley, epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T10318, T10688

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

authored by

Chad Little and committed by
chad
23867058 00425cac

+122 -1
+2
src/__phutil_library_map__.php
··· 1865 1865 'PhabricatorBadgesApplication' => 'applications/badges/application/PhabricatorBadgesApplication.php', 1866 1866 'PhabricatorBadgesArchiveController' => 'applications/badges/controller/PhabricatorBadgesArchiveController.php', 1867 1867 'PhabricatorBadgesAward' => 'applications/badges/storage/PhabricatorBadgesAward.php', 1868 + 'PhabricatorBadgesAwardController' => 'applications/badges/controller/PhabricatorBadgesAwardController.php', 1868 1869 'PhabricatorBadgesAwardQuery' => 'applications/badges/query/PhabricatorBadgesAwardQuery.php', 1869 1870 'PhabricatorBadgesBadge' => 'applications/badges/storage/PhabricatorBadgesBadge.php', 1870 1871 'PhabricatorBadgesCommentController' => 'applications/badges/controller/PhabricatorBadgesCommentController.php', ··· 6223 6224 'PhabricatorDestructibleInterface', 6224 6225 'PhabricatorPolicyInterface', 6225 6226 ), 6227 + 'PhabricatorBadgesAwardController' => 'PhabricatorBadgesController', 6226 6228 'PhabricatorBadgesAwardQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 6227 6229 'PhabricatorBadgesBadge' => array( 6228 6230 'PhabricatorBadgesDAO',
+2
src/applications/badges/application/PhabricatorBadgesApplication.php
··· 39 39 '/badges/' => array( 40 40 '(?:query/(?P<queryKey>[^/]+)/)?' 41 41 => 'PhabricatorBadgesListController', 42 + 'award/(?:(?P<id>\d+)/)?' 43 + => 'PhabricatorBadgesAwardController', 42 44 'create/' 43 45 => 'PhabricatorBadgesEditController', 44 46 'comment/(?P<id>[1-9]\d*)/'
+85
src/applications/badges/controller/PhabricatorBadgesAwardController.php
··· 1 + <?php 2 + 3 + final class PhabricatorBadgesAwardController 4 + extends PhabricatorBadgesController { 5 + 6 + public function handleRequest(AphrontRequest $request) { 7 + $viewer = $request->getViewer(); 8 + $id = $request->getURIData('id'); 9 + 10 + $user = id(new PhabricatorPeopleQuery()) 11 + ->setViewer($viewer) 12 + ->withIDs(array($id)) 13 + ->executeOne(); 14 + if (!$user) { 15 + return new Aphront404Response(); 16 + } 17 + 18 + $view_uri = '/p/'.$user->getUsername(); 19 + 20 + if ($request->isFormPost()) { 21 + $xactions = array(); 22 + $badge_phid = $request->getStr('badgePHID'); 23 + $badge = id(new PhabricatorBadgesQuery()) 24 + ->setViewer($viewer) 25 + ->withPHIDs(array($badge_phid)) 26 + ->needRecipients(true) 27 + ->requireCapabilities( 28 + array( 29 + PhabricatorPolicyCapability::CAN_EDIT, 30 + PhabricatorPolicyCapability::CAN_VIEW, 31 + )) 32 + ->executeOne(); 33 + if (!$badge) { 34 + return new Aphront404Response(); 35 + } 36 + $award_phids = array($user->getPHID()); 37 + 38 + $xactions[] = id(new PhabricatorBadgesTransaction()) 39 + ->setTransactionType(PhabricatorBadgesTransaction::TYPE_AWARD) 40 + ->setNewValue($award_phids); 41 + 42 + $editor = id(new PhabricatorBadgesEditor($badge)) 43 + ->setActor($viewer) 44 + ->setContentSourceFromRequest($request) 45 + ->setContinueOnNoEffect(true) 46 + ->setContinueOnMissingFields(true) 47 + ->applyTransactions($badge, $xactions); 48 + 49 + return id(new AphrontRedirectResponse()) 50 + ->setURI($view_uri); 51 + } 52 + 53 + $badges = id(new PhabricatorBadgesQuery()) 54 + ->setViewer($viewer) 55 + ->withStatuses(array( 56 + PhabricatorBadgesBadge::STATUS_ACTIVE, 57 + )) 58 + ->requireCapabilities( 59 + array( 60 + PhabricatorPolicyCapability::CAN_VIEW, 61 + PhabricatorPolicyCapability::CAN_EDIT, 62 + )) 63 + ->execute(); 64 + 65 + $options = mpull($badges, 'getName', 'getPHID'); 66 + asort($options); 67 + 68 + $form = id(new AphrontFormView()) 69 + ->setUser($viewer) 70 + ->appendChild( 71 + id(new AphrontFormSelectControl()) 72 + ->setLabel(pht('Badge')) 73 + ->setName('badgePHID') 74 + ->setOptions($options)); 75 + 76 + $dialog = $this->newDialog() 77 + ->setTitle(pht('Grant Badge')) 78 + ->appendForm($form) 79 + ->addCancelButton($view_uri) 80 + ->addSubmitButton(pht('Award')); 81 + 82 + return $dialog; 83 + } 84 + 85 + }
+33 -1
src/applications/people/controller/PhabricatorPeopleProfileViewController.php
··· 211 211 ->appendChild($error); 212 212 } 213 213 214 + // Best option? 215 + $badges = id(new PhabricatorBadgesQuery()) 216 + ->setViewer($viewer) 217 + ->withStatuses(array( 218 + PhabricatorBadgesBadge::STATUS_ACTIVE, 219 + )) 220 + ->requireCapabilities( 221 + array( 222 + PhabricatorPolicyCapability::CAN_VIEW, 223 + PhabricatorPolicyCapability::CAN_EDIT, 224 + )) 225 + ->execute(); 226 + 227 + $button = id(new PHUIButtonView()) 228 + ->setTag('a') 229 + ->setIcon('fa-plus') 230 + ->setText(pht('Award')) 231 + ->setWorkflow(true) 232 + ->setHref('/badges/award/'.$user->getID().'/'); 233 + 234 + $can_award = false; 235 + if (count($badges)) { 236 + $can_award = true; 237 + } 238 + 239 + $header = id(new PHUIHeaderView()) 240 + ->setHeader(pht('Badges')); 241 + 242 + if (count($badges)) { 243 + $header->addActionLink($button); 244 + } 245 + 214 246 $box = id(new PHUIObjectBoxView()) 215 - ->setHeaderText(pht('Badges')) 247 + ->setHeader($header) 216 248 ->addClass('project-view-badges') 217 249 ->appendChild($flex) 218 250 ->setBackground(PHUIObjectBoxView::GREY);