Path: blob/master/src/applications/legalpad/policyrule/PhabricatorLegalpadSignaturePolicyRule.php
13498 views
<?php12final class PhabricatorLegalpadSignaturePolicyRule3extends PhabricatorPolicyRule {45private $signatures = array();67public function getRuleDescription() {8return pht('signers of legalpad documents');9}1011public function willApplyRules(12PhabricatorUser $viewer,13array $values,14array $objects) {1516$values = array_unique(array_filter(array_mergev($values)));17if (!$values) {18return;19}2021// TODO: This accepts signature of any version of the document, even an22// older version.2324$documents = id(new LegalpadDocumentQuery())25->setViewer(PhabricatorUser::getOmnipotentUser())26->withPHIDs($values)27->withSignerPHIDs(array($viewer->getPHID()))28->execute();29$this->signatures = mpull($documents, 'getPHID', 'getPHID');30}3132public function applyRule(33PhabricatorUser $viewer,34$value,35PhabricatorPolicyInterface $object) {3637foreach ($value as $document_phid) {38if (!isset($this->signatures[$document_phid])) {39return false;40}41}4243return true;44}4546public function getValueControlType() {47return self::CONTROL_TYPE_TOKENIZER;48}4950public function getValueControlTemplate() {51return $this->getDatasourceTemplate(new LegalpadDocumentDatasource());52}5354public function getRuleOrder() {55return 900;56}5758public function getValueForStorage($value) {59PhutilTypeSpec::newFromString('list<string>')->check($value);60return array_values($value);61}6263public function getValueForDisplay(PhabricatorUser $viewer, $value) {64$handles = id(new PhabricatorHandleQuery())65->setViewer($viewer)66->withPHIDs($value)67->execute();68return mpull($handles, 'getFullName', 'getPHID');69}7071public function ruleHasEffect($value) {72return (bool)$value;73}7475}767778