mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-19 03:01:11 +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:
parent
192a11bfdc
commit
dec69e21b3
9 changed files with 103 additions and 30 deletions
|
@ -1750,6 +1750,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorAutoEventListener' => 'infrastructure/events/PhabricatorAutoEventListener.php',
|
'PhabricatorAutoEventListener' => 'infrastructure/events/PhabricatorAutoEventListener.php',
|
||||||
'PhabricatorBadgeHasRecipientEdgeType' => 'applications/badges/edge/PhabricatorBadgeHasRecipientEdgeType.php',
|
'PhabricatorBadgeHasRecipientEdgeType' => 'applications/badges/edge/PhabricatorBadgeHasRecipientEdgeType.php',
|
||||||
'PhabricatorBadgesApplication' => 'applications/badges/application/PhabricatorBadgesApplication.php',
|
'PhabricatorBadgesApplication' => 'applications/badges/application/PhabricatorBadgesApplication.php',
|
||||||
|
'PhabricatorBadgesArchiveController' => 'applications/badges/controller/PhabricatorBadgesArchiveController.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',
|
||||||
'PhabricatorBadgesController' => 'applications/badges/controller/PhabricatorBadgesController.php',
|
'PhabricatorBadgesController' => 'applications/badges/controller/PhabricatorBadgesController.php',
|
||||||
|
@ -5807,6 +5808,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorAutoEventListener' => 'PhabricatorEventListener',
|
'PhabricatorAutoEventListener' => 'PhabricatorEventListener',
|
||||||
'PhabricatorBadgeHasRecipientEdgeType' => 'PhabricatorEdgeType',
|
'PhabricatorBadgeHasRecipientEdgeType' => 'PhabricatorEdgeType',
|
||||||
'PhabricatorBadgesApplication' => 'PhabricatorApplication',
|
'PhabricatorBadgesApplication' => 'PhabricatorApplication',
|
||||||
|
'PhabricatorBadgesArchiveController' => 'PhabricatorBadgesController',
|
||||||
'PhabricatorBadgesBadge' => array(
|
'PhabricatorBadgesBadge' => array(
|
||||||
'PhabricatorBadgesDAO',
|
'PhabricatorBadgesDAO',
|
||||||
'PhabricatorPolicyInterface',
|
'PhabricatorPolicyInterface',
|
||||||
|
|
|
@ -45,6 +45,8 @@ final class PhabricatorBadgesApplication extends PhabricatorApplication {
|
||||||
=> 'PhabricatorBadgesCommentController',
|
=> 'PhabricatorBadgesCommentController',
|
||||||
'edit/(?:(?P<id>\d+)/)?'
|
'edit/(?:(?P<id>\d+)/)?'
|
||||||
=> 'PhabricatorBadgesEditController',
|
=> 'PhabricatorBadgesEditController',
|
||||||
|
'archive/(?:(?P<id>\d+)/)?'
|
||||||
|
=> 'PhabricatorBadgesArchiveController',
|
||||||
'view/(?:(?P<id>\d+)/)?'
|
'view/(?:(?P<id>\d+)/)?'
|
||||||
=> 'PhabricatorBadgesViewController',
|
=> 'PhabricatorBadgesViewController',
|
||||||
'icon/(?P<id>[1-9]\d*)/'
|
'icon/(?P<id>[1-9]\d*)/'
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -43,14 +43,10 @@ final class PhabricatorBadgesEditController
|
||||||
|
|
||||||
$e_name = true;
|
$e_name = true;
|
||||||
$v_name = $badge->getName();
|
$v_name = $badge->getName();
|
||||||
|
|
||||||
$v_icon = $badge->getIcon();
|
$v_icon = $badge->getIcon();
|
||||||
|
|
||||||
$v_flav = $badge->getFlavor();
|
$v_flav = $badge->getFlavor();
|
||||||
$v_desc = $badge->getDescription();
|
$v_desc = $badge->getDescription();
|
||||||
$v_qual = $badge->getQuality();
|
$v_qual = $badge->getQuality();
|
||||||
$v_stat = $badge->getStatus();
|
|
||||||
|
|
||||||
$v_edit = $badge->getEditPolicy();
|
$v_edit = $badge->getEditPolicy();
|
||||||
|
|
||||||
$validation_exception = null;
|
$validation_exception = null;
|
||||||
|
@ -59,7 +55,6 @@ final class PhabricatorBadgesEditController
|
||||||
$v_flav = $request->getStr('flavor');
|
$v_flav = $request->getStr('flavor');
|
||||||
$v_desc = $request->getStr('description');
|
$v_desc = $request->getStr('description');
|
||||||
$v_icon = $request->getStr('icon');
|
$v_icon = $request->getStr('icon');
|
||||||
$v_stat = $request->getStr('status');
|
|
||||||
$v_qual = $request->getStr('quality');
|
$v_qual = $request->getStr('quality');
|
||||||
|
|
||||||
$v_view = $request->getStr('viewPolicy');
|
$v_view = $request->getStr('viewPolicy');
|
||||||
|
@ -70,7 +65,6 @@ final class PhabricatorBadgesEditController
|
||||||
$type_desc = PhabricatorBadgesTransaction::TYPE_DESCRIPTION;
|
$type_desc = PhabricatorBadgesTransaction::TYPE_DESCRIPTION;
|
||||||
$type_icon = PhabricatorBadgesTransaction::TYPE_ICON;
|
$type_icon = PhabricatorBadgesTransaction::TYPE_ICON;
|
||||||
$type_qual = PhabricatorBadgesTransaction::TYPE_QUALITY;
|
$type_qual = PhabricatorBadgesTransaction::TYPE_QUALITY;
|
||||||
$type_stat = PhabricatorBadgesTransaction::TYPE_STATUS;
|
|
||||||
|
|
||||||
$type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY;
|
$type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY;
|
||||||
|
|
||||||
|
@ -96,10 +90,6 @@ final class PhabricatorBadgesEditController
|
||||||
->setTransactionType($type_qual)
|
->setTransactionType($type_qual)
|
||||||
->setNewValue($v_qual);
|
->setNewValue($v_qual);
|
||||||
|
|
||||||
$xactions[] = id(new PhabricatorBadgesTransaction())
|
|
||||||
->setTransactionType($type_stat)
|
|
||||||
->setNewValue($v_stat);
|
|
||||||
|
|
||||||
$xactions[] = id(new PhabricatorBadgesTransaction())
|
$xactions[] = id(new PhabricatorBadgesTransaction())
|
||||||
->setTransactionType($type_edit)
|
->setTransactionType($type_edit)
|
||||||
->setNewValue($v_edit);
|
->setNewValue($v_edit);
|
||||||
|
@ -160,12 +150,6 @@ final class PhabricatorBadgesEditController
|
||||||
->setLabel(pht('Quality'))
|
->setLabel(pht('Quality'))
|
||||||
->setValue($v_qual)
|
->setValue($v_qual)
|
||||||
->setOptions($badge->getQualityNameMap()))
|
->setOptions($badge->getQualityNameMap()))
|
||||||
->appendChild(
|
|
||||||
id(new AphrontFormSelectControl())
|
|
||||||
->setLabel(pht('Status'))
|
|
||||||
->setName('status')
|
|
||||||
->setValue($v_stat)
|
|
||||||
->setOptions($badge->getStatusNameMap()))
|
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new PhabricatorRemarkupControl())
|
id(new PhabricatorRemarkupControl())
|
||||||
->setUser($viewer)
|
->setUser($viewer)
|
||||||
|
|
|
@ -24,7 +24,7 @@ final class PhabricatorBadgesViewController
|
||||||
$crumbs->addTextCrumb($badge->getName());
|
$crumbs->addTextCrumb($badge->getName());
|
||||||
$title = $badge->getName();
|
$title = $badge->getName();
|
||||||
|
|
||||||
if ($badge->isClosed()) {
|
if ($badge->isArchived()) {
|
||||||
$status_icon = 'fa-ban';
|
$status_icon = 'fa-ban';
|
||||||
$status_color = 'dark';
|
$status_color = 'dark';
|
||||||
} else {
|
} else {
|
||||||
|
@ -138,9 +138,26 @@ final class PhabricatorBadgesViewController
|
||||||
->setName(pht('Edit Badge'))
|
->setName(pht('Edit Badge'))
|
||||||
->setIcon('fa-pencil')
|
->setIcon('fa-pencil')
|
||||||
->setDisabled(!$can_edit)
|
->setDisabled(!$can_edit)
|
||||||
->setWorkflow(!$can_edit)
|
|
||||||
->setHref($this->getApplicationURI("/edit/{$id}/")));
|
->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(
|
$view->addAction(
|
||||||
id(new PhabricatorActionView())
|
id(new PhabricatorActionView())
|
||||||
->setName('Manage Recipients')
|
->setName('Manage Recipients')
|
||||||
|
|
|
@ -35,7 +35,7 @@ final class PhabricatorBadgesPHIDType extends PhabricatorPHIDType {
|
||||||
$id = $badge->getID();
|
$id = $badge->getID();
|
||||||
$name = $badge->getName();
|
$name = $badge->getName();
|
||||||
|
|
||||||
if ($badge->isClosed()) {
|
if ($badge->isArchived()) {
|
||||||
$handle->setStatus(PhabricatorObjectHandle::STATUS_CLOSED);
|
$handle->setStatus(PhabricatorObjectHandle::STATUS_CLOSED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ final class PhabricatorBadgesSearchEngine
|
||||||
return $query->setParameter(
|
return $query->setParameter(
|
||||||
'statuses',
|
'statuses',
|
||||||
array(
|
array(
|
||||||
PhabricatorBadgesBadge::STATUS_OPEN,
|
PhabricatorBadgesBadge::STATUS_ACTIVE,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ final class PhabricatorBadgesSearchEngine
|
||||||
->addAttribute($quality)
|
->addAttribute($quality)
|
||||||
->addAttribute($badge->getFlavor());
|
->addAttribute($badge->getFlavor());
|
||||||
|
|
||||||
if ($badge->isClosed()) {
|
if ($badge->isArchived()) {
|
||||||
$item->setDisabled(true);
|
$item->setDisabled(true);
|
||||||
$item->addIcon('fa-ban', pht('Archived'));
|
$item->addIcon('fa-ban', pht('Archived'));
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,8 @@ final class PhabricatorBadgesBadge extends PhabricatorBadgesDAO
|
||||||
|
|
||||||
private $recipientPHIDs = self::ATTACHABLE;
|
private $recipientPHIDs = self::ATTACHABLE;
|
||||||
|
|
||||||
const STATUS_OPEN = 'open';
|
const STATUS_ACTIVE = 'open';
|
||||||
const STATUS_CLOSED = 'closed';
|
const STATUS_ARCHIVED = 'closed';
|
||||||
|
|
||||||
const DEFAULT_ICON = 'fa-star';
|
const DEFAULT_ICON = 'fa-star';
|
||||||
const DEFAULT_QUALITY = 'green';
|
const DEFAULT_QUALITY = 'green';
|
||||||
|
@ -37,8 +37,8 @@ final class PhabricatorBadgesBadge extends PhabricatorBadgesDAO
|
||||||
|
|
||||||
public static function getStatusNameMap() {
|
public static function getStatusNameMap() {
|
||||||
return array(
|
return array(
|
||||||
self::STATUS_OPEN => pht('Active'),
|
self::STATUS_ACTIVE => pht('Active'),
|
||||||
self::STATUS_CLOSED => pht('Archived'),
|
self::STATUS_ARCHIVED => pht('Archived'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ final class PhabricatorBadgesBadge extends PhabricatorBadgesDAO
|
||||||
->setQuality(self::DEFAULT_QUALITY)
|
->setQuality(self::DEFAULT_QUALITY)
|
||||||
->setCreatorPHID($actor->getPHID())
|
->setCreatorPHID($actor->getPHID())
|
||||||
->setEditPolicy($edit_policy)
|
->setEditPolicy($edit_policy)
|
||||||
->setStatus(self::STATUS_OPEN);
|
->setStatus(self::STATUS_ACTIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getConfiguration() {
|
protected function getConfiguration() {
|
||||||
|
@ -102,8 +102,8 @@ final class PhabricatorBadgesBadge extends PhabricatorBadgesDAO
|
||||||
PhabricatorPHID::generateNewPHID(PhabricatorBadgesPHIDType::TYPECONST);
|
PhabricatorPHID::generateNewPHID(PhabricatorBadgesPHIDType::TYPECONST);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isClosed() {
|
public function isArchived() {
|
||||||
return ($this->getStatus() == self::STATUS_CLOSED);
|
return ($this->getStatus() == self::STATUS_ARCHIVED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function attachRecipientPHIDs(array $phids) {
|
public function attachRecipientPHIDs(array $phids) {
|
||||||
|
|
|
@ -155,12 +155,12 @@ final class PhabricatorBadgesTransaction
|
||||||
$this->renderHandleLink($object_phid));
|
$this->renderHandleLink($object_phid));
|
||||||
case self::TYPE_STATUS:
|
case self::TYPE_STATUS:
|
||||||
switch ($new) {
|
switch ($new) {
|
||||||
case PhabricatorBadgesBadge::STATUS_OPEN:
|
case PhabricatorBadgesBadge::STATUS_ACTIVE:
|
||||||
return pht(
|
return pht(
|
||||||
'%s activated %s.',
|
'%s activated %s.',
|
||||||
$this->renderHandleLink($author_phid),
|
$this->renderHandleLink($author_phid),
|
||||||
$this->renderHandleLink($object_phid));
|
$this->renderHandleLink($object_phid));
|
||||||
case PhabricatorBadgesBadge::STATUS_CLOSED:
|
case PhabricatorBadgesBadge::STATUS_ARCHIVED:
|
||||||
return pht(
|
return pht(
|
||||||
'%s archived %s.',
|
'%s archived %s.',
|
||||||
$this->renderHandleLink($author_phid),
|
$this->renderHandleLink($author_phid),
|
||||||
|
|
Loading…
Reference in a new issue