2014-04-29 18:42:54 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorApplicationTransactionValueController
|
|
|
|
extends PhabricatorApplicationTransactionController {
|
|
|
|
|
2015-11-30 15:41:43 +01:00
|
|
|
public function shouldAllowPublic() {
|
|
|
|
return true;
|
2014-04-29 18:42:54 +02:00
|
|
|
}
|
|
|
|
|
2015-11-30 15:41:43 +01:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
2015-12-02 04:46:57 +01:00
|
|
|
$viewer = $this->getViewer();
|
2015-11-30 15:41:43 +01:00
|
|
|
$phid = $request->getURIData('phid');
|
|
|
|
$type = $request->getURIData('value');
|
|
|
|
|
2014-04-29 18:42:54 +02:00
|
|
|
$xaction = id(new PhabricatorObjectQuery())
|
|
|
|
->setViewer($viewer)
|
2015-11-30 15:41:43 +01:00
|
|
|
->withPHIDs(array($phid))
|
2014-04-29 18:42:54 +02:00
|
|
|
->executeOne();
|
|
|
|
if (!$xaction) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
// For now, this pathway only supports policy transactions
|
|
|
|
// to show the details of custom policies. If / when this pathway
|
|
|
|
// supports more transaction types, rendering coding should be moved
|
|
|
|
// into PhabricatorTransactions e.g. feed rendering code.
|
2014-04-29 19:57:32 +02:00
|
|
|
|
|
|
|
// TODO: This should be some kind of "hey do you support this?" thing on
|
|
|
|
// the transactions themselves.
|
|
|
|
|
2014-04-29 18:42:54 +02:00
|
|
|
switch ($xaction->getTransactionType()) {
|
|
|
|
case PhabricatorTransactions::TYPE_VIEW_POLICY:
|
|
|
|
case PhabricatorTransactions::TYPE_EDIT_POLICY:
|
|
|
|
case PhabricatorTransactions::TYPE_JOIN_POLICY:
|
Modularize Repository transactions
Summary: Depends on D19828. Ref T13216. Before adding new transactions to repositories (filesize limit, copy time limit, etc) modularize the existing transactions.
Test Plan:
- Created repository.
- Edited callsign (invalid, valid, duplicate, add, remove).
- Edited short name (invaild, valid, duplicate, add, remove).
- Edited description (add, remove).
- Edited encoding (invalid, valid, remove).
- Allowed/denied dangerous changes.
- Allowed/denied enormous chagnes.
- Activated, deactivated, reactivated.
- Changed tags.
- Changed push policy.
- Changed default branch (add, remove).
- Changed track only: add, remove, invalid function, invalid regex.
- Changed autoclose only: add, remove, invalid function, invalid regex.
- Changed publish/notify.
- Changed autoclose.
- Changed staging area (add, remove, invalid).
- Changed blueprints (add, remove).
- Changed symbols (add, remove).
- Grepped for `PhabricatorRepositoryTransaction::TYPE_`.
- Reviewed transaction history:
{F6021036}
Reviewers: amckinley
Reviewed By: amckinley
Maniphest Tasks: T13216
Differential Revision: https://secure.phabricator.com/D19829
2018-11-21 21:21:57 +01:00
|
|
|
case PhabricatorRepositoryPushPolicyTransaction::TRANSACTIONTYPE:
|
2014-04-29 18:42:54 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return new Aphront404Response();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-11-30 15:41:43 +01:00
|
|
|
if ($type == 'old') {
|
2014-04-29 18:42:54 +02:00
|
|
|
$value = $xaction->getOldValue();
|
|
|
|
} else {
|
|
|
|
$value = $xaction->getNewValue();
|
|
|
|
}
|
2015-11-30 15:41:43 +01:00
|
|
|
|
2014-04-29 18:42:54 +02:00
|
|
|
$policy = id(new PhabricatorPolicyQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withPHIDs(array($value))
|
|
|
|
->executeOne();
|
|
|
|
if (!$policy) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
2015-11-30 15:41:43 +01:00
|
|
|
|
2014-04-29 18:42:54 +02:00
|
|
|
if ($policy->getType() != PhabricatorPolicyType::TYPE_CUSTOM) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$rule_objects = array();
|
|
|
|
foreach ($policy->getCustomRuleClasses() as $class) {
|
|
|
|
$rule_objects[$class] = newv($class, array());
|
|
|
|
}
|
|
|
|
$policy->attachRuleObjects($rule_objects);
|
|
|
|
|
|
|
|
$this->requireResource('policy-transaction-detail-css');
|
|
|
|
$cancel_uri = $this->guessCancelURI($viewer, $xaction);
|
2015-11-30 15:41:43 +01:00
|
|
|
|
|
|
|
return $this->newDialog()
|
2014-04-29 18:42:54 +02:00
|
|
|
->setTitle($policy->getFullName())
|
|
|
|
->setWidth(AphrontDialogView::WIDTH_FORM)
|
2015-11-30 15:41:43 +01:00
|
|
|
->appendChild($this->renderPolicyDetails($policy, $rule_objects))
|
2014-04-29 18:42:54 +02:00
|
|
|
->addCancelButton($cancel_uri, pht('Close'));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function extractPHIDs(
|
|
|
|
PhabricatorPolicy $policy,
|
|
|
|
array $rule_objects) {
|
|
|
|
|
|
|
|
$phids = array();
|
|
|
|
foreach ($policy->getRules() as $rule) {
|
|
|
|
$rule_object = $rule_objects[$rule['rule']];
|
|
|
|
$phids[] =
|
|
|
|
$rule_object->getRequiredHandlePHIDsForSummary($rule['value']);
|
|
|
|
}
|
|
|
|
return array_filter(array_mergev($phids));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderPolicyDetails(
|
|
|
|
PhabricatorPolicy $policy,
|
|
|
|
array $rule_objects) {
|
|
|
|
$details = array();
|
|
|
|
$details[] = phutil_tag(
|
|
|
|
'p',
|
|
|
|
array(
|
2014-10-07 15:01:04 +02:00
|
|
|
'class' => 'policy-transaction-detail-intro',
|
2014-04-29 18:42:54 +02:00
|
|
|
),
|
|
|
|
pht('These rules are processed in order:'));
|
|
|
|
|
|
|
|
foreach ($policy->getRules() as $index => $rule) {
|
|
|
|
$rule_object = $rule_objects[$rule['rule']];
|
|
|
|
if ($rule['action'] == 'allow') {
|
|
|
|
$icon = 'fa-check-circle green';
|
|
|
|
} else {
|
|
|
|
$icon = 'fa-minus-circle red';
|
|
|
|
}
|
|
|
|
$icon = id(new PHUIIconView())
|
2016-01-28 05:38:01 +01:00
|
|
|
->setIcon($icon)
|
2014-04-29 18:42:54 +02:00
|
|
|
->setText(
|
|
|
|
ucfirst($rule['action']).' '.$rule_object->getRuleDescription());
|
2015-03-30 16:39:37 +02:00
|
|
|
|
|
|
|
$handle_phids = $rule_object->getRequiredHandlePHIDsForSummary(
|
|
|
|
$rule['value']);
|
2014-04-29 18:42:54 +02:00
|
|
|
if ($handle_phids) {
|
2015-03-30 16:39:37 +02:00
|
|
|
$value = $this->getViewer()
|
|
|
|
->renderHandleList($handle_phids)
|
2015-04-09 22:10:19 +02:00
|
|
|
->setAsInline(true);
|
2014-04-29 18:42:54 +02:00
|
|
|
} else {
|
|
|
|
$value = $rule['value'];
|
|
|
|
}
|
2015-03-30 16:39:37 +02:00
|
|
|
|
2014-04-29 18:42:54 +02:00
|
|
|
$details[] = phutil_tag('div',
|
|
|
|
array(
|
2014-10-07 15:01:04 +02:00
|
|
|
'class' => 'policy-transaction-detail-row',
|
2014-04-29 18:42:54 +02:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
$icon,
|
2014-10-07 15:01:04 +02:00
|
|
|
$value,
|
|
|
|
));
|
2014-04-29 18:42:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$details[] = phutil_tag(
|
|
|
|
'p',
|
|
|
|
array(
|
2014-10-07 15:01:04 +02:00
|
|
|
'class' => 'policy-transaction-detail-end',
|
2014-04-29 18:42:54 +02:00
|
|
|
),
|
|
|
|
pht(
|
|
|
|
'If no rules match, %s all other users.',
|
|
|
|
phutil_tag('b',
|
|
|
|
array(),
|
|
|
|
$policy->getDefaultAction())));
|
|
|
|
return $details;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|