Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F18034772
D7977.id18049.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D7977.id18049.diff
View Options
Index: src/__phutil_library_map__.php
===================================================================
--- src/__phutil_library_map__.php
+++ src/__phutil_library_map__.php
@@ -1763,6 +1763,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',
@@ -4393,6 +4394,7 @@
'PhabricatorPolicyPHIDTypePolicy' => 'PhabricatorPHIDType',
'PhabricatorPolicyQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorPolicyRuleAdministrators' => 'PhabricatorPolicyRule',
+ 'PhabricatorPolicyRuleLegalpadSignature' => 'PhabricatorPolicyRule',
'PhabricatorPolicyRuleLunarPhase' => 'PhabricatorPolicyRule',
'PhabricatorPolicyRuleProjects' => 'PhabricatorPolicyRule',
'PhabricatorPolicyRuleUsers' => 'PhabricatorPolicyRule',
Index: src/applications/policy/rule/PhabricatorPolicyRuleLegalpadSignature.php
===================================================================
--- /dev/null
+++ src/applications/policy/rule/PhabricatorPolicyRuleLegalpadSignature.php
@@ -0,0 +1,81 @@
+<?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)
+ ->execute();
+ $documents = mpull($documents, null, 'getPHID');
+
+ $signatures = id(new LegalpadDocumentSignature())
+ ->loadAllWhere('signerPHID = %s', $viewer->getPHID());
+ foreach ($signatures as $signature) {
+ $document = idx($documents, $signature->getDocumentPHID());
+ if (!$document) {
+ continue;
+ }
+ if ($signature->getDocumentVersion() == $document->getVersions()) {
+ $this->signatures[$signature->getDocumentPHID()] = true;
+ }
+ }
+ }
+
+ public function applyRule(PhabricatorUser $viewer, $value) {
+
+ foreach ($value as $document_phid) {
+ if (isset($this->signatures[$document_phid])) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ 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
Details
Attached
Mime Type
text/plain
Expires
Aug 4 2025, 1:17 AM (11 w, 5 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
8894071
Default Alt Text
D7977.id18049.diff (5 KB)
Attached To
Mode
D7977: Legalpad - add policy rule for legalpad document signatures
Attached
Detach File
Event Timeline
Log In to Comment