1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-30 09:20:58 +01:00

Allow editPolicy, viewPolicy, and repositoryPHID to be edited from the web UI in Differential

Summary: Ref T603. I think T2222 is fraught with peril so I'm not going to try to sequence it ahead of T603 for Differential. Provide access to policy controls in Differential's edit view.

Test Plan: See screenshot.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T603

Differential Revision: https://secure.phabricator.com/D7142
This commit is contained in:
epriestley 2013-09-26 14:17:11 -07:00
parent 7421a42ba5
commit 3d354d205f
5 changed files with 144 additions and 0 deletions

View file

@ -352,6 +352,7 @@ phutil_register_library_map(array(
'DifferentialDiffViewController' => 'applications/differential/controller/DifferentialDiffViewController.php',
'DifferentialDiffViewPolicyFieldSpecification' => 'applications/differential/field/specification/DifferentialDiffViewPolicyFieldSpecification.php',
'DifferentialDoorkeeperRevisionFeedStoryPublisher' => 'applications/differential/doorkeeper/DifferentialDoorkeeperRevisionFeedStoryPublisher.php',
'DifferentialEditPolicyFieldSpecification' => 'applications/differential/field/specification/DifferentialEditPolicyFieldSpecification.php',
'DifferentialException' => 'applications/differential/exception/DifferentialException.php',
'DifferentialExceptionMail' => 'applications/differential/mail/DifferentialExceptionMail.php',
'DifferentialExportPatchFieldSpecification' => 'applications/differential/field/specification/DifferentialExportPatchFieldSpecification.php',
@ -393,6 +394,7 @@ phutil_register_library_map(array(
'DifferentialReleephRequestFieldSpecification' => 'applications/releeph/differential/DifferentialReleephRequestFieldSpecification.php',
'DifferentialRemarkupRule' => 'applications/differential/remarkup/DifferentialRemarkupRule.php',
'DifferentialReplyHandler' => 'applications/differential/mail/DifferentialReplyHandler.php',
'DifferentialRepositoryFieldSpecification' => 'applications/differential/field/specification/DifferentialRepositoryFieldSpecification.php',
'DifferentialResultsTableView' => 'applications/differential/view/DifferentialResultsTableView.php',
'DifferentialRevertPlanFieldSpecification' => 'applications/differential/field/specification/DifferentialRevertPlanFieldSpecification.php',
'DifferentialReviewRequestMail' => 'applications/differential/mail/DifferentialReviewRequestMail.php',
@ -431,6 +433,7 @@ phutil_register_library_map(array(
'DifferentialUnitFieldSpecification' => 'applications/differential/field/specification/DifferentialUnitFieldSpecification.php',
'DifferentialUnitStatus' => 'applications/differential/constants/DifferentialUnitStatus.php',
'DifferentialUnitTestResult' => 'applications/differential/constants/DifferentialUnitTestResult.php',
'DifferentialViewPolicyFieldSpecification' => 'applications/differential/field/specification/DifferentialViewPolicyFieldSpecification.php',
'DiffusionBranchInformation' => 'applications/diffusion/data/DiffusionBranchInformation.php',
'DiffusionBranchTableController' => 'applications/diffusion/controller/DiffusionBranchTableController.php',
'DiffusionBranchTableView' => 'applications/diffusion/view/DiffusionBranchTableView.php',
@ -2425,6 +2428,7 @@ phutil_register_library_map(array(
'DifferentialDiffViewController' => 'DifferentialController',
'DifferentialDiffViewPolicyFieldSpecification' => 'DifferentialFieldSpecification',
'DifferentialDoorkeeperRevisionFeedStoryPublisher' => 'DoorkeeperFeedStoryPublisher',
'DifferentialEditPolicyFieldSpecification' => 'DifferentialFieldSpecification',
'DifferentialException' => 'Exception',
'DifferentialExceptionMail' => 'DifferentialMail',
'DifferentialExportPatchFieldSpecification' => 'DifferentialFieldSpecification',
@ -2465,6 +2469,7 @@ phutil_register_library_map(array(
'DifferentialReleephRequestFieldSpecification' => 'DifferentialFieldSpecification',
'DifferentialRemarkupRule' => 'PhabricatorRemarkupRuleObject',
'DifferentialReplyHandler' => 'PhabricatorMailReplyHandler',
'DifferentialRepositoryFieldSpecification' => 'DifferentialFieldSpecification',
'DifferentialResultsTableView' => 'AphrontView',
'DifferentialRevertPlanFieldSpecification' => 'DifferentialFieldSpecification',
'DifferentialReviewRequestMail' => 'DifferentialMail',
@ -2505,6 +2510,7 @@ phutil_register_library_map(array(
'DifferentialTransaction' => 'PhabricatorApplicationTransaction',
'DifferentialTransactionComment' => 'PhabricatorApplicationTransactionComment',
'DifferentialUnitFieldSpecification' => 'DifferentialFieldSpecification',
'DifferentialViewPolicyFieldSpecification' => 'DifferentialFieldSpecification',
'DiffusionBranchTableController' => 'DiffusionController',
'DiffusionBranchTableView' => 'DiffusionView',
'DiffusionBrowseController' => 'DiffusionController',

View file

@ -13,6 +13,9 @@ final class DifferentialDefaultFieldSelector
new DifferentialReviewersFieldSpecification(),
new DifferentialReviewedByFieldSpecification(),
new DifferentialCCsFieldSpecification(),
new DifferentialRepositoryFieldSpecification(),
new DifferentialViewPolicyFieldSpecification(),
new DifferentialEditPolicyFieldSpecification(),
new DifferentialLintFieldSpecification(),
new DifferentialUnitFieldSpecification(),
new DifferentialCommitsFieldSpecification(),

View file

@ -0,0 +1,45 @@
<?php
final class DifferentialEditPolicyFieldSpecification
extends DifferentialFieldSpecification {
private $value;
public function shouldAppearOnEdit() {
return true;
}
protected function didSetRevision() {
$this->value = $this->getRevision()->getEditPolicy();
}
public function setValueFromRequest(AphrontRequest $request) {
$this->value = $request->getStr('editPolicy');
return $this;
}
public function renderEditControl() {
$viewer = $this->getUser();
$revision = $this->getRevision();
$policies = id(new PhabricatorPolicyQuery())
->setViewer($viewer)
->setObject($revision)
->execute();
return id(new AphrontFormPolicyControl())
->setUser($viewer)
->setCapability(PhabricatorPolicyCapability::CAN_EDIT)
->setPolicyObject($revision)
->setPolicies($policies)
->setName('editPolicy')
->setCaption(
pht(
'NOTE: These policy features are not yet fully supported.'));
}
public function willWriteRevision(DifferentialRevisionEditor $editor) {
$this->getRevision()->setEditPolicy($this->value);
}
}

View file

@ -0,0 +1,48 @@
<?php
final class DifferentialRepositoryFieldSpecification
extends DifferentialFieldSpecification {
private $value;
public function shouldAppearOnEdit() {
return true;
}
protected function didSetRevision() {
$this->value = $this->getRevision()->getRepositoryPHID();
}
public function setValueFromRequest(AphrontRequest $request) {
$value = head($request->getArr('repositoryPHID'));
$this->value = nonempty($value, null);
return $this;
}
public function getRequiredHandlePHIDsForRevisionEdit() {
return array_filter(array($this->value));
}
public function renderEditControl() {
$value = array();
if ($this->value) {
$value = array(
$this->getHandle($this->value),
);
}
return id(new AphrontFormTokenizerControl())
->setLabel('Repository')
->setName('repositoryPHID')
->setUser($this->getUser())
->setLimit(1)
->setDatasource('/typeahead/common/repositories/')
->setValue($value);
}
public function willWriteRevision(DifferentialRevisionEditor $editor) {
$this->getRevision()->setRepositoryPHID($this->value);
}
}

View file

@ -0,0 +1,42 @@
<?php
final class DifferentialViewPolicyFieldSpecification
extends DifferentialFieldSpecification {
private $value;
public function shouldAppearOnEdit() {
return true;
}
protected function didSetRevision() {
$this->value = $this->getRevision()->getViewPolicy();
}
public function setValueFromRequest(AphrontRequest $request) {
$this->value = $request->getStr('viewPolicy');
return $this;
}
public function renderEditControl() {
$viewer = $this->getUser();
$revision = $this->getRevision();
$policies = id(new PhabricatorPolicyQuery())
->setViewer($viewer)
->setObject($revision)
->execute();
return id(new AphrontFormPolicyControl())
->setUser($viewer)
->setCapability(PhabricatorPolicyCapability::CAN_VIEW)
->setPolicyObject($revision)
->setPolicies($policies)
->setName('viewPolicy');
}
public function willWriteRevision(DifferentialRevisionEditor $editor) {
$this->getRevision()->setViewPolicy($this->value);
}
}