@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.

Give "owners.search" a "paths" attachment and a default "owners" value

Summary:
Ref T9964.

- Add a "paths" attachment for fetching paths.
- Always load owners. We will need this to do policy checks in the future, anyway, and this data is not large, is very useful, and is reasonable to load unconditionally.

Test Plan:
- Queried packages via API.
- Edited packages (paths, owners).
- Created a package.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9964

Differential Revision: https://secure.phabricator.com/D14775

+95 -34
+2
src/__phutil_library_map__.php
··· 2616 2616 'PhabricatorOwnersPackageTransactionQuery' => 'applications/owners/query/PhabricatorOwnersPackageTransactionQuery.php', 2617 2617 'PhabricatorOwnersPath' => 'applications/owners/storage/PhabricatorOwnersPath.php', 2618 2618 'PhabricatorOwnersPathsController' => 'applications/owners/controller/PhabricatorOwnersPathsController.php', 2619 + 'PhabricatorOwnersPathsSearchEngineAttachment' => 'applications/owners/engineextension/PhabricatorOwnersPathsSearchEngineAttachment.php', 2619 2620 'PhabricatorOwnersSchemaSpec' => 'applications/owners/storage/PhabricatorOwnersSchemaSpec.php', 2620 2621 'PhabricatorOwnersSearchField' => 'applications/owners/searchfield/PhabricatorOwnersSearchField.php', 2621 2622 'PhabricatorPHDConfigOptions' => 'applications/config/option/PhabricatorPHDConfigOptions.php', ··· 6846 6847 'PhabricatorOwnersPackageTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 6847 6848 'PhabricatorOwnersPath' => 'PhabricatorOwnersDAO', 6848 6849 'PhabricatorOwnersPathsController' => 'PhabricatorOwnersController', 6850 + 'PhabricatorOwnersPathsSearchEngineAttachment' => 'PhabricatorSearchEngineAttachment', 6849 6851 'PhabricatorOwnersSchemaSpec' => 'PhabricatorConfigSchemaSpec', 6850 6852 'PhabricatorOwnersSearchField' => 'PhabricatorSearchTokenizerField', 6851 6853 'PhabricatorPHDConfigOptions' => 'PhabricatorApplicationConfigOptions',
-1
src/applications/owners/controller/PhabricatorOwnersDetailController.php
··· 14 14 ->setViewer($viewer) 15 15 ->withIDs(array($request->getURIData('id'))) 16 16 ->needPaths(true) 17 - ->needOwners(true) 18 17 ->executeOne(); 19 18 if (!$package) { 20 19 return new Aphront404Response();
+1 -2
src/applications/owners/editor/PhabricatorOwnersPackageEditEngine.php
··· 18 18 } 19 19 20 20 protected function newObjectQuery() { 21 - return id(new PhabricatorOwnersPackageQuery()) 22 - ->needOwners(true); 21 + return id(new PhabricatorOwnersPackageQuery()); 23 22 } 24 23 25 24 protected function getObjectCreateTitleText($object) {
+3 -6
src/applications/owners/editor/PhabricatorOwnersPackageTransactionEditor.php
··· 32 32 case PhabricatorOwnersPackageTransaction::TYPE_NAME: 33 33 return $object->getName(); 34 34 case PhabricatorOwnersPackageTransaction::TYPE_OWNERS: 35 - // TODO: needOwners() this on the Query. 36 - $phids = mpull($object->loadOwners(), 'getUserPHID'); 35 + $phids = mpull($object->getOwners(), 'getUserPHID'); 37 36 $phids = array_values($phids); 38 37 return $phids; 39 38 case PhabricatorOwnersPackageTransaction::TYPE_AUDITING: ··· 125 124 $old = $xaction->getOldValue(); 126 125 $new = $xaction->getNewValue(); 127 126 128 - // TODO: needOwners this 129 - $owners = $object->loadOwners(); 127 + $owners = $object->getOwners(); 130 128 $owners = mpull($owners, null, 'getUserPHID'); 131 129 132 130 $rem = array_diff($old, $new); ··· 222 220 } 223 221 224 222 protected function getMailCC(PhabricatorLiskDAO $object) { 225 - // TODO: needOwners() this 226 - return mpull($object->loadOwners(), 'getUserPHID'); 223 + return mpull($object->getOwners(), 'getUserPHID'); 227 224 } 228 225 229 226 protected function buildReplyHandler(PhabricatorLiskDAO $object) {
+35
src/applications/owners/engineextension/PhabricatorOwnersPathsSearchEngineAttachment.php
··· 1 + <?php 2 + 3 + final class PhabricatorOwnersPathsSearchEngineAttachment 4 + extends PhabricatorSearchEngineAttachment { 5 + 6 + public function getAttachmentName() { 7 + return pht('Included Paths'); 8 + } 9 + 10 + public function getAttachmentDescription() { 11 + return pht('Get the paths for each package.'); 12 + } 13 + 14 + public function willLoadAttachmentData($query, $spec) { 15 + $query->needPaths(true); 16 + } 17 + 18 + public function getAttachmentForObject($object, $data, $spec) { 19 + $paths = $object->getPaths(); 20 + 21 + $list = array(); 22 + foreach ($paths as $path) { 23 + $list[] = array( 24 + 'repositoryPHID' => $path->getRepositoryPHID(), 25 + 'path' => $path->getPath(), 26 + 'isExcluded' => (bool)$path->getExcluded(), 27 + ); 28 + } 29 + 30 + return array( 31 + 'paths' => $list, 32 + ); 33 + } 34 + 35 + }
+17 -22
src/applications/owners/query/PhabricatorOwnersPackageQuery.php
··· 16 16 private $controlResults; 17 17 18 18 private $needPaths; 19 - private $needOwners; 20 19 21 20 22 21 /** ··· 89 88 return $this; 90 89 } 91 90 92 - public function needOwners($need_owners) { 93 - $this->needOwners = $need_owners; 94 - return $this; 95 - } 96 - 97 91 public function newResultObject() { 98 92 return new PhabricatorOwnersPackage(); 99 93 } ··· 103 97 } 104 98 105 99 protected function loadPage() { 106 - return $this->loadStandardPage(new PhabricatorOwnersPackage()); 100 + return $this->loadStandardPage($this->newResultObject()); 101 + } 102 + 103 + protected function willFilterPage(array $packages) { 104 + $package_ids = mpull($packages, 'getID'); 105 + 106 + $owners = id(new PhabricatorOwnersOwner())->loadAllWhere( 107 + 'packageID IN (%Ld)', 108 + $package_ids); 109 + $owners = mgroup($owners, 'getPackageID'); 110 + foreach ($packages as $package) { 111 + $package->attachOwners(idx($owners, $package->getID(), array())); 112 + } 113 + 114 + return $packages; 107 115 } 108 116 109 117 protected function didFilterPage(array $packages) { 110 - if ($this->needPaths) { 111 - $package_ids = mpull($packages, 'getID'); 118 + $package_ids = mpull($packages, 'getID'); 112 119 120 + if ($this->needPaths) { 113 121 $paths = id(new PhabricatorOwnersPath())->loadAllWhere( 114 122 'packageID IN (%Ld)', 115 123 $package_ids); ··· 117 125 118 126 foreach ($packages as $package) { 119 127 $package->attachPaths(idx($paths, $package->getID(), array())); 120 - } 121 - } 122 - 123 - if ($this->needOwners) { 124 - $package_ids = mpull($packages, 'getID'); 125 - 126 - $owners = id(new PhabricatorOwnersOwner())->loadAllWhere( 127 - 'packageID IN (%Ld)', 128 - $package_ids); 129 - $owners = mgroup($owners, 'getPackageID'); 130 - 131 - foreach ($packages as $package) { 132 - $package->attachOwners(idx($owners, $package->getID(), array())); 133 128 } 134 129 } 135 130
+36 -2
src/applications/owners/storage/PhabricatorOwnersPackage.php
··· 273 273 return mpull($this->getOwners(), 'getUserPHID'); 274 274 } 275 275 276 + public function isOwnerPHID($phid) { 277 + if (!$phid) { 278 + return false; 279 + } 280 + 281 + $owner_phids = $this->getOwnerPHIDs(); 282 + $owner_phids = array_fuse($owner_phids); 283 + 284 + return isset($owner_phids[$phid]); 285 + } 286 + 276 287 277 288 /* -( PhabricatorPolicyInterface )----------------------------------------- */ 278 289 ··· 290 301 } 291 302 292 303 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 304 + switch ($capability) { 305 + case PhabricatorPolicyCapability::CAN_VIEW: 306 + if ($this->isOwnerPHID($viewer->getPHID())) { 307 + return true; 308 + } 309 + break; 310 + } 311 + 293 312 return false; 294 313 } 295 314 296 315 public function describeAutomaticCapability($capability) { 297 - return null; 316 + return pht('Owners of a package may always view it.'); 298 317 } 299 318 300 319 ··· 384 403 'type' => 'string', 385 404 'description' => pht('Active or archived status of the package.'), 386 405 ), 406 + 'owners' => array( 407 + 'type' => 'list<map<string, wild>>', 408 + 'description' => pht('List of package owners.'), 409 + ), 387 410 ); 388 411 } 389 412 390 413 public function getFieldValuesForConduit() { 414 + $owner_list = array(); 415 + foreach ($this->getOwners() as $owner) { 416 + $owner_list[] = array( 417 + 'ownerPHID' => $owner->getUserPHID(), 418 + ); 419 + } 420 + 391 421 return array( 392 422 'name' => $this->getName(), 393 423 'description' => $this->getDescription(), 394 424 'status' => $this->getStatus(), 425 + 'owners' => $owner_list, 395 426 ); 396 427 } 397 428 398 429 public function getConduitSearchAttachments() { 399 - return array(); 430 + return array( 431 + id(new PhabricatorOwnersPathsSearchEngineAttachment()) 432 + ->setAttachmentKey('paths'), 433 + ); 400 434 } 401 435 402 436 }
+1 -1
src/applications/paste/engineextension/PhabricatorPasteContentSearchEngineAttachment.php
··· 17 17 18 18 public function getAttachmentForObject($object, $data, $spec) { 19 19 return array( 20 - 'data' => $object->getRawContent(), 20 + 'content' => $object->getRawContent(), 21 21 ); 22 22 } 23 23