Page MenuHomePhabricator

D8287.id.diff
No OneTemporary

D8287.id.diff

Index: src/__phutil_library_map__.php
===================================================================
--- src/__phutil_library_map__.php
+++ src/__phutil_library_map__.php
@@ -381,6 +381,7 @@
'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 @@
'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 @@
'DifferentialDiffViewPolicyFieldSpecification' => 'DifferentialFieldSpecification',
'DifferentialDoorkeeperRevisionFeedStoryPublisher' => 'DoorkeeperFeedStoryPublisher',
'DifferentialDraft' => 'DifferentialDAO',
+ 'DifferentialEditPolicyField' => 'DifferentialCoreCustomField',
'DifferentialEditPolicyFieldSpecification' => 'DifferentialFieldSpecification',
'DifferentialException' => 'Exception',
'DifferentialExceptionMail' => 'DifferentialMail',
@@ -3021,6 +3024,7 @@
'DifferentialTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
'DifferentialTransactionView' => 'PhabricatorApplicationTransactionView',
'DifferentialUnitFieldSpecification' => 'DifferentialFieldSpecification',
+ 'DifferentialViewPolicyField' => 'DifferentialCoreCustomField',
'DifferentialViewPolicyFieldSpecification' => 'DifferentialFieldSpecification',
'DiffusionBranchTableController' => 'DiffusionController',
'DiffusionBranchTableView' => 'DiffusionView',
Index: src/applications/differential/customfield/DifferentialEditPolicyField.php
===================================================================
--- /dev/null
+++ src/applications/differential/customfield/DifferentialEditPolicyField.php
@@ -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;
+ }
+
+}
Index: src/applications/differential/customfield/DifferentialViewPolicyField.php
===================================================================
--- /dev/null
+++ src/applications/differential/customfield/DifferentialViewPolicyField.php
@@ -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;
+ }
+
+}
Index: src/applications/differential/editor/DifferentialTransactionEditor.php
===================================================================
--- src/applications/differential/editor/DifferentialTransactionEditor.php
+++ src/applications/differential/editor/DifferentialTransactionEditor.php
@@ -6,11 +6,12 @@
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 @@
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 @@
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 @@
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 @@
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
+ case PhabricatorTransactions::TYPE_VIEW_POLICY:
+ case PhabricatorTransactions::TYPE_EDIT_POLICY:
+ return;
}
return parent::applyCustomExternalTransaction($object, $xaction);
Index: src/applications/differential/storage/DifferentialRevision.php
===================================================================
--- src/applications/differential/storage/DifferentialRevision.php
+++ src/applications/differential/storage/DifferentialRevision.php
@@ -470,6 +470,8 @@
new DifferentialSummaryField(),
new DifferentialTestPlanField(),
new DifferentialRepositoryField(),
+ new DifferentialViewPolicyField(),
+ new DifferentialEditPolicyField(),
);
return array_fill_keys(
Index: src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
===================================================================
--- src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
+++ src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
@@ -738,7 +738,12 @@
$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)));
}
}
Index: src/infrastructure/customfield/field/PhabricatorCustomField.php
===================================================================
--- src/infrastructure/customfield/field/PhabricatorCustomField.php
+++ src/infrastructure/customfield/field/PhabricatorCustomField.php
@@ -736,6 +736,17 @@
/**
* @task appxaction
*/
+ public function getApplicationTransactionType() {
+ if ($this->proxy) {
+ return $this->proxy->getApplicationTransactionType();
+ }
+ return PhabricatorTransactions::TYPE_CUSTOMFIELD;
+ }
+
+
+ /**
+ * @task appxaction
+ */
public function getOldValueForApplicationTransactions() {
if ($this->proxy) {
return $this->proxy->getOldValueForApplicationTransactions();
Index: src/infrastructure/customfield/field/PhabricatorCustomFieldList.php
===================================================================
--- src/infrastructure/customfield/field/PhabricatorCustomFieldList.php
+++ src/infrastructure/customfield/field/PhabricatorCustomFieldList.php
@@ -202,13 +202,19 @@
$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;
}

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 1, 10:39 PM (2 w, 3 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6720339
Default Alt Text
D8287.id.diff (11 KB)

Event Timeline