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

Implement PhabricatorProjectInterface on Almanac Services and Devices

Summary:
Ref T5833. Allow services and devices to be tagged with projects.

(These fluff apply implementations are a good example of the issue discussed in T6403.)

Test Plan: {F229569}

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T5833

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

+96 -2
+16
resources/sql/autopatches/20141104.almanac.3.edge.sql
··· 1 + CREATE TABLE {$NAMESPACE}_almanac.edge ( 2 + src VARBINARY(64) NOT NULL, 3 + type INT UNSIGNED NOT NULL, 4 + dst VARBINARY(64) NOT NULL, 5 + dateCreated INT UNSIGNED NOT NULL, 6 + seq INT UNSIGNED NOT NULL, 7 + dataID INT UNSIGNED, 8 + PRIMARY KEY (src, type, dst), 9 + KEY `src` (src, type, dateCreated, seq), 10 + UNIQUE KEY `key_dst` (dst, type, src) 11 + ) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT}; 12 + 13 + CREATE TABLE {$NAMESPACE}_almanac.edgedata ( 14 + id INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, 15 + data LONGTEXT NOT NULL COLLATE {$COLLATE_TEXT} 16 + ) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT};
+4
src/__phutil_library_map__.php
··· 66 66 'AlmanacPropertyInterface' => 'applications/almanac/property/AlmanacPropertyInterface.php', 67 67 'AlmanacPropertyQuery' => 'applications/almanac/query/AlmanacPropertyQuery.php', 68 68 'AlmanacQuery' => 'applications/almanac/query/AlmanacQuery.php', 69 + 'AlmanacSchemaSpec' => 'applications/almanac/storage/AlmanacSchemaSpec.php', 69 70 'AlmanacService' => 'applications/almanac/storage/AlmanacService.php', 70 71 'AlmanacServiceController' => 'applications/almanac/controller/AlmanacServiceController.php', 71 72 'AlmanacServiceEditController' => 'applications/almanac/controller/AlmanacServiceEditController.php', ··· 3002 3003 'PhabricatorPolicyInterface', 3003 3004 'PhabricatorCustomFieldInterface', 3004 3005 'PhabricatorApplicationTransactionInterface', 3006 + 'PhabricatorProjectInterface', 3005 3007 'AlmanacPropertyInterface', 3006 3008 ), 3007 3009 'AlmanacDeviceController' => 'AlmanacController', ··· 3049 3051 'AlmanacPropertyEditController' => 'AlmanacDeviceController', 3050 3052 'AlmanacPropertyQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 3051 3053 'AlmanacQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 3054 + 'AlmanacSchemaSpec' => 'PhabricatorConfigSchemaSpec', 3052 3055 'AlmanacService' => array( 3053 3056 'AlmanacDAO', 3054 3057 'PhabricatorPolicyInterface', 3055 3058 'PhabricatorCustomFieldInterface', 3056 3059 'PhabricatorApplicationTransactionInterface', 3060 + 'PhabricatorProjectInterface', 3057 3061 'AlmanacPropertyInterface', 3058 3062 ), 3059 3063 'AlmanacServiceController' => 'AlmanacController',
+28
src/applications/almanac/controller/AlmanacDeviceEditController.php
··· 44 44 $e_name = true; 45 45 $validation_exception = null; 46 46 47 + if ($is_new) { 48 + $v_projects = array(); 49 + } else { 50 + $v_projects = PhabricatorEdgeQuery::loadDestinationPHIDs( 51 + $device->getPHID(), 52 + PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); 53 + $v_projects = array_reverse($v_projects); 54 + } 55 + 47 56 if ($request->isFormPost()) { 48 57 $v_name = $request->getStr('name'); 49 58 $v_view = $request->getStr('viewPolicy'); 50 59 $v_edit = $request->getStr('editPolicy'); 60 + $v_projects = $request->getArr('projects'); 51 61 52 62 $type_name = AlmanacDeviceTransaction::TYPE_NAME; 53 63 $type_view = PhabricatorTransactions::TYPE_VIEW_POLICY; ··· 67 77 ->setTransactionType($type_edit) 68 78 ->setNewValue($v_edit); 69 79 80 + $proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; 81 + $xactions[] = id(new AlmanacDeviceTransaction()) 82 + ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) 83 + ->setMetadataValue('edge:type', $proj_edge_type) 84 + ->setNewValue(array('=' => array_fuse($v_projects))); 85 + 70 86 $editor = id(new AlmanacDeviceEditor()) 71 87 ->setActor($viewer) 72 88 ->setContentSourceFromRequest($request) ··· 91 107 ->setObject($device) 92 108 ->execute(); 93 109 110 + if ($v_projects) { 111 + $project_handles = $this->loadViewerHandles($v_projects); 112 + } else { 113 + $project_handles = array(); 114 + } 115 + 94 116 $form = id(new AphrontFormView()) 95 117 ->setUser($viewer) 96 118 ->appendChild( ··· 111 133 ->setPolicyObject($device) 112 134 ->setCapability(PhabricatorPolicyCapability::CAN_EDIT) 113 135 ->setPolicies($policies)) 136 + ->appendChild( 137 + id(new AphrontFormTokenizerControl()) 138 + ->setLabel(pht('Projects')) 139 + ->setName('projects') 140 + ->setValue($project_handles) 141 + ->setDatasource(new PhabricatorProjectDatasource())) 114 142 ->appendChild( 115 143 id(new AphrontFormSubmitControl()) 116 144 ->addCancelButton($cancel_uri)
+2 -1
src/applications/almanac/controller/AlmanacDeviceViewController.php
··· 68 68 $viewer = $this->getViewer(); 69 69 70 70 $properties = id(new PHUIPropertyListView()) 71 - ->setUser($viewer); 71 + ->setUser($viewer) 72 + ->setObject($device); 72 73 73 74 return $properties; 74 75 }
+28
src/applications/almanac/controller/AlmanacServiceEditController.php
··· 44 44 $e_name = true; 45 45 $validation_exception = null; 46 46 47 + if ($is_new) { 48 + $v_projects = array(); 49 + } else { 50 + $v_projects = PhabricatorEdgeQuery::loadDestinationPHIDs( 51 + $service->getPHID(), 52 + PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); 53 + $v_projects = array_reverse($v_projects); 54 + } 55 + 47 56 if ($request->isFormPost()) { 48 57 $v_name = $request->getStr('name'); 49 58 $v_view = $request->getStr('viewPolicy'); 50 59 $v_edit = $request->getStr('editPolicy'); 60 + $v_projects = $request->getArr('projects'); 51 61 52 62 $type_name = AlmanacServiceTransaction::TYPE_NAME; 53 63 $type_view = PhabricatorTransactions::TYPE_VIEW_POLICY; ··· 67 77 ->setTransactionType($type_edit) 68 78 ->setNewValue($v_edit); 69 79 80 + $proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; 81 + $xactions[] = id(new AlmanacServiceTransaction()) 82 + ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) 83 + ->setMetadataValue('edge:type', $proj_edge_type) 84 + ->setNewValue(array('=' => array_fuse($v_projects))); 85 + 70 86 $editor = id(new AlmanacServiceEditor()) 71 87 ->setActor($viewer) 72 88 ->setContentSourceFromRequest($request) ··· 91 107 ->setObject($service) 92 108 ->execute(); 93 109 110 + if ($v_projects) { 111 + $project_handles = $this->loadViewerHandles($v_projects); 112 + } else { 113 + $project_handles = array(); 114 + } 115 + 94 116 $form = id(new AphrontFormView()) 95 117 ->setUser($viewer) 96 118 ->appendChild( ··· 111 133 ->setPolicyObject($service) 112 134 ->setCapability(PhabricatorPolicyCapability::CAN_EDIT) 113 135 ->setPolicies($policies)) 136 + ->appendChild( 137 + id(new AphrontFormTokenizerControl()) 138 + ->setLabel(pht('Projects')) 139 + ->setName('projects') 140 + ->setValue($project_handles) 141 + ->setDatasource(new PhabricatorProjectDatasource())) 114 142 ->appendChild( 115 143 id(new AphrontFormSubmitControl()) 116 144 ->addCancelButton($cancel_uri)
+2 -1
src/applications/almanac/controller/AlmanacServiceViewController.php
··· 68 68 $viewer = $this->getViewer(); 69 69 70 70 $properties = id(new PHUIPropertyListView()) 71 - ->setUser($viewer); 71 + ->setUser($viewer) 72 + ->setObject($service); 72 73 73 74 return $properties; 74 75 }
+2
src/applications/almanac/editor/AlmanacDeviceEditor.php
··· 57 57 case AlmanacDeviceTransaction::TYPE_INTERFACE: 58 58 case PhabricatorTransactions::TYPE_VIEW_POLICY: 59 59 case PhabricatorTransactions::TYPE_EDIT_POLICY: 60 + case PhabricatorTransactions::TYPE_EDGE: 60 61 return; 61 62 } 62 63 ··· 71 72 case AlmanacDeviceTransaction::TYPE_NAME: 72 73 case PhabricatorTransactions::TYPE_VIEW_POLICY: 73 74 case PhabricatorTransactions::TYPE_EDIT_POLICY: 75 + case PhabricatorTransactions::TYPE_EDGE: 74 76 return; 75 77 case AlmanacDeviceTransaction::TYPE_INTERFACE: 76 78 $old = $xaction->getOldValue();
+2
src/applications/almanac/editor/AlmanacServiceEditor.php
··· 54 54 return; 55 55 case PhabricatorTransactions::TYPE_VIEW_POLICY: 56 56 case PhabricatorTransactions::TYPE_EDIT_POLICY: 57 + case PhabricatorTransactions::TYPE_EDGE: 57 58 return; 58 59 } 59 60 ··· 68 69 case AlmanacServiceTransaction::TYPE_NAME: 69 70 case PhabricatorTransactions::TYPE_VIEW_POLICY: 70 71 case PhabricatorTransactions::TYPE_EDIT_POLICY: 72 + case PhabricatorTransactions::TYPE_EDGE: 71 73 return; 72 74 } 73 75
+1
src/applications/almanac/storage/AlmanacDevice.php
··· 6 6 PhabricatorPolicyInterface, 7 7 PhabricatorCustomFieldInterface, 8 8 PhabricatorApplicationTransactionInterface, 9 + PhabricatorProjectInterface, 9 10 AlmanacPropertyInterface { 10 11 11 12 protected $name;
+10
src/applications/almanac/storage/AlmanacSchemaSpec.php
··· 1 + <?php 2 + 3 + final class AlmanacSchemaSpec 4 + extends PhabricatorConfigSchemaSpec { 5 + 6 + public function buildSchemata() { 7 + $this->buildEdgeSchemata(new AlmanacService()); 8 + } 9 + 10 + }
+1
src/applications/almanac/storage/AlmanacService.php
··· 6 6 PhabricatorPolicyInterface, 7 7 PhabricatorCustomFieldInterface, 8 8 PhabricatorApplicationTransactionInterface, 9 + PhabricatorProjectInterface, 9 10 AlmanacPropertyInterface { 10 11 11 12 protected $name;