Differential D14606 Diff 35328 src/applications/transactions/controller/PhabricatorApplicationTransactionValueController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/controller/PhabricatorApplicationTransactionValueController.php
<?php | <?php | ||||
final class PhabricatorApplicationTransactionValueController | final class PhabricatorApplicationTransactionValueController | ||||
extends PhabricatorApplicationTransactionController { | extends PhabricatorApplicationTransactionController { | ||||
private $value; | public function shouldAllowPublic() { | ||||
private $phid; | return true; | ||||
public function willProcessRequest(array $data) { | |||||
$this->phid = $data['phid']; | |||||
$this->value = $data['value']; | |||||
} | } | ||||
public function processRequest() { | public function handleRequest(AphrontRequest $request) { | ||||
$request = $this->getRequest(); | $request = $this->getRequest(); | ||||
$viewer = $request->getUser(); | $viewer = $request->getUser(); | ||||
$phid = $request->getURIData('phid'); | |||||
$type = $request->getURIData('value'); | |||||
$xaction = id(new PhabricatorObjectQuery()) | $xaction = id(new PhabricatorObjectQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withPHIDs(array($this->phid)) | ->withPHIDs(array($phid)) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$xaction) { | if (!$xaction) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
// For now, this pathway only supports policy transactions | // For now, this pathway only supports policy transactions | ||||
// to show the details of custom policies. If / when this pathway | // to show the details of custom policies. If / when this pathway | ||||
// supports more transaction types, rendering coding should be moved | // supports more transaction types, rendering coding should be moved | ||||
// into PhabricatorTransactions e.g. feed rendering code. | // into PhabricatorTransactions e.g. feed rendering code. | ||||
// TODO: This should be some kind of "hey do you support this?" thing on | // TODO: This should be some kind of "hey do you support this?" thing on | ||||
// the transactions themselves. | // the transactions themselves. | ||||
switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
case PhabricatorTransactions::TYPE_VIEW_POLICY: | case PhabricatorTransactions::TYPE_VIEW_POLICY: | ||||
case PhabricatorTransactions::TYPE_EDIT_POLICY: | case PhabricatorTransactions::TYPE_EDIT_POLICY: | ||||
case PhabricatorTransactions::TYPE_JOIN_POLICY: | case PhabricatorTransactions::TYPE_JOIN_POLICY: | ||||
case PhabricatorRepositoryTransaction::TYPE_PUSH_POLICY: | case PhabricatorRepositoryTransaction::TYPE_PUSH_POLICY: | ||||
break; | break; | ||||
default: | default: | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
break; | break; | ||||
} | } | ||||
if ($this->value == 'old') { | if ($type == 'old') { | ||||
$value = $xaction->getOldValue(); | $value = $xaction->getOldValue(); | ||||
} else { | } else { | ||||
$value = $xaction->getNewValue(); | $value = $xaction->getNewValue(); | ||||
} | } | ||||
$policy = id(new PhabricatorPolicyQuery()) | $policy = id(new PhabricatorPolicyQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withPHIDs(array($value)) | ->withPHIDs(array($value)) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$policy) { | if (!$policy) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
if ($policy->getType() != PhabricatorPolicyType::TYPE_CUSTOM) { | if ($policy->getType() != PhabricatorPolicyType::TYPE_CUSTOM) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
$rule_objects = array(); | $rule_objects = array(); | ||||
foreach ($policy->getCustomRuleClasses() as $class) { | foreach ($policy->getCustomRuleClasses() as $class) { | ||||
$rule_objects[$class] = newv($class, array()); | $rule_objects[$class] = newv($class, array()); | ||||
} | } | ||||
$policy->attachRuleObjects($rule_objects); | $policy->attachRuleObjects($rule_objects); | ||||
$this->requireResource('policy-transaction-detail-css'); | $this->requireResource('policy-transaction-detail-css'); | ||||
$cancel_uri = $this->guessCancelURI($viewer, $xaction); | $cancel_uri = $this->guessCancelURI($viewer, $xaction); | ||||
$dialog = id(new AphrontDialogView()) | |||||
->setUser($viewer) | return $this->newDialog() | ||||
->setTitle($policy->getFullName()) | ->setTitle($policy->getFullName()) | ||||
->setWidth(AphrontDialogView::WIDTH_FORM) | ->setWidth(AphrontDialogView::WIDTH_FORM) | ||||
->appendChild( | ->appendChild($this->renderPolicyDetails($policy, $rule_objects)) | ||||
$this->renderPolicyDetails($policy, $rule_objects)) | |||||
->addCancelButton($cancel_uri, pht('Close')); | ->addCancelButton($cancel_uri, pht('Close')); | ||||
return id(new AphrontDialogResponse())->setDialog($dialog); | |||||
} | } | ||||
private function extractPHIDs( | private function extractPHIDs( | ||||
PhabricatorPolicy $policy, | PhabricatorPolicy $policy, | ||||
array $rule_objects) { | array $rule_objects) { | ||||
$phids = array(); | $phids = array(); | ||||
foreach ($policy->getRules() as $rule) { | foreach ($policy->getRules() as $rule) { | ||||
▲ Show 20 Lines • Show All 64 Lines • Show Last 20 Lines |