1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-24 06:20:56 +01:00

Allow users to search for signatures across documents

Summary:
Ref T3116. You can already search for sigatures on a specific document, but allow them to be searched across documents too.

In particular, this lets users answer questions like "Which of these 5 documents has alincoln signed?" / "Has alincoln signed all the stuff I care about?" / "who has signed either L5 or equivalent document L22?", etc.

Test Plan: {F171658}

Reviewers: chad

Reviewed By: chad

Subscribers: epriestley

Maniphest Tasks: T3116

Differential Revision: https://secure.phabricator.com/D9770
This commit is contained in:
epriestley 2014-06-28 16:37:36 -07:00
parent 5242fb0572
commit 88d9366701
5 changed files with 99 additions and 33 deletions

View file

@ -49,8 +49,8 @@ final class PhabricatorApplicationLegalpad extends PhabricatorApplication {
'done/' => 'LegalpadDocumentDoneController',
'verify/(?P<code>[^/]+)/' =>
'LegalpadDocumentSignatureVerificationController',
'signatures/(?P<id>\d+)/(?:query/(?P<queryKey>[^/]+)/)?'
=> 'LegalpadDocumentSignatureListController',
'signatures/(?:(?P<id>\d+)/)?(?:query/(?P<queryKey>[^/]+)/)?' =>
'LegalpadDocumentSignatureListController',
'document/' => array(
'preview/' => 'PhabricatorMarkupPreviewController'),
));

View file

@ -19,6 +19,9 @@ abstract class LegalpadController extends PhabricatorController {
->setViewer($user)
->addNavigationItems($nav->getMenu());
$nav->addLabel(pht('Signatures'));
$nav->addFilter('signatures/', pht('Find Signatures'));
return $nav;
}

View file

@ -7,7 +7,7 @@ final class LegalpadDocumentSignatureListController extends LegalpadController {
private $document;
public function willProcessRequest(array $data) {
$this->documentID = $data['id'];
$this->documentID = idx($data, 'id');
$this->queryKey = idx($data, 'queryKey');
}
@ -15,6 +15,7 @@ final class LegalpadDocumentSignatureListController extends LegalpadController {
$request = $this->getRequest();
$user = $request->getUser();
if ($this->documentID) {
$document = id(new LegalpadDocumentQuery())
->setViewer($user)
->withIDs(array($this->documentID))
@ -29,9 +30,13 @@ final class LegalpadDocumentSignatureListController extends LegalpadController {
}
$this->document = $document;
}
$engine = id(new LegalpadDocumentSignatureSearchEngine())
->setDocument($document);
$engine = id(new LegalpadDocumentSignatureSearchEngine());
if ($this->document) {
$engine->setDocument($this->document);
}
$controller = id(new PhabricatorApplicationSearchController($request))
->setQueryKey($this->queryKey)
@ -47,10 +52,14 @@ final class LegalpadDocumentSignatureListController extends LegalpadController {
$nav = new AphrontSideNavFilterView();
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
id(new LegalpadDocumentSignatureSearchEngine())
->setViewer($user)
->setDocument($this->document)
->addNavigationItems($nav->getMenu());
$engine = id(new LegalpadDocumentSignatureSearchEngine())
->setViewer($user);
if ($this->document) {
$engine->setDocument($this->document);
}
$engine->addNavigationItems($nav->getMenu());
return $nav;
}
@ -58,9 +67,15 @@ final class LegalpadDocumentSignatureListController extends LegalpadController {
public function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs();
if ($this->document) {
$crumbs->addTextCrumb(
$this->document->getMonogram(),
'/'.$this->document->getMonogram());
} else {
$crumbs->addTextCrumb(
pht('Signatures'),
'/legalpad/signatures/');
}
return $crumbs;
}

View file

@ -37,8 +37,8 @@ final class PhabricatorLegalpadPHIDTypeDocument extends PhabricatorPHIDType {
$document = $objects[$phid];
$name = $document->getDocumentBody()->getTitle();
$handle->setName($name);
$handle->setFullName($name);
$handle->setURI('/legalpad/view/'.$document->getID().'/');
$handle->setFullName($document->getMonogram().' '.$name);
$handle->setURI('/'.$document->getMonogram());
}
}

View file

@ -25,6 +25,15 @@ final class LegalpadDocumentSignatureSearchEngine
'signerPHIDs',
$this->readUsersFromRequest($request, 'signers'));
$saved->setParameter(
'documentPHIDs',
$this->readPHIDsFromRequest(
$request,
'documents',
array(
PhabricatorLegalpadPHIDTypeDocument::TYPECONST,
)));
return $saved;
}
@ -38,6 +47,11 @@ final class LegalpadDocumentSignatureSearchEngine
if ($this->document) {
$query->withDocumentPHIDs(array($this->document->getPHID()));
} else {
$document_phids = $saved->getParameter('documentPHIDs', array());
if ($document_phids) {
$query->withDocumentPHIDs($document_phids);
}
}
return $query;
@ -47,14 +61,25 @@ final class LegalpadDocumentSignatureSearchEngine
AphrontFormView $form,
PhabricatorSavedQuery $saved_query) {
$document_phids = $saved_query->getParameter('documentPHIDs', array());
$signer_phids = $saved_query->getParameter('signerPHIDs', array());
$phids = array_merge($signer_phids);
$phids = array_merge($document_phids, $signer_phids);
$handles = id(new PhabricatorHandleQuery())
->setViewer($this->requireViewer())
->withPHIDs($phids)
->execute();
if (!$this->document) {
$form
->appendChild(
id(new AphrontFormTokenizerControl())
->setDatasource('/typeahead/common/legalpaddocuments/')
->setName('documents')
->setLabel(pht('Documents'))
->setValue(array_select_keys($handles, $document_phids)));
}
$form
->appendChild(
id(new AphrontFormTokenizerControl())
@ -68,10 +93,7 @@ final class LegalpadDocumentSignatureSearchEngine
if ($this->document) {
return '/legalpad/signatures/'.$this->document->getID().'/'.$path;
} else {
throw new Exception(
pht(
'Searching for signatures outside of a document context is not '.
'currently supported.'));
return '/legalpad/signatures/'.$path;
}
}
@ -97,9 +119,12 @@ final class LegalpadDocumentSignatureSearchEngine
}
protected function getRequiredHandlePHIDsForResultList(
array $documents,
array $signatures,
PhabricatorSavedQuery $query) {
return mpull($documents, 'getSignerPHID');
return array_merge(
mpull($signatures, 'getSignerPHID'),
mpull($signatures, 'getDocumentPHID'));
}
protected function renderResultList(
@ -150,6 +175,7 @@ final class LegalpadDocumentSignatureSearchEngine
$rows[] = array(
$sig_icon,
$handles[$document->getPHID()]->renderLink(),
$handles[$signature->getSignerPHID()]->renderLink(),
$name,
phutil_tag(
@ -166,16 +192,26 @@ final class LegalpadDocumentSignatureSearchEngine
->setHeaders(
array(
'',
pht('Document'),
pht('Account'),
pht('Name'),
pht('Email'),
pht('Signed'),
))
->setColumnVisibility(
array(
true,
// Only show the "Document" column if we aren't scoped to a
// particular document.
!$this->document,
))
->setColumnClasses(
array(
'',
'',
'',
'',
'wide',
'right',
));
@ -184,6 +220,18 @@ final class LegalpadDocumentSignatureSearchEngine
->setHeaderText(pht('Signatures'))
->appendChild($table);
if (!$this->document) {
$policy_notice = id(new AphrontErrorView())
->setSeverity(AphrontErrorView::SEVERITY_NOTICE)
->setErrors(
array(
pht(
'NOTE: You can only see your own signatures and signatures on '.
'documents you have permission to edit.'),
));
$box->setErrorView($policy_notice);
}
return $box;
}