mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-26 07:20:57 +01:00
c467cc464f
Summary: Ref T603. This swaps almost all queries against the repository table over to be policy aware. Test Plan: - Made an audit comment on a commit. - Ran `save_lint.php`. - Looked up a commit with `diffusion.getcommits`. - Looked up lint messages with `diffusion.getlintmessages`. - Clicked an external/submodule in Diffusion. - Viewed main lint and repository lint in Diffusion. - Completed and validated Owners paths in Owners. - Executed dry runs via Herald. - Queried for package owners with `owners.query`. - Viewed Owners package. - Edited Owners package. - Viewed Owners package list. - Executed `repository.query`. - Viewed "Repository" tool repository list. - Edited Arcanist project. - Hit "Delete" on repository (this just tells you to use the CLI). - Created a repository. - Edited a repository. - Ran `bin/repository list`. - Ran `bin/search index rGTESTff45d13dffcfb3ea85b03aac8cc36251cacdf01c` - Pushed and parsed a commit. - Skipped all the Drydock stuff, as it it's hard to test and isn't normally reachable. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T603 Differential Revision: https://secure.phabricator.com/D7132
72 lines
1.8 KiB
PHP
72 lines
1.8 KiB
PHP
<?php
|
|
|
|
final class DiffusionPathValidateController extends DiffusionController {
|
|
|
|
public function willProcessRequest(array $data) {
|
|
// Don't build a DiffusionRequest.
|
|
}
|
|
|
|
public function processRequest() {
|
|
$request = $this->getRequest();
|
|
|
|
$repository_phid = $request->getStr('repositoryPHID');
|
|
$repository = id(new PhabricatorRepositoryQuery())
|
|
->setViewer($request->getUser())
|
|
->withPHIDs(array($repository_phid))
|
|
->executeOne();
|
|
if (!$repository) {
|
|
return new Aphront400Response();
|
|
}
|
|
|
|
$path = $request->getStr('path');
|
|
$path = ltrim($path, '/');
|
|
|
|
$drequest = DiffusionRequest::newFromDictionary(
|
|
array(
|
|
'user' => $request->getUser(),
|
|
'repository' => $repository,
|
|
'path' => $path,
|
|
));
|
|
$this->setDiffusionRequest($drequest);
|
|
|
|
$browse_results = DiffusionBrowseResultSet::newFromConduit(
|
|
$this->callConduitWithDiffusionRequest(
|
|
'diffusion.browsequery',
|
|
array(
|
|
'path' => $drequest->getPath(),
|
|
'commit' => $drequest->getCommit(),
|
|
'needValidityOnly' => true,
|
|
)));
|
|
$valid = $browse_results->isValidResults();
|
|
|
|
if (!$valid) {
|
|
switch ($browse_results->getReasonForEmptyResultSet()) {
|
|
case DiffusionBrowseResultSet::REASON_IS_FILE:
|
|
$valid = true;
|
|
break;
|
|
case DiffusionBrowseResultSet::REASON_IS_EMPTY:
|
|
$valid = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
$output = array(
|
|
'valid' => (bool)$valid,
|
|
);
|
|
|
|
if (!$valid) {
|
|
$branch = $drequest->getBranch();
|
|
if ($branch) {
|
|
$message = pht('Not found in %s', $branch);
|
|
} else {
|
|
$message = pht('Not found at HEAD');
|
|
}
|
|
} else {
|
|
$message = pht('OK');
|
|
}
|
|
|
|
$output['message'] = $message;
|
|
|
|
return id(new AphrontAjaxResponse())->setContent($output);
|
|
}
|
|
}
|