[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/policy/controller/ -> PhabricatorPolicyExplainController.php (source)

   1  <?php
   2  
   3  final class PhabricatorPolicyExplainController
   4    extends PhabricatorPolicyController {
   5  
   6    private $phid;
   7    private $capability;
   8  
   9    public function shouldAllowPublic() {
  10      return true;
  11    }
  12  
  13    public function willProcessRequest(array $data) {
  14      $this->phid = $data['phid'];
  15      $this->capability = $data['capability'];
  16    }
  17  
  18    public function processRequest() {
  19      $request = $this->getRequest();
  20      $viewer = $request->getUser();
  21  
  22      $phid = $this->phid;
  23      $capability = $this->capability;
  24  
  25      $object = id(new PhabricatorObjectQuery())
  26        ->setViewer($viewer)
  27        ->withPHIDs(array($phid))
  28        ->executeOne();
  29      if (!$object) {
  30        return new Aphront404Response();
  31      }
  32  
  33      $policies = PhabricatorPolicyQuery::loadPolicies(
  34        $viewer,
  35        $object);
  36  
  37      $policy = idx($policies, $capability);
  38      if (!$policy) {
  39        return new Aphront404Response();
  40      }
  41  
  42      $handle = id(new PhabricatorHandleQuery())
  43        ->setViewer($viewer)
  44        ->withPHIDs(array($phid))
  45        ->executeOne();
  46      $object_uri = nonempty($handle->getURI(), '/');
  47  
  48      $explanation = PhabricatorPolicy::getPolicyExplanation(
  49        $viewer,
  50        $policy->getPHID());
  51  
  52      $auto_info = (array)$object->describeAutomaticCapability($capability);
  53  
  54      $auto_info = array_merge(
  55        array($explanation),
  56        $auto_info);
  57      $auto_info = array_filter($auto_info);
  58  
  59      foreach ($auto_info as $key => $info) {
  60        $auto_info[$key] = phutil_tag('li', array(), $info);
  61      }
  62      if ($auto_info) {
  63        $auto_info = phutil_tag('ul', array(), $auto_info);
  64      }
  65  
  66      $capability_name = $capability;
  67      $capobj = PhabricatorPolicyCapability::getCapabilityByKey($capability);
  68      if ($capobj) {
  69        $capability_name = $capobj->getCapabilityName();
  70      }
  71  
  72      $content = array(
  73        pht('Users with the "%s" capability:', $capability_name),
  74        $auto_info,
  75      );
  76  
  77      $object_name = pht(
  78        '%s %s',
  79        $handle->getTypeName(),
  80        $handle->getObjectName());
  81  
  82      $dialog = id(new AphrontDialogView())
  83        ->setUser($viewer)
  84        ->setClass('aphront-access-dialog')
  85        ->setTitle(pht('Policy Details: %s', $object_name))
  86        ->appendChild($content)
  87        ->addCancelButton($object_uri, pht('Done'));
  88  
  89      return id(new AphrontDialogResponse())->setDialog($dialog);
  90    }
  91  
  92  }


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