mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-22 05:20:56 +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:
parent
3db175f79d
commit
10cdc55cf7
8 changed files with 95 additions and 34 deletions
|
@ -2616,6 +2616,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorOwnersPackageTransactionQuery' => 'applications/owners/query/PhabricatorOwnersPackageTransactionQuery.php',
|
||||
'PhabricatorOwnersPath' => 'applications/owners/storage/PhabricatorOwnersPath.php',
|
||||
'PhabricatorOwnersPathsController' => 'applications/owners/controller/PhabricatorOwnersPathsController.php',
|
||||
'PhabricatorOwnersPathsSearchEngineAttachment' => 'applications/owners/engineextension/PhabricatorOwnersPathsSearchEngineAttachment.php',
|
||||
'PhabricatorOwnersSchemaSpec' => 'applications/owners/storage/PhabricatorOwnersSchemaSpec.php',
|
||||
'PhabricatorOwnersSearchField' => 'applications/owners/searchfield/PhabricatorOwnersSearchField.php',
|
||||
'PhabricatorPHDConfigOptions' => 'applications/config/option/PhabricatorPHDConfigOptions.php',
|
||||
|
@ -6846,6 +6847,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorOwnersPackageTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||
'PhabricatorOwnersPath' => 'PhabricatorOwnersDAO',
|
||||
'PhabricatorOwnersPathsController' => 'PhabricatorOwnersController',
|
||||
'PhabricatorOwnersPathsSearchEngineAttachment' => 'PhabricatorSearchEngineAttachment',
|
||||
'PhabricatorOwnersSchemaSpec' => 'PhabricatorConfigSchemaSpec',
|
||||
'PhabricatorOwnersSearchField' => 'PhabricatorSearchTokenizerField',
|
||||
'PhabricatorPHDConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
||||
|
|
|
@ -14,7 +14,6 @@ final class PhabricatorOwnersDetailController
|
|||
->setViewer($viewer)
|
||||
->withIDs(array($request->getURIData('id')))
|
||||
->needPaths(true)
|
||||
->needOwners(true)
|
||||
->executeOne();
|
||||
if (!$package) {
|
||||
return new Aphront404Response();
|
||||
|
|
|
@ -18,8 +18,7 @@ final class PhabricatorOwnersPackageEditEngine
|
|||
}
|
||||
|
||||
protected function newObjectQuery() {
|
||||
return id(new PhabricatorOwnersPackageQuery())
|
||||
->needOwners(true);
|
||||
return id(new PhabricatorOwnersPackageQuery());
|
||||
}
|
||||
|
||||
protected function getObjectCreateTitleText($object) {
|
||||
|
|
|
@ -32,8 +32,7 @@ final class PhabricatorOwnersPackageTransactionEditor
|
|||
case PhabricatorOwnersPackageTransaction::TYPE_NAME:
|
||||
return $object->getName();
|
||||
case PhabricatorOwnersPackageTransaction::TYPE_OWNERS:
|
||||
// TODO: needOwners() this on the Query.
|
||||
$phids = mpull($object->loadOwners(), 'getUserPHID');
|
||||
$phids = mpull($object->getOwners(), 'getUserPHID');
|
||||
$phids = array_values($phids);
|
||||
return $phids;
|
||||
case PhabricatorOwnersPackageTransaction::TYPE_AUDITING:
|
||||
|
@ -125,8 +124,7 @@ final class PhabricatorOwnersPackageTransactionEditor
|
|||
$old = $xaction->getOldValue();
|
||||
$new = $xaction->getNewValue();
|
||||
|
||||
// TODO: needOwners this
|
||||
$owners = $object->loadOwners();
|
||||
$owners = $object->getOwners();
|
||||
$owners = mpull($owners, null, 'getUserPHID');
|
||||
|
||||
$rem = array_diff($old, $new);
|
||||
|
@ -222,8 +220,7 @@ final class PhabricatorOwnersPackageTransactionEditor
|
|||
}
|
||||
|
||||
protected function getMailCC(PhabricatorLiskDAO $object) {
|
||||
// TODO: needOwners() this
|
||||
return mpull($object->loadOwners(), 'getUserPHID');
|
||||
return mpull($object->getOwners(), 'getUserPHID');
|
||||
}
|
||||
|
||||
protected function buildReplyHandler(PhabricatorLiskDAO $object) {
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -16,7 +16,6 @@ final class PhabricatorOwnersPackageQuery
|
|||
private $controlResults;
|
||||
|
||||
private $needPaths;
|
||||
private $needOwners;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -89,11 +88,6 @@ final class PhabricatorOwnersPackageQuery
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function needOwners($need_owners) {
|
||||
$this->needOwners = $need_owners;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function newResultObject() {
|
||||
return new PhabricatorOwnersPackage();
|
||||
}
|
||||
|
@ -103,13 +97,27 @@ final class PhabricatorOwnersPackageQuery
|
|||
}
|
||||
|
||||
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) {
|
||||
if ($this->needPaths) {
|
||||
$package_ids = mpull($packages, 'getID');
|
||||
$package_ids = mpull($packages, 'getID');
|
||||
|
||||
if ($this->needPaths) {
|
||||
$paths = id(new PhabricatorOwnersPath())->loadAllWhere(
|
||||
'packageID IN (%Ld)',
|
||||
$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) {
|
||||
$this->controlResults += mpull($packages, null, 'getID');
|
||||
}
|
||||
|
|
|
@ -273,6 +273,17 @@ final class PhabricatorOwnersPackage
|
|||
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 )----------------------------------------- */
|
||||
|
||||
|
@ -290,11 +301,19 @@ final class PhabricatorOwnersPackage
|
|||
}
|
||||
|
||||
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
||||
switch ($capability) {
|
||||
case PhabricatorPolicyCapability::CAN_VIEW:
|
||||
if ($this->isOwnerPHID($viewer->getPHID())) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
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',
|
||||
'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() {
|
||||
$owner_list = array();
|
||||
foreach ($this->getOwners() as $owner) {
|
||||
$owner_list[] = array(
|
||||
'ownerPHID' => $owner->getUserPHID(),
|
||||
);
|
||||
}
|
||||
|
||||
return array(
|
||||
'name' => $this->getName(),
|
||||
'description' => $this->getDescription(),
|
||||
'status' => $this->getStatus(),
|
||||
'owners' => $owner_list,
|
||||
);
|
||||
}
|
||||
|
||||
public function getConduitSearchAttachments() {
|
||||
return array();
|
||||
return array(
|
||||
id(new PhabricatorOwnersPathsSearchEngineAttachment())
|
||||
->setAttachmentKey('paths'),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ final class PhabricatorPasteContentSearchEngineAttachment
|
|||
|
||||
public function getAttachmentForObject($object, $data, $spec) {
|
||||
return array(
|
||||
'data' => $object->getRawContent(),
|
||||
'content' => $object->getRawContent(),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue