mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 22:10:55 +01:00
Further modernize OwnersPackageQuery
Summary: Ref T8320. - Add needOwners(). - Split withOwnerPHIDs() [exact owners] and withAuthorityPHIDs() [indirect authority] apart. - Restore searching by path. Test Plan: Browsed pacakges, edited packages, edited paths. Reviewers: chad Reviewed By: chad Maniphest Tasks: T8320 Differential Revision: https://secure.phabricator.com/D13922
This commit is contained in:
parent
f5ea5ba9fe
commit
6cfeb9e540
7 changed files with 138 additions and 40 deletions
|
@ -20,7 +20,7 @@ final class PhabricatorAuditCommentEditor extends PhabricatorEditor {
|
||||||
|
|
||||||
$owned_packages = id(new PhabricatorOwnersPackageQuery())
|
$owned_packages = id(new PhabricatorOwnersPackageQuery())
|
||||||
->setViewer($user)
|
->setViewer($user)
|
||||||
->withOwnerPHIDs(array($user->getPHID()))
|
->withAuthorityPHIDs(array($user->getPHID()))
|
||||||
->execute();
|
->execute();
|
||||||
foreach ($owned_packages as $package) {
|
foreach ($owned_packages as $package) {
|
||||||
$phids[$package->getPHID()] = true;
|
$phids[$package->getPHID()] = true;
|
||||||
|
|
|
@ -141,7 +141,7 @@ final class OwnersQueryConduitAPIMethod extends OwnersConduitAPIMethod {
|
||||||
$query = id(new PhabricatorOwnersPackageQuery())
|
$query = id(new PhabricatorOwnersPackageQuery())
|
||||||
->setViewer($request->getUser());
|
->setViewer($request->getUser());
|
||||||
|
|
||||||
$query->withOwnerPHIDs(array($request->getValue('userAffiliated')));
|
$query->withAuthorityPHIDs(array($request->getValue('userAffiliated')));
|
||||||
|
|
||||||
$packages = $query->execute();
|
$packages = $query->execute();
|
||||||
} else if ($is_owner_query) {
|
} else if ($is_owner_query) {
|
||||||
|
|
|
@ -14,6 +14,7 @@ final class PhabricatorOwnersDetailController
|
||||||
->setViewer($viewer)
|
->setViewer($viewer)
|
||||||
->withIDs(array($request->getURIData('id')))
|
->withIDs(array($request->getURIData('id')))
|
||||||
->needPaths(true)
|
->needPaths(true)
|
||||||
|
->needOwners(true)
|
||||||
->executeOne();
|
->executeOne();
|
||||||
if (!$package) {
|
if (!$package) {
|
||||||
return new Aphront404Response();
|
return new Aphront404Response();
|
||||||
|
@ -150,8 +151,7 @@ final class PhabricatorOwnersDetailController
|
||||||
$view = id(new PHUIPropertyListView())
|
$view = id(new PHUIPropertyListView())
|
||||||
->setUser($viewer);
|
->setUser($viewer);
|
||||||
|
|
||||||
// TODO: needOwners() this on the Query.
|
$owners = $package->getOwners();
|
||||||
$owners = $package->loadOwners();
|
|
||||||
if ($owners) {
|
if ($owners) {
|
||||||
$owner_list = $viewer->renderHandleList(mpull($owners, 'getUserPHID'));
|
$owner_list = $viewer->renderHandleList(mpull($owners, 'getUserPHID'));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -17,6 +17,7 @@ final class PhabricatorOwnersEditController
|
||||||
// TODO: Support this capability.
|
// TODO: Support this capability.
|
||||||
// PhabricatorPolicyCapability::CAN_EDIT,
|
// PhabricatorPolicyCapability::CAN_EDIT,
|
||||||
))
|
))
|
||||||
|
->needOwners(true)
|
||||||
->executeOne();
|
->executeOne();
|
||||||
if (!$package) {
|
if (!$package) {
|
||||||
return new Aphront404Response();
|
return new Aphront404Response();
|
||||||
|
@ -30,8 +31,7 @@ final class PhabricatorOwnersEditController
|
||||||
$e_name = true;
|
$e_name = true;
|
||||||
|
|
||||||
$v_name = $package->getName();
|
$v_name = $package->getName();
|
||||||
// TODO: Pull these off needOwners() on the Query.
|
$v_owners = mpull($package->getOwners(), 'getUserPHID');
|
||||||
$v_owners = mpull($package->loadOwners(), 'getUserPHID');
|
|
||||||
$v_auditing = $package->getAuditingEnabled();
|
$v_auditing = $package->getAuditingEnabled();
|
||||||
$v_description = $package->getDescription();
|
$v_description = $package->getDescription();
|
||||||
|
|
||||||
|
|
|
@ -6,21 +6,37 @@ final class PhabricatorOwnersPackageQuery
|
||||||
private $ids;
|
private $ids;
|
||||||
private $phids;
|
private $phids;
|
||||||
private $ownerPHIDs;
|
private $ownerPHIDs;
|
||||||
|
private $authorityPHIDs;
|
||||||
private $repositoryPHIDs;
|
private $repositoryPHIDs;
|
||||||
|
private $paths;
|
||||||
private $namePrefix;
|
private $namePrefix;
|
||||||
private $needPaths;
|
|
||||||
|
|
||||||
private $controlMap = array();
|
private $controlMap = array();
|
||||||
private $controlResults;
|
private $controlResults;
|
||||||
|
|
||||||
|
private $needPaths;
|
||||||
|
private $needOwners;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Owners are direct owners, and members of owning projects.
|
* Query owner PHIDs exactly. This does not expand authorities, so a user
|
||||||
|
* PHID will not match projects the user is a member of.
|
||||||
*/
|
*/
|
||||||
public function withOwnerPHIDs(array $phids) {
|
public function withOwnerPHIDs(array $phids) {
|
||||||
$this->ownerPHIDs = $phids;
|
$this->ownerPHIDs = $phids;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query owner authority. This will expand authorities, so a user PHID will
|
||||||
|
* match both packages they own directly and packages owned by a project they
|
||||||
|
* are a member of.
|
||||||
|
*/
|
||||||
|
public function withAuthorityPHIDs(array $phids) {
|
||||||
|
$this->authorityPHIDs = $phids;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function withPHIDs(array $phids) {
|
public function withPHIDs(array $phids) {
|
||||||
$this->phids = $phids;
|
$this->phids = $phids;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -36,6 +52,11 @@ final class PhabricatorOwnersPackageQuery
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function withPaths(array $paths) {
|
||||||
|
$this->paths = $paths;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function withControl($repository_phid, array $paths) {
|
public function withControl($repository_phid, array $paths) {
|
||||||
if (empty($this->controlMap[$repository_phid])) {
|
if (empty($this->controlMap[$repository_phid])) {
|
||||||
$this->controlMap[$repository_phid] = array();
|
$this->controlMap[$repository_phid] = array();
|
||||||
|
@ -62,6 +83,11 @@ final class PhabricatorOwnersPackageQuery
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function needOwners($need_owners) {
|
||||||
|
$this->needOwners = $need_owners;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function newResultObject() {
|
public function newResultObject() {
|
||||||
return new PhabricatorOwnersPackage();
|
return new PhabricatorOwnersPackage();
|
||||||
}
|
}
|
||||||
|
@ -88,6 +114,19 @@ final class PhabricatorOwnersPackageQuery
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->needOwners) {
|
||||||
|
$package_ids = mpull($packages, 'getID');
|
||||||
|
|
||||||
|
$owners = id(new PhabricatorOwnersOwner())->loadAllWhere(
|
||||||
|
'packageID IN (%Ld)',
|
||||||
|
$package_ids);
|
||||||
|
$owners = mgroup($owners, 'getPackageID');
|
||||||
|
|
||||||
|
foreach ($packages as $package) {
|
||||||
|
$package->attachOwners(idx($owners, $package->getID(), array()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->controlMap) {
|
if ($this->controlMap) {
|
||||||
$this->controlResults += mpull($packages, null, 'getID');
|
$this->controlResults += mpull($packages, null, 'getID');
|
||||||
}
|
}
|
||||||
|
@ -98,14 +137,14 @@ final class PhabricatorOwnersPackageQuery
|
||||||
protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
|
protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
|
||||||
$joins = parent::buildJoinClauseParts($conn);
|
$joins = parent::buildJoinClauseParts($conn);
|
||||||
|
|
||||||
if ($this->ownerPHIDs !== null) {
|
if ($this->shouldJoinOwnersTable()) {
|
||||||
$joins[] = qsprintf(
|
$joins[] = qsprintf(
|
||||||
$conn,
|
$conn,
|
||||||
'JOIN %T o ON o.packageID = p.id',
|
'JOIN %T o ON o.packageID = p.id',
|
||||||
id(new PhabricatorOwnersOwner())->getTableName());
|
id(new PhabricatorOwnersOwner())->getTableName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->shouldJoinOwnersPathTable()) {
|
if ($this->shouldJoinPathTable()) {
|
||||||
$joins[] = qsprintf(
|
$joins[] = qsprintf(
|
||||||
$conn,
|
$conn,
|
||||||
'JOIN %T rpath ON rpath.packageID = p.id',
|
'JOIN %T rpath ON rpath.packageID = p.id',
|
||||||
|
@ -139,21 +178,26 @@ final class PhabricatorOwnersPackageQuery
|
||||||
$this->repositoryPHIDs);
|
$this->repositoryPHIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->ownerPHIDs !== null) {
|
if ($this->authorityPHIDs !== null) {
|
||||||
$base_phids = $this->ownerPHIDs;
|
$authority_phids = $this->expandAuthority($this->authorityPHIDs);
|
||||||
|
|
||||||
$projects = id(new PhabricatorProjectQuery())
|
|
||||||
->setViewer($this->getViewer())
|
|
||||||
->withMemberPHIDs($base_phids)
|
|
||||||
->execute();
|
|
||||||
$project_phids = mpull($projects, 'getPHID');
|
|
||||||
|
|
||||||
$all_phids = array_merge($base_phids, $project_phids);
|
|
||||||
|
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn,
|
$conn,
|
||||||
'o.userPHID IN (%Ls)',
|
'o.userPHID IN (%Ls)',
|
||||||
$all_phids);
|
$authority_phids);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->ownerPHIDs !== null) {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn,
|
||||||
|
'o.userPHID IN (%Ls)',
|
||||||
|
$this->ownerPHIDs);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->paths !== null) {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn,
|
||||||
|
'rpath.path IN (%Ls)',
|
||||||
|
$this->getFragmentsForPaths($this->paths));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen($this->namePrefix)) {
|
if (strlen($this->namePrefix)) {
|
||||||
|
@ -168,12 +212,7 @@ final class PhabricatorOwnersPackageQuery
|
||||||
if ($this->controlMap) {
|
if ($this->controlMap) {
|
||||||
$clauses = array();
|
$clauses = array();
|
||||||
foreach ($this->controlMap as $repository_phid => $paths) {
|
foreach ($this->controlMap as $repository_phid => $paths) {
|
||||||
$fragments = array();
|
$fragments = $this->getFragmentsForPaths($paths);
|
||||||
foreach ($paths as $path) {
|
|
||||||
foreach (PhabricatorOwnersPackage::splitPath($path) as $fragment) {
|
|
||||||
$fragments[$fragment] = $fragment;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$clauses[] = qsprintf(
|
$clauses[] = qsprintf(
|
||||||
$conn,
|
$conn,
|
||||||
|
@ -188,11 +227,11 @@ final class PhabricatorOwnersPackageQuery
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function shouldGroupQueryResultRows() {
|
protected function shouldGroupQueryResultRows() {
|
||||||
if ($this->shouldJoinOwnersPathTable()) {
|
if ($this->shouldJoinOwnersTable()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->ownerPHIDs) {
|
if ($this->shouldJoinPathTable()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,11 +275,27 @@ final class PhabricatorOwnersPackageQuery
|
||||||
return 'p';
|
return 'p';
|
||||||
}
|
}
|
||||||
|
|
||||||
private function shouldJoinOwnersPathTable() {
|
private function shouldJoinOwnersTable() {
|
||||||
|
if ($this->ownerPHIDs !== null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->authorityPHIDs !== null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function shouldJoinPathTable() {
|
||||||
if ($this->repositoryPHIDs !== null) {
|
if ($this->repositoryPHIDs !== null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->paths !== null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->controlMap) {
|
if ($this->controlMap) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -248,6 +303,28 @@ final class PhabricatorOwnersPackageQuery
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function expandAuthority(array $phids) {
|
||||||
|
$projects = id(new PhabricatorProjectQuery())
|
||||||
|
->setViewer($this->getViewer())
|
||||||
|
->withMemberPHIDs($phids)
|
||||||
|
->execute();
|
||||||
|
$project_phids = mpull($projects, 'getPHID');
|
||||||
|
|
||||||
|
return array_fuse($phids) + array_fuse($project_phids);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getFragmentsForPaths(array $paths) {
|
||||||
|
$fragments = array();
|
||||||
|
|
||||||
|
foreach ($paths as $path) {
|
||||||
|
foreach (PhabricatorOwnersPackage::splitPath($path) as $fragment) {
|
||||||
|
$fragments[$fragment] = $fragment;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $fragments;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -( Path Control )------------------------------------------------------- */
|
/* -( Path Control )------------------------------------------------------- */
|
||||||
|
|
||||||
|
|
|
@ -18,29 +18,37 @@ final class PhabricatorOwnersPackageSearchEngine
|
||||||
protected function buildCustomSearchFields() {
|
protected function buildCustomSearchFields() {
|
||||||
return array(
|
return array(
|
||||||
id(new PhabricatorSearchDatasourceField())
|
id(new PhabricatorSearchDatasourceField())
|
||||||
->setLabel(pht('Owners'))
|
->setLabel(pht('Authority'))
|
||||||
->setKey('ownerPHIDs')
|
->setKey('authorityPHIDs')
|
||||||
->setAliases(array('owner', 'owners'))
|
->setAliases(array('authority', 'authorities'))
|
||||||
->setDatasource(new PhabricatorProjectOrUserDatasource()),
|
->setDatasource(new PhabricatorProjectOrUserDatasource()),
|
||||||
id(new PhabricatorSearchDatasourceField())
|
id(new PhabricatorSearchDatasourceField())
|
||||||
->setLabel(pht('Repositories'))
|
->setLabel(pht('Repositories'))
|
||||||
->setKey('repositoryPHIDs')
|
->setKey('repositoryPHIDs')
|
||||||
->setAliases(array('repository', 'repositories'))
|
->setAliases(array('repository', 'repositories'))
|
||||||
->setDatasource(new DiffusionRepositoryDatasource()),
|
->setDatasource(new DiffusionRepositoryDatasource()),
|
||||||
|
id(new PhabricatorSearchStringListField())
|
||||||
|
->setLabel(pht('Paths'))
|
||||||
|
->setKey('paths')
|
||||||
|
->setAliases(array('path')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function buildQueryFromParameters(array $map) {
|
protected function buildQueryFromParameters(array $map) {
|
||||||
$query = $this->newQuery();
|
$query = $this->newQuery();
|
||||||
|
|
||||||
if ($map['ownerPHIDs']) {
|
if ($map['authorityPHIDs']) {
|
||||||
$query->withOwnerPHIDs($map['ownerPHIDs']);
|
$query->withAuthorityPHIDs($map['authorityPHIDs']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($map['repositoryPHIDs']) {
|
if ($map['repositoryPHIDs']) {
|
||||||
$query->withRepositoryPHIDs($map['repositoryPHIDs']);
|
$query->withRepositoryPHIDs($map['repositoryPHIDs']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($map['paths']) {
|
||||||
|
$query->withPaths($map['paths']);
|
||||||
|
}
|
||||||
|
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +60,7 @@ final class PhabricatorOwnersPackageSearchEngine
|
||||||
$names = array();
|
$names = array();
|
||||||
|
|
||||||
if ($this->requireViewer()->isLoggedIn()) {
|
if ($this->requireViewer()->isLoggedIn()) {
|
||||||
$names['owned'] = pht('Owned');
|
$names['authority'] = pht('Owned');
|
||||||
}
|
}
|
||||||
|
|
||||||
$names += array(
|
$names += array(
|
||||||
|
@ -69,9 +77,9 @@ final class PhabricatorOwnersPackageSearchEngine
|
||||||
switch ($query_key) {
|
switch ($query_key) {
|
||||||
case 'all':
|
case 'all':
|
||||||
return $query;
|
return $query;
|
||||||
case 'owned':
|
case 'authority':
|
||||||
return $query->setParameter(
|
return $query->setParameter(
|
||||||
'ownerPHIDs',
|
'authorityPHIDs',
|
||||||
array($this->requireViewer()->getPHID()));
|
array($this->requireViewer()->getPHID()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,10 +14,13 @@ final class PhabricatorOwnersPackage
|
||||||
protected $mailKey;
|
protected $mailKey;
|
||||||
|
|
||||||
private $paths = self::ATTACHABLE;
|
private $paths = self::ATTACHABLE;
|
||||||
|
private $owners = self::ATTACHABLE;
|
||||||
|
|
||||||
public static function initializeNewPackage(PhabricatorUser $actor) {
|
public static function initializeNewPackage(PhabricatorUser $actor) {
|
||||||
return id(new PhabricatorOwnersPackage())
|
return id(new PhabricatorOwnersPackage())
|
||||||
->setAuditingEnabled(0);
|
->setAuditingEnabled(0)
|
||||||
|
->attachPaths(array())
|
||||||
|
->attachOwners(array());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCapabilities() {
|
public function getCapabilities() {
|
||||||
|
@ -249,6 +252,16 @@ final class PhabricatorOwnersPackage
|
||||||
return $this->assertAttached($this->paths);
|
return $this->assertAttached($this->paths);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function attachOwners(array $owners) {
|
||||||
|
assert_instances_of($owners, 'PhabricatorOwnersOwner');
|
||||||
|
$this->owners = $owners;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getOwners() {
|
||||||
|
return $this->assertAttached($this->owners);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
|
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue