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

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
This commit is contained in:
epriestley 2015-12-14 06:11:03 -08:00
parent 3db175f79d
commit 10cdc55cf7
8 changed files with 95 additions and 34 deletions

View file

@ -2616,6 +2616,7 @@ phutil_register_library_map(array(
'PhabricatorOwnersPackageTransactionQuery' => 'applications/owners/query/PhabricatorOwnersPackageTransactionQuery.php', 'PhabricatorOwnersPackageTransactionQuery' => 'applications/owners/query/PhabricatorOwnersPackageTransactionQuery.php',
'PhabricatorOwnersPath' => 'applications/owners/storage/PhabricatorOwnersPath.php', 'PhabricatorOwnersPath' => 'applications/owners/storage/PhabricatorOwnersPath.php',
'PhabricatorOwnersPathsController' => 'applications/owners/controller/PhabricatorOwnersPathsController.php', 'PhabricatorOwnersPathsController' => 'applications/owners/controller/PhabricatorOwnersPathsController.php',
'PhabricatorOwnersPathsSearchEngineAttachment' => 'applications/owners/engineextension/PhabricatorOwnersPathsSearchEngineAttachment.php',
'PhabricatorOwnersSchemaSpec' => 'applications/owners/storage/PhabricatorOwnersSchemaSpec.php', 'PhabricatorOwnersSchemaSpec' => 'applications/owners/storage/PhabricatorOwnersSchemaSpec.php',
'PhabricatorOwnersSearchField' => 'applications/owners/searchfield/PhabricatorOwnersSearchField.php', 'PhabricatorOwnersSearchField' => 'applications/owners/searchfield/PhabricatorOwnersSearchField.php',
'PhabricatorPHDConfigOptions' => 'applications/config/option/PhabricatorPHDConfigOptions.php', 'PhabricatorPHDConfigOptions' => 'applications/config/option/PhabricatorPHDConfigOptions.php',
@ -6846,6 +6847,7 @@ phutil_register_library_map(array(
'PhabricatorOwnersPackageTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 'PhabricatorOwnersPackageTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
'PhabricatorOwnersPath' => 'PhabricatorOwnersDAO', 'PhabricatorOwnersPath' => 'PhabricatorOwnersDAO',
'PhabricatorOwnersPathsController' => 'PhabricatorOwnersController', 'PhabricatorOwnersPathsController' => 'PhabricatorOwnersController',
'PhabricatorOwnersPathsSearchEngineAttachment' => 'PhabricatorSearchEngineAttachment',
'PhabricatorOwnersSchemaSpec' => 'PhabricatorConfigSchemaSpec', 'PhabricatorOwnersSchemaSpec' => 'PhabricatorConfigSchemaSpec',
'PhabricatorOwnersSearchField' => 'PhabricatorSearchTokenizerField', 'PhabricatorOwnersSearchField' => 'PhabricatorSearchTokenizerField',
'PhabricatorPHDConfigOptions' => 'PhabricatorApplicationConfigOptions', 'PhabricatorPHDConfigOptions' => 'PhabricatorApplicationConfigOptions',

View file

@ -14,7 +14,6 @@ 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();

View file

@ -18,8 +18,7 @@ final class PhabricatorOwnersPackageEditEngine
} }
protected function newObjectQuery() { protected function newObjectQuery() {
return id(new PhabricatorOwnersPackageQuery()) return id(new PhabricatorOwnersPackageQuery());
->needOwners(true);
} }
protected function getObjectCreateTitleText($object) { protected function getObjectCreateTitleText($object) {

View file

@ -32,8 +32,7 @@ final class PhabricatorOwnersPackageTransactionEditor
case PhabricatorOwnersPackageTransaction::TYPE_NAME: case PhabricatorOwnersPackageTransaction::TYPE_NAME:
return $object->getName(); return $object->getName();
case PhabricatorOwnersPackageTransaction::TYPE_OWNERS: case PhabricatorOwnersPackageTransaction::TYPE_OWNERS:
// TODO: needOwners() this on the Query. $phids = mpull($object->getOwners(), 'getUserPHID');
$phids = mpull($object->loadOwners(), 'getUserPHID');
$phids = array_values($phids); $phids = array_values($phids);
return $phids; return $phids;
case PhabricatorOwnersPackageTransaction::TYPE_AUDITING: case PhabricatorOwnersPackageTransaction::TYPE_AUDITING:
@ -125,8 +124,7 @@ final class PhabricatorOwnersPackageTransactionEditor
$old = $xaction->getOldValue(); $old = $xaction->getOldValue();
$new = $xaction->getNewValue(); $new = $xaction->getNewValue();
// TODO: needOwners this $owners = $object->getOwners();
$owners = $object->loadOwners();
$owners = mpull($owners, null, 'getUserPHID'); $owners = mpull($owners, null, 'getUserPHID');
$rem = array_diff($old, $new); $rem = array_diff($old, $new);
@ -222,8 +220,7 @@ final class PhabricatorOwnersPackageTransactionEditor
} }
protected function getMailCC(PhabricatorLiskDAO $object) { protected function getMailCC(PhabricatorLiskDAO $object) {
// TODO: needOwners() this return mpull($object->getOwners(), 'getUserPHID');
return mpull($object->loadOwners(), 'getUserPHID');
} }
protected function buildReplyHandler(PhabricatorLiskDAO $object) { protected function buildReplyHandler(PhabricatorLiskDAO $object) {

View file

@ -0,0 +1,35 @@
<?php
final class PhabricatorOwnersPathsSearchEngineAttachment
extends PhabricatorSearchEngineAttachment {
public function getAttachmentName() {
return pht('Included Paths');
}
public function getAttachmentDescription() {
return pht('Get the paths for each package.');
}
public function willLoadAttachmentData($query, $spec) {
$query->needPaths(true);
}
public function getAttachmentForObject($object, $data, $spec) {
$paths = $object->getPaths();
$list = array();
foreach ($paths as $path) {
$list[] = array(
'repositoryPHID' => $path->getRepositoryPHID(),
'path' => $path->getPath(),
'isExcluded' => (bool)$path->getExcluded(),
);
}
return array(
'paths' => $list,
);
}
}

View file

@ -16,7 +16,6 @@ final class PhabricatorOwnersPackageQuery
private $controlResults; private $controlResults;
private $needPaths; private $needPaths;
private $needOwners;
/** /**
@ -89,11 +88,6 @@ 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();
} }
@ -103,13 +97,27 @@ final class PhabricatorOwnersPackageQuery
} }
protected function loadPage() { protected function loadPage() {
return $this->loadStandardPage(new PhabricatorOwnersPackage()); return $this->loadStandardPage($this->newResultObject());
}
protected function willFilterPage(array $packages) {
$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()));
}
return $packages;
} }
protected function didFilterPage(array $packages) { protected function didFilterPage(array $packages) {
if ($this->needPaths) { $package_ids = mpull($packages, 'getID');
$package_ids = mpull($packages, 'getID');
if ($this->needPaths) {
$paths = id(new PhabricatorOwnersPath())->loadAllWhere( $paths = id(new PhabricatorOwnersPath())->loadAllWhere(
'packageID IN (%Ld)', 'packageID IN (%Ld)',
$package_ids); $package_ids);
@ -120,19 +128,6 @@ 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');
} }

View file

@ -273,6 +273,17 @@ final class PhabricatorOwnersPackage
return mpull($this->getOwners(), 'getUserPHID'); return mpull($this->getOwners(), 'getUserPHID');
} }
public function isOwnerPHID($phid) {
if (!$phid) {
return false;
}
$owner_phids = $this->getOwnerPHIDs();
$owner_phids = array_fuse($owner_phids);
return isset($owner_phids[$phid]);
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */ /* -( PhabricatorPolicyInterface )----------------------------------------- */
@ -290,11 +301,19 @@ final class PhabricatorOwnersPackage
} }
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
switch ($capability) {
case PhabricatorPolicyCapability::CAN_VIEW:
if ($this->isOwnerPHID($viewer->getPHID())) {
return true;
}
break;
}
return false; return false;
} }
public function describeAutomaticCapability($capability) { public function describeAutomaticCapability($capability) {
return null; return pht('Owners of a package may always view it.');
} }
@ -384,19 +403,34 @@ final class PhabricatorOwnersPackage
'type' => 'string', 'type' => 'string',
'description' => pht('Active or archived status of the package.'), 'description' => pht('Active or archived status of the package.'),
), ),
'owners' => array(
'type' => 'list<map<string, wild>>',
'description' => pht('List of package owners.'),
),
); );
} }
public function getFieldValuesForConduit() { public function getFieldValuesForConduit() {
$owner_list = array();
foreach ($this->getOwners() as $owner) {
$owner_list[] = array(
'ownerPHID' => $owner->getUserPHID(),
);
}
return array( return array(
'name' => $this->getName(), 'name' => $this->getName(),
'description' => $this->getDescription(), 'description' => $this->getDescription(),
'status' => $this->getStatus(), 'status' => $this->getStatus(),
'owners' => $owner_list,
); );
} }
public function getConduitSearchAttachments() { public function getConduitSearchAttachments() {
return array(); return array(
id(new PhabricatorOwnersPathsSearchEngineAttachment())
->setAttachmentKey('paths'),
);
} }
} }

View file

@ -17,7 +17,7 @@ final class PhabricatorPasteContentSearchEngineAttachment
public function getAttachmentForObject($object, $data, $spec) { public function getAttachmentForObject($object, $data, $spec) {
return array( return array(
'data' => $object->getRawContent(), 'content' => $object->getRawContent(),
); );
} }