id = $data['id']; $this->action = $data['action']; } public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $project = id(new PhabricatorProject())->load($this->id); if (!$project) { return new Aphront404Response(); } $process_action = false; switch ($this->action) { case 'join': $process_action = $request->isFormPost(); break; case 'leave': $process_action = $request->isDialogFormPost(); break; default: return new Aphront404Response(); } $project_uri = '/project/view/'.$project->getID().'/'; if ($process_action) { $xactions = array(); switch ($this->action) { case 'join': $affils = $project->loadAffiliations(); $affils = mpull($affils, null, 'getUserPHID'); if (empty($affils[$user->getPHID()])) { $affils[$user->getPHID()] = true; $xaction = new PhabricatorProjectTransaction(); $xaction->setTransactionType( PhabricatorProjectTransactionType::TYPE_MEMBERS); $xaction->setNewValue(array_keys($affils)); $xactions[] = $xaction; } break; case 'leave': $affils = $project->loadAffiliations(); $affils = mpull($affils, null, 'getUserPHID'); if (isset($affils[$user->getPHID()])) { unset($affils[$user->getPHID()]); $xaction = new PhabricatorProjectTransaction(); $xaction->setTransactionType( PhabricatorProjectTransactionType::TYPE_MEMBERS); $xaction->setNewValue(array_keys($affils)); $xactions[] = $xaction; } break; } if ($xactions) { $editor = new PhabricatorProjectEditor($project); $editor->setUser($user); $editor->applyTransactions($xactions); } return id(new AphrontRedirectResponse())->setURI($project_uri); } $dialog = null; switch ($this->action) { case 'leave': $dialog = new AphrontDialogView(); $dialog->setUser($user); $dialog->setTitle('Really leave project?'); $dialog->appendChild( '

Your tremendous contributions to this project will be sorely '. 'missed. Are you sure you want to leave?

'); $dialog->addCancelButton($project_uri); $dialog->addSubmitButton('Leave Project'); break; default: return new Aphront404Response(); } return id(new AphrontDialogResponse())->setDialog($dialog); } }