mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-20 20:40:56 +01:00
Consider packages when calculating Differential authority
Summary: Ref T10939. This has no effect yet since packages can not actually become reviewers, I'm just inching toward support. - When searching for "responsible users", include revisions that need review by packages you have authority over. - When calculating review authority, include authority over packages you are a member of (these currently never exist). Test Plan: This isn't reachable so I just `var_dump()`'d stuff and looked at the generated queries, which appeared correct/reasonable. I'll vet this more thoroughly once packages can actually become reviewers. Reviewers: chad Reviewed By: chad Maniphest Tasks: T10939 Differential Revision: https://secure.phabricator.com/D15909
This commit is contained in:
parent
1793e2f945
commit
44057ad269
1 changed files with 44 additions and 10 deletions
|
@ -531,11 +531,26 @@ final class DifferentialRevisionQuery
|
||||||
$basic_authors = $this->authors;
|
$basic_authors = $this->authors;
|
||||||
$basic_reviewers = $this->reviewers;
|
$basic_reviewers = $this->reviewers;
|
||||||
|
|
||||||
|
$authority_phids = $this->responsibles;
|
||||||
|
|
||||||
$authority_projects = id(new PhabricatorProjectQuery())
|
$authority_projects = id(new PhabricatorProjectQuery())
|
||||||
->setViewer($this->getViewer())
|
->setViewer($this->getViewer())
|
||||||
->withMemberPHIDs($this->responsibles)
|
->withMemberPHIDs($this->responsibles)
|
||||||
->execute();
|
->execute();
|
||||||
$authority_phids = mpull($authority_projects, 'getPHID');
|
foreach ($authority_projects as $project) {
|
||||||
|
$authority_phids[] = $project->getPHID();
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: We're querying by explicit owners to make this a little faster,
|
||||||
|
// since we've already expanded project membership so we don't need to
|
||||||
|
// have the PackageQuery do it again.
|
||||||
|
$authority_packages = id(new PhabricatorOwnersPackageQuery())
|
||||||
|
->setViewer($this->getViewer())
|
||||||
|
->withOwnerPHIDs($authority_phids)
|
||||||
|
->execute();
|
||||||
|
foreach ($authority_packages as $package) {
|
||||||
|
$authority_phids[] = $package->getPHID();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Build the query where the responsible users are authors.
|
// Build the query where the responsible users are authors.
|
||||||
|
@ -548,7 +563,6 @@ final class DifferentialRevisionQuery
|
||||||
$this->authors = $basic_authors;
|
$this->authors = $basic_authors;
|
||||||
$this->reviewers = array_merge(
|
$this->reviewers = array_merge(
|
||||||
$basic_reviewers,
|
$basic_reviewers,
|
||||||
$this->responsibles,
|
|
||||||
$authority_phids);
|
$authority_phids);
|
||||||
$selects[] = $this->buildSelectStatement($conn_r);
|
$selects[] = $this->buildSelectStatement($conn_r);
|
||||||
|
|
||||||
|
@ -1105,9 +1119,13 @@ final class DifferentialRevisionQuery
|
||||||
$revision_map = mpull($revisions, null, 'getPHID');
|
$revision_map = mpull($revisions, null, 'getPHID');
|
||||||
$viewer_phid = $this->getViewer()->getPHID();
|
$viewer_phid = $this->getViewer()->getPHID();
|
||||||
|
|
||||||
// Find all the project reviewers which the user may have authority over.
|
// Find all the project/package reviewers which the user may have authority
|
||||||
|
// over.
|
||||||
$project_phids = array();
|
$project_phids = array();
|
||||||
|
$package_phids = array();
|
||||||
$project_type = PhabricatorProjectProjectPHIDType::TYPECONST;
|
$project_type = PhabricatorProjectProjectPHIDType::TYPECONST;
|
||||||
|
$package_type = PhabricatorOwnersPackagePHIDType::TYPECONST;
|
||||||
|
|
||||||
$edge_type = DifferentialRevisionHasReviewerEdgeType::EDGECONST;
|
$edge_type = DifferentialRevisionHasReviewerEdgeType::EDGECONST;
|
||||||
foreach ($edges as $src => $types) {
|
foreach ($edges as $src => $types) {
|
||||||
if (!$allow_self) {
|
if (!$allow_self) {
|
||||||
|
@ -1121,14 +1139,20 @@ final class DifferentialRevisionQuery
|
||||||
}
|
}
|
||||||
$edge_data = idx($types, $edge_type, array());
|
$edge_data = idx($types, $edge_type, array());
|
||||||
foreach ($edge_data as $dst => $data) {
|
foreach ($edge_data as $dst => $data) {
|
||||||
if (phid_get_type($dst) == $project_type) {
|
$phid_type = phid_get_type($dst);
|
||||||
|
if ($phid_type == $project_type) {
|
||||||
$project_phids[] = $dst;
|
$project_phids[] = $dst;
|
||||||
}
|
}
|
||||||
|
if ($phid_type == $package_type) {
|
||||||
|
$package_phids[] = $dst;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now, figure out which of these projects the viewer is actually a
|
// The viewer has authority over themselves.
|
||||||
// member of.
|
$user_authority = array_fuse(array($viewer_phid));
|
||||||
|
|
||||||
|
// And over any projects they are a member of.
|
||||||
$project_authority = array();
|
$project_authority = array();
|
||||||
if ($project_phids) {
|
if ($project_phids) {
|
||||||
$project_authority = id(new PhabricatorProjectQuery())
|
$project_authority = id(new PhabricatorProjectQuery())
|
||||||
|
@ -1137,12 +1161,22 @@ final class DifferentialRevisionQuery
|
||||||
->withMemberPHIDs(array($viewer_phid))
|
->withMemberPHIDs(array($viewer_phid))
|
||||||
->execute();
|
->execute();
|
||||||
$project_authority = mpull($project_authority, 'getPHID');
|
$project_authority = mpull($project_authority, 'getPHID');
|
||||||
|
$project_authority = array_fuse($project_authority);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, the viewer has authority over themselves.
|
// And over any packages they own.
|
||||||
return array(
|
$package_authority = array();
|
||||||
$viewer_phid => true,
|
if ($package_phids) {
|
||||||
) + array_fuse($project_authority);
|
$package_authority = id(new PhabricatorOwnersPackageQuery())
|
||||||
|
->setViewer($this->getViewer())
|
||||||
|
->withPHIDs($package_phids)
|
||||||
|
->withAuthorityPHIDs(array($viewer_phid))
|
||||||
|
->execute();
|
||||||
|
$package_authority = mpull($package_authority, 'getPHID');
|
||||||
|
$package_authority = array_fuse($package_authority);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $user_authority + $project_authority + $package_authority;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getQueryApplicationClass() {
|
public function getQueryApplicationClass() {
|
||||||
|
|
Loading…
Reference in a new issue