diff --git a/src/applications/paste/application/PhabricatorApplicationPaste.php b/src/applications/paste/application/PhabricatorApplicationPaste.php index 5e377fb509..2af2cf275a 100644 --- a/src/applications/paste/application/PhabricatorApplicationPaste.php +++ b/src/applications/paste/application/PhabricatorApplicationPaste.php @@ -36,6 +36,7 @@ final class PhabricatorApplicationPaste extends PhabricatorApplication { 'create/' => 'PhabricatorPasteEditController', 'edit/(?P[1-9]\d*)/' => 'PhabricatorPasteEditController', 'filter/(?P\w+)/' => 'PhabricatorPasteListController', + 'query/(?P\w+)/'=> 'PhabricatorPasteListController', ), ); } diff --git a/src/applications/paste/controller/PhabricatorPasteController.php b/src/applications/paste/controller/PhabricatorPasteController.php index 9e013da314..0797e27e06 100644 --- a/src/applications/paste/controller/PhabricatorPasteController.php +++ b/src/applications/paste/controller/PhabricatorPasteController.php @@ -18,6 +18,7 @@ abstract class PhabricatorPasteController extends PhabricatorController { if ($user->isLoggedIn()) { $nav->addFilter('my', pht('My Pastes')); } + $nav->addFilter('advanced', pht('Advanced Search')); $nav->selectFilter($filter, 'all'); diff --git a/src/applications/paste/controller/PhabricatorPasteListController.php b/src/applications/paste/controller/PhabricatorPasteListController.php index 7aabed01c3..8693319395 100644 --- a/src/applications/paste/controller/PhabricatorPasteListController.php +++ b/src/applications/paste/controller/PhabricatorPasteListController.php @@ -7,24 +7,51 @@ final class PhabricatorPasteListController extends PhabricatorPasteController { } private $filter; + private $queryKey; public function willProcessRequest(array $data) { $this->filter = idx($data, 'filter'); + $this->queryKey = idx($data, 'queryKey'); } public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); - $saved_query = new PhabricatorSavedQuery(); + if ($request->isFormPost()) { + $saved = id(new PhabricatorPasteSearchEngine()) + ->buildSavedQueryFromRequest($request); + if (count($saved->getParameter('authorPHIDs')) == 0) { + return id(new AphrontRedirectResponse()) + ->setURI('/paste/filter/advanced/'); + } + return id(new AphrontRedirectResponse()) + ->setURI('/paste/query/'.$saved->getQueryKey().'/'); + } $nav = $this->buildSideNavView($this->filter); $filter = $nav->getSelectedFilter(); + $saved_query = new PhabricatorSavedQuery(); $engine = id(new PhabricatorPasteSearchEngine()) - ->setPasteSearchFilter($filter); - $saved_query = $engine->buildSavedQueryFromRequest($request); - $query = $engine->buildQueryFromSavedQuery($saved_query); + ->setPasteSearchFilter($filter) + ->setPasteSearchUser($request->getUser()); + + if ($this->queryKey !== null) { + $saved_query = id(new PhabricatorSavedQuery())->loadOneWhere( + 'queryKey = %s', + $this->queryKey); + + if (!$saved_query) { + return new Aphront404Response(); + } + + $query = id(new PhabricatorPasteSearchEngine()) + ->buildQueryFromSavedQuery($saved_query); + } else { + $saved_query = $engine->buildSavedQueryFromRequest($request); + $query = $engine->buildQueryFromSavedQuery($saved_query); + } $pager = new AphrontCursorPagerView(); $pager->readFromRequest($request); @@ -36,6 +63,14 @@ final class PhabricatorPasteListController extends PhabricatorPasteController { $list->setPager($pager); $list->setNoDataString(pht("No results found for this query.")); + if ($this->queryKey !== null || $filter == "advanced") { + $form = $engine->buildSearchForm($saved_query); + $nav->appendChild( + array( + $form + )); + } + $nav->appendChild( array( $list, diff --git a/src/applications/paste/query/PhabricatorPasteSearchEngine.php b/src/applications/paste/query/PhabricatorPasteSearchEngine.php index 080ebfd608..ea92359d34 100644 --- a/src/applications/paste/query/PhabricatorPasteSearchEngine.php +++ b/src/applications/paste/query/PhabricatorPasteSearchEngine.php @@ -9,6 +9,7 @@ final class PhabricatorPasteSearchEngine extends PhabricatorApplicationSearchEngine { protected $filter; + protected $user; /** * Create a saved query object from the request. @@ -23,6 +24,19 @@ final class PhabricatorPasteSearchEngine if ($this->filter == "my") { $user = $request->getUser(); $saved->setParameter('authorPHIDs', array($user->getPHID())); + } else { + $data = $request->getRequestData(); + if (array_key_exists('set_users', $data)) { + $saved->setParameter('authorPHIDs', $data['set_users']); + } + } + + try { + $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); + $saved->save(); + unset($unguarded); + } catch (AphrontQueryDuplicateKeyException $ex) { + // Ignore, this is just a repeated search. } return $saved; @@ -48,9 +62,30 @@ final class PhabricatorPasteSearchEngine * Builds the search form using the request. * * @param PhabricatorSavedQuery The query to populate the form with. - * @return void + * @return AphrontFormView The built form. */ public function buildSearchForm(PhabricatorSavedQuery $saved_query) { + $phids = $saved_query->getParameter('authorPHIDs', array()); + $handles = id(new PhabricatorObjectHandleData($phids)) + ->setViewer($this->user) + ->loadHandles(); + $users_searched = mpull($handles, 'getFullName', 'getPHID'); + + $form = id(new AphrontFormView()) + ->setUser($this->user); + + $form->appendChild( + id(new AphrontFormTokenizerControl()) + ->setDatasource('/typeahead/common/searchowner/') + ->setName('set_users') + ->setLabel(pht('Users')) + ->setValue($users_searched)); + + $form->appendChild( + id(new AphrontFormSubmitControl()) + ->setValue(pht('Filter Pastes'))); + + return $form; } public function setPasteSearchFilter($filter) { @@ -62,4 +97,9 @@ final class PhabricatorPasteSearchEngine return $this->filter; } + public function setPasteSearchUser($user) { + $this->user = $user; + return $this; + } + } diff --git a/src/applications/search/storage/PhabricatorSavedQuery.php b/src/applications/search/storage/PhabricatorSavedQuery.php index 8433e0d7b7..097a1b94b6 100644 --- a/src/applications/search/storage/PhabricatorSavedQuery.php +++ b/src/applications/search/storage/PhabricatorSavedQuery.php @@ -26,11 +26,11 @@ final class PhabricatorSavedQuery extends PhabricatorSearchDAO { } public function save() { - if ($this->getEngineClass() === null) { + if ($this->getEngineClassName() === null) { throw new Exception(pht("Engine class is null.")); } - $serial = $this->getEngineClass().serialize($this->parameters); + $serial = $this->getEngineClassName().serialize($this->parameters); $this->queryKey = PhabricatorHash::digestForIndex($serial); return parent::save();