Changeset View
Changeset View
Standalone View
Standalone View
src/applications/audit/query/PhabricatorCommitSearchEngine.php
| <?php | <?php | ||||
| final class PhabricatorCommitSearchEngine | final class PhabricatorCommitSearchEngine | ||||
| extends PhabricatorApplicationSearchEngine { | extends PhabricatorApplicationSearchEngine { | ||||
| public function getResultTypeDescription() { | public function getResultTypeDescription() { | ||||
| return pht('Commits'); | return pht('Commits'); | ||||
| } | } | ||||
| public function getApplicationClassName() { | public function getApplicationClassName() { | ||||
| return 'PhabricatorDiffusionApplication'; | return 'PhabricatorDiffusionApplication'; | ||||
| } | } | ||||
| public function buildSavedQueryFromRequest(AphrontRequest $request) { | public function newQuery() { | ||||
| $saved = new PhabricatorSavedQuery(); | return id(new DiffusionCommitQuery()) | ||||
| $saved->setParameter( | |||||
| 'auditorPHIDs', | |||||
| $this->readPHIDsFromRequest($request, 'auditorPHIDs')); | |||||
| $saved->setParameter( | |||||
| 'commitAuthorPHIDs', | |||||
| $this->readUsersFromRequest($request, 'authors')); | |||||
| $saved->setParameter( | |||||
| 'auditStatus', | |||||
| $request->getStr('auditStatus')); | |||||
| $saved->setParameter( | |||||
| 'repositoryPHIDs', | |||||
| $this->readPHIDsFromRequest($request, 'repositoryPHIDs')); | |||||
| // -- TODO - T4173 - file location | |||||
| return $saved; | |||||
| } | |||||
| public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { | |||||
| $query = id(new DiffusionCommitQuery()) | |||||
| ->needAuditRequests(true) | ->needAuditRequests(true) | ||||
| ->needCommitData(true); | ->needCommitData(true); | ||||
| } | |||||
| $auditor_phids = $saved->getParameter('auditorPHIDs', array()); | protected function buildQueryFromParameters(array $map) { | ||||
| if ($auditor_phids) { | $query = $this->newQuery(); | ||||
| $query->withAuditorPHIDs($auditor_phids); | |||||
| if ($map['needsAuditByPHIDs']) { | |||||
| $query->withNeedsAuditByPHIDs($map['needsAuditByPHIDs']); | |||||
| } | } | ||||
| $commit_author_phids = $saved->getParameter('commitAuthorPHIDs', array()); | if ($map['auditorPHIDs']) { | ||||
| if ($commit_author_phids) { | $query->withAuditorPHIDs($map['auditorPHIDs']); | ||||
| $query->withAuthorPHIDs($commit_author_phids); | |||||
| } | } | ||||
| $audit_status = $saved->getParameter('auditStatus', null); | if ($map['commitAuthorPHIDs']) { | ||||
| if ($audit_status) { | $query->withAuthorPHIDs($map['commitAuthorPHIDs']); | ||||
| $query->withAuditStatus($audit_status); | |||||
| } | } | ||||
| $awaiting_user_phid = $saved->getParameter('awaitingUserPHID', null); | if ($map['auditStatus']) { | ||||
| if ($awaiting_user_phid) { | $query->withAuditStatus($map['auditStatus']); | ||||
| // 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->withAuditAwaitingUser($this->requireViewer()); | |||||
| } | } | ||||
| $repository_phids = $saved->getParameter('repositoryPHIDs', array()); | if ($map['repositoryPHIDs']) { | ||||
| if ($repository_phids) { | $query->withRepositoryPHIDs($map['repositoryPHIDs']); | ||||
| $query->withRepositoryPHIDs($repository_phids); | |||||
| } | } | ||||
| return $query; | return $query; | ||||
| } | } | ||||
| public function buildSearchForm( | protected function buildCustomSearchFields() { | ||||
| AphrontFormView $form, | return array( | ||||
| PhabricatorSavedQuery $saved) { | id(new PhabricatorSearchDatasourceField()) | ||||
| ->setLabel(pht('Needs Audit By')) | |||||
| $auditor_phids = $saved->getParameter('auditorPHIDs', array()); | ->setKey('needsAuditByPHIDs') | ||||
| $commit_author_phids = $saved->getParameter( | ->setAliases(array('needs', 'need')) | ||||
| 'commitAuthorPHIDs', | ->setDatasource(new DiffusionAuditorFunctionDatasource()), | ||||
| array()); | id(new PhabricatorSearchDatasourceField()) | ||||
| $audit_status = $saved->getParameter('auditStatus', null); | |||||
| $repository_phids = $saved->getParameter('repositoryPHIDs', array()); | |||||
| $form | |||||
| ->appendControl( | |||||
| id(new AphrontFormTokenizerControl()) | |||||
| ->setDatasource(new DiffusionAuditorDatasource()) | |||||
| ->setName('auditorPHIDs') | |||||
| ->setLabel(pht('Auditors')) | ->setLabel(pht('Auditors')) | ||||
| ->setValue($auditor_phids)) | ->setKey('auditorPHIDs') | ||||
| ->appendControl( | ->setAliases(array('auditor', 'auditors')) | ||||
| id(new AphrontFormTokenizerControl()) | ->setDatasource(new DiffusionAuditorFunctionDatasource()), | ||||
| ->setDatasource(new PhabricatorPeopleDatasource()) | id(new PhabricatorUsersSearchField()) | ||||
| ->setName('authors') | ->setLabel(pht('Authors')) | ||||
| ->setLabel(pht('Commit Authors')) | ->setKey('commitAuthorPHIDs') | ||||
| ->setValue($commit_author_phids)) | ->setAliases(array('author', 'authors')), | ||||
| ->appendChild( | id(new PhabricatorSearchSelectField()) | ||||
| id(new AphrontFormSelectControl()) | |||||
| ->setName('auditStatus') | |||||
| ->setLabel(pht('Audit Status')) | ->setLabel(pht('Audit Status')) | ||||
| ->setOptions($this->getAuditStatusOptions()) | ->setKey('auditStatus') | ||||
| ->setValue($audit_status)) | ->setAliases(array('status')) | ||||
| ->appendControl( | ->setOptions($this->getAuditStatusOptions()), | ||||
| id(new AphrontFormTokenizerControl()) | id(new PhabricatorSearchDatasourceField()) | ||||
| ->setLabel(pht('Repositories')) | ->setLabel(pht('Repositories')) | ||||
| ->setName('repositoryPHIDs') | ->setKey('repositoryPHIDs') | ||||
| ->setDatasource(new DiffusionRepositoryDatasource()) | ->setAliases(array('repository', 'repositories')) | ||||
| ->setValue($repository_phids)); | ->setDatasource(new DiffusionRepositoryDatasource()), | ||||
| ); | |||||
| } | } | ||||
| protected function getURI($path) { | protected function getURI($path) { | ||||
| return '/audit/'.$path; | return '/audit/'.$path; | ||||
| } | } | ||||
| protected function getBuiltinQueryNames() { | protected function getBuiltinQueryNames() { | ||||
| $names = array(); | $names = array(); | ||||
| if ($this->requireViewer()->isLoggedIn()) { | if ($this->requireViewer()->isLoggedIn()) { | ||||
| $names['need'] = pht('Need Attention'); | $names['need'] = pht('Needs Audit'); | ||||
| $names['problem'] = pht('Problem Commits'); | $names['problem'] = pht('Problem Commits'); | ||||
| } | } | ||||
| $names['open'] = pht('Open Audits'); | $names['open'] = pht('Open Audits'); | ||||
| if ($this->requireViewer()->isLoggedIn()) { | if ($this->requireViewer()->isLoggedIn()) { | ||||
| $names['authored'] = pht('Authored Commits'); | $names['authored'] = pht('Authored Commits'); | ||||
| } | } | ||||
| $names['all'] = pht('All Commits'); | $names['all'] = pht('All Commits'); | ||||
| return $names; | return $names; | ||||
| } | } | ||||
| public function buildSavedQueryFromBuiltin($query_key) { | public function buildSavedQueryFromBuiltin($query_key) { | ||||
| $query = $this->newSavedQuery(); | $query = $this->newSavedQuery(); | ||||
| $query->setQueryKey($query_key); | $query->setQueryKey($query_key); | ||||
| $viewer = $this->requireViewer(); | $viewer = $this->requireViewer(); | ||||
| $viewer_phid = $viewer->getPHID(); | |||||
| $status_open = DiffusionCommitQuery::AUDIT_STATUS_OPEN; | |||||
| switch ($query_key) { | switch ($query_key) { | ||||
| case 'all': | case 'all': | ||||
| return $query; | return $query; | ||||
| case 'open': | case 'open': | ||||
| $query->setParameter( | $query->setParameter('auditStatus', $status_open); | ||||
| 'auditStatus', | |||||
| DiffusionCommitQuery::AUDIT_STATUS_OPEN); | |||||
| return $query; | return $query; | ||||
| case 'need': | case 'need': | ||||
| $query->setParameter('awaitingUserPHID', $viewer->getPHID()); | $needs_tokens = array( | ||||
| $query->setParameter( | $viewer_phid, | ||||
| 'auditStatus', | 'projects('.$viewer_phid.')', | ||||
| DiffusionCommitQuery::AUDIT_STATUS_OPEN); | 'packages('.$viewer_phid.')', | ||||
| $query->setParameter( | ); | ||||
| 'auditorPHIDs', | |||||
| PhabricatorAuditCommentEditor::loadAuditPHIDsForUser($viewer)); | $query->setParameter('needsAuditByPHIDs', $needs_tokens); | ||||
| $query->setParameter('auditStatus', $status_open); | |||||
| return $query; | return $query; | ||||
| case 'authored': | case 'authored': | ||||
| $query->setParameter('commitAuthorPHIDs', array($viewer->getPHID())); | $query->setParameter('commitAuthorPHIDs', array($viewer->getPHID())); | ||||
| return $query; | return $query; | ||||
| case 'problem': | case 'problem': | ||||
| $query->setParameter('commitAuthorPHIDs', array($viewer->getPHID())); | $query->setParameter('commitAuthorPHIDs', array($viewer->getPHID())); | ||||
| $query->setParameter( | $query->setParameter( | ||||
| 'auditStatus', | 'auditStatus', | ||||
| ▲ Show 20 Lines • Show All 53 Lines • Show Last 20 Lines | |||||