mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +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:
parent
00425cac94
commit
2386705873
4 changed files with 122 additions and 1 deletions
|
@ -1865,6 +1865,7 @@ phutil_register_library_map(array(
|
|||
'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 @@ phutil_register_library_map(array(
|
|||
'PhabricatorDestructibleInterface',
|
||||
'PhabricatorPolicyInterface',
|
||||
),
|
||||
'PhabricatorBadgesAwardController' => 'PhabricatorBadgesController',
|
||||
'PhabricatorBadgesAwardQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PhabricatorBadgesBadge' => array(
|
||||
'PhabricatorBadgesDAO',
|
||||
|
|
|
@ -39,6 +39,8 @@ final class PhabricatorBadgesApplication extends PhabricatorApplication {
|
|||
'/badges/' => array(
|
||||
'(?:query/(?P<queryKey>[^/]+)/)?'
|
||||
=> 'PhabricatorBadgesListController',
|
||||
'award/(?:(?P<id>\d+)/)?'
|
||||
=> 'PhabricatorBadgesAwardController',
|
||||
'create/'
|
||||
=> 'PhabricatorBadgesEditController',
|
||||
'comment/(?P<id>[1-9]\d*)/'
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -211,8 +211,40 @@ final class PhabricatorPeopleProfileViewController
|
|||
->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);
|
||||
|
|
Loading…
Reference in a new issue