1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-27 07:50:57 +01:00

Introduce PhabricatorSavedQueryQuery

Summary: Same as D6051, but for SavedQueries instead of NamedQueries. These are POLICY_PUBLIC because you need to know the hash to access them, and because we want to let users copy/paste query URLs. Ref T2625.

Test Plan: Saved a query, reused a saved query.

Reviewers: btrahan, blc

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2625

Differential Revision: https://secure.phabricator.com/D6054
This commit is contained in:
epriestley 2013-05-27 13:41:20 -07:00
parent dcb5eb8e35
commit 215553c261
5 changed files with 106 additions and 12 deletions

View file

@ -1354,6 +1354,7 @@ phutil_register_library_map(array(
'PhabricatorSQLPatchList' => 'infrastructure/storage/patch/PhabricatorSQLPatchList.php',
'PhabricatorSSHWorkflow' => 'infrastructure/ssh/PhabricatorSSHWorkflow.php',
'PhabricatorSavedQuery' => 'applications/search/storage/PhabricatorSavedQuery.php',
'PhabricatorSavedQueryQuery' => 'applications/search/query/PhabricatorSavedQueryQuery.php',
'PhabricatorScopedEnv' => 'infrastructure/env/PhabricatorScopedEnv.php',
'PhabricatorSearchAbstractDocument' => 'applications/search/index/PhabricatorSearchAbstractDocument.php',
'PhabricatorSearchAttachController' => 'applications/search/controller/PhabricatorSearchAttachController.php',
@ -3135,7 +3136,12 @@ phutil_register_library_map(array(
'PhabricatorRepositoryTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
'PhabricatorS3FileStorageEngine' => 'PhabricatorFileStorageEngine',
'PhabricatorSSHWorkflow' => 'PhutilArgumentWorkflow',
'PhabricatorSavedQuery' => 'PhabricatorSearchDAO',
'PhabricatorSavedQuery' =>
array(
0 => 'PhabricatorSearchDAO',
1 => 'PhabricatorPolicyInterface',
),
'PhabricatorSavedQueryQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorSearchAttachController' => 'PhabricatorSearchBaseController',
'PhabricatorSearchBaseController' => 'PhabricatorController',
'PhabricatorSearchConfigOptions' => 'PhabricatorApplicationConfigOptions',

View file

@ -34,9 +34,10 @@ final class PhabricatorPasteListController extends PhabricatorPasteController {
->setPasteSearchUser($request->getUser());
if ($this->queryKey !== null) {
$saved_query = id(new PhabricatorSavedQuery())->loadOneWhere(
'queryKey = %s',
$this->queryKey);
$saved_query = id(new PhabricatorSavedQueryQuery())
->setViewer($user)
->withQueryKeys(array($this->queryKey))
->executeOne();
if (!$saved_query) {
return new Aphront404Response();

View file

@ -17,9 +17,10 @@ final class PhabricatorSearchNameController
$user = $request->getUser();
if ($this->queryKey) {
$saved_query = id(new PhabricatorSavedQuery())->loadOneWhere(
'queryKey = %s',
$this->queryKey);
$saved_query = id(new PhabricatorSavedQueryQuery())
->setViewer($user)
->withQueryKeys(array($this->queryKey))
->executeOne();
if (!$saved_query) {
return new Aphront404Response();
}
@ -28,12 +29,10 @@ final class PhabricatorSearchNameController
}
if ($request->isFormPost()) {
$request_data = $request->getRequestData();
$named_query = id(new PhabricatorNamedQuery())
->setUserPHID($user->getPHID())
->setQueryKey($saved_query->getQueryKey())
->setQueryName($request_data["set_name"])
->setQueryName($request->getStr('name'))
->setEngineClassName($saved_query->getEngineClassName());
try {
@ -51,7 +50,7 @@ final class PhabricatorSearchNameController
$form->appendChild(
id(new AphrontFormTextControl())
->setName('set_name')
->setName('name')
->setLabel(pht('Query Name')));
$form->appendChild(

View file

@ -0,0 +1,68 @@
<?php
final class PhabricatorSavedQueryQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $ids;
private $engineClassNames;
private $queryKeys;
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withEngineClassNames(array $engine_class_names) {
$this->engineClassNames = $engine_class_names;
return $this;
}
public function withQueryKeys(array $query_keys) {
$this->queryKeys = $query_keys;
return $this;
}
protected function loadPage() {
$table = new PhabricatorSavedQuery();
$conn_r = $table->establishConnection('r');
$data = queryfx_all(
$conn_r,
'SELECT * FROM %T %Q %Q %Q',
$table->getTableName(),
$this->buildWhereClause($conn_r),
$this->buildOrderClause($conn_r),
$this->buildLimitClause($conn_r));
return $table->loadAllFromArray($data);
}
private function buildWhereClause($conn_r) {
$where = array();
if ($this->ids) {
$where[] = qsprintf(
$conn_r,
'id IN (%Ld)',
$this->ids);
}
if ($this->engineClassNames) {
$where[] = qsprintf(
$conn_r,
'engineClassName IN (%Ls)',
$this->engineClassNames);
}
if ($this->queryKeys) {
$where[] = qsprintf(
$conn_r,
'queryKey IN (%Ls)',
$this->queryKeys);
}
$where[] = $this->buildPagingClause($conn_r);
return $this->formatWhereClause($where);
}
}

View file

@ -3,7 +3,8 @@
/**
* @group search
*/
final class PhabricatorSavedQuery extends PhabricatorSearchDAO {
final class PhabricatorSavedQuery extends PhabricatorSearchDAO
implements PhabricatorPolicyInterface {
protected $parameters = array();
protected $queryKey = "";
@ -35,4 +36,23 @@ final class PhabricatorSavedQuery extends PhabricatorSearchDAO {
return parent::save();
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
);
}
public function getPolicy($capability) {
return PhabricatorPolicies::POLICY_PUBLIC;
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
return false;
}
}