[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/phragment/controller/ -> PhragmentPolicyController.php (source)

   1  <?php
   2  
   3  final class PhragmentPolicyController extends PhragmentController {
   4  
   5    private $dblob;
   6  
   7    public function willProcessRequest(array $data) {
   8      $this->dblob = idx($data, 'dblob', '');
   9    }
  10  
  11    public function processRequest() {
  12      $request = $this->getRequest();
  13      $viewer = $request->getUser();
  14  
  15      $parents = $this->loadParentFragments($this->dblob);
  16      if ($parents === null) {
  17        return new Aphront404Response();
  18      }
  19      $fragment = idx($parents, count($parents) - 1, null);
  20  
  21      $error_view = null;
  22  
  23      if ($request->isFormPost()) {
  24        $errors = array();
  25  
  26        $v_view_policy = $request->getStr('viewPolicy');
  27        $v_edit_policy = $request->getStr('editPolicy');
  28        $v_replace_children = $request->getBool('replacePoliciesOnChildren');
  29  
  30        $fragment->setViewPolicy($v_view_policy);
  31        $fragment->setEditPolicy($v_edit_policy);
  32  
  33        $fragment->save();
  34  
  35        if ($v_replace_children) {
  36          // If you can edit a fragment, you can forcibly set the policies
  37          // on child fragments, regardless of whether you can see them or not.
  38          $children = id(new PhragmentFragmentQuery())
  39            ->setViewer(PhabricatorUser::getOmnipotentUser())
  40            ->withLeadingPath($fragment->getPath().'/')
  41            ->execute();
  42          $children_phids = mpull($children, 'getPHID');
  43  
  44          $fragment->openTransaction();
  45            foreach ($children as $child) {
  46              $child->setViewPolicy($v_view_policy);
  47              $child->setEditPolicy($v_edit_policy);
  48              $child->save();
  49            }
  50          $fragment->saveTransaction();
  51        }
  52  
  53        return id(new AphrontRedirectResponse())
  54          ->setURI('/phragment/browse/'.$fragment->getPath());
  55      }
  56  
  57      $policies = id(new PhabricatorPolicyQuery())
  58        ->setViewer($viewer)
  59        ->setObject($fragment)
  60        ->execute();
  61  
  62      $form = id(new AphrontFormView())
  63        ->setUser($viewer)
  64        ->appendChild(
  65          id(new AphrontFormPolicyControl())
  66            ->setName('viewPolicy')
  67            ->setPolicyObject($fragment)
  68            ->setCapability(PhabricatorPolicyCapability::CAN_VIEW)
  69            ->setPolicies($policies))
  70        ->appendChild(
  71          id(new AphrontFormPolicyControl())
  72            ->setName('editPolicy')
  73            ->setPolicyObject($fragment)
  74            ->setCapability(PhabricatorPolicyCapability::CAN_EDIT)
  75            ->setPolicies($policies))
  76        ->appendChild(
  77          id(new AphrontFormCheckboxControl())
  78            ->addCheckbox(
  79              'replacePoliciesOnChildren',
  80              'true',
  81              pht(
  82                'Replace policies on child fragments with '.
  83                'the policies above.')))
  84        ->appendChild(
  85          id(new AphrontFormSubmitControl())
  86            ->setValue(pht('Save Fragment Policies'))
  87            ->addCancelButton(
  88              $this->getApplicationURI('browse/'.$fragment->getPath())));
  89  
  90      $crumbs = $this->buildApplicationCrumbsWithPath($parents);
  91      $crumbs->addTextCrumb(pht('Edit Fragment Policies'));
  92  
  93      $box = id(new PHUIObjectBoxView())
  94        ->setHeaderText(pht('Edit Fragment Policies: %s', $fragment->getPath()))
  95        ->setValidationException(null)
  96        ->setForm($form);
  97  
  98      return $this->buildApplicationPage(
  99        array(
 100          $crumbs,
 101          $this->renderConfigurationWarningIfRequired(),
 102          $box,
 103        ),
 104        array(
 105          'title' => pht('Edit Fragment Policies'),
 106        ));
 107    }
 108  
 109  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1