Page MenuHomePhabricator

D7977.diff
No OneTemporary

D7977.diff

Index: resources/sql/autopatches/20140115.legalpadsigkey.sql
===================================================================
--- /dev/null
+++ resources/sql/autopatches/20140115.legalpadsigkey.sql
@@ -0,0 +1,5 @@
+ALTER TABLE {$NAMESPACE}_legalpad.legalpad_documentsignature
+ DROP KEY `key_document`;
+
+ALTER TABLE {$NAMESPACE}_legalpad.legalpad_documentsignature
+ ADD KEY `key_document` (`documentPHID`,`signerPHID`, `documentVersion`);
Index: src/__phutil_library_map__.php
===================================================================
--- src/__phutil_library_map__.php
+++ src/__phutil_library_map__.php
@@ -1764,6 +1764,7 @@
'PhabricatorPolicyQuery' => 'applications/policy/query/PhabricatorPolicyQuery.php',
'PhabricatorPolicyRule' => 'applications/policy/rule/PhabricatorPolicyRule.php',
'PhabricatorPolicyRuleAdministrators' => 'applications/policy/rule/PhabricatorPolicyRuleAdministrators.php',
+ 'PhabricatorPolicyRuleLegalpadSignature' => 'applications/policy/rule/PhabricatorPolicyRuleLegalpadSignature.php',
'PhabricatorPolicyRuleLunarPhase' => 'applications/policy/rule/PhabricatorPolicyRuleLunarPhase.php',
'PhabricatorPolicyRuleProjects' => 'applications/policy/rule/PhabricatorPolicyRuleProjects.php',
'PhabricatorPolicyRuleUsers' => 'applications/policy/rule/PhabricatorPolicyRuleUsers.php',
@@ -4395,6 +4396,7 @@
'PhabricatorPolicyPHIDTypePolicy' => 'PhabricatorPHIDType',
'PhabricatorPolicyQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorPolicyRuleAdministrators' => 'PhabricatorPolicyRule',
+ 'PhabricatorPolicyRuleLegalpadSignature' => 'PhabricatorPolicyRule',
'PhabricatorPolicyRuleLunarPhase' => 'PhabricatorPolicyRule',
'PhabricatorPolicyRuleProjects' => 'PhabricatorPolicyRule',
'PhabricatorPolicyRuleUsers' => 'PhabricatorPolicyRule',
Index: src/applications/legalpad/controller/LegalpadDocumentSignController.php
===================================================================
--- src/applications/legalpad/controller/LegalpadDocumentSignController.php
+++ src/applications/legalpad/controller/LegalpadDocumentSignController.php
@@ -58,10 +58,10 @@
if ($signer_phid) {
$signature = id(new LegalpadDocumentSignature())
->loadOneWhere(
- 'documentPHID = %s AND documentVersion = %d AND signerPHID = %s',
+ 'documentPHID = %s AND signerPHID = %s AND documentVersion = %d',
$document->getPHID(),
- $document->getVersions(),
- $signer_phid);
+ $signer_phid,
+ $document->getVersions());
}
if (!$signature) {
Index: src/applications/legalpad/query/LegalpadDocumentQuery.php
===================================================================
--- src/applications/legalpad/query/LegalpadDocumentQuery.php
+++ src/applications/legalpad/query/LegalpadDocumentQuery.php
@@ -10,6 +10,7 @@
private $phids;
private $creatorPHIDs;
private $contributorPHIDs;
+ private $signerPHIDs;
private $dateCreatedAfter;
private $dateCreatedBefore;
@@ -36,6 +37,11 @@
return $this;
}
+ public function withSignerPHIDs(array $phids) {
+ $this->signerPHIDs = $phids;
+ return $this;
+ }
+
public function needDocumentBodies($need_bodies) {
$this->needDocumentBodies = $need_bodies;
return $this;
@@ -75,6 +81,27 @@
}
protected function willFilterPage(array $documents) {
+ if ($this->signerPHIDs) {
+ $document_map = mpull($documents, null, 'getPHID');
+ $signatures = id(new LegalpadDocumentSignature())
+ ->loadAllWhere(
+ 'documentPHID IN (%Ls) AND signerPHID IN (%Ls)',
+ array_keys($document_map),
+ $this->signerPHIDs);
+ $signatures = mgroup($signatures, 'getDocumentPHID');
+ foreach ($document_map as $document_phid => $document) {
+ $sigs = idx($signatures, $document_phid, array());
+ foreach ($sigs as $index => $sig) {
+ if ($sig->getDocumentVersion() != $document->getVersions()) {
+ unset($sigs[$index]);
+ }
+ }
+ $signer_phids = mpull($sigs, 'getSignerPHID');
+ if (array_diff($this->signerPHIDs, $signer_phids)) {
+ unset($documents[$document->getID()]);
+ }
+ }
+ }
if ($this->needDocumentBodies) {
$documents = $this->loadDocumentBodies($documents);
}
Index: src/applications/policy/rule/PhabricatorPolicyRuleLegalpadSignature.php
===================================================================
--- /dev/null
+++ src/applications/policy/rule/PhabricatorPolicyRuleLegalpadSignature.php
@@ -0,0 +1,69 @@
+<?php
+
+final class PhabricatorPolicyRuleLegalpadSignature
+ extends PhabricatorPolicyRule {
+
+ private $signatures = array();
+
+ public function getRuleDescription() {
+ return pht('signers of legalpad documents');
+ }
+
+ public function willApplyRules(PhabricatorUser $viewer, array $values) {
+ $values = array_unique(array_filter(array_mergev($values)));
+ if (!$values) {
+ return;
+ }
+
+ $documents = id(new LegalpadDocumentQuery())
+ ->setViewer(PhabricatorUser::getOmnipotentUser())
+ ->withPHIDs($values)
+ ->withSignerPHIDs(array($viewer->getPHID()))
+ ->execute();
+ $this->signatures = mpull($documents, 'getPHID', 'getPHID');
+ }
+
+ public function applyRule(PhabricatorUser $viewer, $value) {
+ foreach ($value as $document_phid) {
+ if (!isset($this->signatures[$document_phid])) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public function getValueControlType() {
+ return self::CONTROL_TYPE_TOKENIZER;
+ }
+
+ public function getValueControlTemplate() {
+ return array(
+ 'markup' => new AphrontTokenizerTemplateView(),
+ 'uri' => '/typeahead/common/legalpaddocuments/',
+ 'placeholder' => pht('Type a document title...'),
+ );
+ }
+
+ public function getRuleOrder() {
+ return 900;
+ }
+
+ public function getValueForStorage($value) {
+ PhutilTypeSpec::newFromString('list<string>')->check($value);
+ return array_values($value);
+ }
+
+ public function getValueForDisplay(PhabricatorUser $viewer, $value) {
+ $handles = id(new PhabricatorHandleQuery())
+ ->setViewer($viewer)
+ ->withPHIDs($value)
+ ->execute();
+
+ return mpull($handles, 'getFullName', 'getPHID');
+ }
+
+ public function ruleHasEffect($value) {
+ return (bool)$value;
+ }
+
+}
Index: src/applications/typeahead/controller/PhabricatorTypeaheadCommonDatasourceController.php
===================================================================
--- src/applications/typeahead/controller/PhabricatorTypeaheadCommonDatasourceController.php
+++ src/applications/typeahead/controller/PhabricatorTypeaheadCommonDatasourceController.php
@@ -37,6 +37,7 @@
$need_jump_objects = false;
$need_build_plans = false;
$need_macros = false;
+ $need_legalpad_documents = false;
switch ($this->type) {
case 'mainsearch':
$need_users = true;
@@ -101,6 +102,9 @@
case 'macros':
$need_macros = true;
break;
+ case 'legalpaddocuments':
+ $need_legalpad_documents = true;
+ break;
}
$results = array();
@@ -252,6 +256,18 @@
}
}
+ if ($need_legalpad_documents) {
+ $documents = id(new LegalpadDocumentQuery())
+ ->setViewer($viewer)
+ ->execute();
+ $documents = mpull($documents, 'getTitle', 'getPHID');
+ foreach ($documents as $phid => $title) {
+ $results[] = id(new PhabricatorTypeaheadResult())
+ ->setPHID($phid)
+ ->setName($title);
+ }
+ }
+
if ($need_projs) {
$projs = id(new PhabricatorProjectQuery())
->setViewer($viewer)

File Metadata

Mime Type
text/plain
Expires
Mon, Mar 24, 5:26 PM (6 d, 11 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7717610
Default Alt Text
D7977.diff (7 KB)

Event Timeline