@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Slightly modernize NuanceSource

Summary:
Ref T8434. Minor cleanup/modernization. I made type selection modal (like Herald, Auth, etc) so we can render the form on the next screen based on the type.

{F472519}

Test Plan: Created a new source, edited an existing source.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T8434

Differential Revision: https://secure.phabricator.com/D13161

+145 -113
+3
src/__phutil_library_map__.php
··· 1138 1138 'NuanceRequestorViewController' => 'applications/nuance/controller/NuanceRequestorViewController.php', 1139 1139 'NuanceSchemaSpec' => 'applications/nuance/storage/NuanceSchemaSpec.php', 1140 1140 'NuanceSource' => 'applications/nuance/storage/NuanceSource.php', 1141 + 'NuanceSourceCreateController' => 'applications/nuance/controller/NuanceSourceCreateController.php', 1141 1142 'NuanceSourceDefaultEditCapability' => 'applications/nuance/capability/NuanceSourceDefaultEditCapability.php', 1142 1143 'NuanceSourceDefaultViewCapability' => 'applications/nuance/capability/NuanceSourceDefaultViewCapability.php', 1143 1144 'NuanceSourceDefinition' => 'applications/nuance/source/NuanceSourceDefinition.php', ··· 4455 4456 'NuanceQueue' => array( 4456 4457 'NuanceDAO', 4457 4458 'PhabricatorPolicyInterface', 4459 + 'PhabricatorApplicationTransactionInterface', 4458 4460 ), 4459 4461 'NuanceQueueEditController' => 'NuanceController', 4460 4462 'NuanceQueueEditor' => 'PhabricatorApplicationTransactionEditor', ··· 4481 4483 'PhabricatorApplicationTransactionInterface', 4482 4484 'PhabricatorPolicyInterface', 4483 4485 ), 4486 + 'NuanceSourceCreateController' => 'NuanceController', 4484 4487 'NuanceSourceDefaultEditCapability' => 'PhabricatorPolicyCapability', 4485 4488 'NuanceSourceDefaultViewCapability' => 'PhabricatorPolicyCapability', 4486 4489 'NuanceSourceDefinition' => 'Phobject',
+2 -1
src/applications/nuance/application/PhabricatorNuanceApplication.php
··· 46 46 'source/' => array( 47 47 'view/(?P<id>[1-9]\d*)/' => 'NuanceSourceViewController', 48 48 'edit/(?P<id>[1-9]\d*)/' => 'NuanceSourceEditController', 49 - 'new/' => 'NuanceSourceEditController', 49 + 'new/(?P<type>[^/]+)/' => 'NuanceSourceEditController', 50 + 'create/' => 'NuanceSourceCreateController', 50 51 ), 51 52 'queue/' => array( 52 53 'view/(?P<id>[1-9]\d*)/' => 'NuanceQueueViewController',
+57
src/applications/nuance/controller/NuanceSourceCreateController.php
··· 1 + <?php 2 + 3 + final class NuanceSourceCreateController extends NuanceController { 4 + 5 + public function handleRequest(AphrontRequest $request) { 6 + $can_edit = $this->requireApplicationCapability( 7 + NuanceSourceManageCapability::CAPABILITY); 8 + 9 + $viewer = $this->getViewer(); 10 + $map = NuanceSourceDefinition::getAllDefinitions(); 11 + $cancel_uri = $this->getApplicationURI('source/'); 12 + 13 + if ($request->isFormPost()) { 14 + $type = $request->getStr('type'); 15 + if (isset($map[$type])) { 16 + $uri = $this->getApplicationURI('source/new/'.$type.'/'); 17 + return id(new AphrontRedirectResponse())->setURI($uri); 18 + } 19 + } 20 + 21 + $source_types = id(new AphrontFormRadioButtonControl()) 22 + ->setName('type') 23 + ->setLabel(pht('Source Type')); 24 + 25 + foreach ($map as $type => $definition) { 26 + $source_types->addButton( 27 + $type, 28 + $definition->getName(), 29 + $definition->getSourceDescription()); 30 + } 31 + 32 + $form = id(new AphrontFormView()) 33 + ->setUser($viewer) 34 + ->appendChild($source_types) 35 + ->appendChild( 36 + id(new AphrontFormSubmitControl()) 37 + ->setValue(pht('Continue')) 38 + ->addCancelButton($cancel_uri)); 39 + 40 + $box = id(new PHUIObjectBoxView()) 41 + ->setHeaderText(pht('Choose Source Type')) 42 + ->appendChild($form); 43 + 44 + $crumbs = $this->buildApplicationCrumbs(); 45 + $crumbs->addTextCrumb(pht('Sources'), $cancel_uri); 46 + $crumbs->addTextCrumb(pht('New')); 47 + 48 + return $this->buildApplicationPage( 49 + array( 50 + $crumbs, 51 + $box, 52 + ), 53 + array( 54 + 'title' => pht('Choose Source Type'), 55 + )); 56 + } 57 + }
+31 -25
src/applications/nuance/controller/NuanceSourceEditController.php
··· 2 2 3 3 final class NuanceSourceEditController extends NuanceController { 4 4 5 - private $sourceID; 6 - 7 - public function setSourceID($source_id) { 8 - $this->sourceID = $source_id; 9 - return $this; 10 - } 11 - public function getSourceID() { 12 - return $this->sourceID; 13 - } 14 - 15 - public function willProcessRequest(array $data) { 16 - $this->setSourceID(idx($data, 'id')); 17 - } 18 - 19 - public function processRequest() { 5 + public function handleRequest(AphrontRequest $request) { 20 6 $can_edit = $this->requireApplicationCapability( 21 7 NuanceSourceManageCapability::CAPABILITY); 22 8 23 - $request = $this->getRequest(); 24 - $user = $request->getUser(); 9 + $viewer = $this->getViewer(); 25 10 26 - $source_id = $this->getSourceID(); 11 + $sources_uri = $this->getApplicationURI('source/'); 12 + 13 + $source_id = $request->getURIData('id'); 27 14 $is_new = !$source_id; 28 15 29 16 if ($is_new) { 30 - $source = NuanceSource::initializeNewSource($user); 17 + $source = NuanceSource::initializeNewSource($viewer); 18 + 19 + $type = $request->getURIData('type'); 20 + $map = NuanceSourceDefinition::getAllDefinitions(); 21 + 22 + if (empty($map[$type])) { 23 + return new Aphront404Response(); 24 + } 25 + 26 + $source->setType($type); 27 + $cancel_uri = $sources_uri; 31 28 } else { 32 29 $source = id(new NuanceSourceQuery()) 33 - ->setViewer($user) 30 + ->setViewer($viewer) 34 31 ->withIDs(array($source_id)) 35 32 ->requireCapabilities( 36 33 array( ··· 38 35 PhabricatorPolicyCapability::CAN_EDIT, 39 36 )) 40 37 ->executeOne(); 41 - } 42 - 43 - if (!$source) { 44 - return new Aphront404Response(); 38 + if (!$source) { 39 + return new Aphront404Response(); 40 + } 41 + $cancel_uri = $source->getURI(); 45 42 } 46 43 47 44 $definition = NuanceSourceDefinition::getDefinitionForSource($source); 48 - $definition->setActor($user); 45 + $definition->setActor($viewer); 49 46 50 47 $response = $definition->buildEditLayout($request); 51 48 if ($response instanceof AphrontResponse) { ··· 54 51 $layout = $response; 55 52 56 53 $crumbs = $this->buildApplicationCrumbs(); 54 + $crumbs->addTextCrumb(pht('Sources'), $sources_uri); 55 + 56 + if ($is_new) { 57 + $crumbs->addTextCrumb(pht('New')); 58 + } else { 59 + $crumbs->addTextCrumb($source->getName(), $cancel_uri); 60 + $crumbs->addTextCrumb(pht('Edit')); 61 + } 62 + 57 63 return $this->buildApplicationPage( 58 64 array( 59 65 $crumbs,
+12 -29
src/applications/nuance/controller/NuanceSourceViewController.php
··· 2 2 3 3 final class NuanceSourceViewController extends NuanceController { 4 4 5 - private $sourceID; 6 - 7 - public function setSourceID($source_id) { 8 - $this->sourceID = $source_id; 9 - return $this; 10 - } 11 - public function getSourceID() { 12 - return $this->sourceID; 13 - } 5 + public function handleRequest(AphrontRequest $request) { 6 + $viewer = $this->getViewer(); 14 7 15 - public function willProcessRequest(array $data) { 16 - $this->setSourceID($data['id']); 17 - } 18 - 19 - public function processRequest() { 20 - $request = $this->getRequest(); 21 - $viewer = $request->getUser(); 22 - 23 - $source_id = $this->getSourceID(); 24 8 $source = id(new NuanceSourceQuery()) 25 9 ->setViewer($viewer) 26 - ->withIDs(array($source_id)) 10 + ->withIDs(array($request->getURIData('id'))) 27 11 ->executeOne(); 28 - 29 12 if (!$source) { 30 13 return new Aphront404Response(); 31 14 } ··· 37 20 new NuanceSourceTransactionQuery()); 38 21 $timeline->setShouldTerminate(true); 39 22 40 - $title = pht('%s', $source->getName()); 41 - $crumbs = $this->buildApplicationCrumbs(); 42 - $crumbs->addTextCrumb($title); 43 - 44 23 $header = $this->buildHeaderView($source); 45 24 $actions = $this->buildActionView($source); 46 25 $properties = $this->buildPropertyView($source, $actions); ··· 49 28 ->setHeader($header) 50 29 ->addPropertyList($properties); 51 30 31 + $title = $source->getName(); 32 + $crumbs = $this->buildApplicationCrumbs(); 33 + $crumbs->addTextCrumb(pht('Sources'), $this->getApplicationURI('source/')); 34 + 35 + $crumbs->addTextCrumb($title); 36 + 52 37 return $this->buildApplicationPage( 53 38 array( 54 39 $crumbs, ··· 58 43 array( 59 44 'title' => $title, 60 45 )); 61 - 62 46 } 63 47 64 - 65 - private function buildHeaderView(NuanceSource $source) { 66 - $viewer = $this->getRequest()->getUser(); 48 + private function buildHeaderView(NuanceSource $source) { 49 + $viewer = $this->getViewer(); 67 50 68 51 $header = id(new PHUIHeaderView()) 69 52 ->setUser($viewer) ··· 74 57 } 75 58 76 59 private function buildActionView(NuanceSource $source) { 77 - $viewer = $this->getRequest()->getUser(); 60 + $viewer = $this->getViewer(); 78 61 $id = $source->getID(); 79 62 80 63 $actions = id(new PhabricatorActionListView())
+17 -32
src/applications/nuance/query/NuanceSourceQuery.php
··· 5 5 6 6 private $ids; 7 7 private $phids; 8 - private $creatorPHIDs; 9 8 private $types; 10 9 11 10 public function withIDs(array $ids) { ··· 18 17 return $this; 19 18 } 20 19 21 - public function withCreatorPHIDs(array $phids) { 22 - $this->CreatorPHIDs = $phids; 23 - return $this; 24 - } 25 - 26 20 public function withTypes($types) { 27 21 $this->types = $types; 28 22 return $this; 29 23 } 30 - 31 24 32 25 protected function loadPage() { 33 26 $table = new NuanceSource(); 34 - $conn_r = $table->establishConnection('r'); 27 + $conn = $table->establishConnection('r'); 35 28 36 29 $data = queryfx_all( 37 - $conn_r, 38 - 'SELECT * FROM %T %Q %Q %Q', 30 + $conn, 31 + '%Q FROM %T %Q %Q %Q', 32 + $this->buildSelectClause($conn), 39 33 $table->getTableName(), 40 - $this->buildWhereClause($conn_r), 41 - $this->buildOrderClause($conn_r), 42 - $this->buildLimitClause($conn_r)); 34 + $this->buildWhereClause($conn), 35 + $this->buildOrderClause($conn), 36 + $this->buildLimitClause($conn)); 43 37 44 38 return $table->loadAllFromArray($data); 45 39 } 46 40 47 - protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { 48 - $where = array(); 41 + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 42 + $where = parent::buildWhereClauseParts($conn); 49 43 50 - $where[] = $this->buildPagingClause($conn_r); 51 - 52 - if ($this->creatorPHIDs) { 44 + if ($this->types !== null) { 53 45 $where[] = qsprintf( 54 - $conn_r, 55 - 'creatorPHID IN (%Ls)', 56 - $this->creatorPHIDs); 57 - } 58 - 59 - if ($this->types) { 60 - $where[] = qsprintf( 61 - $conn_r, 62 - 'type IN (%Ld)', 46 + $conn, 47 + 'type IN (%Ls)', 63 48 $this->types); 64 49 } 65 50 66 - if ($this->ids) { 51 + if ($this->ids !== null) { 67 52 $where[] = qsprintf( 68 - $conn_r, 53 + $conn, 69 54 'id IN (%Ld)', 70 55 $this->ids); 71 56 } 72 57 73 - if ($this->phids) { 58 + if ($this->phids !== null) { 74 59 $where[] = qsprintf( 75 - $conn_r, 60 + $conn, 76 61 'phid IN (%Ls)', 77 62 $this->phids); 78 63 } 79 64 80 - return $this->formatWhereClause($where); 65 + return $where; 81 66 } 82 67 83 68 }
+4
src/applications/nuance/source/NuancePhabricatorFormSourceDefinition.php
··· 7 7 return pht('Phabricator Form'); 8 8 } 9 9 10 + public function getSourceDescription() { 11 + return pht('Create a web form that submits into a Nuance queue.'); 12 + } 13 + 10 14 public function getSourceTypeConstant() { 11 15 return 'phabricator-form'; 12 16 }
+15 -21
src/applications/nuance/source/NuanceSourceDefinition.php
··· 9 9 $this->actor = $actor; 10 10 return $this; 11 11 } 12 + 12 13 public function getActor() { 13 14 return $this->actor; 14 15 } 16 + 15 17 public function requireActor() { 16 18 $actor = $this->getActor(); 17 19 if (!$actor) { ··· 25 27 $this->sourceObject = $source; 26 28 return $this; 27 29 } 30 + 28 31 public function getSourceObject() { 29 32 return $this->sourceObject; 30 33 } 34 + 31 35 public function requireSourceObject() { 32 36 $source = $this->getSourceObject(); 33 37 if (!$source) { ··· 36 40 return $source; 37 41 } 38 42 39 - public static function getSelectOptions() { 40 - $definitions = self::getAllDefinitions(); 41 - 42 - $options = array(); 43 - foreach ($definitions as $definition) { 44 - $key = $definition->getSourceTypeConstant(); 45 - $name = $definition->getName(); 46 - $options[$key] = $name; 47 - } 48 - 49 - return $options; 50 - } 51 - 52 43 /** 53 44 * Gives a @{class:NuanceSourceDefinition} object for a given 54 45 * @{class:NuanceSource}. Note you still need to @{method:setActor} ··· 67 58 static $definitions; 68 59 69 60 if ($definitions === null) { 61 + $definitions = array(); 62 + 70 63 $objects = id(new PhutilSymbolLoader()) 71 64 ->setAncestorClass(__CLASS__) 72 65 ->loadObjects(); ··· 82 75 $conflict, 83 76 $name)); 84 77 } 78 + $definitions[$key] = $definition; 85 79 } 86 - $definitions = $objects; 87 80 } 81 + 88 82 return $definitions; 89 83 } 90 84 ··· 92 86 * A human readable string like "Twitter" or "Phabricator Form". 93 87 */ 94 88 abstract public function getName(); 89 + 90 + 91 + /** 92 + * Human readable description of this source, a sentence or two long. 93 + */ 94 + abstract public function getSourceDescription(); 95 95 96 96 /** 97 97 * This should be a any VARCHAR(32). ··· 193 193 ->setLabel(pht('Name')) 194 194 ->setName('name') 195 195 ->setError($e_name) 196 - ->setValue($source->getName())) 197 - ->appendChild( 198 - id(new AphrontFormSelectControl()) 199 - ->setLabel(pht('Type')) 200 - ->setName('type') 201 - ->setOptions(self::getSelectOptions()) 202 - ->setValue($source->getType())); 196 + ->setValue($source->getName())); 203 197 204 198 $form = $this->augmentEditForm($form, $ex); 205 199
+4 -5
src/applications/nuance/storage/NuanceSource.php
··· 57 57 $edit_policy = $app->getPolicy( 58 58 NuanceSourceDefaultEditCapability::CAPABILITY); 59 59 60 - $definitions = NuanceSourceDefinition::getAllDefinitions(); 61 - $lucky_definition = head($definitions); 62 - 63 60 return id(new NuanceSource()) 64 61 ->setViewPolicy($view_policy) 65 - ->setEditPolicy($edit_policy) 66 - ->setType($lucky_definition->getSourceTypeConstant()); 62 + ->setEditPolicy($edit_policy); 67 63 } 68 64 69 65 ··· 88 84 89 85 return $timeline; 90 86 } 87 + 88 + 89 + /* -( PhabricatorPolicyInterface )----------------------------------------- */ 91 90 92 91 93 92 public function getCapabilities() {