Update rendering of policy edit transactions in Applications
Summary: Ref T13411. Since circa D19829, transactions have rendered policy changes in a modern way, notably making "Custom Policy" clickable to show the policy rules. Edit transactions in Applications still use a separate, older approach to render policies. This produces policy renderings which don't use modern quoting rules and don't link in a modern way. Make Applications use the same rendering code that other transactions (like normal edit/view edits) use. Test Plan: Edited policies in Applications, saw more useful transactions in the log. Clicked "Custom Policy" in the transaction log and got a useful explanation of the policy. Maniphest Tasks: T13411 Differential Revision: https://secure.phabricator.com/D20801
This commit is contained in:
@@ -52,15 +52,12 @@ final class PhabricatorApplicationPolicyChangeTransaction
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getTitle() {
|
public function getTitle() {
|
||||||
$old = $this->renderApplicationPolicy($this->getOldValue());
|
|
||||||
$new = $this->renderApplicationPolicy($this->getNewValue());
|
|
||||||
|
|
||||||
return pht(
|
return pht(
|
||||||
'%s changed the "%s" policy from "%s" to "%s".',
|
'%s changed the %s policy from %s to %s.',
|
||||||
$this->renderAuthor(),
|
$this->renderAuthor(),
|
||||||
$this->renderCapability(),
|
$this->renderCapability(),
|
||||||
$old,
|
$this->renderOldPolicy(),
|
||||||
$new);
|
$this->renderNewPolicy());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTitleForFeed() {
|
public function getTitleForFeed() {
|
||||||
@@ -68,12 +65,12 @@ final class PhabricatorApplicationPolicyChangeTransaction
|
|||||||
$new = $this->renderApplicationPolicy($this->getNewValue());
|
$new = $this->renderApplicationPolicy($this->getNewValue());
|
||||||
|
|
||||||
return pht(
|
return pht(
|
||||||
'%s changed the "%s" policy for application %s from "%s" to "%s".',
|
'%s changed the %s policy for application %s from %s to %s.',
|
||||||
$this->renderAuthor(),
|
$this->renderAuthor(),
|
||||||
$this->renderCapability(),
|
$this->renderCapability(),
|
||||||
$this->renderObject(),
|
$this->renderObject(),
|
||||||
$old,
|
$this->renderOldPolicy(),
|
||||||
$new);
|
$this->renderNewPolicy());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validateTransactions($object, array $xactions) {
|
public function validateTransactions($object, array $xactions) {
|
||||||
@@ -165,38 +162,11 @@ final class PhabricatorApplicationPolicyChangeTransaction
|
|||||||
return $errors;
|
return $errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function renderApplicationPolicy($name) {
|
|
||||||
$policies = $this->getAllPolicies();
|
|
||||||
if (empty($policies[$name])) {
|
|
||||||
// Not a standard policy, check for a custom policy.
|
|
||||||
$policy = id(new PhabricatorPolicyQuery())
|
|
||||||
->setViewer($this->getViewer())
|
|
||||||
->withPHIDs(array($name))
|
|
||||||
->executeOne();
|
|
||||||
$policies[$name] = $policy;
|
|
||||||
}
|
|
||||||
|
|
||||||
$policy = idx($policies, $name);
|
|
||||||
return $this->renderValue($policy->getFullName());
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getAllPolicies() {
|
|
||||||
if (!$this->policies) {
|
|
||||||
$viewer = $this->getViewer();
|
|
||||||
$application = $this->getObject();
|
|
||||||
$this->policies = id(new PhabricatorPolicyQuery())
|
|
||||||
->setViewer($viewer)
|
|
||||||
->setObject($application)
|
|
||||||
->execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->policies;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function renderCapability() {
|
private function renderCapability() {
|
||||||
$application = $this->getObject();
|
$application = $this->getObject();
|
||||||
$capability = $this->getCapabilityName();
|
$capability = $this->getCapabilityName();
|
||||||
return $application->getCapabilityLabel($capability);
|
$label = $application->getCapabilityLabel($capability);
|
||||||
|
return $this->renderValue($label);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getCapabilityName() {
|
private function getCapabilityName() {
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ final class PhabricatorApplicationTransactionValueController
|
|||||||
case PhabricatorTransactions::TYPE_EDIT_POLICY:
|
case PhabricatorTransactions::TYPE_EDIT_POLICY:
|
||||||
case PhabricatorTransactions::TYPE_JOIN_POLICY:
|
case PhabricatorTransactions::TYPE_JOIN_POLICY:
|
||||||
case PhabricatorRepositoryPushPolicyTransaction::TRANSACTIONTYPE:
|
case PhabricatorRepositoryPushPolicyTransaction::TRANSACTIONTYPE:
|
||||||
|
case PhabricatorApplicationPolicyChangeTransaction::TRANSACTIONTYPE:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return new Aphront404Response();
|
return new Aphront404Response();
|
||||||
|
|||||||
Reference in New Issue
Block a user