Page MenuHomePhabricator

D15544.id37498.diff
No OneTemporary

D15544.id37498.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -1865,6 +1865,7 @@
'PhabricatorBadgesApplication' => 'applications/badges/application/PhabricatorBadgesApplication.php',
'PhabricatorBadgesArchiveController' => 'applications/badges/controller/PhabricatorBadgesArchiveController.php',
'PhabricatorBadgesAward' => 'applications/badges/storage/PhabricatorBadgesAward.php',
+ 'PhabricatorBadgesAwardController' => 'applications/badges/controller/PhabricatorBadgesAwardController.php',
'PhabricatorBadgesAwardQuery' => 'applications/badges/query/PhabricatorBadgesAwardQuery.php',
'PhabricatorBadgesBadge' => 'applications/badges/storage/PhabricatorBadgesBadge.php',
'PhabricatorBadgesCommentController' => 'applications/badges/controller/PhabricatorBadgesCommentController.php',
@@ -6223,6 +6224,7 @@
'PhabricatorDestructibleInterface',
'PhabricatorPolicyInterface',
),
+ 'PhabricatorBadgesAwardController' => 'PhabricatorBadgesController',
'PhabricatorBadgesAwardQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorBadgesBadge' => array(
'PhabricatorBadgesDAO',
diff --git a/src/applications/badges/application/PhabricatorBadgesApplication.php b/src/applications/badges/application/PhabricatorBadgesApplication.php
--- a/src/applications/badges/application/PhabricatorBadgesApplication.php
+++ b/src/applications/badges/application/PhabricatorBadgesApplication.php
@@ -39,6 +39,8 @@
'/badges/' => array(
'(?:query/(?P<queryKey>[^/]+)/)?'
=> 'PhabricatorBadgesListController',
+ 'award/(?:(?P<id>\d+)/)?'
+ => 'PhabricatorBadgesAwardController',
'create/'
=> 'PhabricatorBadgesEditController',
'comment/(?P<id>[1-9]\d*)/'
diff --git a/src/applications/badges/controller/PhabricatorBadgesAwardController.php b/src/applications/badges/controller/PhabricatorBadgesAwardController.php
new file mode 100644
--- /dev/null
+++ b/src/applications/badges/controller/PhabricatorBadgesAwardController.php
@@ -0,0 +1,85 @@
+<?php
+
+final class PhabricatorBadgesAwardController
+ extends PhabricatorBadgesController {
+
+ public function handleRequest(AphrontRequest $request) {
+ $viewer = $request->getViewer();
+ $id = $request->getURIData('id');
+
+ $user = id(new PhabricatorPeopleQuery())
+ ->setViewer($viewer)
+ ->withIDs(array($id))
+ ->executeOne();
+ if (!$user) {
+ return new Aphront404Response();
+ }
+
+ $view_uri = '/p/'.$user->getUsername();
+
+ if ($request->isFormPost()) {
+ $xactions = array();
+ $badge_phid = $request->getStr('badgePHID');
+ $badge = id(new PhabricatorBadgesQuery())
+ ->setViewer($viewer)
+ ->withPHIDs(array($badge_phid))
+ ->needRecipients(true)
+ ->requireCapabilities(
+ array(
+ PhabricatorPolicyCapability::CAN_EDIT,
+ PhabricatorPolicyCapability::CAN_VIEW,
+ ))
+ ->executeOne();
+ if (!$badge) {
+ return new Aphront404Response();
+ }
+ $award_phids = array($user->getPHID());
+
+ $xactions[] = id(new PhabricatorBadgesTransaction())
+ ->setTransactionType(PhabricatorBadgesTransaction::TYPE_AWARD)
+ ->setNewValue($award_phids);
+
+ $editor = id(new PhabricatorBadgesEditor($badge))
+ ->setActor($viewer)
+ ->setContentSourceFromRequest($request)
+ ->setContinueOnNoEffect(true)
+ ->setContinueOnMissingFields(true)
+ ->applyTransactions($badge, $xactions);
+
+ return id(new AphrontRedirectResponse())
+ ->setURI($view_uri);
+ }
+
+ $badges = id(new PhabricatorBadgesQuery())
+ ->setViewer($viewer)
+ ->withStatuses(array(
+ PhabricatorBadgesBadge::STATUS_ACTIVE,
+ ))
+ ->requireCapabilities(
+ array(
+ PhabricatorPolicyCapability::CAN_VIEW,
+ PhabricatorPolicyCapability::CAN_EDIT,
+ ))
+ ->execute();
+
+ $options = mpull($badges, 'getName', 'getPHID');
+ asort($options);
+
+ $form = id(new AphrontFormView())
+ ->setUser($viewer)
+ ->appendChild(
+ id(new AphrontFormSelectControl())
+ ->setLabel(pht('Badge'))
+ ->setName('badgePHID')
+ ->setOptions($options));
+
+ $dialog = $this->newDialog()
+ ->setTitle(pht('Grant Badge'))
+ ->appendForm($form)
+ ->addCancelButton($view_uri)
+ ->addSubmitButton(pht('Award'));
+
+ return $dialog;
+ }
+
+}
diff --git a/src/applications/people/controller/PhabricatorPeopleProfileViewController.php b/src/applications/people/controller/PhabricatorPeopleProfileViewController.php
--- a/src/applications/people/controller/PhabricatorPeopleProfileViewController.php
+++ b/src/applications/people/controller/PhabricatorPeopleProfileViewController.php
@@ -211,8 +211,40 @@
->appendChild($error);
}
+ // Best option?
+ $badges = id(new PhabricatorBadgesQuery())
+ ->setViewer($viewer)
+ ->withStatuses(array(
+ PhabricatorBadgesBadge::STATUS_ACTIVE,
+ ))
+ ->requireCapabilities(
+ array(
+ PhabricatorPolicyCapability::CAN_VIEW,
+ PhabricatorPolicyCapability::CAN_EDIT,
+ ))
+ ->execute();
+
+ $button = id(new PHUIButtonView())
+ ->setTag('a')
+ ->setIcon('fa-plus')
+ ->setText(pht('Award'))
+ ->setWorkflow(true)
+ ->setHref('/badges/award/'.$user->getID().'/');
+
+ $can_award = false;
+ if (count($badges)) {
+ $can_award = true;
+ }
+
+ $header = id(new PHUIHeaderView())
+ ->setHeader(pht('Badges'));
+
+ if (count($badges)) {
+ $header->addActionLink($button);
+ }
+
$box = id(new PHUIObjectBoxView())
- ->setHeaderText(pht('Badges'))
+ ->setHeader($header)
->addClass('project-view-badges')
->appendChild($flex)
->setBackground(PHUIObjectBoxView::GREY);

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 10, 11:41 AM (1 w, 2 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6746727
Default Alt Text
D15544.id37498.diff (5 KB)

Event Timeline