Path: blob/master/src/applications/differential/customfield/DifferentialRequiredSignaturesField.php
13419 views
<?php12final class DifferentialRequiredSignaturesField3extends DifferentialCoreCustomField {45public function getFieldKey() {6return 'differential:required-signatures';7}89public function getFieldName() {10return pht('Required Signatures');11}1213public function getFieldDescription() {14return pht('Display required legal agreements.');15}1617public function shouldAppearInPropertyView() {18return true;19}2021protected function readValueFromRevision(DifferentialRevision $revision) {22return self::loadForRevision($revision);23}2425public static function loadForRevision($revision) {26$app_legalpad = 'PhabricatorLegalpadApplication';27if (!PhabricatorApplication::isClassInstalled($app_legalpad)) {28return array();29}3031if (!$revision->getPHID()) {32return array();33}3435$phids = PhabricatorEdgeQuery::loadDestinationPHIDs(36$revision->getPHID(),37LegalpadObjectNeedsSignatureEdgeType::EDGECONST);3839if ($phids) {4041// NOTE: We're bypassing permissions to pull these. We have to expose42// some information about signature status in order to implement this43// field meaningfully (otherwise, we could not tell reviewers that they44// can't accept the revision yet), but that's OK because the only way to45// require signatures is with a "Global" Herald rule, which requires a46// high level of access.4748$signatures = id(new LegalpadDocumentSignatureQuery())49->setViewer(PhabricatorUser::getOmnipotentUser())50->withDocumentPHIDs($phids)51->withSignerPHIDs(array($revision->getAuthorPHID()))52->execute();53$signatures = mpull($signatures, null, 'getDocumentPHID');5455$phids = array_fuse($phids);56foreach ($phids as $phid) {57$phids[$phid] = isset($signatures[$phid]);58}59}6061return $phids;62}6364public function getRequiredHandlePHIDsForPropertyView() {65return array_keys($this->getValue());66}6768public function renderPropertyViewValue(array $handles) {69if (!$handles) {70return null;71}7273$author_phid = $this->getObject()->getAuthorPHID();74$viewer_phid = $this->getViewer()->getPHID();7576$viewer_is_author = ($author_phid == $viewer_phid);7778$view = new PHUIStatusListView();79foreach ($handles as $handle) {80$item = id(new PHUIStatusItemView())81->setTarget($handle->renderLink());8283// NOTE: If the viewer isn't the author, we just show generic document84// icons, because the granular information isn't very useful and there85// is no need to disclose it.8687// If the viewer is the author, we show exactly what they need to sign.8889if (!$viewer_is_author) {90$item->setIcon('fa-file-text-o bluegrey');91} else {92if (idx($this->getValue(), $handle->getPHID())) {93$item->setIcon('fa-check-square-o green');94} else {95$item->setIcon('fa-times red');96}97}9899$view->addItem($item);100}101102return $view;103}104105public function getWarningsForDetailView() {106if (!$this->haveAnyUnsignedDocuments()) {107return array();108}109110return array(111pht(112'The author of this revision has not signed all the required '.113'legal documents. The revision can not be accepted until the '.114'documents are signed.'),115);116}117118private function haveAnyUnsignedDocuments() {119foreach ($this->getValue() as $phid => $signed) {120if (!$signed) {121return true;122}123}124125return false;126}127128public function getWarningsForRevisionHeader(array $handles) {129if (!$this->haveAnyUnsignedDocuments()) {130return array();131}132133return array(134pht(135'This revision can not be accepted until the required legal '.136'agreements have been signed.'),137);138}139140}141142143