2013-08-15 00:38:52 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class ReleephRequestSearchEngine
|
|
|
|
extends PhabricatorApplicationSearchEngine {
|
|
|
|
|
|
|
|
private $branch;
|
|
|
|
private $baseURI;
|
|
|
|
|
|
|
|
public function setBranch(ReleephBranch $branch) {
|
|
|
|
$this->branch = $branch;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getBranch() {
|
|
|
|
return $this->branch;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setBaseURI($base_uri) {
|
|
|
|
$this->baseURI = $base_uri;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
|
|
|
$saved = new PhabricatorSavedQuery();
|
|
|
|
|
|
|
|
$saved->setParameter('status', $request->getStr('status'));
|
|
|
|
$saved->setParameter('severity', $request->getStr('severity'));
|
Allow construction of ApplicationSearch queries with GET
Summary:
Ref T3775 (discussion here). Ref T2625.
T3775 presents two problems:
# Existing tools which linked to `/differential/active/epriestley/` (that is, put a username in the URL) can't generate search links now.
# Humans can't edit the URL anymore, either.
I think (1) is an actual issue, and this fixes it. I think (2) is pretty fluff, and this doesn't really try to fix it, although it probably improves it.
The fix for (1) is:
- Provide a helper to read a parameter containing either a list of user PHIDs or a list of usernames, so `/?users[]=PHID-USER-xyz` (from a tokenizer) and `/?users=alincoln,htaft` (from an external program) are equivalent inputs.
- Rename all the form parameters to be more digestable (`authorPHIDs` -> `authors`). Almost all of them were in this form already anyway. This just gives us `?users=alincoln` instead of `userPHIDs=alincoln`.
- Inside ApplicationSearch, if a request has no query associated with it but does have query parameters, build a query from the request instead of issuing the user's default query. Basically, this means that `/differential/` runs the default query, while `/differential/?users=x` runs a custom query.
Test Plan: {F56612}
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T2625, T3775
Differential Revision: https://secure.phabricator.com/D6840
2013-08-29 20:52:29 +02:00
|
|
|
$saved->setParameter(
|
|
|
|
'requestorPHIDs',
|
|
|
|
$this->readUsersFromRequest($request, 'requestors'));
|
2013-08-15 00:38:52 +02:00
|
|
|
|
|
|
|
return $saved;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
|
|
|
$query = id(new ReleephRequestQuery())
|
|
|
|
->withBranchIDs(array($this->getBranch()->getID()));
|
|
|
|
|
|
|
|
$status = $saved->getParameter('status');
|
|
|
|
$status = idx($this->getStatusValues(), $status);
|
|
|
|
if ($status) {
|
|
|
|
$query->withStatus($status);
|
|
|
|
}
|
|
|
|
|
|
|
|
$severity = $saved->getParameter('severity');
|
|
|
|
if ($severity) {
|
|
|
|
$query->withSeverities(array($severity));
|
|
|
|
}
|
|
|
|
|
|
|
|
$requestor_phids = $saved->getParameter('requestorPHIDs');
|
|
|
|
if ($requestor_phids) {
|
|
|
|
$query->withRequestorPHIDs($requestor_phids);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildSearchForm(
|
|
|
|
AphrontFormView $form,
|
|
|
|
PhabricatorSavedQuery $saved_query) {
|
|
|
|
|
|
|
|
$phids = $saved_query->getParameter('requestorPHIDs', array());
|
2013-09-11 21:27:28 +02:00
|
|
|
$handles = id(new PhabricatorHandleQuery())
|
2013-08-15 00:38:52 +02:00
|
|
|
->setViewer($this->requireViewer())
|
2013-09-11 21:27:28 +02:00
|
|
|
->withPHIDs($phids)
|
|
|
|
->execute();
|
2013-08-15 00:38:52 +02:00
|
|
|
$requestor_tokens = mpull($handles, 'getFullName', 'getPHID');
|
|
|
|
|
|
|
|
$form
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSelectControl())
|
|
|
|
->setName('status')
|
|
|
|
->setLabel(pht('Status'))
|
|
|
|
->setValue($saved_query->getParameter('status'))
|
|
|
|
->setOptions($this->getStatusOptions()))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSelectControl())
|
|
|
|
->setName('severity')
|
|
|
|
->setLabel(pht('Severity'))
|
|
|
|
->setValue($saved_query->getParameter('severity'))
|
|
|
|
->setOptions($this->getSeverityOptions()))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTokenizerControl())
|
|
|
|
->setDatasource('/typeahead/common/users/')
|
Allow construction of ApplicationSearch queries with GET
Summary:
Ref T3775 (discussion here). Ref T2625.
T3775 presents two problems:
# Existing tools which linked to `/differential/active/epriestley/` (that is, put a username in the URL) can't generate search links now.
# Humans can't edit the URL anymore, either.
I think (1) is an actual issue, and this fixes it. I think (2) is pretty fluff, and this doesn't really try to fix it, although it probably improves it.
The fix for (1) is:
- Provide a helper to read a parameter containing either a list of user PHIDs or a list of usernames, so `/?users[]=PHID-USER-xyz` (from a tokenizer) and `/?users=alincoln,htaft` (from an external program) are equivalent inputs.
- Rename all the form parameters to be more digestable (`authorPHIDs` -> `authors`). Almost all of them were in this form already anyway. This just gives us `?users=alincoln` instead of `userPHIDs=alincoln`.
- Inside ApplicationSearch, if a request has no query associated with it but does have query parameters, build a query from the request instead of issuing the user's default query. Basically, this means that `/differential/` runs the default query, while `/differential/?users=x` runs a custom query.
Test Plan: {F56612}
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T2625, T3775
Differential Revision: https://secure.phabricator.com/D6840
2013-08-29 20:52:29 +02:00
|
|
|
->setName('requestors')
|
2013-08-15 00:38:52 +02:00
|
|
|
->setLabel(pht('Requestors'))
|
|
|
|
->setValue($requestor_tokens));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getURI($path) {
|
|
|
|
return $this->baseURI.$path;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getBuiltinQueryNames() {
|
|
|
|
$names = array(
|
|
|
|
'open' => pht('Open Requests'),
|
|
|
|
'all' => pht('All Requests'),
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($this->requireViewer()->isLoggedIn()) {
|
|
|
|
$names['requested'] = pht('Requested');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $names;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildSavedQueryFromBuiltin($query_key) {
|
|
|
|
|
|
|
|
$query = $this->newSavedQuery();
|
|
|
|
$query->setQueryKey($query_key);
|
|
|
|
|
|
|
|
switch ($query_key) {
|
|
|
|
case 'open':
|
|
|
|
return $query->setParameter('status', 'open');
|
|
|
|
case 'all':
|
|
|
|
return $query;
|
|
|
|
case 'requested':
|
|
|
|
return $query->setParameter(
|
|
|
|
'requestorPHIDs',
|
|
|
|
array($this->requireViewer()->getPHID()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::buildSavedQueryFromBuiltin($query_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getStatusOptions() {
|
|
|
|
return array(
|
|
|
|
'' => pht('(All Requests)'),
|
|
|
|
'open' => pht('Open Requests'),
|
|
|
|
'requested' => pht('Pull Requested'),
|
|
|
|
'needs-pull' => pht('Needs Pull'),
|
|
|
|
'rejected' => pht('Rejected'),
|
|
|
|
'abandoned' => pht('Abandoned'),
|
|
|
|
'pulled' => pht('Pulled'),
|
|
|
|
'needs-revert' => pht('Needs Revert'),
|
|
|
|
'reverted' => pht('Reverted'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getStatusValues() {
|
|
|
|
return array(
|
|
|
|
'open' => ReleephRequestQuery::STATUS_OPEN,
|
|
|
|
'requested' => ReleephRequestQuery::STATUS_REQUESTED,
|
|
|
|
'needs-pull' => ReleephRequestQuery::STATUS_NEEDS_PULL,
|
|
|
|
'rejected' => ReleephRequestQuery::STATUS_REJECTED,
|
|
|
|
'abandoned' => ReleephRequestQuery::STATUS_ABANDONED,
|
|
|
|
'pulled' => ReleephRequestQuery::STATUS_PULLED,
|
|
|
|
'needs-revert' => ReleephRequestQuery::STATUS_NEEDS_REVERT,
|
|
|
|
'reverted' => ReleephRequestQuery::STATUS_REVERTED,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getSeverityOptions() {
|
2013-08-28 22:06:29 +02:00
|
|
|
if (ReleephDefaultFieldSelector::isFacebook()) {
|
|
|
|
return array(
|
|
|
|
'' => pht('(All Severities)'),
|
|
|
|
11 => 'HOTFIX',
|
|
|
|
12 => 'PIGGYBACK',
|
|
|
|
13 => 'RELEASE',
|
|
|
|
14 => 'DAILY',
|
|
|
|
15 => 'PARKING',
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return array(
|
|
|
|
'' => pht('(All Severities)'),
|
|
|
|
ReleephSeverityFieldSpecification::HOTFIX => pht('Hotfix'),
|
|
|
|
ReleephSeverityFieldSpecification::RELEASE => pht('Release'),
|
|
|
|
);
|
|
|
|
}
|
2013-08-15 00:38:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|