1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 00:42:41 +01:00

Fix packages(project) to work properly and add it to "MailableFunctionDatasource"

Summary:
Ref T13210. See PHI937. This function datasource isn't quite implemented correctly: it doesn't resolve `package(project)` properly, since the logic only handles users.

This blames back to D14013, where it looks like `packages(..)` was added mostly as a general nice-to-have as part of a larger modernization change.

Test Plan: Ran a `packages(project)` query in Differential, got accurate results (previously: no results).

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13210

Differential Revision: https://secure.phabricator.com/D19747
This commit is contained in:
epriestley 2018-10-19 04:41:40 -07:00
parent bc6c8c0e93
commit e0dea4c486
2 changed files with 18 additions and 9 deletions

View file

@ -23,6 +23,7 @@ final class PhabricatorMetaMTAMailableFunctionDatasource
new PhabricatorProjectMembersDatasource(), new PhabricatorProjectMembersDatasource(),
new PhabricatorProjectDatasource(), new PhabricatorProjectDatasource(),
new PhabricatorOwnersPackageDatasource(), new PhabricatorOwnersPackageDatasource(),
new PhabricatorOwnersPackageOwnerDatasource(),
); );
} }

View file

@ -27,7 +27,7 @@ final class PhabricatorOwnersPackageOwnerDatasource
'packages' => array( 'packages' => array(
'name' => pht('Packages: ...'), 'name' => pht('Packages: ...'),
'arguments' => pht('owner'), 'arguments' => pht('owner'),
'summary' => pht("Find results in any of an owner's projects."), 'summary' => pht("Find results in any of an owner's packages."),
'description' => pht( 'description' => pht(
"This function allows you to find results associated with any ". "This function allows you to find results associated with any ".
"of the packages a specified user or project is an owner of. ". "of the packages a specified user or project is an owner of. ".
@ -61,18 +61,21 @@ final class PhabricatorOwnersPackageOwnerDatasource
$phids = $this->resolvePHIDs($phids); $phids = $this->resolvePHIDs($phids);
$user_phids = array(); $owner_phids = array();
foreach ($phids as $key => $phid) { foreach ($phids as $key => $phid) {
if (phid_get_type($phid) == PhabricatorPeopleUserPHIDType::TYPECONST) { switch (phid_get_type($phid)) {
$user_phids[] = $phid; case PhabricatorPeopleUserPHIDType::TYPECONST:
unset($phids[$key]); case PhabricatorProjectProjectPHIDType::TYPECONST:
$owner_phids[] = $phid;
unset($phids[$key]);
break;
} }
} }
if ($user_phids) { if ($owner_phids) {
$packages = id(new PhabricatorOwnersPackageQuery()) $packages = id(new PhabricatorOwnersPackageQuery())
->setViewer($this->getViewer()) ->setViewer($this->getViewer())
->withOwnerPHIDs($user_phids) ->withOwnerPHIDs($owner_phids)
->execute(); ->execute();
foreach ($packages as $package) { foreach ($packages as $package) {
$phids[] = $package->getPHID(); $phids[] = $package->getPHID();
@ -116,8 +119,13 @@ final class PhabricatorOwnersPackageOwnerDatasource
$usernames = array(); $usernames = array();
foreach ($phids as $key => $phid) { foreach ($phids as $key => $phid) {
if (phid_get_type($phid) != PhabricatorPeopleUserPHIDType::TYPECONST) { switch (phid_get_type($phid)) {
$usernames[$key] = $phid; case PhabricatorPeopleUserPHIDType::TYPECONST:
case PhabricatorProjectProjectPHIDType::TYPECONST:
break;
default:
$usernames[$key] = $phid;
break;
} }
} }