1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-10 22:08:32 +01:00
phorge-phorge/src/applications/owners/controller/PhabricatorOwnersPathsController.php
epriestley 37532a0bf0 Remove various additional calls to getCallsign()
Summary: Ref T4245. These are all straightforward to remove.

Test Plan:
- Edited paths in a package.
- Ran `bin/audit delete --repositories ...` with various identifiers.
- Searched by repository for `R3`, `rAAAA` in Harbormaster.
- Did a Herald dry run on a commit.
- Browsed commits, made comments.
- Viewed a Releeph product list.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T4245

Differential Revision: https://secure.phabricator.com/D14927
2016-01-02 11:04:22 -08:00

166 lines
4.7 KiB
PHP

<?php
final class PhabricatorOwnersPathsController
extends PhabricatorOwnersController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getUser();
$package = id(new PhabricatorOwnersPackageQuery())
->setViewer($viewer)
->withIDs(array($request->getURIData('id')))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
// TODO: Support this capability.
// PhabricatorPolicyCapability::CAN_EDIT,
))
->needPaths(true)
->executeOne();
if (!$package) {
return new Aphront404Response();
}
if ($request->isFormPost()) {
$paths = $request->getArr('path');
$repos = $request->getArr('repo');
$excludes = $request->getArr('exclude');
$path_refs = array();
foreach ($paths as $key => $path) {
if (!isset($repos[$key])) {
throw new Exception(
pht(
'No repository PHID for path "%s"!',
$key));
}
if (!isset($excludes[$key])) {
throw new Exception(
pht(
'No exclusion value for path "%s"!',
$key));
}
$path_refs[] = array(
'repositoryPHID' => $repos[$key],
'path' => $path,
'excluded' => (int)$excludes[$key],
);
}
$type_paths = PhabricatorOwnersPackageTransaction::TYPE_PATHS;
$xactions = array();
$xactions[] = id(new PhabricatorOwnersPackageTransaction())
->setTransactionType($type_paths)
->setNewValue($path_refs);
$editor = id(new PhabricatorOwnersPackageTransactionEditor())
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true);
$editor->applyTransactions($package, $xactions);
return id(new AphrontRedirectResponse())
->setURI('/owners/package/'.$package->getID().'/');
} else {
$paths = $package->getPaths();
$path_refs = mpull($paths, 'getRef');
}
$repos = id(new PhabricatorRepositoryQuery())
->setViewer($viewer)
->execute();
$default_paths = array();
foreach ($repos as $repo) {
$default_path = $repo->getDetail('default-owners-path');
if ($default_path) {
$default_paths[$repo->getPHID()] = $default_path;
}
}
$repos = mpull($repos, 'getMonogram', 'getPHID');
asort($repos);
$template = new AphrontTypeaheadTemplateView();
$template = $template->render();
Javelin::initBehavior(
'owners-path-editor',
array(
'root' => 'path-editor',
'table' => 'paths',
'add_button' => 'addpath',
'repositories' => $repos,
'input_template' => $template,
'pathRefs' => $path_refs,
'completeURI' => '/diffusion/services/path/complete/',
'validateURI' => '/diffusion/services/path/validate/',
'repositoryDefaultPaths' => $default_paths,
));
require_celerity_resource('owners-path-editor-css');
$cancel_uri = '/owners/package/'.$package->getID().'/';
$form = id(new AphrontFormView())
->setUser($viewer)
->appendChild(
id(new PHUIFormInsetView())
->setTitle(pht('Paths'))
->addDivAttributes(array('id' => 'path-editor'))
->setRightButton(javelin_tag(
'a',
array(
'href' => '#',
'class' => 'button green',
'sigil' => 'addpath',
'mustcapture' => true,
),
pht('Add New Path')))
->setDescription(
pht(
'Specify the files and directories which comprise '.
'this package.'))
->setContent(javelin_tag(
'table',
array(
'class' => 'owners-path-editor-table',
'sigil' => 'paths',
),
'')))
->appendChild(
id(new AphrontFormSubmitControl())
->addCancelButton($cancel_uri)
->setValue(pht('Save Paths')));
$form_box = id(new PHUIObjectBoxView())
->setHeaderText(pht('Edit Paths'))
->setForm($form);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(
$package->getName(),
$this->getApplicationURI('package/'.$package->getID().'/'));
$crumbs->addTextCrumb(pht('Edit Paths'));
return $this->buildApplicationPage(
array(
$crumbs,
$form_box,
),
array(
'title' => array(
$package->getName(),
pht('Edit Paths'),
),
));
}
}