1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-18 19:40:55 +01:00

Allow Owners Packages to be archived

Summary: Fixes T8428. Adds status to packages, allows setting and application search. I presume though these need checked elsewhere?

Test Plan: New package, edit package, archive package, run search queries.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T8428

Differential Revision: https://secure.phabricator.com/D13925
This commit is contained in:
Chad Little 2015-08-18 13:36:05 -07:00
parent 0a509ea7ec
commit e0faa66772
12 changed files with 111 additions and 2 deletions

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_owners.owners_package
ADD status VARCHAR(32) NOT NULL COLLATE {$COLLATE_TEXT};

View file

@ -0,0 +1,2 @@
UPDATE {$NAMESPACE}_owners.owners_package
SET status = 'active' WHERE status = '';

View file

@ -47,6 +47,7 @@ abstract class DifferentialController extends PhabricatorController {
if ($viewer->getPHID()) { if ($viewer->getPHID()) {
$packages = id(new PhabricatorOwnersPackageQuery()) $packages = id(new PhabricatorOwnersPackageQuery())
->setViewer($viewer) ->setViewer($viewer)
->withStatuses(array(PhabricatorOwnersPackage::STATUS_ACTIVE))
->withAuthorityPHIDs(array($viewer->getPHID())) ->withAuthorityPHIDs(array($viewer->getPHID()))
->execute(); ->execute();
$toc_view->setAuthorityPackages($packages); $toc_view->setAuthorityPackages($packages);
@ -58,6 +59,7 @@ abstract class DifferentialController extends PhabricatorController {
$control_query = id(new PhabricatorOwnersPackageQuery()) $control_query = id(new PhabricatorOwnersPackageQuery())
->setViewer($viewer) ->setViewer($viewer)
->withStatuses(array(PhabricatorOwnersPackage::STATUS_ACTIVE))
->withControl($repository_phid, $paths); ->withControl($repository_phid, $paths);
$control_query->execute(); $control_query->execute();
} }

View file

@ -167,6 +167,7 @@ abstract class DiffusionBrowseController extends DiffusionController {
if (PhabricatorApplication::isClassInstalled($owners)) { if (PhabricatorApplication::isClassInstalled($owners)) {
$package_query = id(new PhabricatorOwnersPackageQuery()) $package_query = id(new PhabricatorOwnersPackageQuery())
->setViewer($viewer) ->setViewer($viewer)
->withStatuses(array(PhabricatorOwnersPackage::STATUS_ACTIVE))
->withControl( ->withControl(
$repository->getPHID(), $repository->getPHID(),
array( array(

View file

@ -1089,6 +1089,7 @@ final class DiffusionCommitController extends DiffusionController {
if ($viewer->getPHID()) { if ($viewer->getPHID()) {
$packages = id(new PhabricatorOwnersPackageQuery()) $packages = id(new PhabricatorOwnersPackageQuery())
->setViewer($viewer) ->setViewer($viewer)
->withStatuses(array(PhabricatorOwnersPackage::STATUS_ACTIVE))
->withAuthorityPHIDs(array($viewer->getPHID())) ->withAuthorityPHIDs(array($viewer->getPHID()))
->execute(); ->execute();
$toc_view->setAuthorityPackages($packages); $toc_view->setAuthorityPackages($packages);
@ -1099,6 +1100,7 @@ final class DiffusionCommitController extends DiffusionController {
$control_query = id(new PhabricatorOwnersPackageQuery()) $control_query = id(new PhabricatorOwnersPackageQuery())
->setViewer($viewer) ->setViewer($viewer)
->withStatuses(array(PhabricatorOwnersPackage::STATUS_ACTIVE))
->withControl($repository_phid, mpull($changesets, 'getFilename')); ->withControl($repository_phid, mpull($changesets, 'getFilename'));
$control_query->execute(); $control_query->execute();
} }

View file

@ -41,9 +41,20 @@ final class PhabricatorOwnersDetailController
$properties = $this->buildPackagePropertyView($package); $properties = $this->buildPackagePropertyView($package);
$properties->setActionList($actions); $properties->setActionList($actions);
if ($package->isArchived()) {
$header_icon = 'fa-ban';
$header_name = pht('Archived');
$header_color = 'dark';
} else {
$header_icon = 'fa-check';
$header_name = pht('Active');
$header_color = 'bluegrey';
}
$header = id(new PHUIHeaderView()) $header = id(new PHUIHeaderView())
->setUser($viewer) ->setUser($viewer)
->setHeader($package->getName()) ->setHeader($package->getName())
->setStatus($header_icon, $header_color, $header_name)
->setPolicyObject($package); ->setPolicyObject($package);
$panel = id(new PHUIObjectBoxView()) $panel = id(new PHUIObjectBoxView())

View file

@ -34,6 +34,7 @@ final class PhabricatorOwnersEditController
$v_owners = mpull($package->getOwners(), 'getUserPHID'); $v_owners = mpull($package->getOwners(), 'getUserPHID');
$v_auditing = $package->getAuditingEnabled(); $v_auditing = $package->getAuditingEnabled();
$v_description = $package->getDescription(); $v_description = $package->getDescription();
$v_status = $package->getStatus();
$errors = array(); $errors = array();
@ -44,11 +45,13 @@ final class PhabricatorOwnersEditController
$v_owners = $request->getArr('owners'); $v_owners = $request->getArr('owners');
$v_auditing = ($request->getStr('auditing') == 'enabled'); $v_auditing = ($request->getStr('auditing') == 'enabled');
$v_description = $request->getStr('description'); $v_description = $request->getStr('description');
$v_status = $request->getStr('status');
$type_name = PhabricatorOwnersPackageTransaction::TYPE_NAME; $type_name = PhabricatorOwnersPackageTransaction::TYPE_NAME;
$type_owners = PhabricatorOwnersPackageTransaction::TYPE_OWNERS; $type_owners = PhabricatorOwnersPackageTransaction::TYPE_OWNERS;
$type_auditing = PhabricatorOwnersPackageTransaction::TYPE_AUDITING; $type_auditing = PhabricatorOwnersPackageTransaction::TYPE_AUDITING;
$type_description = PhabricatorOwnersPackageTransaction::TYPE_DESCRIPTION; $type_description = PhabricatorOwnersPackageTransaction::TYPE_DESCRIPTION;
$type_status = PhabricatorOwnersPackageTransaction::TYPE_STATUS;
$xactions[] = id(new PhabricatorOwnersPackageTransaction()) $xactions[] = id(new PhabricatorOwnersPackageTransaction())
->setTransactionType($type_name) ->setTransactionType($type_name)
@ -66,6 +69,12 @@ final class PhabricatorOwnersEditController
->setTransactionType($type_description) ->setTransactionType($type_description)
->setNewValue($v_description); ->setNewValue($v_description);
if (!$is_new) {
$xactions[] = id(new PhabricatorOwnersPackageTransaction())
->setTransactionType($type_status)
->setNewValue($v_status);
}
$editor = id(new PhabricatorOwnersPackageTransactionEditor()) $editor = id(new PhabricatorOwnersPackageTransactionEditor())
->setActor($viewer) ->setActor($viewer)
->setContentSourceFromRequest($request) ->setContentSourceFromRequest($request)
@ -115,8 +124,18 @@ final class PhabricatorOwnersEditController
->setDatasource(new PhabricatorProjectOrUserDatasource()) ->setDatasource(new PhabricatorProjectOrUserDatasource())
->setLabel(pht('Owners')) ->setLabel(pht('Owners'))
->setName('owners') ->setName('owners')
->setValue($v_owners)) ->setValue($v_owners));
->appendChild(
if (!$is_new) {
$form->appendChild(
id(new AphrontFormSelectControl())
->setLabel(pht('Status'))
->setName('status')
->setValue($v_status)
->setOptions($package->getStatusNameMap()));
}
$form->appendChild(
id(new AphrontFormSelectControl()) id(new AphrontFormSelectControl())
->setName('auditing') ->setName('auditing')
->setLabel(pht('Auditing')) ->setLabel(pht('Auditing'))

View file

@ -19,6 +19,7 @@ final class PhabricatorOwnersPackageTransactionEditor
$types[] = PhabricatorOwnersPackageTransaction::TYPE_AUDITING; $types[] = PhabricatorOwnersPackageTransaction::TYPE_AUDITING;
$types[] = PhabricatorOwnersPackageTransaction::TYPE_DESCRIPTION; $types[] = PhabricatorOwnersPackageTransaction::TYPE_DESCRIPTION;
$types[] = PhabricatorOwnersPackageTransaction::TYPE_PATHS; $types[] = PhabricatorOwnersPackageTransaction::TYPE_PATHS;
$types[] = PhabricatorOwnersPackageTransaction::TYPE_STATUS;
return $types; return $types;
} }
@ -42,6 +43,8 @@ final class PhabricatorOwnersPackageTransactionEditor
case PhabricatorOwnersPackageTransaction::TYPE_PATHS: case PhabricatorOwnersPackageTransaction::TYPE_PATHS:
$paths = $object->getPaths(); $paths = $object->getPaths();
return mpull($paths, 'getRef'); return mpull($paths, 'getRef');
case PhabricatorOwnersPackageTransaction::TYPE_STATUS:
return $object->getStatus();
} }
} }
@ -53,6 +56,7 @@ final class PhabricatorOwnersPackageTransactionEditor
case PhabricatorOwnersPackageTransaction::TYPE_NAME: case PhabricatorOwnersPackageTransaction::TYPE_NAME:
case PhabricatorOwnersPackageTransaction::TYPE_DESCRIPTION: case PhabricatorOwnersPackageTransaction::TYPE_DESCRIPTION:
case PhabricatorOwnersPackageTransaction::TYPE_PATHS: case PhabricatorOwnersPackageTransaction::TYPE_PATHS:
case PhabricatorOwnersPackageTransaction::TYPE_STATUS:
return $xaction->getNewValue(); return $xaction->getNewValue();
case PhabricatorOwnersPackageTransaction::TYPE_AUDITING: case PhabricatorOwnersPackageTransaction::TYPE_AUDITING:
return (int)$xaction->getNewValue(); return (int)$xaction->getNewValue();
@ -99,6 +103,9 @@ final class PhabricatorOwnersPackageTransactionEditor
case PhabricatorOwnersPackageTransaction::TYPE_OWNERS: case PhabricatorOwnersPackageTransaction::TYPE_OWNERS:
case PhabricatorOwnersPackageTransaction::TYPE_PATHS: case PhabricatorOwnersPackageTransaction::TYPE_PATHS:
return; return;
case PhabricatorOwnersPackageTransaction::TYPE_STATUS:
$object->setStatus($xaction->getNewValue());
return;
} }
return parent::applyCustomInternalTransaction($object, $xaction); return parent::applyCustomInternalTransaction($object, $xaction);
@ -112,6 +119,7 @@ final class PhabricatorOwnersPackageTransactionEditor
case PhabricatorOwnersPackageTransaction::TYPE_NAME: case PhabricatorOwnersPackageTransaction::TYPE_NAME:
case PhabricatorOwnersPackageTransaction::TYPE_DESCRIPTION: case PhabricatorOwnersPackageTransaction::TYPE_DESCRIPTION:
case PhabricatorOwnersPackageTransaction::TYPE_AUDITING: case PhabricatorOwnersPackageTransaction::TYPE_AUDITING:
case PhabricatorOwnersPackageTransaction::TYPE_STATUS:
return; return;
case PhabricatorOwnersPackageTransaction::TYPE_OWNERS: case PhabricatorOwnersPackageTransaction::TYPE_OWNERS:
$old = $xaction->getOldValue(); $old = $xaction->getOldValue();

View file

@ -10,6 +10,7 @@ final class PhabricatorOwnersPackageQuery
private $repositoryPHIDs; private $repositoryPHIDs;
private $paths; private $paths;
private $namePrefix; private $namePrefix;
private $statuses;
private $controlMap = array(); private $controlMap = array();
private $controlResults; private $controlResults;
@ -57,6 +58,11 @@ final class PhabricatorOwnersPackageQuery
return $this; return $this;
} }
public function withStatuses(array $statuses) {
$this->statuses = $statuses;
return $this;
}
public function withControl($repository_phid, array $paths) { public function withControl($repository_phid, array $paths) {
if (empty($this->controlMap[$repository_phid])) { if (empty($this->controlMap[$repository_phid])) {
$this->controlMap[$repository_phid] = array(); $this->controlMap[$repository_phid] = array();
@ -200,6 +206,13 @@ final class PhabricatorOwnersPackageQuery
$this->getFragmentsForPaths($this->paths)); $this->getFragmentsForPaths($this->paths));
} }
if ($this->statuses !== null) {
$where[] = qsprintf(
$conn,
'p.status IN (%Ls)',
$this->statuses);
}
if (strlen($this->namePrefix)) { if (strlen($this->namePrefix)) {
// NOTE: This is a hacky mess, but this column is currently case // NOTE: This is a hacky mess, but this column is currently case
// sensitive and unique. // sensitive and unique.

View file

@ -31,6 +31,12 @@ final class PhabricatorOwnersPackageSearchEngine
->setLabel(pht('Paths')) ->setLabel(pht('Paths'))
->setKey('paths') ->setKey('paths')
->setAliases(array('path')), ->setAliases(array('path')),
id(new PhabricatorSearchCheckboxesField())
->setKey('statuses')
->setLabel(pht('Status'))
->setOptions(
id(new PhabricatorOwnersPackage())
->getStatusNameMap()),
); );
} }
@ -49,6 +55,10 @@ final class PhabricatorOwnersPackageSearchEngine
$query->withPaths($map['paths']); $query->withPaths($map['paths']);
} }
if ($map['statuses']) {
$query->withStatuses($map['statuses']);
}
return $query; return $query;
} }
@ -64,6 +74,7 @@ final class PhabricatorOwnersPackageSearchEngine
} }
$names += array( $names += array(
'active' => pht('Active Packages'),
'all' => pht('All Packages'), 'all' => pht('All Packages'),
); );
@ -77,6 +88,12 @@ final class PhabricatorOwnersPackageSearchEngine
switch ($query_key) { switch ($query_key) {
case 'all': case 'all':
return $query; return $query;
case 'active':
return $query->setParameter(
'statuses',
array(
PhabricatorOwnersPackage::STATUS_ACTIVE,
));
case 'authority': case 'authority':
return $query->setParameter( return $query->setParameter(
'authorityPHIDs', 'authorityPHIDs',
@ -105,6 +122,10 @@ final class PhabricatorOwnersPackageSearchEngine
->setHeader($package->getName()) ->setHeader($package->getName())
->setHref('/owners/package/'.$id.'/'); ->setHref('/owners/package/'.$id.'/');
if ($package->isArchived()) {
$item->setDisabled(true);
}
$list->addItem($item); $list->addItem($item);
} }

View file

@ -12,14 +12,19 @@ final class PhabricatorOwnersPackage
protected $description; protected $description;
protected $primaryOwnerPHID; protected $primaryOwnerPHID;
protected $mailKey; protected $mailKey;
protected $status;
private $paths = self::ATTACHABLE; private $paths = self::ATTACHABLE;
private $owners = self::ATTACHABLE; private $owners = self::ATTACHABLE;
const STATUS_ACTIVE = 'active';
const STATUS_ARCHIVED = 'archived';
public static function initializeNewPackage(PhabricatorUser $actor) { public static function initializeNewPackage(PhabricatorUser $actor) {
return id(new PhabricatorOwnersPackage()) return id(new PhabricatorOwnersPackage())
->setAuditingEnabled(0) ->setAuditingEnabled(0)
->attachPaths(array()) ->attachPaths(array())
->setStatus(self::STATUS_ACTIVE)
->attachOwners(array()); ->attachOwners(array());
} }
@ -41,6 +46,13 @@ final class PhabricatorOwnersPackage
return null; return null;
} }
public static function getStatusNameMap() {
return array(
self::STATUS_ACTIVE => pht('Active'),
self::STATUS_ARCHIVED => pht('Archived'),
);
}
protected function getConfiguration() { protected function getConfiguration() {
return array( return array(
// This information is better available from the history table. // This information is better available from the history table.
@ -53,6 +65,7 @@ final class PhabricatorOwnersPackage
'primaryOwnerPHID' => 'phid?', 'primaryOwnerPHID' => 'phid?',
'auditingEnabled' => 'bool', 'auditingEnabled' => 'bool',
'mailKey' => 'bytes20', 'mailKey' => 'bytes20',
'status' => 'text32',
), ),
self::CONFIG_KEY_SCHEMA => array( self::CONFIG_KEY_SCHEMA => array(
'key_phid' => null, 'key_phid' => null,
@ -81,6 +94,10 @@ final class PhabricatorOwnersPackage
return parent::save(); return parent::save();
} }
public function isArchived() {
return ($this->getStatus() == self::STATUS_ARCHIVED);
}
public function setName($name) { public function setName($name) {
$this->name = $name; $this->name = $name;
if (!$this->getID()) { if (!$this->getID()) {

View file

@ -9,6 +9,7 @@ final class PhabricatorOwnersPackageTransaction
const TYPE_AUDITING = 'owners.auditing'; const TYPE_AUDITING = 'owners.auditing';
const TYPE_DESCRIPTION = 'owners.description'; const TYPE_DESCRIPTION = 'owners.description';
const TYPE_PATHS = 'owners.paths'; const TYPE_PATHS = 'owners.paths';
const TYPE_STATUS = 'owners.status';
public function getApplicationName() { public function getApplicationName() {
return 'owners'; return 'owners';
@ -115,6 +116,16 @@ final class PhabricatorOwnersPackageTransaction
return pht( return pht(
'%s updated paths for this package.', '%s updated paths for this package.',
$this->renderHandleLink($author_phid)); $this->renderHandleLink($author_phid));
case self::TYPE_STATUS:
if ($new == PhabricatorOwnersPackage::STATUS_ACTIVE) {
return pht(
'%s activated this package.',
$this->renderHandleLink($author_phid));
} else if ($new == PhabricatorOwnersPackage::STATUS_ARCHIVED) {
return pht(
'%s archived this package.',
$this->renderHandleLink($author_phid));
}
} }
return parent::getTitle(); return parent::getTitle();