~ubuntu-branches/ubuntu/wily/phabricator/wily

« back to all changes in this revision

Viewing changes to phabricator/src/applications/owners/controller/PhabricatorOwnersPathsController.php

  • Committer: Package Import Robot
  • Author(s): Richard Sellam
  • Date: 2015-06-13 10:52:10 UTC
  • mfrom: (0.30.1) (0.29.1) (0.17.4) (2.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20150613105210-5uirr7tvnk0n6e6y
Tags: 0~git20150613-1
* New snapshot release (closes: #787805)
* fixed typo in logrotate script (closes: #787645)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
final class PhabricatorOwnersPathsController
 
4
  extends PhabricatorOwnersController {
 
5
 
 
6
  public function handleRequest(AphrontRequest $request) {
 
7
    $viewer = $request->getUser();
 
8
 
 
9
    $package = id(new PhabricatorOwnersPackageQuery())
 
10
      ->setViewer($viewer)
 
11
      ->withIDs(array($request->getURIData('id')))
 
12
      ->requireCapabilities(
 
13
        array(
 
14
          PhabricatorPolicyCapability::CAN_VIEW,
 
15
          // TODO: Support this capability.
 
16
          // PhabricatorPolicyCapability::CAN_EDIT,
 
17
        ))
 
18
      ->executeOne();
 
19
    if (!$package) {
 
20
      return new Aphront404Response();
 
21
    }
 
22
 
 
23
    if ($request->isFormPost()) {
 
24
      $paths = $request->getArr('path');
 
25
      $repos = $request->getArr('repo');
 
26
      $excludes = $request->getArr('exclude');
 
27
 
 
28
      $path_refs = array();
 
29
      foreach ($paths as $key => $path) {
 
30
        if (!isset($repos[$key])) {
 
31
          throw new Exception(
 
32
            pht(
 
33
              'No repository PHID for path "%s"!',
 
34
              $key));
 
35
        }
 
36
 
 
37
        if (!isset($excludes[$key])) {
 
38
          throw new Exception(
 
39
            pht(
 
40
              'No exclusion value for path "%s"!',
 
41
              $key));
 
42
        }
 
43
 
 
44
        $path_refs[] = array(
 
45
          'repositoryPHID' => $repos[$key],
 
46
          'path' => $path,
 
47
          'excluded' => (int)$excludes[$key],
 
48
        );
 
49
      }
 
50
 
 
51
      $type_paths = PhabricatorOwnersPackageTransaction::TYPE_PATHS;
 
52
 
 
53
      $xactions = array();
 
54
      $xactions[] = id(new PhabricatorOwnersPackageTransaction())
 
55
        ->setTransactionType($type_paths)
 
56
        ->setNewValue($path_refs);
 
57
 
 
58
      $editor = id(new PhabricatorOwnersPackageTransactionEditor())
 
59
        ->setActor($viewer)
 
60
        ->setContentSourceFromRequest($request)
 
61
        ->setContinueOnNoEffect(true)
 
62
        ->setContinueOnMissingFields(true);
 
63
 
 
64
      $editor->applyTransactions($package, $xactions);
 
65
 
 
66
      return id(new AphrontRedirectResponse())
 
67
        ->setURI('/owners/package/'.$package->getID().'/');
 
68
    } else {
 
69
      $paths = $package->loadPaths();
 
70
      $path_refs = mpull($paths, 'getRef');
 
71
    }
 
72
 
 
73
    $repos = id(new PhabricatorRepositoryQuery())
 
74
      ->setViewer($viewer)
 
75
      ->execute();
 
76
 
 
77
    $default_paths = array();
 
78
    foreach ($repos as $repo) {
 
79
      $default_path = $repo->getDetail('default-owners-path');
 
80
      if ($default_path) {
 
81
        $default_paths[$repo->getPHID()] = $default_path;
 
82
      }
 
83
    }
 
84
 
 
85
    $repos = mpull($repos, 'getCallsign', 'getPHID');
 
86
    asort($repos);
 
87
 
 
88
    $template = new AphrontTypeaheadTemplateView();
 
89
    $template = $template->render();
 
90
 
 
91
    Javelin::initBehavior(
 
92
      'owners-path-editor',
 
93
      array(
 
94
        'root'                => 'path-editor',
 
95
        'table'               => 'paths',
 
96
        'add_button'          => 'addpath',
 
97
        'repositories'        => $repos,
 
98
        'input_template'      => $template,
 
99
        'pathRefs'            => $path_refs,
 
100
 
 
101
        'completeURI'         => '/diffusion/services/path/complete/',
 
102
        'validateURI'         => '/diffusion/services/path/validate/',
 
103
 
 
104
        'repositoryDefaultPaths' => $default_paths,
 
105
      ));
 
106
 
 
107
    require_celerity_resource('owners-path-editor-css');
 
108
 
 
109
    $cancel_uri = '/owners/package/'.$package->getID().'/';
 
110
 
 
111
    $form = id(new AphrontFormView())
 
112
      ->setUser($viewer)
 
113
      ->appendChild(
 
114
        id(new PHUIFormInsetView())
 
115
          ->setTitle(pht('Paths'))
 
116
          ->addDivAttributes(array('id' => 'path-editor'))
 
117
          ->setRightButton(javelin_tag(
 
118
              'a',
 
119
              array(
 
120
                'href' => '#',
 
121
                'class' => 'button green',
 
122
                'sigil' => 'addpath',
 
123
                'mustcapture' => true,
 
124
              ),
 
125
              pht('Add New Path')))
 
126
          ->setDescription(
 
127
            pht(
 
128
              'Specify the files and directories which comprise '.
 
129
              'this package.'))
 
130
          ->setContent(javelin_tag(
 
131
              'table',
 
132
              array(
 
133
                'class' => 'owners-path-editor-table',
 
134
                'sigil' => 'paths',
 
135
              ),
 
136
              '')))
 
137
      ->appendChild(
 
138
        id(new AphrontFormSubmitControl())
 
139
          ->addCancelButton($cancel_uri)
 
140
          ->setValue(pht('Save Paths')));
 
141
 
 
142
    $form_box = id(new PHUIObjectBoxView())
 
143
      ->setHeaderText(pht('Edit Paths'))
 
144
      ->setForm($form);
 
145
 
 
146
    $crumbs = $this->buildApplicationCrumbs();
 
147
    $crumbs->addTextCrumb(
 
148
      $package->getName(),
 
149
      $this->getApplicationURI('package/'.$package->getID().'/'));
 
150
    $crumbs->addTextCrumb(pht('Edit Paths'));
 
151
 
 
152
    return $this->buildApplicationPage(
 
153
      array(
 
154
        $crumbs,
 
155
        $form_box,
 
156
      ),
 
157
      array(
 
158
        'title' => array(
 
159
          $package->getName(),
 
160
          pht('Edit Paths'),
 
161
        ),
 
162
      ));
 
163
  }
 
164
 
 
165
}