Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/legalpad/query/LegalpadDocumentSignatureQuery.php b/src/applications/legalpad/query/LegalpadDocumentSignatureQuery.php
index ade76679c3..a7dd22d189 100644
--- a/src/applications/legalpad/query/LegalpadDocumentSignatureQuery.php
+++ b/src/applications/legalpad/query/LegalpadDocumentSignatureQuery.php
@@ -1,101 +1,124 @@
<?php
final class LegalpadDocumentSignatureQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $ids;
private $documentPHIDs;
private $signerPHIDs;
private $documentVersions;
private $secretKeys;
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withDocumentPHIDs(array $phids) {
$this->documentPHIDs = $phids;
return $this;
}
public function withSignerPHIDs(array $phids) {
$this->signerPHIDs = $phids;
return $this;
}
public function withDocumentVersions(array $versions) {
$this->documentVersions = $versions;
return $this;
}
public function withSecretKeys(array $keys) {
$this->secretKeys = $keys;
return $this;
}
protected function loadPage() {
$table = new LegalpadDocumentSignature();
$conn_r = $table->establishConnection('r');
$data = queryfx_all(
$conn_r,
'SELECT * FROM %T %Q %Q %Q',
$table->getTableName(),
$this->buildWhereClause($conn_r),
$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) {
$where = array();
$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)',
$this->secretKeys);
}
return $this->formatWhereClause($where);
}
public function getQueryApplicationClass() {
return 'PhabricatorApplicationLegalpad';
}
}
diff --git a/src/applications/legalpad/storage/LegalpadDocumentSignature.php b/src/applications/legalpad/storage/LegalpadDocumentSignature.php
index 5c66b06d19..d9f569f45d 100644
--- a/src/applications/legalpad/storage/LegalpadDocumentSignature.php
+++ b/src/applications/legalpad/storage/LegalpadDocumentSignature.php
@@ -1,58 +1,73 @@
<?php
final class LegalpadDocumentSignature
extends LegalpadDAO
implements PhabricatorPolicyInterface {
const VERIFIED = 0;
const UNVERIFIED = 1;
protected $documentPHID;
protected $documentVersion;
protected $signerPHID;
protected $signatureData = array();
protected $verified;
protected $secretKey;
+ private $document = self::ATTACHABLE;
+
public function getConfiguration() {
return array(
self::CONFIG_SERIALIZATION => array(
'signatureData' => self::SERIALIZATION_JSON,
),
) + parent::getConfiguration();
}
public function save() {
if (!$this->getSecretKey()) {
$this->setSecretKey(Filesystem::readRandomCharacters(20));
}
return parent::save();
}
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,
);
}
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) {
return null;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Mon, Jul 28, 7:17 PM (1 w, 3 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
187406
Default Alt Text
(5 KB)

Event Timeline