[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/differential/customfield/ -> DifferentialRequiredSignaturesField.php (source)

   1  <?php
   2  
   3  final class DifferentialRequiredSignaturesField
   4    extends DifferentialCoreCustomField {
   5  
   6    public function getFieldKey() {
   7      return 'differential:required-signatures';
   8    }
   9  
  10    public function getFieldName() {
  11      return pht('Required Signatures');
  12    }
  13  
  14    public function getFieldDescription() {
  15      return pht('Display required legal agreements.');
  16    }
  17  
  18    public function shouldAppearInPropertyView() {
  19      return true;
  20    }
  21  
  22    public function shouldAppearInEditView() {
  23      return false;
  24    }
  25  
  26    protected function readValueFromRevision(DifferentialRevision $revision) {
  27      return self::loadForRevision($revision);
  28    }
  29  
  30    public static function loadForRevision($revision) {
  31      $app_legalpad = 'PhabricatorLegalpadApplication';
  32      if (!PhabricatorApplication::isClassInstalled($app_legalpad)) {
  33        return array();
  34      }
  35  
  36      if (!$revision->getPHID()) {
  37        return array();
  38      }
  39  
  40      $phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
  41        $revision->getPHID(),
  42        PhabricatorEdgeConfig::TYPE_OBJECT_NEEDS_SIGNATURE);
  43  
  44      if ($phids) {
  45  
  46        // NOTE: We're bypassing permissions to pull these. We have to expose
  47        // some information about signature status in order to implement this
  48        // field meaningfully (otherwise, we could not tell reviewers that they
  49        // can't accept the revision yet), but that's OK because the only way to
  50        // require signatures is with a "Global" Herald rule, which requires a
  51        // high level of access.
  52  
  53        $signatures = id(new LegalpadDocumentSignatureQuery())
  54          ->setViewer(PhabricatorUser::getOmnipotentUser())
  55          ->withDocumentPHIDs($phids)
  56          ->withSignerPHIDs(array($revision->getAuthorPHID()))
  57          ->execute();
  58        $signatures = mpull($signatures, null, 'getDocumentPHID');
  59  
  60        $phids = array_fuse($phids);
  61        foreach ($phids as $phid) {
  62          $phids[$phid] = isset($signatures[$phid]);
  63        }
  64      }
  65  
  66      return $phids;
  67    }
  68  
  69    public function getRequiredHandlePHIDsForPropertyView() {
  70      return array_keys($this->getValue());
  71    }
  72  
  73    public function renderPropertyViewValue(array $handles) {
  74      if (!$handles) {
  75        return null;
  76      }
  77  
  78      $author_phid = $this->getObject()->getAuthorPHID();
  79      $viewer_phid = $this->getViewer()->getPHID();
  80  
  81      $viewer_is_author = ($author_phid == $viewer_phid);
  82  
  83      $view = new PHUIStatusListView();
  84      foreach ($handles as $handle) {
  85        $item = id(new PHUIStatusItemView())
  86          ->setTarget($handle->renderLink());
  87  
  88        // NOTE: If the viewer isn't the author, we just show generic document
  89        // icons, because the granular information isn't very useful and there
  90        // is no need to disclose it.
  91  
  92        // If the viewer is the author, we show exactly what they need to sign.
  93  
  94        if (!$viewer_is_author) {
  95          $item->setIcon('fa-file-text-o bluegrey');
  96        } else {
  97          if (idx($this->getValue(), $handle->getPHID())) {
  98            $item->setIcon('fa-check-square-o green');
  99          } else {
 100            $item->setIcon('fa-times red');
 101          }
 102        }
 103  
 104        $view->addItem($item);
 105      }
 106  
 107      return $view;
 108    }
 109  
 110    public function getWarningsForDetailView() {
 111      if (!$this->haveAnyUnsignedDocuments()) {
 112        return array();
 113      }
 114  
 115      return array(
 116        pht(
 117          'The author of this revision has not signed all the required '.
 118          'legal documents. The revision can not be accepted until the '.
 119          'documents are signed.'),
 120      );
 121    }
 122  
 123    private function haveAnyUnsignedDocuments() {
 124      foreach ($this->getValue() as $phid => $signed) {
 125        if (!$signed) {
 126          return true;
 127        }
 128      }
 129  
 130      return false;
 131    }
 132  
 133    public function getWarningsForRevisionHeader(array $handles) {
 134      if (!$this->haveAnyUnsignedDocuments()) {
 135        return array();
 136      }
 137  
 138      return array(
 139        pht(
 140          'This revision can not be accepted until the required legal '.
 141          'agreements have been signed.'),
 142      );
 143    }
 144  
 145  }


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