[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/transactions/controller/ -> PhabricatorApplicationTransactionValueController.php (source)

   1  <?php
   2  
   3  final class PhabricatorApplicationTransactionValueController
   4    extends PhabricatorApplicationTransactionController {
   5  
   6    private $value;
   7    private $phid;
   8  
   9    public function willProcessRequest(array $data) {
  10      $this->phid = $data['phid'];
  11      $this->value = $data['value'];
  12    }
  13  
  14    public function processRequest() {
  15      $request = $this->getRequest();
  16      $viewer = $request->getUser();
  17  
  18      $xaction = id(new PhabricatorObjectQuery())
  19        ->setViewer($viewer)
  20        ->withPHIDs(array($this->phid))
  21        ->executeOne();
  22      if (!$xaction) {
  23        return new Aphront404Response();
  24      }
  25  
  26      // For now, this pathway only supports policy transactions
  27      // to show the details of custom policies. If / when this pathway
  28      // supports more transaction types, rendering coding should be moved
  29      // into PhabricatorTransactions e.g. feed rendering code.
  30  
  31      // TODO: This should be some kind of "hey do you support this?" thing on
  32      // the transactions themselves.
  33  
  34      switch ($xaction->getTransactionType()) {
  35        case PhabricatorTransactions::TYPE_VIEW_POLICY:
  36        case PhabricatorTransactions::TYPE_EDIT_POLICY:
  37        case PhabricatorTransactions::TYPE_JOIN_POLICY:
  38        case PhabricatorRepositoryTransaction::TYPE_PUSH_POLICY:
  39          break;
  40        default:
  41          return new Aphront404Response();
  42          break;
  43      }
  44  
  45      if ($this->value == 'old') {
  46        $value = $xaction->getOldValue();
  47      } else {
  48        $value = $xaction->getNewValue();
  49      }
  50      $policy = id(new PhabricatorPolicyQuery())
  51        ->setViewer($viewer)
  52        ->withPHIDs(array($value))
  53        ->executeOne();
  54      if (!$policy) {
  55        return new Aphront404Response();
  56      }
  57      if ($policy->getType() != PhabricatorPolicyType::TYPE_CUSTOM) {
  58        return new Aphront404Response();
  59      }
  60  
  61      $rule_objects = array();
  62      foreach ($policy->getCustomRuleClasses() as $class) {
  63        $rule_objects[$class] = newv($class, array());
  64      }
  65      $policy->attachRuleObjects($rule_objects);
  66      $handle_phids = $this->extractPHIDs($policy, $rule_objects);
  67      $handles = $this->loadHandles($handle_phids);
  68  
  69      $this->requireResource('policy-transaction-detail-css');
  70      $cancel_uri = $this->guessCancelURI($viewer, $xaction);
  71      $dialog = id(new AphrontDialogView())
  72        ->setUser($viewer)
  73        ->setTitle($policy->getFullName())
  74        ->setWidth(AphrontDialogView::WIDTH_FORM)
  75        ->appendChild(
  76          $this->renderPolicyDetails($policy, $rule_objects))
  77        ->addCancelButton($cancel_uri, pht('Close'));
  78  
  79      return id(new AphrontDialogResponse())->setDialog($dialog);
  80    }
  81  
  82    private function extractPHIDs(
  83      PhabricatorPolicy $policy,
  84      array $rule_objects) {
  85  
  86      $phids = array();
  87      foreach ($policy->getRules() as $rule) {
  88        $rule_object = $rule_objects[$rule['rule']];
  89        $phids[] =
  90          $rule_object->getRequiredHandlePHIDsForSummary($rule['value']);
  91      }
  92      return array_filter(array_mergev($phids));
  93    }
  94  
  95    private function renderPolicyDetails(
  96      PhabricatorPolicy $policy,
  97      array $rule_objects) {
  98      $details = array();
  99      $details[] = phutil_tag(
 100        'p',
 101        array(
 102          'class' => 'policy-transaction-detail-intro',
 103        ),
 104        pht('These rules are processed in order:'));
 105  
 106      foreach ($policy->getRules() as $index => $rule) {
 107        $rule_object = $rule_objects[$rule['rule']];
 108        if ($rule['action'] == 'allow') {
 109          $icon = 'fa-check-circle green';
 110        } else {
 111          $icon = 'fa-minus-circle red';
 112        }
 113        $icon = id(new PHUIIconView())
 114          ->setIconFont($icon)
 115          ->setText(
 116            ucfirst($rule['action']).' '.$rule_object->getRuleDescription());
 117        $handle_phids =
 118          $rule_object->getRequiredHandlePHIDsForSummary($rule['value']);
 119        if ($handle_phids) {
 120          $value = $this->renderHandlesForPHIDs($handle_phids, ',');
 121        } else {
 122          $value = $rule['value'];
 123        }
 124        $details[] = phutil_tag('div',
 125          array(
 126            'class' => 'policy-transaction-detail-row',
 127          ),
 128          array(
 129            $icon,
 130            $value,
 131          ));
 132      }
 133  
 134      $details[] = phutil_tag(
 135        'p',
 136        array(
 137          'class' => 'policy-transaction-detail-end',
 138        ),
 139        pht(
 140          'If no rules match, %s all other users.',
 141          phutil_tag('b',
 142          array(),
 143          $policy->getDefaultAction())));
 144      return $details;
 145    }
 146  
 147  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1