From 90c4880aaa7b67e9eea023949e8676bd62583c0a Mon Sep 17 00:00:00 2001 From: Chad Little Date: Wed, 9 Dec 2015 13:41:31 -0800 Subject: [PATCH] Add PhabricatorOwnersArchiveController Summary: Ability to Archive and Activate Packages from the view page. Ref T9414 Test Plan: New Package, Edit Package, Archive Package, Activate Package Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Maniphest Tasks: T9414 Differential Revision: https://secure.phabricator.com/D14728 --- src/__phutil_library_map__.php | 2 + .../PhabricatorOwnersApplication.php | 1 + .../PhabricatorOwnersArchiveController.php | 65 +++++++++++++++++++ .../PhabricatorOwnersDetailController.php | 32 +++++++-- .../PhabricatorOwnersPackageEditEngine.php | 7 -- 5 files changed, 94 insertions(+), 13 deletions(-) create mode 100644 src/applications/owners/controller/PhabricatorOwnersArchiveController.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 3dd5886d86..a549dd55f2 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2568,6 +2568,7 @@ phutil_register_library_map(array( 'PhabricatorOpcodeCacheSpec' => 'applications/cache/spec/PhabricatorOpcodeCacheSpec.php', 'PhabricatorOwnerPathQuery' => 'applications/owners/query/PhabricatorOwnerPathQuery.php', 'PhabricatorOwnersApplication' => 'applications/owners/application/PhabricatorOwnersApplication.php', + 'PhabricatorOwnersArchiveController' => 'applications/owners/controller/PhabricatorOwnersArchiveController.php', 'PhabricatorOwnersConfigOptions' => 'applications/owners/config/PhabricatorOwnersConfigOptions.php', 'PhabricatorOwnersConfiguredCustomField' => 'applications/owners/customfield/PhabricatorOwnersConfiguredCustomField.php', 'PhabricatorOwnersController' => 'applications/owners/controller/PhabricatorOwnersController.php', @@ -6762,6 +6763,7 @@ phutil_register_library_map(array( 'PhabricatorOpcodeCacheSpec' => 'PhabricatorCacheSpec', 'PhabricatorOwnerPathQuery' => 'Phobject', 'PhabricatorOwnersApplication' => 'PhabricatorApplication', + 'PhabricatorOwnersArchiveController' => 'PhabricatorOwnersController', 'PhabricatorOwnersConfigOptions' => 'PhabricatorApplicationConfigOptions', 'PhabricatorOwnersConfiguredCustomField' => array( 'PhabricatorOwnersCustomField', diff --git a/src/applications/owners/application/PhabricatorOwnersApplication.php b/src/applications/owners/application/PhabricatorOwnersApplication.php index 39933f3dce..8511ce401d 100644 --- a/src/applications/owners/application/PhabricatorOwnersApplication.php +++ b/src/applications/owners/application/PhabricatorOwnersApplication.php @@ -45,6 +45,7 @@ final class PhabricatorOwnersApplication extends PhabricatorApplication { '(?:query/(?P[^/]+)/)?' => 'PhabricatorOwnersListController', 'new/' => 'PhabricatorOwnersEditController', 'package/(?P[1-9]\d*)/' => 'PhabricatorOwnersDetailController', + 'archive/(?P[1-9]\d*)/' => 'PhabricatorOwnersArchiveController', 'paths/(?P[1-9]\d*)/' => 'PhabricatorOwnersPathsController', $this->getEditRoutePattern('edit/') diff --git a/src/applications/owners/controller/PhabricatorOwnersArchiveController.php b/src/applications/owners/controller/PhabricatorOwnersArchiveController.php new file mode 100644 index 0000000000..2ef618a2d5 --- /dev/null +++ b/src/applications/owners/controller/PhabricatorOwnersArchiveController.php @@ -0,0 +1,65 @@ +getViewer(); + $id = $request->getURIData('id'); + + $package = id(new PhabricatorOwnersPackageQuery()) + ->setViewer($viewer) + ->withIDs(array($id)) + ->requireCapabilities( + array( + PhabricatorPolicyCapability::CAN_VIEW, + PhabricatorPolicyCapability::CAN_EDIT, + )) + ->executeOne(); + if (!$package) { + return new Aphront404Response(); + } + + $view_uri = $this->getApplicationURI('package/'.$package->getID().'/'); + + if ($request->isFormPost()) { + if ($package->isArchived()) { + $new_status = PhabricatorOwnersPackage::STATUS_ACTIVE; + } else { + $new_status = PhabricatorOwnersPackage::STATUS_ARCHIVED; + } + + $xactions = array(); + + $xactions[] = id(new PhabricatorOwnersPackageTransaction()) + ->setTransactionType(PhabricatorOwnersPackageTransaction::TYPE_STATUS) + ->setNewValue($new_status); + + id(new PhabricatorOwnersPackageTransactionEditor()) + ->setActor($viewer) + ->setContentSourceFromRequest($request) + ->setContinueOnNoEffect(true) + ->setContinueOnMissingFields(true) + ->applyTransactions($package, $xactions); + + return id(new AphrontRedirectResponse())->setURI($view_uri); + } + + if ($package->isArchived()) { + $title = pht('Activate Package'); + $body = pht('This package will become active again.'); + $button = pht('Activate Package'); + } else { + $title = pht('Archive Package'); + $body = pht('This package will be marked as archived.'); + $button = pht('Archive Package'); + } + + return $this->newDialog() + ->setTitle($title) + ->appendChild($body) + ->addCancelButton($view_uri) + ->addSubmitButton($button); + } + +} diff --git a/src/applications/owners/controller/PhabricatorOwnersDetailController.php b/src/applications/owners/controller/PhabricatorOwnersDetailController.php index 80fd67bcdb..7dd4bdb6d6 100644 --- a/src/applications/owners/controller/PhabricatorOwnersDetailController.php +++ b/src/applications/owners/controller/PhabricatorOwnersDetailController.php @@ -219,17 +219,37 @@ final class PhabricatorOwnersDetailController $edit_uri = $this->getApplicationURI("/edit/{$id}/"); $paths_uri = $this->getApplicationURI("/paths/{$id}/"); - $view = id(new PhabricatorActionListView()) + $action_list = id(new PhabricatorActionListView()) ->setUser($viewer) - ->setObject($package) - ->addAction( + ->setObject($package); + + $action_list->addAction( id(new PhabricatorActionView()) ->setName(pht('Edit Package')) ->setIcon('fa-pencil') ->setDisabled(!$can_edit) ->setWorkflow(!$can_edit) - ->setHref($edit_uri)) - ->addAction( + ->setHref($edit_uri)); + + if ($package->isArchived()) { + $action_list->addAction( + id(new PhabricatorActionView()) + ->setName(pht('Activate Package')) + ->setIcon('fa-check') + ->setDisabled(!$can_edit) + ->setWorkflow($can_edit) + ->setHref($this->getApplicationURI("/archive/{$id}/"))); + } else { + $action_list->addAction( + id(new PhabricatorActionView()) + ->setName(pht('Archive Package')) + ->setIcon('fa-ban') + ->setDisabled(!$can_edit) + ->setWorkflow($can_edit) + ->setHref($this->getApplicationURI("/archive/{$id}/"))); + } + + $action_list->addAction( id(new PhabricatorActionView()) ->setName(pht('Edit Paths')) ->setIcon('fa-folder-open') @@ -237,7 +257,7 @@ final class PhabricatorOwnersDetailController ->setWorkflow(!$can_edit) ->setHref($paths_uri)); - return $view; + return $action_list; } private function renderPathsTable(array $paths, array $repositories) { diff --git a/src/applications/owners/editor/PhabricatorOwnersPackageEditEngine.php b/src/applications/owners/editor/PhabricatorOwnersPackageEditEngine.php index e17c59a2a2..0294c66279 100644 --- a/src/applications/owners/editor/PhabricatorOwnersPackageEditEngine.php +++ b/src/applications/owners/editor/PhabricatorOwnersPackageEditEngine.php @@ -60,13 +60,6 @@ final class PhabricatorOwnersPackageEditEngine ->setDatasource(new PhabricatorProjectOrUserDatasource()) ->setIsCopyable(true) ->setValue($object->getOwnerPHIDs()), - id(new PhabricatorSelectEditField()) - ->setKey('status') - ->setLabel(pht('Status')) - ->setDescription(pht('Archive or enable the package.')) - ->setTransactionType(PhabricatorOwnersPackageTransaction::TYPE_STATUS) - ->setValue($object->getStatus()) - ->setOptions($object->getStatusNameMap()), id(new PhabricatorSelectEditField()) ->setKey('auditing') ->setLabel(pht('Auditing'))