@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

Support Spaces in Diffusion

Summary:
Ref T8493. Diffusion is probably the strongest upstream use case we have for Spaces right now, so I want to get us on it to kick the tires a bit.

Small amount of hackiness around the multi-page form thing but it shouldn't create any problems.

Test Plan:
- Created a new repo.
- Edited a repo.
- Tried invalid edits, saw value preserved.
- Viewed edit full detail screen, saw space info.
- Viewed repo detail view, saw space.
- Viewed repo list view, saw space.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T8493

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

+64 -18
+2
resources/sql/autopatches/20150624.spaces.1.repo.sql
··· 1 + ALTER TABLE {$NAMESPACE}_repository.repository 2 + ADD spacePHID VARBINARY(64);
+1
src/__phutil_library_map__.php
··· 6185 6185 'PhabricatorMarkupInterface', 6186 6186 'PhabricatorDestructibleInterface', 6187 6187 'PhabricatorProjectInterface', 6188 + 'PhabricatorSpacesInterface', 6188 6189 ), 6189 6190 'PhabricatorRepositoryArcanistProject' => array( 6190 6191 'PhabricatorRepositoryDAO',
+21 -15
src/applications/diffusion/controller/DiffusionRepositoryCreateController.php
··· 137 137 $type_credential = PhabricatorRepositoryTransaction::TYPE_CREDENTIAL; 138 138 $type_view = PhabricatorTransactions::TYPE_VIEW_POLICY; 139 139 $type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY; 140 + $type_space = PhabricatorTransactions::TYPE_SPACE; 140 141 $type_push = PhabricatorRepositoryTransaction::TYPE_PUSH_POLICY; 141 142 $type_service = PhabricatorRepositoryTransaction::TYPE_SERVICE; 142 143 ··· 225 226 } 226 227 227 228 if ($is_policy) { 229 + $policy_page = $form->getPage('policy'); 230 + 228 231 $xactions[] = id(clone $template) 229 232 ->setTransactionType($type_view) 230 - ->setNewValue( 231 - $form->getPage('policy')->getControl('viewPolicy')->getValue()); 233 + ->setNewValue($policy_page->getControl('viewPolicy')->getValue()); 232 234 233 235 $xactions[] = id(clone $template) 234 236 ->setTransactionType($type_edit) 235 - ->setNewValue( 236 - $form->getPage('policy')->getControl('editPolicy')->getValue()); 237 + ->setNewValue($policy_page->getControl('editPolicy')->getValue()); 237 238 238 239 if ($is_init || $repository->isHosted()) { 239 240 $xactions[] = id(clone $template) 240 241 ->setTransactionType($type_push) 241 - ->setNewValue( 242 - $form->getPage('policy')->getControl('pushPolicy')->getValue()); 242 + ->setNewValue($policy_page->getControl('pushPolicy')->getValue()); 243 243 } 244 + 245 + $xactions[] = id(clone $template) 246 + ->setTransactionType($type_space) 247 + ->setNewValue( 248 + $policy_page->getControl('viewPolicy')->getSpacePHID()); 244 249 } 245 250 246 251 id(new PhabricatorRepositoryEditor()) ··· 261 266 'viewPolicy' => $repository->getViewPolicy(), 262 267 'editPolicy' => $repository->getEditPolicy(), 263 268 'pushPolicy' => $repository->getPushPolicy(), 269 + 'spacePHID' => $repository->getSpacePHID(), 264 270 ); 265 271 } 266 272 $form->readFromObject($dict); ··· 729 735 ->setName('pushPolicy'); 730 736 731 737 return id(new PHUIFormPageView()) 732 - ->setPageName(pht('Policies')) 733 - ->setValidateFormPageCallback(array($this, 'validatePolicyPage')) 734 - ->setAdjustFormPageCallback(array($this, 'adjustPolicyPage')) 735 - ->setUser($viewer) 736 - ->addRemarkupInstructions( 737 - pht('Select access policies for this repository.')) 738 - ->addControl($view_policy) 739 - ->addControl($edit_policy) 740 - ->addControl($push_policy); 738 + ->setPageName(pht('Policies')) 739 + ->setValidateFormPageCallback(array($this, 'validatePolicyPage')) 740 + ->setAdjustFormPageCallback(array($this, 'adjustPolicyPage')) 741 + ->setUser($viewer) 742 + ->addRemarkupInstructions( 743 + pht('Select access policies for this repository.')) 744 + ->addControl($view_policy) 745 + ->addControl($edit_policy) 746 + ->addControl($push_policy); 741 747 } 742 748 743 749 public function adjustPolicyPage(PHUIFormPageView $page) {
+9 -1
src/applications/diffusion/controller/DiffusionRepositoryEditMainController.php
··· 386 386 $viewer, 387 387 $repository); 388 388 389 + $view_parts = array(); 390 + if (PhabricatorSpacesNamespaceQuery::getViewerSpacesExist($viewer)) { 391 + $space_phid = PhabricatorSpacesNamespaceQuery::getObjectSpacePHID( 392 + $repository); 393 + $view_parts[] = $viewer->renderHandle($space_phid); 394 + } 395 + $view_parts[] = $descriptions[PhabricatorPolicyCapability::CAN_VIEW]; 396 + 389 397 $view->addProperty( 390 398 pht('Visible To'), 391 - $descriptions[PhabricatorPolicyCapability::CAN_VIEW]); 399 + phutil_implode_html(" \xC2\xB7 ", $view_parts)); 392 400 393 401 $view->addProperty( 394 402 pht('Editable By'),
+1
src/applications/repository/query/PhabricatorRepositorySearchEngine.php
··· 153 153 154 154 $item = id(new PHUIObjectItemView()) 155 155 ->setUser($viewer) 156 + ->setObject($repository) 156 157 ->setHeader($repository->getName()) 157 158 ->setObjectName('r'.$repository->getCallsign()) 158 159 ->setHref($this->getApplicationURI($repository->getCallsign().'/'));
+14 -2
src/applications/repository/storage/PhabricatorRepository.php
··· 11 11 PhabricatorFlaggableInterface, 12 12 PhabricatorMarkupInterface, 13 13 PhabricatorDestructibleInterface, 14 - PhabricatorProjectInterface { 14 + PhabricatorProjectInterface, 15 + PhabricatorSpacesInterface { 15 16 16 17 /** 17 18 * Shortest hash we'll recognize in raw "a829f32" form. ··· 54 55 protected $details = array(); 55 56 protected $credentialPHID; 56 57 protected $almanacServicePHID; 58 + protected $spacePHID; 57 59 58 60 private $commitCount = self::ATTACHABLE; 59 61 private $mostRecentCommit = self::ATTACHABLE; ··· 72 74 $repository = id(new PhabricatorRepository()) 73 75 ->setViewPolicy($view_policy) 74 76 ->setEditPolicy($edit_policy) 75 - ->setPushPolicy($push_policy); 77 + ->setPushPolicy($push_policy) 78 + ->setSpacePHID($actor->getDefaultSpacePHID()); 76 79 77 80 // Put the repository in "Importing" mode until we finish 78 81 // parsing it. ··· 1909 1912 1910 1913 /* -( PhabricatorDestructibleInterface )----------------------------------- */ 1911 1914 1915 + 1912 1916 public function destroyObjectPermanently( 1913 1917 PhabricatorDestructionEngine $engine) { 1914 1918 ··· 1933 1937 } 1934 1938 1935 1939 $this->saveTransaction(); 1940 + } 1941 + 1942 + 1943 + /* -( PhabricatorSpacesInterface )----------------------------------------- */ 1944 + 1945 + 1946 + public function getSpacePHID() { 1947 + return $this->spacePHID; 1936 1948 } 1937 1949 1938 1950 }
+16
src/view/form/control/AphrontFormPolicyControl.php
··· 39 39 return $this; 40 40 } 41 41 42 + public function readValueFromDictionary(array $dictionary) { 43 + // TODO: This is a little hacky but will only get us into trouble if we 44 + // have multiple view policy controls in multiple paged form views on the 45 + // same page, which seems unlikely. 46 + $this->setSpacePHID(idx($dictionary, 'spacePHID')); 47 + 48 + return parent::readValueFromDictionary($dictionary); 49 + } 50 + 51 + public function readValueFromRequest(AphrontRequest $request) { 52 + // See note in readValueFromDictionary(). 53 + $this->setSpacePHID($request->getStr('spacePHID')); 54 + 55 + return parent::readValueFromRequest($request); 56 + } 57 + 42 58 public function setCapability($capability) { 43 59 $this->capability = $capability; 44 60