mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +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:
parent
215553c261
commit
587530d973
6 changed files with 31 additions and 12 deletions
|
@ -36,7 +36,7 @@ final class PhabricatorApplicationPaste extends PhabricatorApplication {
|
||||||
'create/' => 'PhabricatorPasteEditController',
|
'create/' => 'PhabricatorPasteEditController',
|
||||||
'edit/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteEditController',
|
'edit/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteEditController',
|
||||||
'filter/(?P<filter>\w+)/' => 'PhabricatorPasteListController',
|
'filter/(?P<filter>\w+)/' => 'PhabricatorPasteListController',
|
||||||
'query/(?P<queryKey>\w+)/'=> 'PhabricatorPasteListController',
|
'query/(?P<queryKey>[^/]+)/'=> 'PhabricatorPasteListController',
|
||||||
'savedqueries/' => 'PhabricatorPasteQueriesController',
|
'savedqueries/' => 'PhabricatorPasteQueriesController',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -105,4 +105,8 @@ final class PhabricatorPasteSearchEngine
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getQueryResultsPageURI(PhabricatorSavedQuery $query) {
|
||||||
|
return '/paste/query/'.$query->getQueryKey().'/';
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ final class PhabricatorApplicationSearch extends PhabricatorApplication {
|
||||||
'index/(?P<phid>[^/]+)/' => 'PhabricatorSearchIndexController',
|
'index/(?P<phid>[^/]+)/' => 'PhabricatorSearchIndexController',
|
||||||
'hovercard/(?P<mode>retrieve|test)/' =>
|
'hovercard/(?P<mode>retrieve|test)/' =>
|
||||||
'PhabricatorSearchHovercardController',
|
'PhabricatorSearchHovercardController',
|
||||||
'name/(?P<queryKey>\w+)/' => 'PhabricatorSearchNameController',
|
'name/(?P<queryKey>[^/]+)/' => 'PhabricatorSearchNameController',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,18 +16,17 @@ final class PhabricatorSearchNameController
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
$user = $request->getUser();
|
$user = $request->getUser();
|
||||||
|
|
||||||
if ($this->queryKey) {
|
$saved_query = id(new PhabricatorSavedQueryQuery())
|
||||||
$saved_query = id(new PhabricatorSavedQueryQuery())
|
->setViewer($user)
|
||||||
->setViewer($user)
|
->withQueryKeys(array($this->queryKey))
|
||||||
->withQueryKeys(array($this->queryKey))
|
->executeOne();
|
||||||
->executeOne();
|
|
||||||
if (!$saved_query) {
|
if (!$saved_query) {
|
||||||
return new Aphront404Response();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return new Aphront404Response();
|
return new Aphront404Response();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$engine = $saved_query->newEngine();
|
||||||
|
|
||||||
if ($request->isFormPost()) {
|
if ($request->isFormPost()) {
|
||||||
$named_query = id(new PhabricatorNamedQuery())
|
$named_query = id(new PhabricatorNamedQuery())
|
||||||
->setUserPHID($user->getPHID())
|
->setUserPHID($user->getPHID())
|
||||||
|
@ -42,7 +41,7 @@ final class PhabricatorSearchNameController
|
||||||
}
|
}
|
||||||
|
|
||||||
return id(new AphrontRedirectResponse())
|
return id(new AphrontRedirectResponse())
|
||||||
->setURI('/search/');
|
->setURI($engine->getQueryResultsPageURI($saved_query));
|
||||||
}
|
}
|
||||||
|
|
||||||
$form = id(new AphrontFormView())
|
$form = id(new AphrontFormView())
|
||||||
|
|
|
@ -34,4 +34,13 @@ abstract class PhabricatorApplicationSearchEngine {
|
||||||
*/
|
*/
|
||||||
abstract public function buildSearchForm(PhabricatorSavedQuery $query);
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,12 +31,19 @@ final class PhabricatorSavedQuery extends PhabricatorSearchDAO
|
||||||
throw new Exception(pht("Engine class is null."));
|
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);
|
$serial = $this->getEngineClassName().serialize($this->parameters);
|
||||||
$this->queryKey = PhabricatorHash::digestForIndex($serial);
|
$this->queryKey = PhabricatorHash::digestForIndex($serial);
|
||||||
|
|
||||||
return parent::save();
|
return parent::save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function newEngine() {
|
||||||
|
return newv($this->getEngineClassName(), array());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue