1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-18 11:30:55 +01:00

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
This commit is contained in:
epriestley 2015-06-24 10:56:46 -07:00
parent c1dca8238f
commit fcb35a55fd
7 changed files with 64 additions and 18 deletions

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_repository.repository
ADD spacePHID VARBINARY(64);

View file

@ -6185,6 +6185,7 @@ phutil_register_library_map(array(
'PhabricatorMarkupInterface',
'PhabricatorDestructibleInterface',
'PhabricatorProjectInterface',
'PhabricatorSpacesInterface',
),
'PhabricatorRepositoryArcanistProject' => array(
'PhabricatorRepositoryDAO',

View file

@ -137,6 +137,7 @@ final class DiffusionRepositoryCreateController
$type_credential = PhabricatorRepositoryTransaction::TYPE_CREDENTIAL;
$type_view = PhabricatorTransactions::TYPE_VIEW_POLICY;
$type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY;
$type_space = PhabricatorTransactions::TYPE_SPACE;
$type_push = PhabricatorRepositoryTransaction::TYPE_PUSH_POLICY;
$type_service = PhabricatorRepositoryTransaction::TYPE_SERVICE;
@ -225,22 +226,26 @@ final class DiffusionRepositoryCreateController
}
if ($is_policy) {
$policy_page = $form->getPage('policy');
$xactions[] = id(clone $template)
->setTransactionType($type_view)
->setNewValue(
$form->getPage('policy')->getControl('viewPolicy')->getValue());
->setNewValue($policy_page->getControl('viewPolicy')->getValue());
$xactions[] = id(clone $template)
->setTransactionType($type_edit)
->setNewValue(
$form->getPage('policy')->getControl('editPolicy')->getValue());
->setNewValue($policy_page->getControl('editPolicy')->getValue());
if ($is_init || $repository->isHosted()) {
$xactions[] = id(clone $template)
->setTransactionType($type_push)
->setNewValue(
$form->getPage('policy')->getControl('pushPolicy')->getValue());
->setNewValue($policy_page->getControl('pushPolicy')->getValue());
}
$xactions[] = id(clone $template)
->setTransactionType($type_space)
->setNewValue(
$policy_page->getControl('viewPolicy')->getSpacePHID());
}
id(new PhabricatorRepositoryEditor())
@ -261,6 +266,7 @@ final class DiffusionRepositoryCreateController
'viewPolicy' => $repository->getViewPolicy(),
'editPolicy' => $repository->getEditPolicy(),
'pushPolicy' => $repository->getPushPolicy(),
'spacePHID' => $repository->getSpacePHID(),
);
}
$form->readFromObject($dict);
@ -729,15 +735,15 @@ final class DiffusionRepositoryCreateController
->setName('pushPolicy');
return id(new PHUIFormPageView())
->setPageName(pht('Policies'))
->setValidateFormPageCallback(array($this, 'validatePolicyPage'))
->setAdjustFormPageCallback(array($this, 'adjustPolicyPage'))
->setUser($viewer)
->addRemarkupInstructions(
pht('Select access policies for this repository.'))
->addControl($view_policy)
->addControl($edit_policy)
->addControl($push_policy);
->setPageName(pht('Policies'))
->setValidateFormPageCallback(array($this, 'validatePolicyPage'))
->setAdjustFormPageCallback(array($this, 'adjustPolicyPage'))
->setUser($viewer)
->addRemarkupInstructions(
pht('Select access policies for this repository.'))
->addControl($view_policy)
->addControl($edit_policy)
->addControl($push_policy);
}
public function adjustPolicyPage(PHUIFormPageView $page) {

View file

@ -386,9 +386,17 @@ final class DiffusionRepositoryEditMainController
$viewer,
$repository);
$view_parts = array();
if (PhabricatorSpacesNamespaceQuery::getViewerSpacesExist($viewer)) {
$space_phid = PhabricatorSpacesNamespaceQuery::getObjectSpacePHID(
$repository);
$view_parts[] = $viewer->renderHandle($space_phid);
}
$view_parts[] = $descriptions[PhabricatorPolicyCapability::CAN_VIEW];
$view->addProperty(
pht('Visible To'),
$descriptions[PhabricatorPolicyCapability::CAN_VIEW]);
phutil_implode_html(" \xC2\xB7 ", $view_parts));
$view->addProperty(
pht('Editable By'),

View file

@ -153,6 +153,7 @@ final class PhabricatorRepositorySearchEngine
$item = id(new PHUIObjectItemView())
->setUser($viewer)
->setObject($repository)
->setHeader($repository->getName())
->setObjectName('r'.$repository->getCallsign())
->setHref($this->getApplicationURI($repository->getCallsign().'/'));

View file

@ -11,7 +11,8 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
PhabricatorFlaggableInterface,
PhabricatorMarkupInterface,
PhabricatorDestructibleInterface,
PhabricatorProjectInterface {
PhabricatorProjectInterface,
PhabricatorSpacesInterface {
/**
* Shortest hash we'll recognize in raw "a829f32" form.
@ -54,6 +55,7 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
protected $details = array();
protected $credentialPHID;
protected $almanacServicePHID;
protected $spacePHID;
private $commitCount = self::ATTACHABLE;
private $mostRecentCommit = self::ATTACHABLE;
@ -72,7 +74,8 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
$repository = id(new PhabricatorRepository())
->setViewPolicy($view_policy)
->setEditPolicy($edit_policy)
->setPushPolicy($push_policy);
->setPushPolicy($push_policy)
->setSpacePHID($actor->getDefaultSpacePHID());
// Put the repository in "Importing" mode until we finish
// parsing it.
@ -1909,6 +1912,7 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
/* -( PhabricatorDestructibleInterface )----------------------------------- */
public function destroyObjectPermanently(
PhabricatorDestructionEngine $engine) {
@ -1935,4 +1939,12 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
$this->saveTransaction();
}
/* -( PhabricatorSpacesInterface )----------------------------------------- */
public function getSpacePHID() {
return $this->spacePHID;
}
}

View file

@ -39,6 +39,22 @@ final class AphrontFormPolicyControl extends AphrontFormControl {
return $this;
}
public function readValueFromDictionary(array $dictionary) {
// TODO: This is a little hacky but will only get us into trouble if we
// have multiple view policy controls in multiple paged form views on the
// same page, which seems unlikely.
$this->setSpacePHID(idx($dictionary, 'spacePHID'));
return parent::readValueFromDictionary($dictionary);
}
public function readValueFromRequest(AphrontRequest $request) {
// See note in readValueFromDictionary().
$this->setSpacePHID($request->getStr('spacePHID'));
return parent::readValueFromRequest($request);
}
public function setCapability($capability) {
$this->capability = $capability;