[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/project/controller/ -> PhabricatorProjectUpdateController.php (source)

   1  <?php
   2  
   3  final class PhabricatorProjectUpdateController
   4    extends PhabricatorProjectController {
   5  
   6    private $id;
   7    private $action;
   8  
   9    public function willProcessRequest(array $data) {
  10      $this->id = $data['id'];
  11      $this->action = $data['action'];
  12    }
  13  
  14    public function processRequest() {
  15      $request = $this->getRequest();
  16      $user = $request->getUser();
  17  
  18      $capabilities = array(
  19        PhabricatorPolicyCapability::CAN_VIEW,
  20      );
  21  
  22      $process_action = false;
  23      switch ($this->action) {
  24        case 'join':
  25          $capabilities[] = PhabricatorPolicyCapability::CAN_JOIN;
  26          $process_action = $request->isFormPost();
  27          break;
  28        case 'leave':
  29          $process_action = $request->isDialogFormPost();
  30          break;
  31        default:
  32          return new Aphront404Response();
  33      }
  34  
  35      $project = id(new PhabricatorProjectQuery())
  36        ->setViewer($user)
  37        ->withIDs(array($this->id))
  38        ->needMembers(true)
  39        ->requireCapabilities($capabilities)
  40        ->executeOne();
  41      if (!$project) {
  42        return new Aphront404Response();
  43      }
  44  
  45      $project_uri = '/project/view/'.$project->getID().'/';
  46  
  47      if ($process_action) {
  48  
  49        $edge_action = null;
  50        switch ($this->action) {
  51          case 'join':
  52            $edge_action = '+';
  53            break;
  54          case 'leave':
  55            $edge_action = '-';
  56            break;
  57        }
  58  
  59        $type_member = PhabricatorEdgeConfig::TYPE_PROJ_MEMBER;
  60        $member_spec = array(
  61          $edge_action => array($user->getPHID() => $user->getPHID()),
  62        );
  63  
  64        $xactions = array();
  65        $xactions[] = id(new PhabricatorProjectTransaction())
  66          ->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
  67          ->setMetadataValue('edge:type', $type_member)
  68          ->setNewValue($member_spec);
  69  
  70        $editor = id(new PhabricatorProjectTransactionEditor($project))
  71          ->setActor($user)
  72          ->setContentSourceFromRequest($request)
  73          ->setContinueOnNoEffect(true)
  74          ->setContinueOnMissingFields(true)
  75          ->applyTransactions($project, $xactions);
  76  
  77        return id(new AphrontRedirectResponse())->setURI($project_uri);
  78      }
  79  
  80      $dialog = null;
  81      switch ($this->action) {
  82        case 'leave':
  83          $dialog = new AphrontDialogView();
  84          $dialog->setUser($user);
  85          if ($this->userCannotLeave($project)) {
  86           $dialog->setTitle(pht('You can not leave this project.'));
  87            $body = pht('The membership is locked for this project.');
  88          } else {
  89            $dialog->setTitle(pht('Really leave project?'));
  90            $body = pht(
  91              'Your tremendous contributions to this project will be sorely '.
  92              'missed. Are you sure you want to leave?');
  93            $dialog->addSubmitButton(pht('Leave Project'));
  94          }
  95          $dialog->appendParagraph($body);
  96          $dialog->addCancelButton($project_uri);
  97          break;
  98        default:
  99          return new Aphront404Response();
 100      }
 101  
 102      return id(new AphrontDialogResponse())->setDialog($dialog);
 103    }
 104  
 105    /**
 106     * This is enforced in @{class:PhabricatorProjectTransactionEditor}. We use
 107     * this logic to render a better form for users hitting this case.
 108     */
 109    private function userCannotLeave(PhabricatorProject $project) {
 110      $user = $this->getRequest()->getUser();
 111  
 112      return
 113        $project->getIsMembershipLocked() &&
 114        !PhabricatorPolicyFilter::hasCapability(
 115          $user,
 116          $project,
 117          PhabricatorPolicyCapability::CAN_EDIT);
 118    }
 119  }


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