1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-20 12:30:56 +01:00

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
This commit is contained in:
Chad Little 2016-03-31 20:39:06 +00:00 committed by chad
parent 00425cac94
commit 2386705873
4 changed files with 122 additions and 1 deletions

View file

@ -1865,6 +1865,7 @@ phutil_register_library_map(array(
'PhabricatorBadgesApplication' => 'applications/badges/application/PhabricatorBadgesApplication.php', 'PhabricatorBadgesApplication' => 'applications/badges/application/PhabricatorBadgesApplication.php',
'PhabricatorBadgesArchiveController' => 'applications/badges/controller/PhabricatorBadgesArchiveController.php', 'PhabricatorBadgesArchiveController' => 'applications/badges/controller/PhabricatorBadgesArchiveController.php',
'PhabricatorBadgesAward' => 'applications/badges/storage/PhabricatorBadgesAward.php', 'PhabricatorBadgesAward' => 'applications/badges/storage/PhabricatorBadgesAward.php',
'PhabricatorBadgesAwardController' => 'applications/badges/controller/PhabricatorBadgesAwardController.php',
'PhabricatorBadgesAwardQuery' => 'applications/badges/query/PhabricatorBadgesAwardQuery.php', 'PhabricatorBadgesAwardQuery' => 'applications/badges/query/PhabricatorBadgesAwardQuery.php',
'PhabricatorBadgesBadge' => 'applications/badges/storage/PhabricatorBadgesBadge.php', 'PhabricatorBadgesBadge' => 'applications/badges/storage/PhabricatorBadgesBadge.php',
'PhabricatorBadgesCommentController' => 'applications/badges/controller/PhabricatorBadgesCommentController.php', 'PhabricatorBadgesCommentController' => 'applications/badges/controller/PhabricatorBadgesCommentController.php',
@ -6223,6 +6224,7 @@ phutil_register_library_map(array(
'PhabricatorDestructibleInterface', 'PhabricatorDestructibleInterface',
'PhabricatorPolicyInterface', 'PhabricatorPolicyInterface',
), ),
'PhabricatorBadgesAwardController' => 'PhabricatorBadgesController',
'PhabricatorBadgesAwardQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorBadgesAwardQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorBadgesBadge' => array( 'PhabricatorBadgesBadge' => array(
'PhabricatorBadgesDAO', 'PhabricatorBadgesDAO',

View file

@ -39,6 +39,8 @@ final class PhabricatorBadgesApplication extends PhabricatorApplication {
'/badges/' => array( '/badges/' => array(
'(?:query/(?P<queryKey>[^/]+)/)?' '(?:query/(?P<queryKey>[^/]+)/)?'
=> 'PhabricatorBadgesListController', => 'PhabricatorBadgesListController',
'award/(?:(?P<id>\d+)/)?'
=> 'PhabricatorBadgesAwardController',
'create/' 'create/'
=> 'PhabricatorBadgesEditController', => 'PhabricatorBadgesEditController',
'comment/(?P<id>[1-9]\d*)/' 'comment/(?P<id>[1-9]\d*)/'

View file

@ -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;
}
}

View file

@ -211,8 +211,40 @@ final class PhabricatorPeopleProfileViewController
->appendChild($error); ->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()) $box = id(new PHUIObjectBoxView())
->setHeaderText(pht('Badges')) ->setHeader($header)
->addClass('project-view-badges') ->addClass('project-view-badges')
->appendChild($flex) ->appendChild($flex)
->setBackground(PHUIObjectBoxView::GREY); ->setBackground(PHUIObjectBoxView::GREY);