@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.

Build AlmanacNetwork

Summary: Ref T5833. This differentiates address spaces like the public internet from VPNs, so when a service is available at `192.168.0.1`, we'll know it's on some specific NAT block or whatever.

Test Plan: See screenshots.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T5833

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

+821 -1
+11
resources/sql/autopatches/20141016.almanac.network.sql
··· 1 + CREATE TABLE {$NAMESPACE}_almanac.almanac_network ( 2 + id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 3 + phid VARBINARY(64) NOT NULL, 4 + name VARCHAR(128) NOT NULL COLLATE utf8_bin, 5 + mailKey BINARY(20) NOT NULL, 6 + viewPolicy VARBINARY(64) NOT NULL, 7 + editPolicy VARBINARY(64) NOT NULL, 8 + dateCreated INT UNSIGNED NOT NULL, 9 + dateModified INT UNSIGNED NOT NULL, 10 + UNIQUE KEY `key_phid` (phid) 11 + ) ENGINE=InnoDB, COLLATE utf8_general_ci;
+19
resources/sql/autopatches/20141016.almanac.nxaction.sql
··· 1 + CREATE TABLE {$NAMESPACE}_almanac.almanac_networktransaction ( 2 + id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 3 + phid VARCHAR(64) COLLATE utf8_bin NOT NULL, 4 + authorPHID VARCHAR(64) COLLATE utf8_bin NOT NULL, 5 + objectPHID VARCHAR(64) COLLATE utf8_bin NOT NULL, 6 + viewPolicy VARCHAR(64) COLLATE utf8_bin NOT NULL, 7 + editPolicy VARCHAR(64) COLLATE utf8_bin NOT NULL, 8 + commentPHID VARCHAR(64) COLLATE utf8_bin DEFAULT NULL, 9 + commentVersion INT UNSIGNED NOT NULL, 10 + transactionType VARCHAR(32) COLLATE utf8_bin NOT NULL, 11 + oldValue LONGTEXT COLLATE utf8_bin NOT NULL, 12 + newValue LONGTEXT COLLATE utf8_bin NOT NULL, 13 + contentSource LONGTEXT COLLATE utf8_bin NOT NULL, 14 + metadata LONGTEXT COLLATE utf8_bin NOT NULL, 15 + dateCreated INT UNSIGNED NOT NULL, 16 + dateModified INT UNSIGNED NOT NULL, 17 + UNIQUE KEY `key_phid` (`phid`), 18 + KEY `key_object` (`objectPHID`) 19 + ) ENGINE=InnoDB, COLLATE utf8_general_ci;
+27
src/__phutil_library_map__.php
··· 13 13 'AlmanacConsoleController' => 'applications/almanac/controller/AlmanacConsoleController.php', 14 14 'AlmanacController' => 'applications/almanac/controller/AlmanacController.php', 15 15 'AlmanacCreateDevicesCapability' => 'applications/almanac/capability/AlmanacCreateDevicesCapability.php', 16 + 'AlmanacCreateNetworksCapability' => 'applications/almanac/capability/AlmanacCreateNetworksCapability.php', 16 17 'AlmanacCreateServicesCapability' => 'applications/almanac/capability/AlmanacCreateServicesCapability.php', 17 18 'AlmanacDAO' => 'applications/almanac/storage/AlmanacDAO.php', 18 19 'AlmanacDevice' => 'applications/almanac/storage/AlmanacDevice.php', ··· 31 32 'AlmanacManagementWorkflow' => 'applications/almanac/management/AlmanacManagementWorkflow.php', 32 33 'AlmanacNames' => 'applications/almanac/util/AlmanacNames.php', 33 34 'AlmanacNamesTestCase' => 'applications/almanac/util/__tests__/AlmanacNamesTestCase.php', 35 + 'AlmanacNetwork' => 'applications/almanac/storage/AlmanacNetwork.php', 36 + 'AlmanacNetworkController' => 'applications/almanac/controller/AlmanacNetworkController.php', 37 + 'AlmanacNetworkEditController' => 'applications/almanac/controller/AlmanacNetworkEditController.php', 38 + 'AlmanacNetworkEditor' => 'applications/almanac/editor/AlmanacNetworkEditor.php', 39 + 'AlmanacNetworkListController' => 'applications/almanac/controller/AlmanacNetworkListController.php', 40 + 'AlmanacNetworkPHIDType' => 'applications/almanac/phid/AlmanacNetworkPHIDType.php', 41 + 'AlmanacNetworkQuery' => 'applications/almanac/query/AlmanacNetworkQuery.php', 42 + 'AlmanacNetworkSearchEngine' => 'applications/almanac/query/AlmanacNetworkSearchEngine.php', 43 + 'AlmanacNetworkTransaction' => 'applications/almanac/storage/AlmanacNetworkTransaction.php', 44 + 'AlmanacNetworkTransactionQuery' => 'applications/almanac/query/AlmanacNetworkTransactionQuery.php', 45 + 'AlmanacNetworkViewController' => 'applications/almanac/controller/AlmanacNetworkViewController.php', 34 46 'AlmanacService' => 'applications/almanac/storage/AlmanacService.php', 35 47 'AlmanacServiceController' => 'applications/almanac/controller/AlmanacServiceController.php', 36 48 'AlmanacServiceEditController' => 'applications/almanac/controller/AlmanacServiceEditController.php', ··· 2932 2944 'AlmanacConsoleController' => 'AlmanacController', 2933 2945 'AlmanacController' => 'PhabricatorController', 2934 2946 'AlmanacCreateDevicesCapability' => 'PhabricatorPolicyCapability', 2947 + 'AlmanacCreateNetworksCapability' => 'PhabricatorPolicyCapability', 2935 2948 'AlmanacCreateServicesCapability' => 'PhabricatorPolicyCapability', 2936 2949 'AlmanacDAO' => 'PhabricatorLiskDAO', 2937 2950 'AlmanacDevice' => array( ··· 2953 2966 'AlmanacManagementWorkflow' => 'PhabricatorManagementWorkflow', 2954 2967 'AlmanacNames' => 'Phobject', 2955 2968 'AlmanacNamesTestCase' => 'PhabricatorTestCase', 2969 + 'AlmanacNetwork' => array( 2970 + 'AlmanacDAO', 2971 + 'PhabricatorPolicyInterface', 2972 + ), 2973 + 'AlmanacNetworkController' => 'AlmanacController', 2974 + 'AlmanacNetworkEditController' => 'AlmanacNetworkController', 2975 + 'AlmanacNetworkEditor' => 'PhabricatorApplicationTransactionEditor', 2976 + 'AlmanacNetworkListController' => 'AlmanacNetworkController', 2977 + 'AlmanacNetworkPHIDType' => 'PhabricatorPHIDType', 2978 + 'AlmanacNetworkQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 2979 + 'AlmanacNetworkSearchEngine' => 'PhabricatorApplicationSearchEngine', 2980 + 'AlmanacNetworkTransaction' => 'PhabricatorApplicationTransaction', 2981 + 'AlmanacNetworkTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 2982 + 'AlmanacNetworkViewController' => 'AlmanacNetworkController', 2956 2983 'AlmanacService' => array( 2957 2984 'AlmanacDAO', 2958 2985 'PhabricatorPolicyInterface',
+8
src/applications/almanac/application/PhabricatorAlmanacApplication.php
··· 44 44 'edit/(?:(?P<id>\d+)/)?' => 'AlmanacDeviceEditController', 45 45 'view/(?P<name>[^/]+)/' => 'AlmanacDeviceViewController', 46 46 ), 47 + 'network/' => array( 48 + '(?:query/(?P<queryKey>[^/]+)/)?' => 'AlmanacNetworkListController', 49 + 'edit/(?:(?P<id>\d+)/)?' => 'AlmanacNetworkEditController', 50 + '(?P<id>\d+)/' => 'AlmanacNetworkViewController', 51 + ), 47 52 ), 48 53 ); 49 54 } ··· 54 59 'default' => PhabricatorPolicies::POLICY_ADMIN, 55 60 ), 56 61 AlmanacCreateDevicesCapability::CAPABILITY => array( 62 + 'default' => PhabricatorPolicies::POLICY_ADMIN, 63 + ), 64 + AlmanacCreateNetworksCapability::CAPABILITY => array( 57 65 'default' => PhabricatorPolicies::POLICY_ADMIN, 58 66 ), 59 67 );
+16
src/applications/almanac/capability/AlmanacCreateNetworksCapability.php
··· 1 + <?php 2 + 3 + final class AlmanacCreateNetworksCapability 4 + extends PhabricatorPolicyCapability { 5 + 6 + const CAPABILITY = 'almanac.networks'; 7 + 8 + public function getCapabilityName() { 9 + return pht('Can Create Networks'); 10 + } 11 + 12 + public function describeCapabilityRejection() { 13 + return pht('You do not have permission to create Almanac networks.'); 14 + } 15 + 16 + }
+8
src/applications/almanac/controller/AlmanacConsoleController.php
··· 28 28 pht( 29 29 'Manage Almanac devices.'))); 30 30 31 + $menu->addItem( 32 + id(new PHUIObjectItemView()) 33 + ->setHeader(pht('Networks')) 34 + ->setHref($this->getApplicationURI('network/')) 35 + ->addAttribute( 36 + pht( 37 + 'Manage Almanac networks.'))); 38 + 31 39 $crumbs = $this->buildApplicationCrumbs(); 32 40 $crumbs->addTextCrumb(pht('Console')); 33 41
+14
src/applications/almanac/controller/AlmanacNetworkController.php
··· 1 + <?php 2 + 3 + abstract class AlmanacNetworkController extends AlmanacController { 4 + 5 + public function buildApplicationCrumbs() { 6 + $crumbs = parent::buildApplicationCrumbs(); 7 + 8 + $list_uri = $this->getApplicationURI('network/'); 9 + $crumbs->addTextCrumb(pht('Networks'), $list_uri); 10 + 11 + return $crumbs; 12 + } 13 + 14 + }
+143
src/applications/almanac/controller/AlmanacNetworkEditController.php
··· 1 + <?php 2 + 3 + final class AlmanacNetworkEditController 4 + extends AlmanacNetworkController { 5 + 6 + public function handleRequest(AphrontRequest $request) { 7 + $viewer = $request->getViewer(); 8 + 9 + $list_uri = $this->getApplicationURI('network/'); 10 + 11 + $id = $request->getURIData('id'); 12 + if ($id) { 13 + $network = id(new AlmanacNetworkQuery()) 14 + ->setViewer($viewer) 15 + ->withIDs(array($id)) 16 + ->requireCapabilities( 17 + array( 18 + PhabricatorPolicyCapability::CAN_VIEW, 19 + PhabricatorPolicyCapability::CAN_EDIT, 20 + )) 21 + ->executeOne(); 22 + if (!$network) { 23 + return new Aphront404Response(); 24 + } 25 + 26 + $is_new = false; 27 + $network_uri = $this->getApplicationURI('network/'.$network->getID().'/'); 28 + $cancel_uri = $network_uri; 29 + $title = pht('Edit Network'); 30 + $save_button = pht('Save Changes'); 31 + } else { 32 + $this->requireApplicationCapability( 33 + AlmanacCreateNetworksCapability::CAPABILITY); 34 + 35 + $network = AlmanacNetwork::initializeNewNetwork(); 36 + $is_new = true; 37 + 38 + $cancel_uri = $list_uri; 39 + $title = pht('Create Network'); 40 + $save_button = pht('Create Network'); 41 + } 42 + 43 + $v_name = $network->getName(); 44 + $e_name = true; 45 + $validation_exception = null; 46 + 47 + if ($request->isFormPost()) { 48 + $v_name = $request->getStr('name'); 49 + $v_view = $request->getStr('viewPolicy'); 50 + $v_edit = $request->getStr('editPolicy'); 51 + 52 + $type_name = AlmanacNetworkTransaction::TYPE_NAME; 53 + $type_view = PhabricatorTransactions::TYPE_VIEW_POLICY; 54 + $type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY; 55 + 56 + $xactions = array(); 57 + 58 + $xactions[] = id(new AlmanacNetworkTransaction()) 59 + ->setTransactionType($type_name) 60 + ->setNewValue($v_name); 61 + 62 + $xactions[] = id(new AlmanacNetworkTransaction()) 63 + ->setTransactionType($type_view) 64 + ->setNewValue($v_view); 65 + 66 + $xactions[] = id(new AlmanacNetworkTransaction()) 67 + ->setTransactionType($type_edit) 68 + ->setNewValue($v_edit); 69 + 70 + $editor = id(new AlmanacNetworkEditor()) 71 + ->setActor($viewer) 72 + ->setContentSourceFromRequest($request) 73 + ->setContinueOnNoEffect(true); 74 + 75 + try { 76 + $editor->applyTransactions($network, $xactions); 77 + 78 + $id = $network->getID(); 79 + $network_uri = $this->getApplicationURI("network/{$id}/"); 80 + return id(new AphrontRedirectResponse())->setURI($network_uri); 81 + } catch (PhabricatorApplicationTransactionValidationException $ex) { 82 + $validation_exception = $ex; 83 + $e_name = $ex->getShortMessage($type_name); 84 + 85 + $network->setViewPolicy($v_view); 86 + $network->setEditPolicy($v_edit); 87 + } 88 + } 89 + 90 + $policies = id(new PhabricatorPolicyQuery()) 91 + ->setViewer($viewer) 92 + ->setObject($network) 93 + ->execute(); 94 + 95 + $form = id(new AphrontFormView()) 96 + ->setUser($viewer) 97 + ->appendChild( 98 + id(new AphrontFormTextControl()) 99 + ->setLabel(pht('Name')) 100 + ->setName('name') 101 + ->setValue($v_name) 102 + ->setError($e_name)) 103 + ->appendChild( 104 + id(new AphrontFormPolicyControl()) 105 + ->setName('viewPolicy') 106 + ->setPolicyObject($network) 107 + ->setCapability(PhabricatorPolicyCapability::CAN_VIEW) 108 + ->setPolicies($policies)) 109 + ->appendChild( 110 + id(new AphrontFormPolicyControl()) 111 + ->setName('editPolicy') 112 + ->setPolicyObject($network) 113 + ->setCapability(PhabricatorPolicyCapability::CAN_EDIT) 114 + ->setPolicies($policies)) 115 + ->appendChild( 116 + id(new AphrontFormSubmitControl()) 117 + ->addCancelButton($cancel_uri) 118 + ->setValue($save_button)); 119 + 120 + $box = id(new PHUIObjectBoxView()) 121 + ->setValidationException($validation_exception) 122 + ->setHeaderText($title) 123 + ->appendChild($form); 124 + 125 + $crumbs = $this->buildApplicationCrumbs(); 126 + if ($is_new) { 127 + $crumbs->addTextCrumb(pht('Create Network')); 128 + } else { 129 + $crumbs->addTextCrumb($network->getName(), $network_uri); 130 + $crumbs->addTextCrumb(pht('Edit')); 131 + } 132 + 133 + return $this->buildApplicationPage( 134 + array( 135 + $crumbs, 136 + $box, 137 + ), 138 + array( 139 + 'title' => $title, 140 + )); 141 + } 142 + 143 + }
+52
src/applications/almanac/controller/AlmanacNetworkListController.php
··· 1 + <?php 2 + 3 + final class AlmanacNetworkListController 4 + extends AlmanacNetworkController { 5 + 6 + public function shouldAllowPublic() { 7 + return true; 8 + } 9 + 10 + public function handleRequest(AphrontRequest $request) { 11 + $controller = id(new PhabricatorApplicationSearchController()) 12 + ->setQueryKey($request->getURIData('queryKey')) 13 + ->setSearchEngine(new AlmanacNetworkSearchEngine()) 14 + ->setNavigation($this->buildSideNavView()); 15 + 16 + return $this->delegateToController($controller); 17 + } 18 + 19 + public function buildApplicationCrumbs() { 20 + $crumbs = parent::buildApplicationCrumbs(); 21 + 22 + $can_create = $this->hasApplicationCapability( 23 + AlmanacCreateNetworksCapability::CAPABILITY); 24 + 25 + $crumbs->addAction( 26 + id(new PHUIListItemView()) 27 + ->setName(pht('Create Network')) 28 + ->setHref($this->getApplicationURI('network/edit/')) 29 + ->setIcon('fa-plus-square') 30 + ->setDisabled(!$can_create) 31 + ->setWorkflow(!$can_create)); 32 + 33 + return $crumbs; 34 + } 35 + 36 + public function buildSideNavView() { 37 + $viewer = $this->getViewer(); 38 + 39 + $nav = new AphrontSideNavFilterView(); 40 + $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); 41 + 42 + id(new AlmanacNetworkSearchEngine()) 43 + ->setViewer($viewer) 44 + ->addNavigationItems($nav->getMenu()); 45 + 46 + $nav->selectFilter(null); 47 + 48 + return $nav; 49 + } 50 + 51 + 52 + }
+95
src/applications/almanac/controller/AlmanacNetworkViewController.php
··· 1 + <?php 2 + 3 + final class AlmanacNetworkViewController 4 + extends AlmanacNetworkController { 5 + 6 + public function shouldAllowPublic() { 7 + return true; 8 + } 9 + 10 + public function handleRequest(AphrontRequest $request) { 11 + $viewer = $request->getViewer(); 12 + 13 + $id = $request->getURIData('id'); 14 + 15 + $network = id(new AlmanacNetworkQuery()) 16 + ->setViewer($viewer) 17 + ->withIDs(array($id)) 18 + ->executeOne(); 19 + if (!$network) { 20 + return new Aphront404Response(); 21 + } 22 + 23 + $title = pht('Network %s', $network->getName()); 24 + 25 + $property_list = $this->buildPropertyList($network); 26 + $action_list = $this->buildActionList($network); 27 + $property_list->setActionList($action_list); 28 + 29 + $header = id(new PHUIHeaderView()) 30 + ->setUser($viewer) 31 + ->setHeader($network->getName()) 32 + ->setPolicyObject($network); 33 + 34 + $box = id(new PHUIObjectBoxView()) 35 + ->setHeader($header) 36 + ->addPropertyList($property_list); 37 + 38 + $crumbs = $this->buildApplicationCrumbs(); 39 + $crumbs->addTextCrumb($network->getName()); 40 + 41 + $xactions = id(new AlmanacNetworkTransactionQuery()) 42 + ->setViewer($viewer) 43 + ->withObjectPHIDs(array($network->getPHID())) 44 + ->execute(); 45 + 46 + $xaction_view = id(new PhabricatorApplicationTransactionView()) 47 + ->setUser($viewer) 48 + ->setObjectPHID($network->getPHID()) 49 + ->setTransactions($xactions) 50 + ->setShouldTerminate(true); 51 + 52 + return $this->buildApplicationPage( 53 + array( 54 + $crumbs, 55 + $box, 56 + $xaction_view, 57 + ), 58 + array( 59 + 'title' => $title, 60 + )); 61 + } 62 + 63 + private function buildPropertyList(AlmanacNetwork $network) { 64 + $viewer = $this->getViewer(); 65 + 66 + $properties = id(new PHUIPropertyListView()) 67 + ->setUser($viewer); 68 + 69 + return $properties; 70 + } 71 + 72 + private function buildActionList(AlmanacNetwork $network) { 73 + $viewer = $this->getViewer(); 74 + $id = $network->getID(); 75 + 76 + $can_edit = PhabricatorPolicyFilter::hasCapability( 77 + $viewer, 78 + $network, 79 + PhabricatorPolicyCapability::CAN_EDIT); 80 + 81 + $actions = id(new PhabricatorActionListView()) 82 + ->setUser($viewer); 83 + 84 + $actions->addAction( 85 + id(new PhabricatorActionView()) 86 + ->setIcon('fa-pencil') 87 + ->setName(pht('Edit Network')) 88 + ->setHref($this->getApplicationURI("network/edit/{$id}/")) 89 + ->setWorkflow(!$can_edit) 90 + ->setDisabled(!$can_edit)); 91 + 92 + return $actions; 93 + } 94 + 95 + }
+1 -1
src/applications/almanac/controller/AlmanacServiceEditController.php
··· 6 6 public function handleRequest(AphrontRequest $request) { 7 7 $viewer = $request->getViewer(); 8 8 9 - $list_uri = $this->getApplicationURI('service'); 9 + $list_uri = $this->getApplicationURI('service/'); 10 10 11 11 $id = $request->getURIData('id'); 12 12 if ($id) {
+108
src/applications/almanac/editor/AlmanacNetworkEditor.php
··· 1 + <?php 2 + 3 + final class AlmanacNetworkEditor 4 + extends PhabricatorApplicationTransactionEditor { 5 + 6 + public function getEditorApplicationClass() { 7 + return 'PhabricatorAlmanacApplication'; 8 + } 9 + 10 + public function getEditorObjectsDescription() { 11 + return pht('Almanac Network'); 12 + } 13 + 14 + public function getTransactionTypes() { 15 + $types = parent::getTransactionTypes(); 16 + 17 + $types[] = AlmanacNetworkTransaction::TYPE_NAME; 18 + $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; 19 + $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; 20 + 21 + return $types; 22 + } 23 + 24 + protected function getCustomTransactionOldValue( 25 + PhabricatorLiskDAO $object, 26 + PhabricatorApplicationTransaction $xaction) { 27 + switch ($xaction->getTransactionType()) { 28 + case AlmanacNetworkTransaction::TYPE_NAME: 29 + return $object->getName(); 30 + } 31 + 32 + return parent::getCustomTransactionOldValue($object, $xaction); 33 + } 34 + 35 + protected function getCustomTransactionNewValue( 36 + PhabricatorLiskDAO $object, 37 + PhabricatorApplicationTransaction $xaction) { 38 + 39 + switch ($xaction->getTransactionType()) { 40 + case AlmanacNetworkTransaction::TYPE_NAME: 41 + return $xaction->getNewValue(); 42 + } 43 + 44 + return parent::getCustomTransactionNewValue($object, $xaction); 45 + } 46 + 47 + protected function applyCustomInternalTransaction( 48 + PhabricatorLiskDAO $object, 49 + PhabricatorApplicationTransaction $xaction) { 50 + 51 + switch ($xaction->getTransactionType()) { 52 + case AlmanacNetworkTransaction::TYPE_NAME: 53 + $object->setName($xaction->getNewValue()); 54 + return; 55 + case PhabricatorTransactions::TYPE_VIEW_POLICY: 56 + case PhabricatorTransactions::TYPE_EDIT_POLICY: 57 + return; 58 + } 59 + 60 + return parent::applyCustomInternalTransaction($object, $xaction); 61 + } 62 + 63 + protected function applyCustomExternalTransaction( 64 + PhabricatorLiskDAO $object, 65 + PhabricatorApplicationTransaction $xaction) { 66 + 67 + switch ($xaction->getTransactionType()) { 68 + case AlmanacNetworkTransaction::TYPE_NAME: 69 + case PhabricatorTransactions::TYPE_VIEW_POLICY: 70 + case PhabricatorTransactions::TYPE_EDIT_POLICY: 71 + return; 72 + } 73 + 74 + return parent::applyCustomExternalTransaction($object, $xaction); 75 + } 76 + 77 + protected function validateTransaction( 78 + PhabricatorLiskDAO $object, 79 + $type, 80 + array $xactions) { 81 + 82 + $errors = parent::validateTransaction($object, $type, $xactions); 83 + 84 + switch ($type) { 85 + case AlmanacServiceTransaction::TYPE_NAME: 86 + $missing = $this->validateIsEmptyTextField( 87 + $object->getName(), 88 + $xactions); 89 + 90 + if ($missing) { 91 + $error = new PhabricatorApplicationTransactionValidationError( 92 + $type, 93 + pht('Required'), 94 + pht('Network name is required.'), 95 + nonempty(last($xactions), null)); 96 + 97 + $error->setIsMissingFieldError(true); 98 + $errors[] = $error; 99 + } 100 + break; 101 + } 102 + 103 + return $errors; 104 + } 105 + 106 + 107 + 108 + }
+39
src/applications/almanac/phid/AlmanacNetworkPHIDType.php
··· 1 + <?php 2 + 3 + final class AlmanacNetworkPHIDType extends PhabricatorPHIDType { 4 + 5 + const TYPECONST = 'ANET'; 6 + 7 + public function getTypeName() { 8 + return pht('Almanac Network'); 9 + } 10 + 11 + public function newObject() { 12 + return new AlmanacNetwork(); 13 + } 14 + 15 + protected function buildQueryForObjects( 16 + PhabricatorObjectQuery $query, 17 + array $phids) { 18 + 19 + return id(new AlmanacNetworkQuery()) 20 + ->withPHIDs($phids); 21 + } 22 + 23 + public function loadHandles( 24 + PhabricatorHandleQuery $query, 25 + array $handles, 26 + array $objects) { 27 + 28 + foreach ($handles as $phid => $handle) { 29 + $network = $objects[$phid]; 30 + 31 + $id = $network->getID(); 32 + $name = $network->getName(); 33 + 34 + $handle->setObjectName(pht('Network %d', $id)); 35 + $handle->setName($name); 36 + } 37 + } 38 + 39 + }
+5
src/applications/almanac/query/AlmanacDeviceSearchEngine.php
··· 7 7 return pht('Almanac Devices'); 8 8 } 9 9 10 + protected function getApplicationClassName() { 11 + return 'PhabricatorAlmanacApplication'; 12 + } 13 + 10 14 public function buildSavedQueryFromRequest(AphrontRequest $request) { 11 15 $saved = new PhabricatorSavedQuery(); 12 16 ··· 76 80 77 81 return $list; 78 82 } 83 + 79 84 }
+60
src/applications/almanac/query/AlmanacNetworkQuery.php
··· 1 + <?php 2 + 3 + final class AlmanacNetworkQuery 4 + extends PhabricatorCursorPagedPolicyAwareQuery { 5 + 6 + private $ids; 7 + private $phids; 8 + 9 + public function withIDs(array $ids) { 10 + $this->ids = $ids; 11 + return $this; 12 + } 13 + 14 + public function withPHIDs(array $phids) { 15 + $this->phids = $phids; 16 + return $this; 17 + } 18 + 19 + protected function loadPage() { 20 + $table = new AlmanacNetwork(); 21 + $conn_r = $table->establishConnection('r'); 22 + 23 + $data = queryfx_all( 24 + $conn_r, 25 + 'SELECT * FROM %T %Q %Q %Q', 26 + $table->getTableName(), 27 + $this->buildWhereClause($conn_r), 28 + $this->buildOrderClause($conn_r), 29 + $this->buildLimitClause($conn_r)); 30 + 31 + return $table->loadAllFromArray($data); 32 + } 33 + 34 + protected function buildWhereClause($conn_r) { 35 + $where = array(); 36 + 37 + if ($this->ids !== null) { 38 + $where[] = qsprintf( 39 + $conn_r, 40 + 'id IN (%Ld)', 41 + $this->ids); 42 + } 43 + 44 + if ($this->phids !== null) { 45 + $where[] = qsprintf( 46 + $conn_r, 47 + 'phid IN (%Ls)', 48 + $this->phids); 49 + } 50 + 51 + $where[] = $this->buildPagingClause($conn_r); 52 + 53 + return $this->formatWhereClause($where); 54 + } 55 + 56 + public function getQueryApplicationClass() { 57 + return 'PhabricatorAlmanacApplication'; 58 + } 59 + 60 + }
+85
src/applications/almanac/query/AlmanacNetworkSearchEngine.php
··· 1 + <?php 2 + 3 + final class AlmanacNetworkSearchEngine 4 + extends PhabricatorApplicationSearchEngine { 5 + 6 + public function getResultTypeDescription() { 7 + return pht('Almanac Networks'); 8 + } 9 + 10 + protected function getApplicationClassName() { 11 + return 'PhabricatorAlmanacApplication'; 12 + } 13 + 14 + public function buildSavedQueryFromRequest(AphrontRequest $request) { 15 + $saved = new PhabricatorSavedQuery(); 16 + 17 + return $saved; 18 + } 19 + 20 + public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { 21 + $query = id(new AlmanacNetworkQuery()); 22 + 23 + return $query; 24 + } 25 + 26 + public function buildSearchForm( 27 + AphrontFormView $form, 28 + PhabricatorSavedQuery $saved_query) {} 29 + 30 + protected function getURI($path) { 31 + return '/almanac/network/'.$path; 32 + } 33 + 34 + public function getBuiltinQueryNames() { 35 + $names = array( 36 + 'all' => pht('All Networks'), 37 + ); 38 + 39 + return $names; 40 + } 41 + 42 + public function buildSavedQueryFromBuiltin($query_key) { 43 + 44 + $query = $this->newSavedQuery(); 45 + $query->setQueryKey($query_key); 46 + 47 + switch ($query_key) { 48 + case 'all': 49 + return $query; 50 + } 51 + 52 + return parent::buildSavedQueryFromBuiltin($query_key); 53 + } 54 + 55 + protected function getRequiredHandlePHIDsForResultList( 56 + array $networks, 57 + PhabricatorSavedQuery $query) { 58 + return array(); 59 + } 60 + 61 + protected function renderResultList( 62 + array $networks, 63 + PhabricatorSavedQuery $query, 64 + array $handles) { 65 + assert_instances_of($networks, 'AlmanacNetwork'); 66 + 67 + $viewer = $this->requireViewer(); 68 + 69 + $list = new PHUIObjectItemListView(); 70 + $list->setUser($viewer); 71 + foreach ($networks as $network) { 72 + $id = $network->getID(); 73 + 74 + $item = id(new PHUIObjectItemView()) 75 + ->setObjectName(pht('Network %d', $id)) 76 + ->setHeader($network->getName()) 77 + ->setHref($this->getApplicationURI("network/{$id}/")) 78 + ->setObject($network); 79 + 80 + $list->addItem($item); 81 + } 82 + 83 + return $list; 84 + } 85 + }
+10
src/applications/almanac/query/AlmanacNetworkTransactionQuery.php
··· 1 + <?php 2 + 3 + final class AlmanacNetworkTransactionQuery 4 + extends PhabricatorApplicationTransactionQuery { 5 + 6 + public function getTemplateApplicationTransaction() { 7 + return new AlmanacNetworkTransaction(); 8 + } 9 + 10 + }
+4
src/applications/almanac/query/AlmanacServiceSearchEngine.php
··· 7 7 return pht('Almanac Services'); 8 8 } 9 9 10 + protected function getApplicationClassName() { 11 + return 'PhabricatorAlmanacApplication'; 12 + } 13 + 10 14 public function buildSavedQueryFromRequest(AphrontRequest $request) { 11 15 $saved = new PhabricatorSavedQuery(); 12 16
+71
src/applications/almanac/storage/AlmanacNetwork.php
··· 1 + <?php 2 + 3 + final class AlmanacNetwork 4 + extends AlmanacDAO 5 + implements PhabricatorPolicyInterface { 6 + 7 + protected $name; 8 + protected $mailKey; 9 + protected $viewPolicy; 10 + protected $editPolicy; 11 + 12 + public static function initializeNewNetwork() { 13 + return id(new AlmanacNetwork()) 14 + ->setViewPolicy(PhabricatorPolicies::POLICY_USER) 15 + ->setEditPolicy(PhabricatorPolicies::POLICY_ADMIN); 16 + } 17 + 18 + public function getConfiguration() { 19 + return array( 20 + self::CONFIG_AUX_PHID => true, 21 + self::CONFIG_COLUMN_SCHEMA => array( 22 + 'name' => 'text128', 23 + ), 24 + ) + parent::getConfiguration(); 25 + } 26 + 27 + public function generatePHID() { 28 + return PhabricatorPHID::generateNewPHID(AlmanacNetworkPHIDType::TYPECONST); 29 + } 30 + 31 + public function save() { 32 + if (!$this->mailKey) { 33 + $this->mailKey = Filesystem::readRandomCharacters(20); 34 + } 35 + 36 + return parent::save(); 37 + } 38 + 39 + public function getURI() { 40 + return '/almanac/network/view/'.$this->getName().'/'; 41 + } 42 + 43 + 44 + /* -( PhabricatorPolicyInterface )----------------------------------------- */ 45 + 46 + 47 + public function getCapabilities() { 48 + return array( 49 + PhabricatorPolicyCapability::CAN_VIEW, 50 + PhabricatorPolicyCapability::CAN_EDIT, 51 + ); 52 + } 53 + 54 + public function getPolicy($capability) { 55 + switch ($capability) { 56 + case PhabricatorPolicyCapability::CAN_VIEW: 57 + return $this->getViewPolicy(); 58 + case PhabricatorPolicyCapability::CAN_EDIT: 59 + return $this->getEditPolicy(); 60 + } 61 + } 62 + 63 + public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 64 + return false; 65 + } 66 + 67 + public function describeAutomaticCapability($capability) { 68 + return null; 69 + } 70 + 71 + }
+45
src/applications/almanac/storage/AlmanacNetworkTransaction.php
··· 1 + <?php 2 + 3 + final class AlmanacNetworkTransaction 4 + extends PhabricatorApplicationTransaction { 5 + 6 + const TYPE_NAME = 'almanac:network:name'; 7 + 8 + public function getApplicationName() { 9 + return 'almanac'; 10 + } 11 + 12 + public function getApplicationTransactionType() { 13 + return AlmanacNetworkPHIDType::TYPECONST; 14 + } 15 + 16 + public function getApplicationTransactionCommentObject() { 17 + return null; 18 + } 19 + 20 + public function getTitle() { 21 + $author_phid = $this->getAuthorPHID(); 22 + 23 + $old = $this->getOldValue(); 24 + $new = $this->getNewValue(); 25 + 26 + switch ($this->getTransactionType()) { 27 + case self::TYPE_NAME: 28 + if ($old === null) { 29 + return pht( 30 + '%s created this network.', 31 + $this->renderHandleLink($author_phid)); 32 + } else { 33 + return pht( 34 + '%s renamed this network from "%s" to "%s".', 35 + $this->renderHandleLink($author_phid), 36 + $old, 37 + $new); 38 + } 39 + break; 40 + } 41 + 42 + return parent::getTitle(); 43 + } 44 + 45 + }