@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+137 -39
+1 -1
src/applications/audit/editor/PhabricatorAuditCommentEditor.php
··· 20 20 21 21 $owned_packages = id(new PhabricatorOwnersPackageQuery()) 22 22 ->setViewer($user) 23 - ->withOwnerPHIDs(array($user->getPHID())) 23 + ->withAuthorityPHIDs(array($user->getPHID())) 24 24 ->execute(); 25 25 foreach ($owned_packages as $package) { 26 26 $phids[$package->getPHID()] = true;
+1 -1
src/applications/owners/conduit/OwnersQueryConduitAPIMethod.php
··· 141 141 $query = id(new PhabricatorOwnersPackageQuery()) 142 142 ->setViewer($request->getUser()); 143 143 144 - $query->withOwnerPHIDs(array($request->getValue('userAffiliated'))); 144 + $query->withAuthorityPHIDs(array($request->getValue('userAffiliated'))); 145 145 146 146 $packages = $query->execute(); 147 147 } else if ($is_owner_query) {
+2 -2
src/applications/owners/controller/PhabricatorOwnersDetailController.php
··· 14 14 ->setViewer($viewer) 15 15 ->withIDs(array($request->getURIData('id'))) 16 16 ->needPaths(true) 17 + ->needOwners(true) 17 18 ->executeOne(); 18 19 if (!$package) { 19 20 return new Aphront404Response(); ··· 150 151 $view = id(new PHUIPropertyListView()) 151 152 ->setUser($viewer); 152 153 153 - // TODO: needOwners() this on the Query. 154 - $owners = $package->loadOwners(); 154 + $owners = $package->getOwners(); 155 155 if ($owners) { 156 156 $owner_list = $viewer->renderHandleList(mpull($owners, 'getUserPHID')); 157 157 } else {
+2 -2
src/applications/owners/controller/PhabricatorOwnersEditController.php
··· 17 17 // TODO: Support this capability. 18 18 // PhabricatorPolicyCapability::CAN_EDIT, 19 19 )) 20 + ->needOwners(true) 20 21 ->executeOne(); 21 22 if (!$package) { 22 23 return new Aphront404Response(); ··· 30 31 $e_name = true; 31 32 32 33 $v_name = $package->getName(); 33 - // TODO: Pull these off needOwners() on the Query. 34 - $v_owners = mpull($package->loadOwners(), 'getUserPHID'); 34 + $v_owners = mpull($package->getOwners(), 'getUserPHID'); 35 35 $v_auditing = $package->getAuditingEnabled(); 36 36 $v_description = $package->getDescription(); 37 37
+101 -24
src/applications/owners/query/PhabricatorOwnersPackageQuery.php
··· 6 6 private $ids; 7 7 private $phids; 8 8 private $ownerPHIDs; 9 + private $authorityPHIDs; 9 10 private $repositoryPHIDs; 11 + private $paths; 10 12 private $namePrefix; 11 - private $needPaths; 12 13 13 14 private $controlMap = array(); 14 15 private $controlResults; 15 16 17 + private $needPaths; 18 + private $needOwners; 19 + 20 + 16 21 /** 17 - * Owners are direct owners, and members of owning projects. 22 + * Query owner PHIDs exactly. This does not expand authorities, so a user 23 + * PHID will not match projects the user is a member of. 18 24 */ 19 25 public function withOwnerPHIDs(array $phids) { 20 26 $this->ownerPHIDs = $phids; 21 27 return $this; 22 28 } 23 29 30 + /** 31 + * Query owner authority. This will expand authorities, so a user PHID will 32 + * match both packages they own directly and packages owned by a project they 33 + * are a member of. 34 + */ 35 + public function withAuthorityPHIDs(array $phids) { 36 + $this->authorityPHIDs = $phids; 37 + return $this; 38 + } 39 + 24 40 public function withPHIDs(array $phids) { 25 41 $this->phids = $phids; 26 42 return $this; ··· 36 52 return $this; 37 53 } 38 54 55 + public function withPaths(array $paths) { 56 + $this->paths = $paths; 57 + return $this; 58 + } 59 + 39 60 public function withControl($repository_phid, array $paths) { 40 61 if (empty($this->controlMap[$repository_phid])) { 41 62 $this->controlMap[$repository_phid] = array(); ··· 62 83 return $this; 63 84 } 64 85 86 + public function needOwners($need_owners) { 87 + $this->needOwners = $need_owners; 88 + return $this; 89 + } 90 + 65 91 public function newResultObject() { 66 92 return new PhabricatorOwnersPackage(); 67 93 } ··· 88 114 } 89 115 } 90 116 117 + if ($this->needOwners) { 118 + $package_ids = mpull($packages, 'getID'); 119 + 120 + $owners = id(new PhabricatorOwnersOwner())->loadAllWhere( 121 + 'packageID IN (%Ld)', 122 + $package_ids); 123 + $owners = mgroup($owners, 'getPackageID'); 124 + 125 + foreach ($packages as $package) { 126 + $package->attachOwners(idx($owners, $package->getID(), array())); 127 + } 128 + } 129 + 91 130 if ($this->controlMap) { 92 131 $this->controlResults += mpull($packages, null, 'getID'); 93 132 } ··· 98 137 protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) { 99 138 $joins = parent::buildJoinClauseParts($conn); 100 139 101 - if ($this->ownerPHIDs !== null) { 140 + if ($this->shouldJoinOwnersTable()) { 102 141 $joins[] = qsprintf( 103 142 $conn, 104 143 'JOIN %T o ON o.packageID = p.id', 105 144 id(new PhabricatorOwnersOwner())->getTableName()); 106 145 } 107 146 108 - if ($this->shouldJoinOwnersPathTable()) { 147 + if ($this->shouldJoinPathTable()) { 109 148 $joins[] = qsprintf( 110 149 $conn, 111 150 'JOIN %T rpath ON rpath.packageID = p.id', ··· 139 178 $this->repositoryPHIDs); 140 179 } 141 180 181 + if ($this->authorityPHIDs !== null) { 182 + $authority_phids = $this->expandAuthority($this->authorityPHIDs); 183 + $where[] = qsprintf( 184 + $conn, 185 + 'o.userPHID IN (%Ls)', 186 + $authority_phids); 187 + } 188 + 142 189 if ($this->ownerPHIDs !== null) { 143 - $base_phids = $this->ownerPHIDs; 190 + $where[] = qsprintf( 191 + $conn, 192 + 'o.userPHID IN (%Ls)', 193 + $this->ownerPHIDs); 194 + } 144 195 145 - $projects = id(new PhabricatorProjectQuery()) 146 - ->setViewer($this->getViewer()) 147 - ->withMemberPHIDs($base_phids) 148 - ->execute(); 149 - $project_phids = mpull($projects, 'getPHID'); 150 - 151 - $all_phids = array_merge($base_phids, $project_phids); 152 - 196 + if ($this->paths !== null) { 153 197 $where[] = qsprintf( 154 198 $conn, 155 - 'o.userPHID IN (%Ls)', 156 - $all_phids); 199 + 'rpath.path IN (%Ls)', 200 + $this->getFragmentsForPaths($this->paths)); 157 201 } 158 202 159 203 if (strlen($this->namePrefix)) { ··· 168 212 if ($this->controlMap) { 169 213 $clauses = array(); 170 214 foreach ($this->controlMap as $repository_phid => $paths) { 171 - $fragments = array(); 172 - foreach ($paths as $path) { 173 - foreach (PhabricatorOwnersPackage::splitPath($path) as $fragment) { 174 - $fragments[$fragment] = $fragment; 175 - } 176 - } 215 + $fragments = $this->getFragmentsForPaths($paths); 177 216 178 217 $clauses[] = qsprintf( 179 218 $conn, ··· 188 227 } 189 228 190 229 protected function shouldGroupQueryResultRows() { 191 - if ($this->shouldJoinOwnersPathTable()) { 230 + if ($this->shouldJoinOwnersTable()) { 192 231 return true; 193 232 } 194 233 195 - if ($this->ownerPHIDs) { 234 + if ($this->shouldJoinPathTable()) { 196 235 return true; 197 236 } 198 237 ··· 236 275 return 'p'; 237 276 } 238 277 239 - private function shouldJoinOwnersPathTable() { 278 + private function shouldJoinOwnersTable() { 279 + if ($this->ownerPHIDs !== null) { 280 + return true; 281 + } 282 + 283 + if ($this->authorityPHIDs !== null) { 284 + return true; 285 + } 286 + 287 + return false; 288 + } 289 + 290 + private function shouldJoinPathTable() { 240 291 if ($this->repositoryPHIDs !== null) { 241 292 return true; 242 293 } 243 294 295 + if ($this->paths !== null) { 296 + return true; 297 + } 298 + 244 299 if ($this->controlMap) { 245 300 return true; 246 301 } 247 302 248 303 return false; 304 + } 305 + 306 + private function expandAuthority(array $phids) { 307 + $projects = id(new PhabricatorProjectQuery()) 308 + ->setViewer($this->getViewer()) 309 + ->withMemberPHIDs($phids) 310 + ->execute(); 311 + $project_phids = mpull($projects, 'getPHID'); 312 + 313 + return array_fuse($phids) + array_fuse($project_phids); 314 + } 315 + 316 + private function getFragmentsForPaths(array $paths) { 317 + $fragments = array(); 318 + 319 + foreach ($paths as $path) { 320 + foreach (PhabricatorOwnersPackage::splitPath($path) as $fragment) { 321 + $fragments[$fragment] = $fragment; 322 + } 323 + } 324 + 325 + return $fragments; 249 326 } 250 327 251 328
+16 -8
src/applications/owners/query/PhabricatorOwnersPackageSearchEngine.php
··· 18 18 protected function buildCustomSearchFields() { 19 19 return array( 20 20 id(new PhabricatorSearchDatasourceField()) 21 - ->setLabel(pht('Owners')) 22 - ->setKey('ownerPHIDs') 23 - ->setAliases(array('owner', 'owners')) 21 + ->setLabel(pht('Authority')) 22 + ->setKey('authorityPHIDs') 23 + ->setAliases(array('authority', 'authorities')) 24 24 ->setDatasource(new PhabricatorProjectOrUserDatasource()), 25 25 id(new PhabricatorSearchDatasourceField()) 26 26 ->setLabel(pht('Repositories')) 27 27 ->setKey('repositoryPHIDs') 28 28 ->setAliases(array('repository', 'repositories')) 29 29 ->setDatasource(new DiffusionRepositoryDatasource()), 30 + id(new PhabricatorSearchStringListField()) 31 + ->setLabel(pht('Paths')) 32 + ->setKey('paths') 33 + ->setAliases(array('path')), 30 34 ); 31 35 } 32 36 33 37 protected function buildQueryFromParameters(array $map) { 34 38 $query = $this->newQuery(); 35 39 36 - if ($map['ownerPHIDs']) { 37 - $query->withOwnerPHIDs($map['ownerPHIDs']); 40 + if ($map['authorityPHIDs']) { 41 + $query->withAuthorityPHIDs($map['authorityPHIDs']); 38 42 } 39 43 40 44 if ($map['repositoryPHIDs']) { 41 45 $query->withRepositoryPHIDs($map['repositoryPHIDs']); 46 + } 47 + 48 + if ($map['paths']) { 49 + $query->withPaths($map['paths']); 42 50 } 43 51 44 52 return $query; ··· 52 60 $names = array(); 53 61 54 62 if ($this->requireViewer()->isLoggedIn()) { 55 - $names['owned'] = pht('Owned'); 63 + $names['authority'] = pht('Owned'); 56 64 } 57 65 58 66 $names += array( ··· 69 77 switch ($query_key) { 70 78 case 'all': 71 79 return $query; 72 - case 'owned': 80 + case 'authority': 73 81 return $query->setParameter( 74 - 'ownerPHIDs', 82 + 'authorityPHIDs', 75 83 array($this->requireViewer()->getPHID())); 76 84 } 77 85
+14 -1
src/applications/owners/storage/PhabricatorOwnersPackage.php
··· 14 14 protected $mailKey; 15 15 16 16 private $paths = self::ATTACHABLE; 17 + private $owners = self::ATTACHABLE; 17 18 18 19 public static function initializeNewPackage(PhabricatorUser $actor) { 19 20 return id(new PhabricatorOwnersPackage()) 20 - ->setAuditingEnabled(0); 21 + ->setAuditingEnabled(0) 22 + ->attachPaths(array()) 23 + ->attachOwners(array()); 21 24 } 22 25 23 26 public function getCapabilities() { ··· 247 250 248 251 public function getPaths() { 249 252 return $this->assertAttached($this->paths); 253 + } 254 + 255 + public function attachOwners(array $owners) { 256 + assert_instances_of($owners, 'PhabricatorOwnersOwner'); 257 + $this->owners = $owners; 258 + return $this; 259 + } 260 + 261 + public function getOwners() { 262 + return $this->assertAttached($this->owners); 250 263 } 251 264 252 265