1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 05:50:55 +01:00

Allow repositories to be activate/deactivated in a transaction-aware way

Summary: Adds activate/deactivate action plus transactions.

Test Plan: See screenshot.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D7057
This commit is contained in:
epriestley 2013-09-21 16:23:35 -07:00
parent a82992e9a5
commit 63818818cb
6 changed files with 117 additions and 2 deletions

View file

@ -494,6 +494,7 @@ phutil_register_library_map(array(
'DiffusionRenameHistoryQuery' => 'applications/diffusion/query/DiffusionRenameHistoryQuery.php',
'DiffusionRepositoryController' => 'applications/diffusion/controller/DiffusionRepositoryController.php',
'DiffusionRepositoryCreateController' => 'applications/diffusion/controller/DiffusionRepositoryCreateController.php',
'DiffusionRepositoryEditActivateController' => 'applications/diffusion/controller/DiffusionRepositoryEditActivateController.php',
'DiffusionRepositoryEditBasicController' => 'applications/diffusion/controller/DiffusionRepositoryEditBasicController.php',
'DiffusionRepositoryEditController' => 'applications/diffusion/controller/DiffusionRepositoryEditController.php',
'DiffusionRepositoryEditEncodingController' => 'applications/diffusion/controller/DiffusionRepositoryEditEncodingController.php',
@ -2554,6 +2555,7 @@ phutil_register_library_map(array(
'DiffusionRemarkupRule' => 'PhabricatorRemarkupRuleObject',
'DiffusionRepositoryController' => 'DiffusionController',
'DiffusionRepositoryCreateController' => 'DiffusionController',
'DiffusionRepositoryEditActivateController' => 'DiffusionController',
'DiffusionRepositoryEditBasicController' => 'DiffusionController',
'DiffusionRepositoryEditController' => 'DiffusionController',
'DiffusionRepositoryEditEncodingController' => 'DiffusionController',

View file

@ -67,6 +67,7 @@ final class PhabricatorApplicationDiffusion extends PhabricatorApplication {
'' => 'DiffusionRepositoryEditController',
'basic/' => 'DiffusionRepositoryEditBasicController',
'encoding/' => 'DiffusionRepositoryEditEncodingController',
'activate/' => 'DiffusionRepositoryEditActivateController',
),
),
'inline/' => array(

View file

@ -0,0 +1,66 @@
<?php
final class DiffusionRepositoryEditActivateController
extends DiffusionController {
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
$drequest = $this->diffusionRequest;
$repository = $drequest->getRepository();
$repository = id(new PhabricatorRepositoryQuery())
->setViewer($viewer)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->withIDs(array($repository->getID()))
->executeOne();
if (!$repository) {
return new Aphront404Response();
}
$edit_uri = $this->getRepositoryControllerURI($repository, 'edit/');
if ($request->isFormPost()) {
$xaction = id(new PhabricatorRepositoryTransaction())
->setTransactionType(PhabricatorRepositoryTransaction::TYPE_ACTIVATE)
->setNewValue(!$repository->isTracked());
$editor = id(new PhabricatorRepositoryEditor())
->setContinueOnNoEffect(true)
->setContentSourceFromRequest($request)
->setActor($viewer)
->applyTransactions($repository, array($xaction));
return id(new AphrontReloadResponse())->setURI($edit_uri);
}
$dialog = id(new AphrontDialogView())
->setUser($viewer);
if ($repository->isTracked()) {
$dialog
->setTitle(pht('Deactivate Repository?'))
->appendChild(
pht('Deactivate this repository?'))
->addSubmitButton(pht('Deactivate Repository'))
->addCancelButton($edit_uri);
} else {
$dialog
->setTitle(pht('Activate Repository?'))
->appendChild(
pht('Activate this repository?'))
->addSubmitButton(pht('Activate Repository'))
->addCancelButton($edit_uri);
}
return id(new AphrontDialogResponse())
->setDialog($dialog);
}
}

View file

@ -18,8 +18,17 @@ final class DiffusionRepositoryEditController extends DiffusionController {
$title = pht('Edit %s', $repository->getName());
$content[] = id(new PHUIHeaderView())
$header = id(new PHUIHeaderView())
->setHeader($title);
if (!$repository->isTracked()) {
$header->addTag(
id(new PhabricatorTagView())
->setType(PhabricatorTagView::TYPE_STATE)
->setName(pht('Inactive'))
->setBackgroundColor(PhabricatorTagView::COLOR_BLACK));
}
$content[] = $header;
$content[] = $this->buildBasicActions($repository);
$content[] = $this->buildBasicProperties($repository);
@ -82,9 +91,28 @@ final class DiffusionRepositoryEditController extends DiffusionController {
->setIcon('edit')
->setName(pht('Edit Basic Information'))
->setHref($this->getRepositoryControllerURI($repository, 'edit/basic/'))
->setDisabled(!$can_edit);
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit);
$view->addAction($edit);
$activate = id(new PhabricatorActionView())
->setHref(
$this->getRepositoryControllerURI($repository, 'edit/activate/'))
->setDisabled(!$can_edit)
->setWorkflow(true);
if ($repository->isTracked()) {
$activate
->setIcon('disable')
->setName(pht('Deactivate Repository'));
} else {
$activate
->setIcon('enable')
->setName(pht('Activate Repository'));
}
$view->addAction($activate);
return $view;
}

View file

@ -6,6 +6,7 @@ final class PhabricatorRepositoryEditor
public function getTransactionTypes() {
$types = parent::getTransactionTypes();
$types[] = PhabricatorRepositoryTransaction::TYPE_ACTIVATE;
$types[] = PhabricatorRepositoryTransaction::TYPE_NAME;
$types[] = PhabricatorRepositoryTransaction::TYPE_DESCRIPTION;
$types[] = PhabricatorRepositoryTransaction::TYPE_ENCODING;
@ -18,6 +19,8 @@ final class PhabricatorRepositoryEditor
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PhabricatorRepositoryTransaction::TYPE_ACTIVATE:
return $object->isTracked();
case PhabricatorRepositoryTransaction::TYPE_NAME:
return $object->getName();
case PhabricatorRepositoryTransaction::TYPE_DESCRIPTION:
@ -32,6 +35,7 @@ final class PhabricatorRepositoryEditor
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PhabricatorRepositoryTransaction::TYPE_ACTIVATE:
case PhabricatorRepositoryTransaction::TYPE_NAME:
case PhabricatorRepositoryTransaction::TYPE_DESCRIPTION:
case PhabricatorRepositoryTransaction::TYPE_ENCODING:
@ -44,6 +48,9 @@ final class PhabricatorRepositoryEditor
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PhabricatorRepositoryTransaction::TYPE_ACTIVATE:
$object->setDetail('tracking-enabled', $xaction->getNewValue());
break;
case PhabricatorRepositoryTransaction::TYPE_NAME:
$object->setName($xaction->getNewValue());
break;

View file

@ -3,6 +3,7 @@
final class PhabricatorRepositoryTransaction
extends PhabricatorApplicationTransaction {
const TYPE_ACTIVATE = 'repo:activate';
const TYPE_NAME = 'repo:name';
const TYPE_DESCRIPTION = 'repo:description';
const TYPE_ENCODING = 'repo:encoding';
@ -26,6 +27,16 @@ final class PhabricatorRepositoryTransaction
$new = $this->getNewValue();
switch ($this->getTransactionType()) {
case self::TYPE_ACTIVATE:
if ($new) {
return pht(
'%s activated this repository.',
$this->renderHandleLink($author_phid));
} else {
return pht(
'%s deactivated this repository.',
$this->renderHandleLink($author_phid));
}
case self::TYPE_NAME:
return pht(
'%s renamed this repository from "%s" to "%s".',