1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 23:02:42 +01:00

After saving a custom query, redirect to its results page

Summary:
Ref T2625. Currently, after saving a query the user is redirected to "/search/", which isn't especially useful. Instead, redirect them back into the application they came from and to the query results page.

Also, query hashes may contain ".", which does not match `\w`. Use `[^/]` instead.

Test Plan: Saved some custom queries.

Reviewers: btrahan, blc

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2625

Differential Revision: https://secure.phabricator.com/D6055
This commit is contained in:
epriestley 2013-05-27 13:41:39 -07:00
parent 215553c261
commit 587530d973
6 changed files with 31 additions and 12 deletions

View file

@ -36,7 +36,7 @@ final class PhabricatorApplicationPaste extends PhabricatorApplication {
'create/' => 'PhabricatorPasteEditController',
'edit/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteEditController',
'filter/(?P<filter>\w+)/' => 'PhabricatorPasteListController',
'query/(?P<queryKey>\w+)/'=> 'PhabricatorPasteListController',
'query/(?P<queryKey>[^/]+)/'=> 'PhabricatorPasteListController',
'savedqueries/' => 'PhabricatorPasteQueriesController',
),
);

View file

@ -105,4 +105,8 @@ final class PhabricatorPasteSearchEngine
return $this;
}
public function getQueryResultsPageURI(PhabricatorSavedQuery $query) {
return '/paste/query/'.$query->getQueryKey().'/';
}
}

View file

@ -34,7 +34,7 @@ final class PhabricatorApplicationSearch extends PhabricatorApplication {
'index/(?P<phid>[^/]+)/' => 'PhabricatorSearchIndexController',
'hovercard/(?P<mode>retrieve|test)/' =>
'PhabricatorSearchHovercardController',
'name/(?P<queryKey>\w+)/' => 'PhabricatorSearchNameController',
'name/(?P<queryKey>[^/]+)/' => 'PhabricatorSearchNameController',
),
);
}

View file

@ -16,18 +16,17 @@ final class PhabricatorSearchNameController
$request = $this->getRequest();
$user = $request->getUser();
if ($this->queryKey) {
$saved_query = id(new PhabricatorSavedQueryQuery())
->setViewer($user)
->withQueryKeys(array($this->queryKey))
->executeOne();
if (!$saved_query) {
return new Aphront404Response();
}
} else {
$saved_query = id(new PhabricatorSavedQueryQuery())
->setViewer($user)
->withQueryKeys(array($this->queryKey))
->executeOne();
if (!$saved_query) {
return new Aphront404Response();
}
$engine = $saved_query->newEngine();
if ($request->isFormPost()) {
$named_query = id(new PhabricatorNamedQuery())
->setUserPHID($user->getPHID())
@ -42,7 +41,7 @@ final class PhabricatorSearchNameController
}
return id(new AphrontRedirectResponse())
->setURI('/search/');
->setURI($engine->getQueryResultsPageURI($saved_query));
}
$form = id(new AphrontFormView())

View file

@ -34,4 +34,13 @@ abstract class PhabricatorApplicationSearchEngine {
*/
abstract public function buildSearchForm(PhabricatorSavedQuery $query);
/**
* Return an application URI corresponding to the results page of a query.
* Normally, this is something like `/application/query/QUERYKEY/`.
*
* @param PhabricatorSavedQuery The query to build a URI for.
* @return string URI where the query can be executed.
*/
abstract public function getQueryResultsPageURI(PhabricatorSavedQuery $query);
}

View file

@ -31,12 +31,19 @@ final class PhabricatorSavedQuery extends PhabricatorSearchDAO
throw new Exception(pht("Engine class is null."));
}
// Instantiate the engine to make sure it's valid.
$this->newEngine();
$serial = $this->getEngineClassName().serialize($this->parameters);
$this->queryKey = PhabricatorHash::digestForIndex($serial);
return parent::save();
}
public function newEngine() {
return newv($this->getEngineClassName(), array());
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */