[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/policy/rule/ -> PhabricatorPolicyRuleLegalpadSignature.php (source)

   1  <?php
   2  
   3  final class PhabricatorPolicyRuleLegalpadSignature
   4    extends PhabricatorPolicyRule {
   5  
   6    private $signatures = array();
   7  
   8    public function getRuleDescription() {
   9      return pht('signers of legalpad documents');
  10    }
  11  
  12    public function willApplyRules(PhabricatorUser $viewer, array $values) {
  13      $values = array_unique(array_filter(array_mergev($values)));
  14      if (!$values) {
  15        return;
  16      }
  17  
  18      // TODO: This accepts signature of any version of the document, even an
  19      // older version.
  20  
  21      $documents = id(new LegalpadDocumentQuery())
  22        ->setViewer(PhabricatorUser::getOmnipotentUser())
  23        ->withPHIDs($values)
  24        ->withSignerPHIDs(array($viewer->getPHID()))
  25        ->execute();
  26      $this->signatures = mpull($documents, 'getPHID', 'getPHID');
  27    }
  28  
  29    public function applyRule(PhabricatorUser $viewer, $value) {
  30      foreach ($value as $document_phid) {
  31        if (!isset($this->signatures[$document_phid])) {
  32          return false;
  33        }
  34      }
  35      return true;
  36    }
  37  
  38    public function getValueControlType() {
  39      return self::CONTROL_TYPE_TOKENIZER;
  40    }
  41  
  42    public function getValueControlTemplate() {
  43      $datasource = new LegalpadDocumentDatasource();
  44  
  45      return array(
  46        'markup' => new AphrontTokenizerTemplateView(),
  47        'uri' => $datasource->getDatasourceURI(),
  48        'placeholder' => $datasource->getPlaceholderText(),
  49      );
  50    }
  51  
  52    public function getRuleOrder() {
  53      return 900;
  54    }
  55  
  56    public function getValueForStorage($value) {
  57      PhutilTypeSpec::newFromString('list<string>')->check($value);
  58      return array_values($value);
  59    }
  60  
  61    public function getValueForDisplay(PhabricatorUser $viewer, $value) {
  62      $handles = id(new PhabricatorHandleQuery())
  63        ->setViewer($viewer)
  64        ->withPHIDs($value)
  65        ->execute();
  66  
  67      return mpull($handles, 'getFullName', 'getPHID');
  68    }
  69  
  70    public function ruleHasEffect($value) {
  71      return (bool)$value;
  72    }
  73  
  74  }


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