1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-18 18:51:12 +01:00

Add PhabricatorBadgeArchiveController

Summary: Allows archive and activate on badges from action list. Ref T9414

Test Plan: Archive, Activate, New, Edit

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T9414

Differential Revision: https://secure.phabricator.com/D14727
This commit is contained in:
Chad Little 2015-12-09 13:26:26 -08:00
parent 192a11bfdc
commit dec69e21b3
9 changed files with 103 additions and 30 deletions

View file

@ -1750,6 +1750,7 @@ phutil_register_library_map(array(
'PhabricatorAutoEventListener' => 'infrastructure/events/PhabricatorAutoEventListener.php',
'PhabricatorBadgeHasRecipientEdgeType' => 'applications/badges/edge/PhabricatorBadgeHasRecipientEdgeType.php',
'PhabricatorBadgesApplication' => 'applications/badges/application/PhabricatorBadgesApplication.php',
'PhabricatorBadgesArchiveController' => 'applications/badges/controller/PhabricatorBadgesArchiveController.php',
'PhabricatorBadgesBadge' => 'applications/badges/storage/PhabricatorBadgesBadge.php',
'PhabricatorBadgesCommentController' => 'applications/badges/controller/PhabricatorBadgesCommentController.php',
'PhabricatorBadgesController' => 'applications/badges/controller/PhabricatorBadgesController.php',
@ -5807,6 +5808,7 @@ phutil_register_library_map(array(
'PhabricatorAutoEventListener' => 'PhabricatorEventListener',
'PhabricatorBadgeHasRecipientEdgeType' => 'PhabricatorEdgeType',
'PhabricatorBadgesApplication' => 'PhabricatorApplication',
'PhabricatorBadgesArchiveController' => 'PhabricatorBadgesController',
'PhabricatorBadgesBadge' => array(
'PhabricatorBadgesDAO',
'PhabricatorPolicyInterface',

View file

@ -45,6 +45,8 @@ final class PhabricatorBadgesApplication extends PhabricatorApplication {
=> 'PhabricatorBadgesCommentController',
'edit/(?:(?P<id>\d+)/)?'
=> 'PhabricatorBadgesEditController',
'archive/(?:(?P<id>\d+)/)?'
=> 'PhabricatorBadgesArchiveController',
'view/(?:(?P<id>\d+)/)?'
=> 'PhabricatorBadgesViewController',
'icon/(?P<id>[1-9]\d*)/'

View file

@ -0,0 +1,68 @@
<?php
final class PhabricatorBadgesArchiveController
extends PhabricatorBadgesController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$badge = id(new PhabricatorBadgesQuery())
->setViewer($viewer)
->withIDs(array($id))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$badge) {
return new Aphront404Response();
}
$view_uri = $this->getApplicationURI('view/'.$badge->getID().'/');
if ($request->isFormPost()) {
if ($badge->isArchived()) {
$new_status = PhabricatorBadgesBadge::STATUS_ACTIVE;
} else {
$new_status = PhabricatorBadgesBadge::STATUS_ARCHIVED;
}
$xactions = array();
$xactions[] = id(new PhabricatorBadgesTransaction())
->setTransactionType(PhabricatorBadgesTransaction::TYPE_STATUS)
->setNewValue($new_status);
id(new PhabricatorBadgesEditor())
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true)
->applyTransactions($badge, $xactions);
return id(new AphrontRedirectResponse())->setURI($view_uri);
}
if ($badge->isArchived()) {
$title = pht('Activate Badge');
$body = pht('This badge will be re-commissioned into service.');
$button = pht('Activate Badge');
} else {
$title = pht('Archive Badge');
$body = pht(
'This dedicated badge, once a distinguish icon of this install, '.
'shall be immediately retired from service, but will never far from '.
'our hearts. Godspeed.');
$button = pht('Archive Badge');
}
return $this->newDialog()
->setTitle($title)
->appendChild($body)
->addCancelButton($view_uri)
->addSubmitButton($button);
}
}

View file

@ -43,14 +43,10 @@ final class PhabricatorBadgesEditController
$e_name = true;
$v_name = $badge->getName();
$v_icon = $badge->getIcon();
$v_flav = $badge->getFlavor();
$v_desc = $badge->getDescription();
$v_qual = $badge->getQuality();
$v_stat = $badge->getStatus();
$v_edit = $badge->getEditPolicy();
$validation_exception = null;
@ -59,7 +55,6 @@ final class PhabricatorBadgesEditController
$v_flav = $request->getStr('flavor');
$v_desc = $request->getStr('description');
$v_icon = $request->getStr('icon');
$v_stat = $request->getStr('status');
$v_qual = $request->getStr('quality');
$v_view = $request->getStr('viewPolicy');
@ -70,7 +65,6 @@ final class PhabricatorBadgesEditController
$type_desc = PhabricatorBadgesTransaction::TYPE_DESCRIPTION;
$type_icon = PhabricatorBadgesTransaction::TYPE_ICON;
$type_qual = PhabricatorBadgesTransaction::TYPE_QUALITY;
$type_stat = PhabricatorBadgesTransaction::TYPE_STATUS;
$type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY;
@ -96,10 +90,6 @@ final class PhabricatorBadgesEditController
->setTransactionType($type_qual)
->setNewValue($v_qual);
$xactions[] = id(new PhabricatorBadgesTransaction())
->setTransactionType($type_stat)
->setNewValue($v_stat);
$xactions[] = id(new PhabricatorBadgesTransaction())
->setTransactionType($type_edit)
->setNewValue($v_edit);
@ -160,12 +150,6 @@ final class PhabricatorBadgesEditController
->setLabel(pht('Quality'))
->setValue($v_qual)
->setOptions($badge->getQualityNameMap()))
->appendChild(
id(new AphrontFormSelectControl())
->setLabel(pht('Status'))
->setName('status')
->setValue($v_stat)
->setOptions($badge->getStatusNameMap()))
->appendChild(
id(new PhabricatorRemarkupControl())
->setUser($viewer)

View file

@ -24,7 +24,7 @@ final class PhabricatorBadgesViewController
$crumbs->addTextCrumb($badge->getName());
$title = $badge->getName();
if ($badge->isClosed()) {
if ($badge->isArchived()) {
$status_icon = 'fa-ban';
$status_color = 'dark';
} else {
@ -138,9 +138,26 @@ final class PhabricatorBadgesViewController
->setName(pht('Edit Badge'))
->setIcon('fa-pencil')
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit)
->setHref($this->getApplicationURI("/edit/{$id}/")));
if ($badge->isArchived()) {
$view->addAction(
id(new PhabricatorActionView())
->setName(pht('Activate Badge'))
->setIcon('fa-check')
->setDisabled(!$can_edit)
->setWorkflow($can_edit)
->setHref($this->getApplicationURI("/archive/{$id}/")));
} else {
$view->addAction(
id(new PhabricatorActionView())
->setName(pht('Archive Badge'))
->setIcon('fa-ban')
->setDisabled(!$can_edit)
->setWorkflow($can_edit)
->setHref($this->getApplicationURI("/archive/{$id}/")));
}
$view->addAction(
id(new PhabricatorActionView())
->setName('Manage Recipients')

View file

@ -35,7 +35,7 @@ final class PhabricatorBadgesPHIDType extends PhabricatorPHIDType {
$id = $badge->getID();
$name = $badge->getName();
if ($badge->isClosed()) {
if ($badge->isArchived()) {
$handle->setStatus(PhabricatorObjectHandle::STATUS_CLOSED);
}

View file

@ -84,7 +84,7 @@ final class PhabricatorBadgesSearchEngine
return $query->setParameter(
'statuses',
array(
PhabricatorBadgesBadge::STATUS_OPEN,
PhabricatorBadgesBadge::STATUS_ACTIVE,
));
}
@ -124,7 +124,7 @@ final class PhabricatorBadgesSearchEngine
->addAttribute($quality)
->addAttribute($badge->getFlavor());
if ($badge->isClosed()) {
if ($badge->isArchived()) {
$item->setDisabled(true);
$item->addIcon('fa-ban', pht('Archived'));
}

View file

@ -21,8 +21,8 @@ final class PhabricatorBadgesBadge extends PhabricatorBadgesDAO
private $recipientPHIDs = self::ATTACHABLE;
const STATUS_OPEN = 'open';
const STATUS_CLOSED = 'closed';
const STATUS_ACTIVE = 'open';
const STATUS_ARCHIVED = 'closed';
const DEFAULT_ICON = 'fa-star';
const DEFAULT_QUALITY = 'green';
@ -37,8 +37,8 @@ final class PhabricatorBadgesBadge extends PhabricatorBadgesDAO
public static function getStatusNameMap() {
return array(
self::STATUS_OPEN => pht('Active'),
self::STATUS_CLOSED => pht('Archived'),
self::STATUS_ACTIVE => pht('Active'),
self::STATUS_ARCHIVED => pht('Archived'),
);
}
@ -74,7 +74,7 @@ final class PhabricatorBadgesBadge extends PhabricatorBadgesDAO
->setQuality(self::DEFAULT_QUALITY)
->setCreatorPHID($actor->getPHID())
->setEditPolicy($edit_policy)
->setStatus(self::STATUS_OPEN);
->setStatus(self::STATUS_ACTIVE);
}
protected function getConfiguration() {
@ -102,8 +102,8 @@ final class PhabricatorBadgesBadge extends PhabricatorBadgesDAO
PhabricatorPHID::generateNewPHID(PhabricatorBadgesPHIDType::TYPECONST);
}
public function isClosed() {
return ($this->getStatus() == self::STATUS_CLOSED);
public function isArchived() {
return ($this->getStatus() == self::STATUS_ARCHIVED);
}
public function attachRecipientPHIDs(array $phids) {

View file

@ -155,12 +155,12 @@ final class PhabricatorBadgesTransaction
$this->renderHandleLink($object_phid));
case self::TYPE_STATUS:
switch ($new) {
case PhabricatorBadgesBadge::STATUS_OPEN:
case PhabricatorBadgesBadge::STATUS_ACTIVE:
return pht(
'%s activated %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
case PhabricatorBadgesBadge::STATUS_CLOSED:
case PhabricatorBadgesBadge::STATUS_ARCHIVED:
return pht(
'%s archived %s.',
$this->renderHandleLink($author_phid),