mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-30 01:10:58 +01:00
Policy - do proper policy queries when updating owners packages in commit workers
Summary: Ref T7094. This makes the underlying class take a $user parameter, and then the worker just hands it an omnipotent user. Said underyling class is the benefactor of a small re-factor, dropping one query per-use, though the single query that now remains is policy-based so maybe its a wash or even worse. Still, gotta love one less query. Test Plan: a little tricky to test so some extra thought instead basic acceptance test with `bin/repository reparse --change rValidHashHere` -- it worked! Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T7094 Differential Revision: https://secure.phabricator.com/D11653
This commit is contained in:
parent
468985c827
commit
026e379483
2 changed files with 22 additions and 10 deletions
|
@ -8,16 +8,25 @@ final class PhabricatorOwnersPackagePathValidator {
|
|||
* paths.
|
||||
*/
|
||||
public static function updateOwnersPackagePaths(
|
||||
PhabricatorRepositoryCommit $commit) {
|
||||
$changes = self::loadDiffusionChangesForCommit($commit);
|
||||
PhabricatorRepositoryCommit $commit,
|
||||
PhabricatorUser $actor) {
|
||||
|
||||
$repository = id(new PhabricatorRepositoryQuery())
|
||||
->setViewer($actor)
|
||||
->withIDs(array($commit->getRepositoryID()))
|
||||
->executeOne();
|
||||
if (!$repository) {
|
||||
return;
|
||||
}
|
||||
$changes = self::loadDiffusionChangesForCommit(
|
||||
$repository,
|
||||
$commit,
|
||||
$actor);
|
||||
|
||||
if (!$changes) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: (T603) This should be policy-aware.
|
||||
$repository =
|
||||
id(new PhabricatorRepository())->load($commit->getRepositoryID());
|
||||
$move_map = array();
|
||||
foreach ($changes as $change) {
|
||||
if ($change->getChangeType() == DifferentialChangeType::TYPE_MOVE_HERE) {
|
||||
|
@ -82,11 +91,12 @@ final class PhabricatorOwnersPackagePathValidator {
|
|||
}
|
||||
}
|
||||
|
||||
private static function loadDiffusionChangesForCommit($commit) {
|
||||
$repository =
|
||||
id(new PhabricatorRepository())->load($commit->getRepositoryID());
|
||||
private static function loadDiffusionChangesForCommit(
|
||||
PhabricatorRepository $repository,
|
||||
PhabricatorRepositoryCommit $commit,
|
||||
PhabricatorUser $actor) {
|
||||
$data = array(
|
||||
'user' => PhabricatorUser::getOmnipotentUser(),
|
||||
'user' => $actor,
|
||||
'repository' => $repository,
|
||||
'commit' => $commit->getCommitIdentifier(),
|
||||
);
|
||||
|
|
|
@ -96,7 +96,9 @@ abstract class PhabricatorRepositoryCommitChangeParserWorker
|
|||
id(new PhabricatorSearchIndexer())
|
||||
->queueDocumentForIndexing($commit->getPHID());
|
||||
|
||||
PhabricatorOwnersPackagePathValidator::updateOwnersPackagePaths($commit);
|
||||
PhabricatorOwnersPackagePathValidator::updateOwnersPackagePaths(
|
||||
$commit,
|
||||
PhabricatorUser::getOmnipotentUser());
|
||||
if ($this->shouldQueueFollowupTasks()) {
|
||||
$this->queueTask(
|
||||
'PhabricatorRepositoryCommitOwnersWorker',
|
||||
|
|
Loading…
Reference in a new issue