Page MenuHomePhabricator

D8805.id20900.diff
No OneTemporary

D8805.id20900.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -1190,7 +1190,6 @@
'PhabricatorAuditComment' => 'applications/audit/storage/PhabricatorAuditComment.php',
'PhabricatorAuditCommentEditor' => 'applications/audit/editor/PhabricatorAuditCommentEditor.php',
'PhabricatorAuditCommitListView' => 'applications/audit/view/PhabricatorAuditCommitListView.php',
- 'PhabricatorAuditCommitQuery' => 'applications/audit/query/PhabricatorAuditCommitQuery.php',
'PhabricatorAuditCommitStatusConstants' => 'applications/audit/constants/PhabricatorAuditCommitStatusConstants.php',
'PhabricatorAuditController' => 'applications/audit/controller/PhabricatorAuditController.php',
'PhabricatorAuditDAO' => 'applications/audit/storage/PhabricatorAuditDAO.php',
@@ -1203,6 +1202,7 @@
'PhabricatorAuditPreviewController' => 'applications/audit/controller/PhabricatorAuditPreviewController.php',
'PhabricatorAuditQuery' => 'applications/audit/query/PhabricatorAuditQuery.php',
'PhabricatorAuditReplyHandler' => 'applications/audit/mail/PhabricatorAuditReplyHandler.php',
+ 'PhabricatorAuditSearchEngine' => 'applications/audit/query/PhabricatorAuditSearchEngine.php',
'PhabricatorAuditStatusConstants' => 'applications/audit/constants/PhabricatorAuditStatusConstants.php',
'PhabricatorAuthAccountView' => 'applications/auth/view/PhabricatorAuthAccountView.php',
'PhabricatorAuthConfirmLinkController' => 'applications/auth/controller/PhabricatorAuthConfirmLinkController.php',
@@ -3938,13 +3938,19 @@
0 => 'PhabricatorAuditDAO',
1 => 'PhabricatorInlineCommentInterface',
),
- 'PhabricatorAuditListController' => 'PhabricatorAuditController',
+ 'PhabricatorAuditListController' =>
+ array(
+ 0 => 'PhabricatorAuditController',
+ 1 => 'PhabricatorApplicationSearchResultsControllerInterface',
+ ),
'PhabricatorAuditListView' => 'AphrontView',
'PhabricatorAuditMailReceiver' => 'PhabricatorObjectMailReceiver',
'PhabricatorAuditManagementDeleteWorkflow' => 'PhabricatorAuditManagementWorkflow',
'PhabricatorAuditManagementWorkflow' => 'PhabricatorManagementWorkflow',
'PhabricatorAuditPreviewController' => 'PhabricatorAuditController',
+ 'PhabricatorAuditQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorAuditReplyHandler' => 'PhabricatorMailReplyHandler',
+ 'PhabricatorAuditSearchEngine' => 'PhabricatorApplicationSearchEngine',
'PhabricatorAuthAccountView' => 'AphrontView',
'PhabricatorAuthConfirmLinkController' => 'PhabricatorAuthController',
'PhabricatorAuthController' => 'PhabricatorController',
@@ -4800,7 +4806,11 @@
'PhabricatorRepositoryArcanistProjectDeleteController' => 'PhabricatorRepositoryController',
'PhabricatorRepositoryArcanistProjectEditController' => 'PhabricatorRepositoryController',
'PhabricatorRepositoryArcanistProjectQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
- 'PhabricatorRepositoryAuditRequest' => 'PhabricatorRepositoryDAO',
+ 'PhabricatorRepositoryAuditRequest' =>
+ array(
+ 0 => 'PhabricatorRepositoryDAO',
+ 1 => 'PhabricatorPolicyInterface',
+ ),
'PhabricatorRepositoryBranch' => 'PhabricatorRepositoryDAO',
'PhabricatorRepositoryCommit' =>
array(
diff --git a/src/applications/audit/application/PhabricatorApplicationAudit.php b/src/applications/audit/application/PhabricatorApplicationAudit.php
--- a/src/applications/audit/application/PhabricatorApplicationAudit.php
+++ b/src/applications/audit/application/PhabricatorApplicationAudit.php
@@ -27,7 +27,7 @@
public function getRoutes() {
return array(
'/audit/' => array(
- '' => 'PhabricatorAuditListController',
+ '(?:query/(?P<queryKey>[^/]+)/)?' => 'PhabricatorAuditListController',
'view/(?P<filter>[^/]+)/(?:(?P<name>[^/]+)/)?'
=> 'PhabricatorAuditListController',
'addcomment/' => 'PhabricatorAuditAddCommentController',
@@ -49,10 +49,12 @@
$phids = PhabricatorAuditCommentEditor::loadAuditPHIDsForUser($user);
- $commits = id(new PhabricatorAuditCommitQuery())
- ->withAuthorPHIDs($phids)
- ->withStatus(PhabricatorAuditCommitQuery::STATUS_CONCERN)
- ->execute();
+ $query = id(new PhabricatorAuditQuery())
+ ->setViewer($user)
+ ->withCommitAuthorPHIDs(array($user->getPHID()))
+ ->withStatus(PhabricatorAuditQuery::STATUS_CONCERN);
+ $audits = $query->execute();
+ $commits = $query->getCommits();
$count = count($commits);
$type = PhabricatorApplicationStatusView::TYPE_NEEDS_ATTENTION;
@@ -61,13 +63,15 @@
->setText(pht('%d Problem Commit(s)', $count))
->setCount($count);
- $audits = id(new PhabricatorAuditQuery())
+ $query = id(new PhabricatorAuditQuery())
+ ->setViewer($user)
->withAuditorPHIDs($phids)
->withStatus(PhabricatorAuditQuery::STATUS_OPEN)
- ->withAwaitingUser($user)
- ->execute();
+ ->withAwaitingUser($user);
+ $audits = $query->execute();
+ $commits = $query->getCommits();
- $count = count($audits);
+ $count = count($commits);
$type = PhabricatorApplicationStatusView::TYPE_WARNING;
$status[] = id(new PhabricatorApplicationStatusView())
->setType($type)
diff --git a/src/applications/audit/controller/PhabricatorAuditController.php b/src/applications/audit/controller/PhabricatorAuditController.php
--- a/src/applications/audit/controller/PhabricatorAuditController.php
+++ b/src/applications/audit/controller/PhabricatorAuditController.php
@@ -6,24 +6,16 @@
public function buildSideNavView() {
+ $user = $this->getRequest()->getUser();
+
$nav = new AphrontSideNavFilterView();
- $nav->setBaseURI(new PhutilURI('/audit/view/'));
- $nav->addLabel(pht('Active'));
- $nav->addFilter('active', pht('Need Attention'));
-
- $nav->addLabel(pht('Audits'));
- $nav->addFilter('audits', pht('All'));
- $nav->addFilter('user', pht('By User'));
- $nav->addFilter('project', pht('By Project'));
- $nav->addFilter('package', pht('By Package'));
- $nav->addFilter('repository', pht('By Repository'));
-
- $nav->addLabel(pht('Commits'));
- $nav->addFilter('commits', pht('All'));
- $nav->addFilter('author', pht('By Author'));
- $nav->addFilter('packagecommits', pht('By Package'));
-
- $this->filter = $nav->selectFilter($this->filter, 'active');
+ $nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
+
+ id(new PhabricatorAuditSearchEngine())
+ ->setViewer($user)
+ ->addNavigationItems($nav->getMenu());
+
+ $nav->selectFilter(null);
return $nav;
}
diff --git a/src/applications/audit/controller/PhabricatorAuditListController.php b/src/applications/audit/controller/PhabricatorAuditListController.php
--- a/src/applications/audit/controller/PhabricatorAuditListController.php
+++ b/src/applications/audit/controller/PhabricatorAuditListController.php
@@ -1,483 +1,44 @@
<?php
-final class PhabricatorAuditListController extends PhabricatorAuditController {
+final class PhabricatorAuditListController
+ extends PhabricatorAuditController
+ implements PhabricatorApplicationSearchResultsControllerInterface {
+ private $queryKey;
private $name;
private $filterStatus;
public function willProcessRequest(array $data) {
- $this->filter = idx($data, 'filter');
- $this->name = idx($data, 'name');
+ $this->queryKey = idx($data, 'queryKey');
}
public function processRequest() {
$request = $this->getRequest();
- $nav = $this->buildSideNavView();
+ $controller = id(new PhabricatorApplicationSearchController($request))
+ ->setQueryKey($this->queryKey)
+ ->setSearchEngine(new PhabricatorAuditSearchEngine())
+ ->setNavigation($this->buildSideNavView());
- if ($request->isFormPost()) {
- // If the list filter is POST'ed, redirect to GET so the page can be
- // bookmarked.
- $uri = $request->getRequestURI();
- $phid = head($request->getArr('set_phid'));
- $user = id(new PhabricatorUser())->loadOneWhere(
- 'phid = %s',
- $phid);
-
- $uri = $request->getRequestURI();
- if ($user) {
- $username = phutil_escape_uri($user->getUsername());
- $uri = '/audit/view/'.$this->filter.'/'.$username.'/';
- } else if ($phid) {
- $uri = $request->getRequestURI();
- $uri = $uri->alter('phid', $phid);
- }
-
- return id(new AphrontRedirectResponse())->setURI($uri);
- }
-
- $this->filterStatus = $request->getStr('status', 'all');
-
- $handle = $this->loadHandle();
-
- $nav->appendChild($this->buildListFilters($handle));
-
-
- $title = null;
- $message = null;
-
- if (!$handle) {
- switch ($this->filter) {
- case 'project':
- $title = pht('Choose A Project');
- $message = pht('Choose a project to view audits for.');
- break;
- case 'repository':
- $title = pht('Choose A Repository');
- $message = pht('Choose a repository to view audits for.');
- break;
- case 'package':
- case 'packagecommits':
- $title = pht('Choose a Package');
- $message = pht('Choose a package to view audits for.');
- break;
- }
- }
-
- if (!$message) {
- $nav->appendChild($this->buildViews($handle));
- } else {
- $panel = id(new AphrontErrorView())
- ->setSeverity(AphrontErrorView::SEVERITY_NODATA)
- ->setTitle($title)
- ->appendChild($message);
- $nav->appendChild($panel);
- }
-
- return $this->buildApplicationPage(
- $nav,
- array(
- 'title' => pht('Audits'),
- 'device' => true,
- ));
- }
-
- private function buildListFilters(PhabricatorObjectHandle $handle = null) {
- $request = $this->getRequest();
- $user = $request->getUser();
-
- $form = new AphrontFormView();
- $form->setUser($user);
-
- $show_status = false;
- $show_user = false;
- $show_project = false;
- $show_package = false;
- $show_repository = false;
-
- switch ($this->filter) {
- case 'audits':
- case 'commits':
- $show_status = true;
- break;
- case 'active':
- $show_user = true;
- break;
- case 'author':
- case 'user':
- $show_user = true;
- $show_status = true;
- break;
- case 'project':
- $show_project = true;
- $show_status = true;
- break;
- case 'repository':
- $show_repository = true;
- $show_status = true;
- break;
- case 'package':
- case 'packagecommits':
- $show_package = true;
- $show_status = true;
- break;
- }
-
- if ($show_user || $show_project || $show_package || $show_repository) {
- if ($show_user) {
- $uri = '/typeahead/common/users/';
- $label = pht('User');
- } else if ($show_project) {
- $uri = '/typeahead/common/projects/';
- $label = pht('Project');
- } else if ($show_package) {
- $uri = '/typeahead/common/packages/';
- $label = pht('Package');
- } else if ($show_repository) {
- $uri = '/typeahead/common/repositories/';
- $label = pht('Repository');
- }
-
- $tok_value = null;
- if ($handle) {
- $tok_value = array($handle);
- }
-
- $form->appendChild(
- id(new AphrontFormTokenizerControl())
- ->setName('set_phid')
- ->setLabel($label)
- ->setLimit(1)
- ->setDatasource($uri)
- ->setValue($tok_value));
- }
-
- if ($show_status) {
- $form->appendChild(
- id(new AphrontFormToggleButtonsControl())
- ->setName('status')
- ->setLabel(pht('Status'))
- ->setBaseURI($request->getRequestURI(), 'status')
- ->setValue($this->filterStatus)
- ->setButtons(
- array(
- 'all' => pht('All'),
- 'open' => pht('Open'),
- 'concern' => pht('Concern Raised'),
- )));
- }
-
- $form->appendChild(
- id(new AphrontFormSubmitControl())
- ->setValue(pht('Filter Audits')));
-
- $view = new AphrontListFilterView();
- $view->appendChild($form);
- return $view;
- }
-
- private function loadHandle() {
- $request = $this->getRequest();
-
- $default = null;
- switch ($this->filter) {
- case 'user':
- case 'active':
- case 'author':
- $default = $request->getUser()->getPHID();
- if ($this->name) {
- $user = id(new PhabricatorUser())->loadOneWhere(
- 'username = %s',
- $this->name);
- if ($user) {
- $default = $user->getPHID();
- }
- }
- break;
- }
-
- $phid = $request->getStr('phid', $default);
- if (!$phid) {
- return null;
- }
-
- $phids = array($phid);
- $handles = $this->loadViewerHandles($phids);
- $handle = $handles[$phid];
-
- $this->validateHandle($handle);
- return $handle;
- }
-
- private function validateHandle(PhabricatorObjectHandle $handle) {
- $type = $handle->getType();
-
- switch ($this->filter) {
- case 'active':
- case 'user':
- case 'author':
- if ($type !== PhabricatorPeoplePHIDTypeUser::TYPECONST) {
- throw new Exception("PHID must be a user PHID!");
- }
- break;
- case 'package':
- case 'packagecommits':
- if ($type !== PhabricatorOwnersPHIDTypePackage::TYPECONST) {
- throw new Exception("PHID must be a package PHID!");
- }
- break;
- case 'project':
- if ($type !== PhabricatorProjectPHIDTypeProject::TYPECONST) {
- throw new Exception("PHID must be a project PHID!");
- }
- break;
- case 'repository':
- if ($type !== PhabricatorRepositoryPHIDTypeRepository::TYPECONST) {
- throw new Exception("PHID must be a repository PHID!");
- }
- break;
- case 'audits':
- case 'commits':
- break;
- default:
- throw new Exception("Unknown filter '{$this->filter}'!");
- }
- }
-
- private function buildViews(PhabricatorObjectHandle $handle = null) {
- $views = array();
- switch ($this->filter) {
- case 'active':
- $views[] = $this->buildCommitView($handle);
- $views[] = $this->buildAuditView($handle);
- break;
- case 'audits':
- case 'user':
- case 'package':
- case 'project':
- case 'repository':
- $views[] = $this->buildAuditView($handle);
- break;
- case 'commits':
- case 'packagecommits':
- case 'author':
- $views[] = $this->buildCommitView($handle);
- break;
- }
- return $views;
- }
-
- private function buildAuditView(PhabricatorObjectHandle $handle = null) {
- $request = $this->getRequest();
-
- $query = new PhabricatorAuditQuery();
-
- $pager = new AphrontPagerView();
- $pager->setURI($request->getRequestURI(), 'offset');
- $pager->setOffset($request->getInt('offset'));
-
- $query->setOffset($pager->getOffset());
- $query->setLimit($pager->getPageSize() + 1);
-
- $awaiting = null;
-
- $phids = null;
- $repository_phids = null;
- switch ($this->filter) {
- case 'user':
- case 'active':
- $obj = id(new PhabricatorUser())->loadOneWhere(
- 'phid = %s',
- $handle->getPHID());
- if (!$obj) {
- throw new Exception("Invalid user!");
- }
- $phids = PhabricatorAuditCommentEditor::loadAuditPHIDsForUser($obj);
- $awaiting = $obj;
- break;
- case 'project':
- case 'package':
- $phids = array($handle->getPHID());
- break;
- case 'repository':
- $repository_phids = array($handle->getPHID());
- break;
- case 'audits';
- break;
- default:
- throw new Exception("Unknown filter!");
- }
-
- if ($phids) {
- $query->withAuditorPHIDs($phids);
- }
-
- if ($repository_phids) {
- $query->withRepositoryPHIDs($repository_phids);
- }
-
- if ($awaiting) {
- $query->withAwaitingUser($awaiting);
- }
-
- switch ($this->filter) {
- case 'active':
- $query->withStatus(PhabricatorAuditQuery::STATUS_OPEN);
- break;
- default:
- switch ($this->filterStatus) {
- case 'open':
- $query->withStatus(PhabricatorAuditQuery::STATUS_OPEN);
- break;
- case 'concern':
- $query->withStatus(PhabricatorAuditQuery::STATUS_CONCERN);
- break;
- }
- break;
- }
-
- if ($handle) {
- $handle_name = $handle->getFullName();
- } else {
- $handle_name = null;
- }
-
- switch ($this->filter) {
- case 'active':
- $header = pht('Required Audits');
- $nodata = pht('No commits require your audit.');
- break;
- case 'user':
- $header = pht("Audits for %s", $handle_name);
- $nodata = pht("No matching audits by %s.", $handle_name);
- break;
- case 'audits':
- $header = pht('Audits');
- $nodata = pht('No matching audits.');
- break;
- case 'project':
- $header = pht("Audits in Project %s", $handle_name);
- $nodata = pht("No matching audits in project %s.", $handle_name);
- break;
- case 'package':
- $header = pht("Audits for Package %s", $handle_name);
- $nodata = pht("No matching audits in package %s.", $handle_name);
- break;
- case 'repository':
- $header = pht("Audits in Repository %s", $handle_name);
- $nodata = pht("No matching audits in repository %s.", $handle_name);
- break;
- }
-
- $query->needCommitData(true);
-
- $audits = $query->execute();
- $audits = $pager->sliceResults($audits);
-
- $view = new PhabricatorAuditListView();
- $view->setAudits($audits);
- $view->setCommits($query->getCommits());
- $view->setUser($request->getUser());
- $view->setNoDataString($nodata);
-
- $phids = $view->getRequiredHandlePHIDs();
- $handles = $this->loadViewerHandles($phids);
- $view->setHandles($handles);
-
- $panel = new AphrontPanelView();
- $panel->setHeader($header);
- $panel->appendChild($view);
- $panel->setNoBackground();
-
- $panel->appendChild($pager);
-
- return $panel;
+ return $this->delegateToController($controller);
}
- private function buildCommitView(PhabricatorObjectHandle $handle = null) {
- $request = $this->getRequest();
-
- $query = new PhabricatorAuditCommitQuery();
- $query->needCommitData(true);
- $query->needAudits(true);
-
- $pager = new AphrontPagerView();
- $pager->setURI($request->getRequestURI(), 'offset');
- $pager->setOffset($request->getInt('offset'));
-
- $query->setOffset($pager->getOffset());
- $query->setLimit($pager->getPageSize() + 1);
+ public function renderResultsList(
+ array $audit_requests,
+ PhabricatorSavedQuery $query) {
+ assert_instances_of($audit_requests, 'PhabricatorRepositoryAuditRequest');
- switch ($this->filter) {
- case 'active':
- case 'author':
- $query->withAuthorPHIDs(array($handle->getPHID()));
- break;
- case 'packagecommits':
- $query->withPackagePHIDs(array($handle->getPHID()));
- break;
- }
-
- switch ($this->filter) {
- case 'active':
- $query->withStatus(PhabricatorAuditCommitQuery::STATUS_CONCERN);
- break;
- default:
- switch ($this->filterStatus) {
- case 'open':
- $query->withStatus(PhabricatorAuditCommitQuery::STATUS_OPEN);
- break;
- case 'concern':
- $query->withStatus(PhabricatorAuditCommitQuery::STATUS_CONCERN);
- break;
- }
- break;
- }
-
- if ($handle) {
- $handle_name = $handle->getName();
- } else {
- $handle_name = null;
- }
-
- switch ($this->filter) {
- case 'active':
- $header = pht('Problem Commits');
- $nodata = pht('None of your commits have open concerns.');
- break;
- case 'author':
- $header = pht("Commits by %s", $handle_name);
- $nodata = pht("No matching commits by %s.", $handle_name);
- break;
- case 'commits':
- $header = pht("Commits");
- $nodata = pht("No matching commits.");
- break;
- case 'packagecommits':
- $header = pht("Commits in Package %s", $handle_name);
- $nodata = pht("No matching commits in package %s.", $handle_name);
- break;
- }
-
- $commits = $query->execute();
- $commits = $pager->sliceResults($commits);
-
- $view = new PhabricatorAuditCommitListView();
- $view->setUser($request->getUser());
- $view->setCommits($commits);
- $view->setNoDataString($nodata);
+ $viewer = $this->getRequest()->getUser();
+ $commits = mpull($audit_requests, 'getCommit', 'getID');
+ $nodata = pht('No matching audits.');
+ $view = id(new PhabricatorAuditListView())
+ ->setUser($viewer)
+ ->setAudits($audit_requests)
+ ->setCommits($commits)
+ ->setNoDataString($nodata);
$phids = $view->getRequiredHandlePHIDs();
$handles = $this->loadViewerHandles($phids);
$view->setHandles($handles);
-
- $panel = new AphrontPanelView();
- $panel->setHeader($header);
- $panel->appendChild($view);
- $panel->setNoBackground();
-
- $panel->appendChild($pager);
-
- return $panel;
+ return $view->buildList();
}
-
}
diff --git a/src/applications/audit/query/PhabricatorAuditCommitQuery.php b/src/applications/audit/query/PhabricatorAuditCommitQuery.php
deleted file mode 100644
--- a/src/applications/audit/query/PhabricatorAuditCommitQuery.php
+++ /dev/null
@@ -1,220 +0,0 @@
-<?php
-
-final class PhabricatorAuditCommitQuery {
-
- private $offset;
- private $limit;
-
- private $commitPHIDs;
- private $authorPHIDs;
- private $packagePHIDs;
- private $identifiers = array();
-
- private $needCommitData;
- private $needAudits;
-
- private $status = 'status-any';
- const STATUS_ANY = 'status-any';
- const STATUS_OPEN = 'status-open';
- const STATUS_CONCERN = 'status-concern';
-
- public function withAuthorPHIDs(array $author_phids) {
- $this->authorPHIDs = $author_phids;
- return $this;
- }
-
- public function withPackagePHIDs(array $phids) {
- $this->packagePHIDs = $phids;
- return $this;
- }
-
- public function withCommitPHIDs(array $phids) {
- $this->commitPHIDs = $phids;
- return $this;
- }
-
- public function withStatus($status) {
- $this->status = $status;
- return $this;
- }
-
- public function withIdentifiers($repository_id, array $identifiers) {
- $this->identifiers[] = array($repository_id, $identifiers);
- return $this;
- }
-
- public function needCommitData($need) {
- $this->needCommitData = $need;
- return $this;
- }
-
- public function needAudits($need) {
- $this->needAudits = $need;
- return $this;
- }
-
- public function setOffset($offset) {
- $this->offset = $offset;
- return $this;
- }
-
- public function setLimit($limit) {
- $this->limit = $limit;
- return $this;
- }
-
- public function execute() {
-
- $table = new PhabricatorRepositoryCommit();
- $conn_r = $table->establishConnection('r');
-
- $join = $this->buildJoinClause($conn_r);
- $where = $this->buildWhereClause($conn_r);
- $order = $this->buildOrderClause($conn_r);
- $limit = $this->buildLimitClause($conn_r);
-
- $data = queryfx_all(
- $conn_r,
- 'SELECT c.* FROM %T c %Q %Q %Q %Q',
- $table->getTableName(),
- $join,
- $where,
- $order,
- $limit);
-
- $commits = $table->loadAllFromArray($data);
-
- if ($this->needCommitData && $commits) {
- $data = id(new PhabricatorRepositoryCommitData())->loadAllWhere(
- 'commitID in (%Ld)',
- mpull($commits, 'getID'));
- $data = mpull($data, null, 'getCommitID');
- foreach ($commits as $commit) {
- if (idx($data, $commit->getID())) {
- $commit->attachCommitData($data[$commit->getID()]);
- } else {
- $commit->attachCommitData(new PhabricatorRepositoryCommitData());
- }
- }
- }
-
- if ($this->needAudits && $commits) {
- $audits = id(new PhabricatorAuditComment())->loadAllWhere(
- 'targetPHID in (%Ls)',
- mpull($commits, 'getPHID'));
- $audits = mgroup($audits, 'getTargetPHID');
- foreach ($commits as $commit) {
- $commit->attachAudits(idx($audits, $commit->getPHID(), array()));
- }
- }
-
- return $commits;
-
- }
-
- private function buildOrderClause($conn_r) {
- return 'ORDER BY c.epoch DESC';
- }
-
- private function buildJoinClause($conn_r) {
- $join = array();
-
- if ($this->packagePHIDs) {
- $join[] = qsprintf(
- $conn_r,
- 'JOIN %T req ON c.phid = req.commitPHID',
- id(new PhabricatorRepositoryAuditRequest())->getTableName());
- }
-
- if ($join) {
- $join = implode(' ', $join);
- } else {
- $join = '';
- }
-
- return $join;
- }
-
- private function buildWhereClause($conn_r) {
- $where = array();
-
- if ($this->commitPHIDs) {
- $where[] = qsprintf(
- $conn_r,
- 'c.phid IN (%Ls)',
- $this->commitPHIDs);
- }
-
- if ($this->authorPHIDs) {
- $where[] = qsprintf(
- $conn_r,
- 'c.authorPHID IN (%Ls)',
- $this->authorPHIDs);
- }
-
- if ($this->packagePHIDs) {
- $where[] = qsprintf(
- $conn_r,
- 'req.auditorPHID in (%Ls)',
- $this->packagePHIDs);
- }
-
- if ($this->identifiers) {
- $clauses = array();
- foreach ($this->identifiers as $spec) {
- list($repository_id, $identifiers) = $spec;
- if ($identifiers) {
- $clauses[] = qsprintf(
- $conn_r,
- 'c.repositoryID = %d AND c.commitIdentifier IN (%Ls)',
- $repository_id,
- $identifiers);
- }
- }
- if ($clauses) {
- $where[] = '('.implode(') OR (', $clauses).')';
- }
- }
-
- $status = $this->status;
- switch ($status) {
- case self::STATUS_CONCERN:
- $where[] = qsprintf(
- $conn_r,
- 'c.auditStatus = %d',
- PhabricatorAuditCommitStatusConstants::CONCERN_RAISED);
- break;
- case self::STATUS_OPEN:
- $where[] = qsprintf(
- $conn_r,
- 'c.auditStatus IN (%Ld)',
- PhabricatorAuditCommitStatusConstants::getOpenStatusConstants());
- break;
- case self::STATUS_ANY:
- break;
- default:
- throw new Exception("Unknown status '{$status}'!");
- }
-
- if ($where) {
- $where = 'WHERE ('.implode(') AND (', $where).')';
- } else {
- $where = '';
- }
-
- return $where;
- }
-
- private function buildLimitClause($conn_r) {
- if ($this->limit && $this->offset) {
- return qsprintf($conn_r, 'LIMIT %d, %d', $this->offset, $this->limit);
- } else if ($this->limit) {
- return qsprintf($conn_r, 'LIMIT %d', $this->limit);
- } else if ($this->offset) {
- return qsprintf($conn_r, 'LIMIT %d, %d', $this->offset, PHP_INT_MAX);
- } else {
- return '';
- }
- }
-
-}
diff --git a/src/applications/audit/query/PhabricatorAuditQuery.php b/src/applications/audit/query/PhabricatorAuditQuery.php
--- a/src/applications/audit/query/PhabricatorAuditQuery.php
+++ b/src/applications/audit/query/PhabricatorAuditQuery.php
@@ -1,17 +1,15 @@
<?php
-final class PhabricatorAuditQuery {
+final class PhabricatorAuditQuery
+ extends PhabricatorCursorPagedPolicyAwareQuery {
private $ids;
- private $offset;
- private $limit;
-
private $auditorPHIDs;
private $commitPHIDs;
+ private $commitAuthorPHIDs;
private $repositoryPHIDs;
- private $needCommits;
private $needCommitData;
private $awaitingUser;
@@ -33,6 +31,11 @@
return $this;
}
+ public function withCommitAuthorPHIDs(array $author_phids) {
+ $this->commitAuthorPHIDs = $author_phids;
+ return $this;
+ }
+
public function withAuditorPHIDs(array $auditor_phids) {
$this->auditorPHIDs = $auditor_phids;
return $this;
@@ -53,27 +56,12 @@
return $this;
}
- public function setOffset($offset) {
- $this->offset = $offset;
- return $this;
- }
-
- public function setLimit($limit) {
- $this->limit = $limit;
- return $this;
- }
-
- public function needCommits($need) {
- $this->needCommits = $need;
- return $this;
- }
-
public function needCommitData($need) {
$this->needCommitData = $need;
return $this;
}
- public function execute() {
+ public function loadPage() {
$table = new PhabricatorRepositoryAuditRequest();
$conn_r = $table->establishConnection('r');
@@ -91,19 +79,33 @@
$order,
$limit);
- $audits = $table->loadAllFromArray($data);
-
- if ($this->needCommits || $this->needCommitData) {
- $phids = mpull($audits, 'getCommitPHID', 'getCommitPHID');
- if ($phids) {
- $cquery = new PhabricatorAuditCommitQuery();
- $cquery->needCommitData($this->needCommitData);
- $cquery->withCommitPHIDs(array_keys($phids));
- $commits = $cquery->execute();
- } else {
- $commits = array();
+ // This will be set to the correct data in willFilterPage *unless* there
+ // are no audits. This is the correct value in that case.
+ $this->commits = array();
+
+ return $table->loadAllFromArray($data);
+ }
+
+ public function willFilterPage(array $audits) {
+ if ($audits) {
+ $audit_dict = mgroup($audits, 'getCommitPHID');
+ $commit_phids = array_keys($audit_dict);
+ $commits = id(new DiffusionCommitQuery())
+ ->setViewer($this->getViewer())
+ ->needCommitData($this->needCommitData)
+ ->withPHIDs($commit_phids)
+ ->execute();
+ } else {
+ $audit_dict = array();
+ $commits = array();
+ }
+ $this->commits = $commits;
+
+ $commits = mpull($commits, null, 'getPHID');
+ foreach ($audit_dict as $commit_phid => $audits_for_commit) {
+ foreach ($audits_for_commit as $audit) {
+ $audit->attachCommit($commits[$commit_phid]);
}
- $this->commits = $commits;
}
return $audits;
@@ -111,9 +113,7 @@
public function getCommits() {
if ($this->commits === null) {
- throw new Exception(
- "Call needCommits() or needCommitData() and then execute() the query ".
- "before calling getCommits()!");
+ throw new Exception('Call execute() before getCommits!');
}
return $this->commits;
@@ -135,9 +135,12 @@
$this->awaitingUser->getPHID());
}
- if ($this->awaitingUser || $this->repositoryPHIDs) {
+ if ($this->awaitingUser ||
+ $this->repositoryPHIDs ||
+ $this->commitAuthorPHIDs) {
// Join the commit table so we can get the commit author or repository id
- // into the result row and filter by it later.
+ // into the result row and filter by it later -OR- so we can select on
+ // commit author phids
$joins[] = qsprintf(
$conn_r,
'JOIN %T commit ON req.commitPHID = commit.phid',
@@ -176,6 +179,13 @@
$this->commitPHIDs);
}
+ if ($this->commitAuthorPHIDs) {
+ $where[] = qsprintf(
+ $conn_r,
+ 'commit.authorPHID in (%Ls)',
+ $this->commitAuthorPHIDs);
+ }
+
if ($this->auditorPHIDs) {
$where[] = qsprintf(
$conn_r,
@@ -234,30 +244,12 @@
"Unknown audit status '{$status}'! Valid statuses are: ".
implode(', ', $valid));
}
-
- if ($where) {
- $where = 'WHERE ('.implode(') AND (', $where).')';
- } else {
- $where = '';
- }
-
- return $where;
- }
-
- private function buildLimitClause($conn_r) {
- if ($this->limit && $this->offset) {
- return qsprintf($conn_r, 'LIMIT %d, %d', $this->offset, $this->limit);
- } else if ($this->limit) {
- return qsprintf($conn_r, 'LIMIT %d', $this->limit);
- } else if ($this->offset) {
- return qsprintf($conn_r, 'LIMIT %d, %d', $this->offset, PHP_INT_MAX);
- } else {
- return '';
- }
+ $where[] = $this->buildPagingClause($conn_r);
+ return $this->formatWhereClause($where);
}
- private function buildOrderClause($conn_r) {
- return 'ORDER BY req.id DESC';
+ public function getQueryApplicationClass() {
+ return 'PhabricatorApplicationAudit';
}
}
diff --git a/src/applications/audit/query/PhabricatorAuditSearchEngine.php b/src/applications/audit/query/PhabricatorAuditSearchEngine.php
new file mode 100644
--- /dev/null
+++ b/src/applications/audit/query/PhabricatorAuditSearchEngine.php
@@ -0,0 +1,182 @@
+<?php
+
+final class PhabricatorAuditSearchEngine
+ extends PhabricatorApplicationSearchEngine {
+
+ public function buildSavedQueryFromRequest(AphrontRequest $request) {
+ $saved = new PhabricatorSavedQuery();
+
+ $saved->setParameter(
+ 'userPHIDs',
+ $this->readUsersFromRequest($request, 'userPHIDs'));
+
+ $saved->setParameter(
+ 'commitAuthorPHIDs',
+ $this->readUsersFromRequest($request, 'commitAuthorPHIDs'));
+
+ $saved->setParameter(
+ 'auditStatus',
+ $request->getStr('auditStatus'));
+
+ $saved->setParameter(
+ 'projectPHIDs',
+ $this->readPHIDsFromRequest($request, 'projectPHIDs'));
+
+ $saved->setParameter(
+ 'packagePHIDs',
+ $this->readPHIDsFromRequest($request, 'packagePHIDs'));
+
+ $saved->setParameter(
+ 'repositoryPHIDs',
+ $this->readPHIDsFromRequest($request, 'repositoryPHIDs'));
+
+ // -- TODO - T4173 - file location
+
+ return $saved;
+ }
+
+ public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
+ $query = id(new PhabricatorAuditQuery())
+ ->needCommitData(true);
+
+ $user_auditor_phids = $saved->getParameter('userPHIDs', array());
+ $project_auditor_phids = $saved->getParameter('projectPHIDs', array());
+ $package_auditor_phids = $saved->getParameter('packagePHIDs', array());
+ $auditor_phids = array_mergev(array(
+ $user_auditor_phids,
+ $project_auditor_phids,
+ $package_auditor_phids));
+ if ($auditor_phids) {
+ $query->withAuditorPHIDs($auditor_phids);
+ }
+
+ $commit_author_phids = $saved->getParameter('commitAuthorPHIDs', array());
+ if ($commit_author_phids) {
+ $query->withCommitAuthorPHIDs($commit_author_phids);
+ }
+
+ $audit_status = $saved->getParameter('auditStatus', null);
+ if ($audit_status) {
+ $query->withStatus($audit_status);
+ }
+
+ $awaiting_user_phid = $saved->getParameter('awaitingUserPHID', null);
+ if ($awaiting_user_phid) {
+ // This is used only for the built-in "needs attention" filter,
+ // so cheat and just use the already-loaded viewer rather than reloading
+ // it.
+ $query->withAwaitingUser($this->requireViewer());
+ }
+
+ return $query;
+ }
+
+ public function buildSearchForm(
+ AphrontFormView $form,
+ PhabricatorSavedQuery $saved) {
+
+ $user_auditor_phids = $saved->getParameter('userPHIDs', array());
+ $project_auditor_phids = $saved->getParameter('projectPHIDs', array());
+ $package_auditor_phids = $saved->getParameter('packagePHIDs', array());
+ $commit_author_phids = $saved->getParameter(
+ 'commitAuthorPHIDs',
+ array());
+ $audit_status = $saved->getParameter('auditStatus', null);
+
+ $phids = array_mergev(
+ array(
+ $user_auditor_phids,
+ $project_auditor_phids,
+ $package_auditor_phids,
+ $commit_author_phids
+ ));
+
+ $handles = id(new PhabricatorHandleQuery())
+ ->setViewer($this->requireViewer())
+ ->withPHIDs($phids)
+ ->execute();
+
+ $form
+ ->appendChild(
+ id(new AphrontFormTokenizerControl())
+ ->setDatasource('/typeahead/common/users/')
+ ->setName('userPHIDs')
+ ->setLabel(pht('User Auditors'))
+ ->setValue(array_select_keys($handles, $user_auditor_phids)))
+ ->appendChild(
+ id(new AphrontFormTokenizerControl())
+ ->setDatasource('/typeahead/common/projects/')
+ ->setName('projectPHIDs')
+ ->setLabel(pht('Project Auditors'))
+ ->setValue(array_select_keys($handles, $project_auditor_phids)))
+ ->appendChild(
+ id(new AphrontFormTokenizerControl())
+ ->setDatasource('/typeahead/common/packages/')
+ ->setName('packagePHIDs')
+ ->setLabel(pht('Package Auditors'))
+ ->setValue(array_select_keys($handles, $package_auditor_phids)))
+ ->appendChild(
+ id(new AphrontFormTokenizerControl())
+ ->setDatasource('/typeahead/common/users/')
+ ->setName('commitAuthorPHIDs')
+ ->setLabel(pht('Commit Authors'))
+ ->setValue(array_select_keys($handles, $commit_author_phids)))
+ ->appendChild(
+ id(new AphrontFormSelectControl())
+ ->setName('auditStatus')
+ ->setLabel(pht('Audit Status'))
+ ->setOptions($this->getAuditStatusOptions())
+ ->setValue($audit_status));
+ }
+
+ protected function getURI($path) {
+ return '/audit/'.$path;
+ }
+
+ public function getBuiltinQueryNames() {
+ $names = array();
+
+ if ($this->requireViewer()->isLoggedIn()) {
+ $names['need_attention'] = pht('Need Attention');
+ }
+ $names['open'] = pht('Open Audits');
+
+ $names['all'] = pht('All Commits');
+
+ return $names;
+ }
+
+ public function buildSavedQueryFromBuiltin($query_key) {
+ $query = $this->newSavedQuery();
+ $query->setQueryKey($query_key);
+ $viewer = $this->requireViewer();
+
+ switch ($query_key) {
+ case 'all':
+ return $query;
+ case 'open':
+ $query->setParameter('auditStatus', PhabricatorAuditQuery::STATUS_OPEN);
+ return $query;
+ case 'need_attention':
+ $query->setParameter('awaitingUserPHID', $viewer->getPHID());
+ $query->setParameter(
+ 'auditStatus',
+ PhabricatorAuditQuery::STATUS_OPEN);
+ $query->setParameter(
+ 'auditorPHIDs',
+ PhabricatorAuditCommentEditor::loadAuditPHIDsForUser($viewer));
+ return $query;
+ }
+
+ return parent::buildSavedQueryFromBuiltin($query_key);
+ }
+
+ private function getAuditStatusOptions() {
+ return array(
+ PhabricatorAuditQuery::STATUS_ANY => pht('Any'),
+ PhabricatorAuditQuery::STATUS_OPEN => pht('Open'),
+ PhabricatorAuditQuery::STATUS_CONCERN => pht('Concern Raised'),
+ );
+ }
+
+}
diff --git a/src/applications/audit/view/PhabricatorAuditListView.php b/src/applications/audit/view/PhabricatorAuditListView.php
--- a/src/applications/audit/view/PhabricatorAuditListView.php
+++ b/src/applications/audit/view/PhabricatorAuditListView.php
@@ -108,11 +108,16 @@
}
public function render() {
+ $list = $this->buildList();
+ $list->setCards(true);
+ $list->setFlush(true);
+ return $list->render();
+ }
+
+ public function buildList() {
$rowc = array();
$list = new PHUIObjectItemListView();
- $list->setCards(true);
- $list->setFlush(true);
foreach ($this->audits as $audit) {
$commit_phid = $audit->getCommitPHID();
$committed = null;
@@ -159,7 +164,7 @@
$list->setNoDataString($this->noDataString);
}
- return $list->render();
+ return $list;
}
}
diff --git a/src/applications/diffusion/controller/DiffusionCommitController.php b/src/applications/diffusion/controller/DiffusionCommitController.php
--- a/src/applications/diffusion/controller/DiffusionCommitController.php
+++ b/src/applications/diffusion/controller/DiffusionCommitController.php
@@ -71,6 +71,7 @@
->setNavigationMarker(true);
$audit_requests = id(new PhabricatorAuditQuery())
+ ->setViewer($user)
->withCommitPHIDs(array($commit->getPHID()))
->execute();
$this->auditAuthorityPHIDs =
diff --git a/src/applications/diffusion/query/filecontent/DiffusionFileContentQuery.php b/src/applications/diffusion/query/filecontent/DiffusionFileContentQuery.php
--- a/src/applications/diffusion/query/filecontent/DiffusionFileContentQuery.php
+++ b/src/applications/diffusion/query/filecontent/DiffusionFileContentQuery.php
@@ -97,10 +97,10 @@
$repository = $this->getRequest()->getRepository();
- $commits = id(new PhabricatorAuditCommitQuery())
- ->withIdentifiers(
- $repository->getID(),
- array_unique($line_rev_dict))
+ $commits = id(new DiffusionCommitQuery())
+ ->setViewer($this->getViewer())
+ ->withDefaultRepository($repository)
+ ->withIdentifiers(array_unique($line_rev_dict))
->execute();
foreach ($commits as $commit) {
@@ -145,6 +145,10 @@
return $this;
}
+ public function getViewer() {
+ return $this->viewer;
+ }
+
protected function processRevList(array $rev_list) {
return $rev_list;
}
diff --git a/src/applications/home/controller/PhabricatorHomeMainController.php b/src/applications/home/controller/PhabricatorHomeMainController.php
--- a/src/applications/home/controller/PhabricatorHomeMainController.php
+++ b/src/applications/home/controller/PhabricatorHomeMainController.php
@@ -413,12 +413,13 @@
$phids = PhabricatorAuditCommentEditor::loadAuditPHIDsForUser($user);
- $query = new PhabricatorAuditQuery();
- $query->withAuditorPHIDs($phids);
- $query->withStatus(PhabricatorAuditQuery::STATUS_OPEN);
- $query->withAwaitingUser($user);
- $query->needCommitData(true);
- $query->setLimit(10);
+ $query = id(new PhabricatorAuditQuery())
+ ->setViewer($user)
+ ->withAuditorPHIDs($phids)
+ ->withStatus(PhabricatorAuditQuery::STATUS_OPEN)
+ ->withAwaitingUser($user)
+ ->needCommitData(true)
+ ->setLimit(10);
$audits = $query->execute();
$commits = $query->getCommits();
@@ -454,13 +455,15 @@
$phids = array($user->getPHID());
- $query = new PhabricatorAuditCommitQuery();
- $query->withAuthorPHIDs($phids);
- $query->withStatus(PhabricatorAuditCommitQuery::STATUS_CONCERN);
- $query->needCommitData(true);
- $query->setLimit(10);
+ $query = id(new PhabricatorAuditQuery())
+ ->setViewer($user)
+ ->withCommitAuthorPHIDs($phids)
+ ->withStatus(PhabricatorAuditQuery::STATUS_CONCERN)
+ ->needCommitData(true)
+ ->setLimit(10);
- $commits = $query->execute();
+ $audits = $query->execute();
+ $commits = $query->getCommits();
if (!$commits) {
return $this->renderMinipanel(
diff --git a/src/applications/owners/controller/PhabricatorOwnersDetailController.php b/src/applications/owners/controller/PhabricatorOwnersDetailController.php
--- a/src/applications/owners/controller/PhabricatorOwnersDetailController.php
+++ b/src/applications/owners/controller/PhabricatorOwnersDetailController.php
@@ -145,13 +145,13 @@
'phid' => $package->getPHID(),
));
- $attention_query = id(new PhabricatorAuditCommitQuery())
- ->withPackagePHIDs(array($package->getPHID()))
- ->withStatus(PhabricatorAuditCommitQuery::STATUS_CONCERN)
+ $attention_query = id(new PhabricatorAuditQuery())
+ ->withAuditorPHIDs(array($package->getPHID()))
+ ->withStatus(PhabricatorAuditQuery::STATUS_CONCERN)
->needCommitData(true)
- ->needAudits(true)
->setLimit(10);
- $attention_commits = $attention_query->execute();
+ $attention_audits = $attention_query->execute();
+ $attention_commits = $attention_query->getCommits();
if ($attention_commits) {
$view = new PhabricatorAuditCommitListView();
$view->setUser($user);
@@ -170,12 +170,12 @@
);
}
- $all_query = id(new PhabricatorAuditCommitQuery())
- ->withPackagePHIDs(array($package->getPHID()))
+ $all_query = id(new PhabricatorAuditQuery())
+ ->withAuditorPHIDs(array($package->getPHID()))
->needCommitData(true)
- ->needAudits(true)
->setLimit(100);
- $all_commits = $all_query->execute();
+ $all_audits = $all_query->execute();
+ $all_commits = $all_query->getCommits();
$view = new PhabricatorAuditCommitListView();
$view->setUser($user);
diff --git a/src/applications/repository/storage/PhabricatorRepositoryAuditRequest.php b/src/applications/repository/storage/PhabricatorRepositoryAuditRequest.php
--- a/src/applications/repository/storage/PhabricatorRepositoryAuditRequest.php
+++ b/src/applications/repository/storage/PhabricatorRepositoryAuditRequest.php
@@ -1,12 +1,16 @@
<?php
-final class PhabricatorRepositoryAuditRequest extends PhabricatorRepositoryDAO {
+final class PhabricatorRepositoryAuditRequest
+ extends PhabricatorRepositoryDAO
+ implements PhabricatorPolicyInterface {
protected $auditorPHID;
protected $commitPHID;
protected $auditReasons = array();
protected $auditStatus;
+ private $commit = self::ATTACHABLE;
+
public function getConfiguration() {
return array(
self::CONFIG_TIMESTAMPS => false,
@@ -21,4 +25,35 @@
return (phid_get_type($this->getAuditorPHID()) == $user_type);
}
+ public function attachCommit(PhabricatorRepositoryCommit $commit) {
+ $this->commit = $commit;
+ return $this;
+ }
+
+ public function getCommit() {
+ return $this->assertAttached($this->commit);
+ }
+
+
+/* -( PhabricatorPolicyInterface )----------------------------------------- */
+
+
+ public function getCapabilities() {
+ return array(
+ PhabricatorPolicyCapability::CAN_VIEW,
+ );
+ }
+
+ public function getPolicy($capability) {
+ return $this->getCommit()->getPolicy($capability);
+ }
+
+ public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
+ return $this->getCommit()->hasAutomaticCapability($capability, $viewer);
+ }
+
+ public function describeAutomaticCapability($capability) {
+ return pht(
+ 'This audit is attached to a commit, and inherits its policies.');
+ }
}

File Metadata

Mime Type
text/plain
Expires
Sun, Mar 16, 6:37 PM (5 d, 20 h ago)
Storage Engine
amazon-s3
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
phabricator/secure/x7/2p/dfnqo7hx6ptjms2m
Default Alt Text
D8805.id20900.diff (45 KB)

Event Timeline