From 8f81930b5d544f64b667cc91576b7c8324b4385e Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 27 Apr 2016 10:32:43 -0700 Subject: [PATCH] Port Repository "Symbols" to Manage/Panel UI Summary: Ref T10748. Port this, add EditEngine support, add some type validation to the transaction. Test Plan: - Edited via EditEngine. - Edited via Conduit. - Viewed via Management UI. Reviewers: chad Reviewed By: chad Maniphest Tasks: T10748 Differential Revision: https://secure.phabricator.com/D15808 --- src/__phutil_library_map__.php | 2 + .../editor/DiffusionRepositoryEditEngine.php | 24 +++++++ ...fusionRepositoryHistoryManagementPanel.php | 2 +- ...fusionRepositorySymbolsManagementPanel.php | 64 +++++++++++++++++++ .../editor/PhabricatorRepositoryEditor.php | 37 +++++++++++ 5 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 src/applications/diffusion/management/DiffusionRepositorySymbolsManagementPanel.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index becb311d7b..09730900c4 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -784,6 +784,7 @@ phutil_register_library_map(array( 'DiffusionRepositoryStatusManagementPanel' => 'applications/diffusion/management/DiffusionRepositoryStatusManagementPanel.php', 'DiffusionRepositoryStorageManagementPanel' => 'applications/diffusion/management/DiffusionRepositoryStorageManagementPanel.php', 'DiffusionRepositorySymbolsController' => 'applications/diffusion/controller/DiffusionRepositorySymbolsController.php', + 'DiffusionRepositorySymbolsManagementPanel' => 'applications/diffusion/management/DiffusionRepositorySymbolsManagementPanel.php', 'DiffusionRepositoryTag' => 'applications/diffusion/data/DiffusionRepositoryTag.php', 'DiffusionRepositoryTestAutomationController' => 'applications/diffusion/controller/DiffusionRepositoryTestAutomationController.php', 'DiffusionRepositoryURIsIndexEngineExtension' => 'applications/diffusion/engineextension/DiffusionRepositoryURIsIndexEngineExtension.php', @@ -5001,6 +5002,7 @@ phutil_register_library_map(array( 'DiffusionRepositoryStatusManagementPanel' => 'DiffusionRepositoryManagementPanel', 'DiffusionRepositoryStorageManagementPanel' => 'DiffusionRepositoryManagementPanel', 'DiffusionRepositorySymbolsController' => 'DiffusionRepositoryEditController', + 'DiffusionRepositorySymbolsManagementPanel' => 'DiffusionRepositoryManagementPanel', 'DiffusionRepositoryTag' => 'Phobject', 'DiffusionRepositoryTestAutomationController' => 'DiffusionRepositoryEditController', 'DiffusionRepositoryURIsIndexEngineExtension' => 'PhabricatorIndexEngineExtension', diff --git a/src/applications/diffusion/editor/DiffusionRepositoryEditEngine.php b/src/applications/diffusion/editor/DiffusionRepositoryEditEngine.php index 37af501bf6..b31f6a2469 100644 --- a/src/applications/diffusion/editor/DiffusionRepositoryEditEngine.php +++ b/src/applications/diffusion/editor/DiffusionRepositoryEditEngine.php @@ -183,6 +183,30 @@ final class DiffusionRepositoryEditEngine ->setConduitDescription(pht('Change automation blueprints.')) ->setConduitTypeDescription(pht('New blueprint PHIDs.')) ->setValue($object->getAutomationBlueprintPHIDs()), + id(new PhabricatorStringListEditField()) + ->setKey('symbolLanguages') + ->setLabel(pht('Languages')) + ->setTransactionType( + PhabricatorRepositoryTransaction::TYPE_SYMBOLS_LANGUAGE) + ->setIsCopyable(true) + ->setDescription( + pht('Languages which define symbols in this repository.')) + ->setConduitDescription( + pht('Change symbol languages for this repository.')) + ->setConduitTypeDescription( + pht('New symbol langauges.')) + ->setValue($object->getSymbolLanguages()), + id(new PhabricatorDatasourceEditField()) + ->setKey('symbolRepositoryPHIDs') + ->setLabel(pht('Uses Symbols From')) + ->setTransactionType( + PhabricatorRepositoryTransaction::TYPE_SYMBOLS_SOURCES) + ->setIsCopyable(true) + ->setDatasource(new DiffusionRepositoryDatasource()) + ->setDescription(pht('Repositories to link symbols from.')) + ->setConduitDescription(pht('Change symbol source repositories.')) + ->setConduitTypeDescription(pht('New symbol repositories.')) + ->setValue($object->getSymbolSources()), id(new PhabricatorPolicyEditField()) ->setKey('policy.push') ->setLabel(pht('Push Policy')) diff --git a/src/applications/diffusion/management/DiffusionRepositoryHistoryManagementPanel.php b/src/applications/diffusion/management/DiffusionRepositoryHistoryManagementPanel.php index c98d3d76ca..e574030bfc 100644 --- a/src/applications/diffusion/management/DiffusionRepositoryHistoryManagementPanel.php +++ b/src/applications/diffusion/management/DiffusionRepositoryHistoryManagementPanel.php @@ -10,7 +10,7 @@ final class DiffusionRepositoryHistoryManagementPanel } public function getManagementPanelOrder() { - return 900; + return 2000; } public function buildManagementPanelContent() { diff --git a/src/applications/diffusion/management/DiffusionRepositorySymbolsManagementPanel.php b/src/applications/diffusion/management/DiffusionRepositorySymbolsManagementPanel.php new file mode 100644 index 0000000000..4e934c67af --- /dev/null +++ b/src/applications/diffusion/management/DiffusionRepositorySymbolsManagementPanel.php @@ -0,0 +1,64 @@ +getRepository(); + $viewer = $this->getViewer(); + + $can_edit = PhabricatorPolicyFilter::hasCapability( + $viewer, + $repository, + PhabricatorPolicyCapability::CAN_EDIT); + + $symbols_uri = $repository->getPathURI('edit/symbols/'); + + return array( + id(new PhabricatorActionView()) + ->setIcon('fa-pencil') + ->setName(pht('Edit Symbols')) + ->setHref($symbols_uri) + ->setDisabled(!$can_edit) + ->setWorkflow(!$can_edit), + ); + } + + public function buildManagementPanelContent() { + $repository = $this->getRepository(); + $viewer = $this->getViewer(); + + $view = id(new PHUIPropertyListView()) + ->setViewer($viewer) + ->setActionList($this->newActions()); + + $languages = $repository->getSymbolLanguages(); + if ($languages) { + $languages = implode(', ', $languages); + } else { + $languages = phutil_tag('em', array(), pht('Any')); + } + $view->addProperty(pht('Languages'), $languages); + + $sources = $repository->getSymbolSources(); + if ($sources) { + $sources = $viewer->renderHandleList($sources); + } else { + $sources = phutil_tag('em', array(), pht('This Repository Only')); + } + $view->addProperty(pht('Uses Symbols From'), $sources); + + return $this->newBox(pht('Symbols'), $view); + } + +} diff --git a/src/applications/repository/editor/PhabricatorRepositoryEditor.php b/src/applications/repository/editor/PhabricatorRepositoryEditor.php index 9ef775fe2d..02f5d2bd19 100644 --- a/src/applications/repository/editor/PhabricatorRepositoryEditor.php +++ b/src/applications/repository/editor/PhabricatorRepositoryEditor.php @@ -636,6 +636,43 @@ final class PhabricatorRepositoryEditor } } break; + + case PhabricatorRepositoryTransaction::TYPE_SYMBOLS_SOURCES: + foreach ($xactions as $xaction) { + $old = $object->getSymbolSources(); + $new = $xaction->getNewValue(); + + // If the viewer is adding new repositories, make sure they are + // valid and visible. + $add = array_diff($new, $old); + if (!$add) { + continue; + } + + $repositories = id(new PhabricatorRepositoryQuery()) + ->setViewer($this->getActor()) + ->withPHIDs($add) + ->execute(); + $repositories = mpull($repositories, null, 'getPHID'); + + foreach ($add as $phid) { + if (isset($repositories[$phid])) { + continue; + } + + $errors[] = new PhabricatorApplicationTransactionValidationError( + $type, + pht('Invalid'), + pht( + 'Repository ("%s") does not exist, or you do not have '. + 'permission to see it.', + $phid), + $xaction); + break; + } + } + break; + } return $errors;