mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-24 06:20:56 +01:00
Implement view and edit policies in Differential CustomFields
Summary: Ref T3886. Ref T418. - Adds "View Policy" and "Edit Policy" fields. - Allows CustomFields to produce arbitrary types of transactions, so these fields can produce standard view/edit policy transactions and get all the strings and validation associated with them. Test Plan: {F116001} Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T418, T3886 Differential Revision: https://secure.phabricator.com/D8287
This commit is contained in:
parent
01572d9d93
commit
f91e94eb90
8 changed files with 162 additions and 5 deletions
|
@ -381,6 +381,7 @@ phutil_register_library_map(array(
|
|||
'DifferentialDiffViewPolicyFieldSpecification' => 'applications/differential/field/specification/DifferentialDiffViewPolicyFieldSpecification.php',
|
||||
'DifferentialDoorkeeperRevisionFeedStoryPublisher' => 'applications/differential/doorkeeper/DifferentialDoorkeeperRevisionFeedStoryPublisher.php',
|
||||
'DifferentialDraft' => 'applications/differential/storage/DifferentialDraft.php',
|
||||
'DifferentialEditPolicyField' => 'applications/differential/customfield/DifferentialEditPolicyField.php',
|
||||
'DifferentialEditPolicyFieldSpecification' => 'applications/differential/field/specification/DifferentialEditPolicyFieldSpecification.php',
|
||||
'DifferentialException' => 'applications/differential/exception/DifferentialException.php',
|
||||
'DifferentialExceptionMail' => 'applications/differential/mail/DifferentialExceptionMail.php',
|
||||
|
@ -478,6 +479,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',
|
||||
'DifferentialViewPolicyField' => 'applications/differential/customfield/DifferentialViewPolicyField.php',
|
||||
'DifferentialViewPolicyFieldSpecification' => 'applications/differential/field/specification/DifferentialViewPolicyFieldSpecification.php',
|
||||
'DiffusionBranchTableController' => 'applications/diffusion/controller/DiffusionBranchTableController.php',
|
||||
'DiffusionBranchTableView' => 'applications/diffusion/view/DiffusionBranchTableView.php',
|
||||
|
@ -2926,6 +2928,7 @@ phutil_register_library_map(array(
|
|||
'DifferentialDiffViewPolicyFieldSpecification' => 'DifferentialFieldSpecification',
|
||||
'DifferentialDoorkeeperRevisionFeedStoryPublisher' => 'DoorkeeperFeedStoryPublisher',
|
||||
'DifferentialDraft' => 'DifferentialDAO',
|
||||
'DifferentialEditPolicyField' => 'DifferentialCoreCustomField',
|
||||
'DifferentialEditPolicyFieldSpecification' => 'DifferentialFieldSpecification',
|
||||
'DifferentialException' => 'Exception',
|
||||
'DifferentialExceptionMail' => 'DifferentialMail',
|
||||
|
@ -3021,6 +3024,7 @@ phutil_register_library_map(array(
|
|||
'DifferentialTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||
'DifferentialTransactionView' => 'PhabricatorApplicationTransactionView',
|
||||
'DifferentialUnitFieldSpecification' => 'DifferentialFieldSpecification',
|
||||
'DifferentialViewPolicyField' => 'DifferentialCoreCustomField',
|
||||
'DifferentialViewPolicyFieldSpecification' => 'DifferentialFieldSpecification',
|
||||
'DiffusionBranchTableController' => 'DiffusionController',
|
||||
'DiffusionBranchTableView' => 'DiffusionView',
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
final class DifferentialEditPolicyField
|
||||
extends DifferentialCoreCustomField {
|
||||
|
||||
public function getFieldKey() {
|
||||
return 'differential:edit-policy';
|
||||
}
|
||||
|
||||
public function getFieldName() {
|
||||
return pht('Edit Policy');
|
||||
}
|
||||
|
||||
public function getFieldDescription() {
|
||||
return pht('Controls who can edit a revision.');
|
||||
}
|
||||
|
||||
protected function readValueFromRevision(
|
||||
DifferentialRevision $revision) {
|
||||
return $revision->getEditPolicy();
|
||||
}
|
||||
|
||||
protected function writeValueToRevision(
|
||||
DifferentialRevision $revision,
|
||||
$value) {
|
||||
$revision->setEditPolicy($value);
|
||||
}
|
||||
|
||||
public function readValueFromRequest(AphrontRequest $request) {
|
||||
$this->setValue($request->getStr($this->getFieldKey()));
|
||||
}
|
||||
|
||||
public function renderEditControl(array $handles) {
|
||||
$viewer = $this->getViewer();
|
||||
$revision = $this->getObject();
|
||||
|
||||
$policies = id(new PhabricatorPolicyQuery())
|
||||
->setViewer($viewer)
|
||||
->setObject($revision)
|
||||
->execute();
|
||||
|
||||
return id(new AphrontFormPolicyControl())
|
||||
->setUser($viewer)
|
||||
->setCapability(PhabricatorPolicyCapability::CAN_EDIT)
|
||||
->setPolicyObject($revision)
|
||||
->setPolicies($policies)
|
||||
->setName($this->getFieldKey())
|
||||
->setValue($this->getValue())
|
||||
->setError($this->getFieldError());
|
||||
}
|
||||
|
||||
public function getApplicationTransactionType() {
|
||||
return PhabricatorTransactions::TYPE_EDIT_POLICY;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
final class DifferentialViewPolicyField
|
||||
extends DifferentialCoreCustomField {
|
||||
|
||||
public function getFieldKey() {
|
||||
return 'differential:view-policy';
|
||||
}
|
||||
|
||||
public function getFieldName() {
|
||||
return pht('View Policy');
|
||||
}
|
||||
|
||||
public function getFieldDescription() {
|
||||
return pht('Controls visibility.');
|
||||
}
|
||||
|
||||
protected function readValueFromRevision(
|
||||
DifferentialRevision $revision) {
|
||||
return $revision->getViewPolicy();
|
||||
}
|
||||
|
||||
protected function writeValueToRevision(
|
||||
DifferentialRevision $revision,
|
||||
$value) {
|
||||
$revision->setViewPolicy($value);
|
||||
}
|
||||
|
||||
public function readValueFromRequest(AphrontRequest $request) {
|
||||
$this->setValue($request->getStr($this->getFieldKey()));
|
||||
}
|
||||
|
||||
public function renderEditControl(array $handles) {
|
||||
$viewer = $this->getViewer();
|
||||
$revision = $this->getObject();
|
||||
|
||||
$policies = id(new PhabricatorPolicyQuery())
|
||||
->setViewer($viewer)
|
||||
->setObject($revision)
|
||||
->execute();
|
||||
|
||||
return id(new AphrontFormPolicyControl())
|
||||
->setUser($viewer)
|
||||
->setCapability(PhabricatorPolicyCapability::CAN_VIEW)
|
||||
->setPolicyObject($revision)
|
||||
->setPolicies($policies)
|
||||
->setName($this->getFieldKey())
|
||||
->setValue($this->getValue())
|
||||
->setError($this->getFieldError());
|
||||
}
|
||||
|
||||
public function getApplicationTransactionType() {
|
||||
return PhabricatorTransactions::TYPE_VIEW_POLICY;
|
||||
}
|
||||
|
||||
}
|
|
@ -6,11 +6,12 @@ final class DifferentialTransactionEditor
|
|||
public function getTransactionTypes() {
|
||||
$types = parent::getTransactionTypes();
|
||||
|
||||
/*
|
||||
$types[] = PhabricatorTransactions::TYPE_EDGE;
|
||||
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
|
||||
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
|
||||
|
||||
/*
|
||||
$types[] = PhabricatorTransactions::TYPE_EDGE;
|
||||
|
||||
$types[] = DifferentialTransaction::TYPE_INLINE;
|
||||
$types[] = DifferentialTransaction::TYPE_UPDATE;
|
||||
$types[] = DifferentialTransaction::TYPE_ACTION;
|
||||
|
@ -24,6 +25,10 @@ final class DifferentialTransactionEditor
|
|||
PhabricatorApplicationTransaction $xaction) {
|
||||
|
||||
switch ($xaction->getTransactionType()) {
|
||||
case PhabricatorTransactions::TYPE_VIEW_POLICY:
|
||||
return $object->getViewPolicy();
|
||||
case PhabricatorTransactions::TYPE_EDIT_POLICY:
|
||||
return $object->getEditPolicy();
|
||||
}
|
||||
|
||||
return parent::getCustomTransactionOldValue($object, $xaction);
|
||||
|
@ -34,6 +39,9 @@ final class DifferentialTransactionEditor
|
|||
PhabricatorApplicationTransaction $xaction) {
|
||||
|
||||
switch ($xaction->getTransactionType()) {
|
||||
case PhabricatorTransactions::TYPE_VIEW_POLICY:
|
||||
case PhabricatorTransactions::TYPE_EDIT_POLICY:
|
||||
return $xaction->getNewValue();
|
||||
}
|
||||
|
||||
return parent::getCustomTransactionNewValue($object, $xaction);
|
||||
|
@ -44,6 +52,12 @@ final class DifferentialTransactionEditor
|
|||
PhabricatorApplicationTransaction $xaction) {
|
||||
|
||||
switch ($xaction->getTransactionType()) {
|
||||
case PhabricatorTransactions::TYPE_VIEW_POLICY:
|
||||
$object->setViewPolicy($xaction->getNewValue());
|
||||
return;
|
||||
case PhabricatorTransactions::TYPE_EDIT_POLICY:
|
||||
$object->setEditPolicy($xaction->getNewValue());
|
||||
return;
|
||||
}
|
||||
|
||||
return parent::applyCustomInternalTransaction($object, $xaction);
|
||||
|
@ -54,6 +68,9 @@ final class DifferentialTransactionEditor
|
|||
PhabricatorApplicationTransaction $xaction) {
|
||||
|
||||
switch ($xaction->getTransactionType()) {
|
||||
case PhabricatorTransactions::TYPE_VIEW_POLICY:
|
||||
case PhabricatorTransactions::TYPE_EDIT_POLICY:
|
||||
return;
|
||||
}
|
||||
|
||||
return parent::applyCustomExternalTransaction($object, $xaction);
|
||||
|
|
|
@ -470,6 +470,8 @@ final class DifferentialRevision extends DifferentialDAO
|
|||
new DifferentialSummaryField(),
|
||||
new DifferentialTestPlanField(),
|
||||
new DifferentialRepositoryField(),
|
||||
new DifferentialViewPolicyField(),
|
||||
new DifferentialEditPolicyField(),
|
||||
);
|
||||
|
||||
return array_fill_keys(
|
||||
|
|
|
@ -738,7 +738,12 @@ abstract class PhabricatorApplicationTransactionEditor
|
|||
|
||||
$type = $xaction->getTransactionType();
|
||||
if (empty($types[$type])) {
|
||||
throw new Exception("Transaction has unknown type '{$type}'.");
|
||||
throw new Exception(
|
||||
pht(
|
||||
'Transaction has type "%s", but that transaction type is not '.
|
||||
'supported by this editor (%s).',
|
||||
$type,
|
||||
get_class($this)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -733,6 +733,17 @@ abstract class PhabricatorCustomField {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @task appxaction
|
||||
*/
|
||||
public function getApplicationTransactionType() {
|
||||
if ($this->proxy) {
|
||||
return $this->proxy->getApplicationTransactionType();
|
||||
}
|
||||
return PhabricatorTransactions::TYPE_CUSTOMFIELD;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @task appxaction
|
||||
*/
|
||||
|
|
|
@ -202,13 +202,19 @@ final class PhabricatorCustomFieldList extends Phobject {
|
|||
$old_value = $field->getOldValueForApplicationTransactions();
|
||||
|
||||
$field->readValueFromRequest($request);
|
||||
$transaction_type = $field->getApplicationTransactionType();
|
||||
|
||||
$xaction = id(clone $template)
|
||||
->setTransactionType(PhabricatorTransactions::TYPE_CUSTOMFIELD)
|
||||
->setTransactionType($transaction_type)
|
||||
->setMetadataValue('customfield:key', $field->getFieldKey())
|
||||
->setOldValue($old_value)
|
||||
->setNewValue($field->getNewValueForApplicationTransactions());
|
||||
|
||||
if ($transaction_type == PhabricatorTransactions::TYPE_CUSTOMFIELD) {
|
||||
// For TYPE_CUSTOMFIELD transactions only, we provide the old value
|
||||
// as an input.
|
||||
$xaction->setOldValue($old_value);
|
||||
}
|
||||
|
||||
$xactions[] = $xaction;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue