3
final class PhabricatorOwnersPathsController
4
extends PhabricatorOwnersController {
6
public function handleRequest(AphrontRequest $request) {
7
$viewer = $request->getUser();
9
$package = id(new PhabricatorOwnersPackageQuery())
11
->withIDs(array($request->getURIData('id')))
12
->requireCapabilities(
14
PhabricatorPolicyCapability::CAN_VIEW,
15
// TODO: Support this capability.
16
// PhabricatorPolicyCapability::CAN_EDIT,
20
return new Aphront404Response();
23
if ($request->isFormPost()) {
24
$paths = $request->getArr('path');
25
$repos = $request->getArr('repo');
26
$excludes = $request->getArr('exclude');
29
foreach ($paths as $key => $path) {
30
if (!isset($repos[$key])) {
33
'No repository PHID for path "%s"!',
37
if (!isset($excludes[$key])) {
40
'No exclusion value for path "%s"!',
45
'repositoryPHID' => $repos[$key],
47
'excluded' => (int)$excludes[$key],
51
$type_paths = PhabricatorOwnersPackageTransaction::TYPE_PATHS;
54
$xactions[] = id(new PhabricatorOwnersPackageTransaction())
55
->setTransactionType($type_paths)
56
->setNewValue($path_refs);
58
$editor = id(new PhabricatorOwnersPackageTransactionEditor())
60
->setContentSourceFromRequest($request)
61
->setContinueOnNoEffect(true)
62
->setContinueOnMissingFields(true);
64
$editor->applyTransactions($package, $xactions);
66
return id(new AphrontRedirectResponse())
67
->setURI('/owners/package/'.$package->getID().'/');
69
$paths = $package->loadPaths();
70
$path_refs = mpull($paths, 'getRef');
73
$repos = id(new PhabricatorRepositoryQuery())
77
$default_paths = array();
78
foreach ($repos as $repo) {
79
$default_path = $repo->getDetail('default-owners-path');
81
$default_paths[$repo->getPHID()] = $default_path;
85
$repos = mpull($repos, 'getCallsign', 'getPHID');
88
$template = new AphrontTypeaheadTemplateView();
89
$template = $template->render();
91
Javelin::initBehavior(
94
'root' => 'path-editor',
96
'add_button' => 'addpath',
97
'repositories' => $repos,
98
'input_template' => $template,
99
'pathRefs' => $path_refs,
101
'completeURI' => '/diffusion/services/path/complete/',
102
'validateURI' => '/diffusion/services/path/validate/',
104
'repositoryDefaultPaths' => $default_paths,
107
require_celerity_resource('owners-path-editor-css');
109
$cancel_uri = '/owners/package/'.$package->getID().'/';
111
$form = id(new AphrontFormView())
114
id(new PHUIFormInsetView())
115
->setTitle(pht('Paths'))
116
->addDivAttributes(array('id' => 'path-editor'))
117
->setRightButton(javelin_tag(
121
'class' => 'button green',
122
'sigil' => 'addpath',
123
'mustcapture' => true,
125
pht('Add New Path')))
128
'Specify the files and directories which comprise '.
130
->setContent(javelin_tag(
133
'class' => 'owners-path-editor-table',
138
id(new AphrontFormSubmitControl())
139
->addCancelButton($cancel_uri)
140
->setValue(pht('Save Paths')));
142
$form_box = id(new PHUIObjectBoxView())
143
->setHeaderText(pht('Edit Paths'))
146
$crumbs = $this->buildApplicationCrumbs();
147
$crumbs->addTextCrumb(
149
$this->getApplicationURI('package/'.$package->getID().'/'));
150
$crumbs->addTextCrumb(pht('Edit Paths'));
152
return $this->buildApplicationPage(