diff --git a/src/applications/legalpad/query/LegalpadDocumentSignatureQuery.php b/src/applications/legalpad/query/LegalpadDocumentSignatureQuery.php --- a/src/applications/legalpad/query/LegalpadDocumentSignatureQuery.php +++ b/src/applications/legalpad/query/LegalpadDocumentSignatureQuery.php @@ -46,9 +46,32 @@ $this->buildOrderClause($conn_r), $this->buildLimitClause($conn_r)); - $documents = $table->loadAllFromArray($data); + $signatures = $table->loadAllFromArray($data); - return $documents; + return $signatures; + } + + protected function willFilterPage(array $signatures) { + $document_phids = mpull($signatures, 'getDocumentPHID'); + + $documents = id(new LegalpadDocumentQuery()) + ->setParentQuery($this) + ->setViewer($this->getViewer()) + ->withPHIDs($document_phids) + ->execute(); + $documents = mpull($documents, null, 'getPHID'); + + foreach ($signatures as $key => $signature) { + $document_phid = $signature->getDocumentPHID(); + $document = idx($documents, $document_phid); + if ($document) { + $signature->attachDocument($document); + } else { + unset($signatures[$key]); + } + } + + return $signatures; } protected function buildWhereClause($conn_r) { @@ -56,35 +79,35 @@ $where[] = $this->buildPagingClause($conn_r); - if ($this->ids) { + if ($this->ids !== null) { $where[] = qsprintf( $conn_r, 'id IN (%Ld)', $this->ids); } - if ($this->documentPHIDs) { + if ($this->documentPHIDs !== null) { $where[] = qsprintf( $conn_r, 'documentPHID IN (%Ls)', $this->documentPHIDs); } - if ($this->signerPHIDs) { + if ($this->signerPHIDs !== null) { $where[] = qsprintf( $conn_r, 'signerPHID IN (%Ls)', $this->signerPHIDs); } - if ($this->documentVersions) { + if ($this->documentVersions !== null) { $where[] = qsprintf( $conn_r, 'documentVersion IN (%Ld)', $this->documentVersions); } - if ($this->secretKeys) { + if ($this->secretKeys !== null) { $where[] = qsprintf( $conn_r, 'secretKey IN (%Ls)', diff --git a/src/applications/legalpad/storage/LegalpadDocumentSignature.php b/src/applications/legalpad/storage/LegalpadDocumentSignature.php --- a/src/applications/legalpad/storage/LegalpadDocumentSignature.php +++ b/src/applications/legalpad/storage/LegalpadDocumentSignature.php @@ -14,6 +14,8 @@ protected $verified; protected $secretKey; + private $document = self::ATTACHABLE; + public function getConfiguration() { return array( self::CONFIG_SERIALIZATION => array( @@ -30,10 +32,22 @@ } public function isVerified() { - return $this->getVerified() != self::UNVERIFIED; + return ($this->getVerified() != self::UNVERIFIED); + } + + public function getDocument() { + return $this->assertAttached($this->document); + } + + public function attachDocument(LegalpadDocument $document) { + $this->document = $document; + return $this; } + + /* -( PhabricatorPolicyInterface )----------------------------------------- */ + public function getCapabilities() { return array( PhabricatorPolicyCapability::CAN_VIEW, @@ -43,12 +57,13 @@ public function getPolicy($capability) { switch ($capability) { case PhabricatorPolicyCapability::CAN_VIEW: - return PhabricatorPolicies::POLICY_USER; + return $this->getDocument()->getPolicy( + PhabricatorPolicyCapability::CAN_EDIT); } } public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { - return false; + return ($viewer->getPHID() == $this->getSignerPHID()); } public function describeAutomaticCapability($capability) {